xref: /llvm-project/llvm/lib/Object/XCOFFObjectFile.cpp (revision 8034daca5f479c30dc68369be8de7e5177247378)
1 //===--- XCOFFObjectFile.cpp - XCOFF object file implementation -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the XCOFFObjectFile class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/Object/XCOFFObjectFile.h"
14 #include <cstddef>
15 #include <cstring>
16 
17 namespace llvm {
18 namespace object {
19 
20 // Checks that [Ptr, Ptr + Size) bytes fall inside the memory buffer
21 // 'M'. Returns a pointer to the underlying object on success.
22 template <typename T>
23 static Expected<const T *> getObject(MemoryBufferRef M, const void *Ptr,
24                                      const uint64_t Size = sizeof(T)) {
25   uintptr_t Addr = uintptr_t(Ptr);
26   if (std::error_code EC = Binary::checkOffset(M, Addr, Size))
27     return errorCodeToError(EC);
28   return reinterpret_cast<const T *>(Addr);
29 }
30 
31 static uintptr_t getWithOffset(uintptr_t Base, ptrdiff_t Offset) {
32   return reinterpret_cast<uintptr_t>(reinterpret_cast<const char *>(Base) +
33                                      Offset);
34 }
35 
36 template <typename T> static const T *viewAs(uintptr_t in) {
37   return reinterpret_cast<const T *>(in);
38 }
39 
40 static StringRef generateStringRef(const char *Name, uint64_t Size) {
41   auto NulCharPtr = static_cast<const char *>(memchr(Name, '\0', Size));
42   return NulCharPtr ? StringRef(Name, NulCharPtr - Name)
43                     : StringRef(Name, Size);
44 }
45 
46 void XCOFFObjectFile::checkSectionAddress(uintptr_t Addr,
47                                           uintptr_t TableAddress) const {
48   if (Addr < TableAddress)
49     report_fatal_error("Section header outside of section header table.");
50 
51   uintptr_t Offset = Addr - TableAddress;
52   if (Offset >= getSectionHeaderSize() * getNumberOfSections())
53     report_fatal_error("Section header outside of section header table.");
54 
55   if (Offset % getSectionHeaderSize() != 0)
56     report_fatal_error(
57         "Section header pointer does not point to a valid section header.");
58 }
59 
60 const XCOFFSectionHeader32 *
61 XCOFFObjectFile::toSection32(DataRefImpl Ref) const {
62   assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
63 #ifndef NDEBUG
64   checkSectionAddress(Ref.p, getSectionHeaderTableAddress());
65 #endif
66   return viewAs<XCOFFSectionHeader32>(Ref.p);
67 }
68 
69 const XCOFFSectionHeader64 *
70 XCOFFObjectFile::toSection64(DataRefImpl Ref) const {
71   assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
72 #ifndef NDEBUG
73   checkSectionAddress(Ref.p, getSectionHeaderTableAddress());
74 #endif
75   return viewAs<XCOFFSectionHeader64>(Ref.p);
76 }
77 
78 const XCOFFSymbolEntry *XCOFFObjectFile::toSymbolEntry(DataRefImpl Ref) const {
79   assert(!is64Bit() && "Symbol table support not implemented for 64-bit.");
80   assert(Ref.p != 0 && "Symbol table pointer can not be nullptr!");
81   auto SymEntPtr = viewAs<XCOFFSymbolEntry>(Ref.p);
82   return SymEntPtr;
83 }
84 
85 const XCOFFFileHeader32 *XCOFFObjectFile::fileHeader32() const {
86   assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
87   return static_cast<const XCOFFFileHeader32 *>(FileHeader);
88 }
89 
90 const XCOFFFileHeader64 *XCOFFObjectFile::fileHeader64() const {
91   assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
92   return static_cast<const XCOFFFileHeader64 *>(FileHeader);
93 }
94 
95 const XCOFFSectionHeader32 *
96 XCOFFObjectFile::sectionHeaderTable32() const {
97   assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
98   return static_cast<const XCOFFSectionHeader32 *>(SectionHeaderTable);
99 }
100 
101 const XCOFFSectionHeader64 *
102 XCOFFObjectFile::sectionHeaderTable64() const {
103   assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
104   return static_cast<const XCOFFSectionHeader64 *>(SectionHeaderTable);
105 }
106 
107 void XCOFFObjectFile::moveSymbolNext(DataRefImpl &Symb) const {
108   const XCOFFSymbolEntry *SymEntPtr = toSymbolEntry(Symb);
109   SymEntPtr += SymEntPtr->NumberOfAuxEntries + 1;
110   Symb.p = reinterpret_cast<uintptr_t>(SymEntPtr);
111 }
112 
113 Expected<StringRef> XCOFFObjectFile::getSymbolName(DataRefImpl Symb) const {
114   const XCOFFSymbolEntry *SymEntPtr = toSymbolEntry(Symb);
115 
116   if (SymEntPtr->NameInStrTbl.Magic != XCOFFSymbolEntry::NAME_IN_STR_TBL_MAGIC)
117     return generateStringRef(SymEntPtr->SymbolName, XCOFF::SymbolNameSize);
118 
119   // A storage class value with the high-order bit on indicates that the name is
120   // a symbolic debugger stabstring.
121   if (SymEntPtr->StorageClass & 0x80)
122     return StringRef("Unimplemented Debug Name");
123 
124   uint32_t Offset = SymEntPtr->NameInStrTbl.Offset;
125   // The byte offset is relative to the start of the string table
126   // or .debug section. A byte offset value of 0 is a null or zero-length symbol
127   // name. A byte offset in the range 1 to 3 (inclusive) points into the length
128   // field; as a soft-error recovery mechanism, we treat such cases as having an
129   // offset of 0.
130   if (Offset < 4)
131     return StringRef(nullptr, 0);
132 
133   if (StringTable.Data != nullptr && StringTable.Size > Offset)
134     return (StringTable.Data + Offset);
135 
136   return make_error<GenericBinaryError>("Symbol Name parse failed",
137                                         object_error::parse_failed);
138 }
139 
140 Expected<uint64_t> XCOFFObjectFile::getSymbolAddress(DataRefImpl Symb) const {
141   uint64_t Result = 0;
142   llvm_unreachable("Not yet implemented!");
143   return Result;
144 }
145 
146 uint64_t XCOFFObjectFile::getSymbolValueImpl(DataRefImpl Symb) const {
147   return toSymbolEntry(Symb)->Value;
148 }
149 
150 uint64_t XCOFFObjectFile::getCommonSymbolSizeImpl(DataRefImpl Symb) const {
151   uint64_t Result = 0;
152   llvm_unreachable("Not yet implemented!");
153   return Result;
154 }
155 
156 Expected<SymbolRef::Type>
157 XCOFFObjectFile::getSymbolType(DataRefImpl Symb) const {
158   llvm_unreachable("Not yet implemented!");
159   return SymbolRef::ST_Other;
160 }
161 
162 Expected<section_iterator>
163 XCOFFObjectFile::getSymbolSection(DataRefImpl Symb) const {
164   const XCOFFSymbolEntry *SymEntPtr = toSymbolEntry(Symb);
165   int16_t SectNum = SymEntPtr->SectionNumber;
166 
167   if (isReservedSectionNumber(SectNum))
168     return section_end();
169 
170   Expected<DataRefImpl> ExpSec = getSectionByNum(SectNum);
171   if (!ExpSec)
172     return ExpSec.takeError();
173 
174   return section_iterator(SectionRef(ExpSec.get(), this));
175 }
176 
177 void XCOFFObjectFile::moveSectionNext(DataRefImpl &Sec) const {
178   const char *Ptr = reinterpret_cast<const char *>(Sec.p);
179   Sec.p = reinterpret_cast<uintptr_t>(Ptr + getSectionHeaderSize());
180 }
181 
182 Expected<StringRef> XCOFFObjectFile::getSectionName(DataRefImpl Sec) const {
183   return generateStringRef(getSectionNameInternal(Sec), XCOFF::SectionNameSize);
184 }
185 
186 uint64_t XCOFFObjectFile::getSectionAddress(DataRefImpl Sec) const {
187   // Avoid ternary due to failure to convert the ubig32_t value to a unit64_t
188   // with MSVC.
189   if (is64Bit())
190     return toSection64(Sec)->VirtualAddress;
191 
192   return toSection32(Sec)->VirtualAddress;
193 }
194 
195 uint64_t XCOFFObjectFile::getSectionIndex(DataRefImpl Sec) const {
196   // Section numbers in XCOFF are numbered beginning at 1. A section number of
197   // zero is used to indicate that a symbol is being imported or is undefined.
198   if (is64Bit())
199     return toSection64(Sec) - sectionHeaderTable64() + 1;
200   else
201     return toSection32(Sec) - sectionHeaderTable32() + 1;
202 }
203 
204 uint64_t XCOFFObjectFile::getSectionSize(DataRefImpl Sec) const {
205   // Avoid ternary due to failure to convert the ubig32_t value to a unit64_t
206   // with MSVC.
207   if (is64Bit())
208     return toSection64(Sec)->SectionSize;
209 
210   return toSection32(Sec)->SectionSize;
211 }
212 
213 Expected<ArrayRef<uint8_t>>
214 XCOFFObjectFile::getSectionContents(DataRefImpl Sec) const {
215   llvm_unreachable("Not yet implemented!");
216 }
217 
218 uint64_t XCOFFObjectFile::getSectionAlignment(DataRefImpl Sec) const {
219   uint64_t Result = 0;
220   llvm_unreachable("Not yet implemented!");
221   return Result;
222 }
223 
224 bool XCOFFObjectFile::isSectionCompressed(DataRefImpl Sec) const {
225   bool Result = false;
226   llvm_unreachable("Not yet implemented!");
227   return Result;
228 }
229 
230 bool XCOFFObjectFile::isSectionText(DataRefImpl Sec) const {
231   return getSectionFlags(Sec) & XCOFF::STYP_TEXT;
232 }
233 
234 bool XCOFFObjectFile::isSectionData(DataRefImpl Sec) const {
235   uint32_t Flags = getSectionFlags(Sec);
236   return Flags & (XCOFF::STYP_DATA | XCOFF::STYP_TDATA);
237 }
238 
239 bool XCOFFObjectFile::isSectionBSS(DataRefImpl Sec) const {
240   uint32_t Flags = getSectionFlags(Sec);
241   return Flags & (XCOFF::STYP_BSS | XCOFF::STYP_TBSS);
242 }
243 
244 bool XCOFFObjectFile::isSectionVirtual(DataRefImpl Sec) const {
245   bool Result = false;
246   llvm_unreachable("Not yet implemented!");
247   return Result;
248 }
249 
250 relocation_iterator XCOFFObjectFile::section_rel_begin(DataRefImpl Sec) const {
251   llvm_unreachable("Not yet implemented!");
252   return relocation_iterator(RelocationRef());
253 }
254 
255 relocation_iterator XCOFFObjectFile::section_rel_end(DataRefImpl Sec) const {
256   llvm_unreachable("Not yet implemented!");
257   return relocation_iterator(RelocationRef());
258 }
259 
260 void XCOFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
261   llvm_unreachable("Not yet implemented!");
262   return;
263 }
264 
265 uint64_t XCOFFObjectFile::getRelocationOffset(DataRefImpl Rel) const {
266   llvm_unreachable("Not yet implemented!");
267   uint64_t Result = 0;
268   return Result;
269 }
270 
271 symbol_iterator XCOFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const {
272   llvm_unreachable("Not yet implemented!");
273   return symbol_iterator(SymbolRef());
274 }
275 
276 uint64_t XCOFFObjectFile::getRelocationType(DataRefImpl Rel) const {
277   llvm_unreachable("Not yet implemented!");
278   uint64_t Result = 0;
279   return Result;
280 }
281 
282 void XCOFFObjectFile::getRelocationTypeName(
283     DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
284   llvm_unreachable("Not yet implemented!");
285   return;
286 }
287 
288 uint32_t XCOFFObjectFile::getSymbolFlags(DataRefImpl Symb) const {
289   uint32_t Result = 0;
290   llvm_unreachable("Not yet implemented!");
291   return Result;
292 }
293 
294 basic_symbol_iterator XCOFFObjectFile::symbol_begin() const {
295   assert(!is64Bit() && "64-bit support not implemented yet.");
296   DataRefImpl SymDRI;
297   SymDRI.p = reinterpret_cast<uintptr_t>(SymbolTblPtr);
298   return basic_symbol_iterator(SymbolRef(SymDRI, this));
299 }
300 
301 basic_symbol_iterator XCOFFObjectFile::symbol_end() const {
302   assert(!is64Bit() && "64-bit support not implemented yet.");
303   DataRefImpl SymDRI;
304   SymDRI.p = reinterpret_cast<uintptr_t>(
305       SymbolTblPtr + getLogicalNumberOfSymbolTableEntries32());
306   return basic_symbol_iterator(SymbolRef(SymDRI, this));
307 }
308 
309 section_iterator XCOFFObjectFile::section_begin() const {
310   DataRefImpl DRI;
311   DRI.p = getSectionHeaderTableAddress();
312   return section_iterator(SectionRef(DRI, this));
313 }
314 
315 section_iterator XCOFFObjectFile::section_end() const {
316   DataRefImpl DRI;
317   DRI.p = getWithOffset(getSectionHeaderTableAddress(),
318                         getNumberOfSections() * getSectionHeaderSize());
319   return section_iterator(SectionRef(DRI, this));
320 }
321 
322 uint8_t XCOFFObjectFile::getBytesInAddress() const { return is64Bit() ? 8 : 4; }
323 
324 StringRef XCOFFObjectFile::getFileFormatName() const {
325   return is64Bit() ? "aix5coff64-rs6000" : "aixcoff-rs6000";
326 }
327 
328 Triple::ArchType XCOFFObjectFile::getArch() const {
329   return is64Bit() ? Triple::ppc64 : Triple::ppc;
330 }
331 
332 SubtargetFeatures XCOFFObjectFile::getFeatures() const {
333   llvm_unreachable("Not yet implemented!");
334   return SubtargetFeatures();
335 }
336 
337 bool XCOFFObjectFile::isRelocatableObject() const {
338   bool Result = false;
339   llvm_unreachable("Not yet implemented!");
340   return Result;
341 }
342 
343 Expected<uint64_t> XCOFFObjectFile::getStartAddress() const {
344   // TODO FIXME Should get from auxiliary_header->o_entry when support for the
345   // auxiliary_header is added.
346   return 0;
347 }
348 
349 size_t XCOFFObjectFile::getFileHeaderSize() const {
350   return is64Bit() ? sizeof(XCOFFFileHeader64) : sizeof(XCOFFFileHeader32);
351 }
352 
353 size_t XCOFFObjectFile::getSectionHeaderSize() const {
354   return is64Bit() ? sizeof(XCOFFSectionHeader64) :
355                      sizeof(XCOFFSectionHeader32);
356 }
357 
358 bool XCOFFObjectFile::is64Bit() const {
359   return Binary::ID_XCOFF64 == getType();
360 }
361 
362 uint16_t XCOFFObjectFile::getMagic() const {
363   return is64Bit() ? fileHeader64()->Magic : fileHeader32()->Magic;
364 }
365 
366 Expected<DataRefImpl> XCOFFObjectFile::getSectionByNum(int16_t Num) const {
367   if (Num <= 0 || Num > getNumberOfSections())
368     return errorCodeToError(object_error::invalid_section_index);
369 
370   DataRefImpl DRI;
371   DRI.p = getWithOffset(getSectionHeaderTableAddress(),
372                         getSectionHeaderSize() * (Num - 1));
373   return DRI;
374 }
375 
376 Expected<StringRef>
377 XCOFFObjectFile::getSymbolSectionName(const XCOFFSymbolEntry *SymEntPtr) const {
378   assert(!is64Bit() && "Symbol table support not implemented for 64-bit.");
379   int16_t SectionNum = SymEntPtr->SectionNumber;
380 
381   switch (SectionNum) {
382   case XCOFF::N_DEBUG:
383     return "N_DEBUG";
384   case XCOFF::N_ABS:
385     return "N_ABS";
386   case XCOFF::N_UNDEF:
387     return "N_UNDEF";
388   default:
389     Expected<DataRefImpl> SecRef = getSectionByNum(SectionNum);
390     if (SecRef)
391       return generateStringRef(getSectionNameInternal(SecRef.get()),
392                                XCOFF::SectionNameSize);
393     return SecRef.takeError();
394   }
395 }
396 
397 bool XCOFFObjectFile::isReservedSectionNumber(int16_t SectionNumber) {
398   return (SectionNumber <= 0 && SectionNumber >= -2);
399 }
400 
401 uint16_t XCOFFObjectFile::getNumberOfSections() const {
402   return is64Bit() ? fileHeader64()->NumberOfSections
403                    : fileHeader32()->NumberOfSections;
404 }
405 
406 int32_t XCOFFObjectFile::getTimeStamp() const {
407   return is64Bit() ? fileHeader64()->TimeStamp : fileHeader32()->TimeStamp;
408 }
409 
410 uint16_t XCOFFObjectFile::getOptionalHeaderSize() const {
411   return is64Bit() ? fileHeader64()->AuxHeaderSize
412                    : fileHeader32()->AuxHeaderSize;
413 }
414 
415 uint32_t XCOFFObjectFile::getSymbolTableOffset32() const {
416   return fileHeader32()->SymbolTableOffset;
417 }
418 
419 int32_t XCOFFObjectFile::getRawNumberOfSymbolTableEntries32() const {
420   // As far as symbol table size is concerned, if this field is negative it is
421   // to be treated as a 0. However since this field is also used for printing we
422   // don't want to truncate any negative values.
423   return fileHeader32()->NumberOfSymTableEntries;
424 }
425 
426 uint32_t XCOFFObjectFile::getLogicalNumberOfSymbolTableEntries32() const {
427   return (fileHeader32()->NumberOfSymTableEntries >= 0
428               ? fileHeader32()->NumberOfSymTableEntries
429               : 0);
430 }
431 
432 uint64_t XCOFFObjectFile::getSymbolTableOffset64() const {
433   return fileHeader64()->SymbolTableOffset;
434 }
435 
436 uint32_t XCOFFObjectFile::getNumberOfSymbolTableEntries64() const {
437   return fileHeader64()->NumberOfSymTableEntries;
438 }
439 
440 uint16_t XCOFFObjectFile::getFlags() const {
441   return is64Bit() ? fileHeader64()->Flags : fileHeader32()->Flags;
442 }
443 
444 const char *XCOFFObjectFile::getSectionNameInternal(DataRefImpl Sec) const {
445   return is64Bit() ? toSection64(Sec)->Name : toSection32(Sec)->Name;
446 }
447 
448 uintptr_t XCOFFObjectFile::getSectionHeaderTableAddress() const {
449   return reinterpret_cast<uintptr_t>(SectionHeaderTable);
450 }
451 
452 int32_t XCOFFObjectFile::getSectionFlags(DataRefImpl Sec) const {
453   return is64Bit() ? toSection64(Sec)->Flags : toSection32(Sec)->Flags;
454 }
455 
456 XCOFFObjectFile::XCOFFObjectFile(unsigned int Type, MemoryBufferRef Object)
457     : ObjectFile(Type, Object) {
458   assert(Type == Binary::ID_XCOFF32 || Type == Binary::ID_XCOFF64);
459 }
460 
461 ArrayRef<XCOFFSectionHeader64> XCOFFObjectFile::sections64() const {
462   assert(is64Bit() && "64-bit interface called for non 64-bit file.");
463   const XCOFFSectionHeader64 *TablePtr = sectionHeaderTable64();
464   return ArrayRef<XCOFFSectionHeader64>(TablePtr,
465                                         TablePtr + getNumberOfSections());
466 }
467 
468 ArrayRef<XCOFFSectionHeader32> XCOFFObjectFile::sections32() const {
469   assert(!is64Bit() && "32-bit interface called for non 32-bit file.");
470   const XCOFFSectionHeader32 *TablePtr = sectionHeaderTable32();
471   return ArrayRef<XCOFFSectionHeader32>(TablePtr,
472                                         TablePtr + getNumberOfSections());
473 }
474 
475 Expected<XCOFFStringTable>
476 XCOFFObjectFile::parseStringTable(const XCOFFObjectFile *Obj, uint64_t Offset) {
477   // If there is a string table, then the buffer must contain at least 4 bytes
478   // for the string table's size. Not having a string table is not an error.
479   if (auto EC = Binary::checkOffset(
480           Obj->Data, reinterpret_cast<uintptr_t>(Obj->base() + Offset), 4))
481     return XCOFFStringTable{0, nullptr};
482 
483   // Read the size out of the buffer.
484   uint32_t Size = support::endian::read32be(Obj->base() + Offset);
485 
486   // If the size is less then 4, then the string table is just a size and no
487   // string data.
488   if (Size <= 4)
489     return XCOFFStringTable{4, nullptr};
490 
491   auto StringTableOrErr =
492       getObject<char>(Obj->Data, Obj->base() + Offset, Size);
493   if (Error E = StringTableOrErr.takeError())
494     return std::move(E);
495 
496   const char *StringTablePtr = StringTableOrErr.get();
497   if (StringTablePtr[Size - 1] != '\0')
498     return errorCodeToError(object_error::string_table_non_null_end);
499 
500   return XCOFFStringTable{Size, StringTablePtr};
501 }
502 
503 Expected<std::unique_ptr<XCOFFObjectFile>>
504 XCOFFObjectFile::create(unsigned Type, MemoryBufferRef MBR) {
505   // Can't use make_unique because of the private constructor.
506   std::unique_ptr<XCOFFObjectFile> Obj;
507   Obj.reset(new XCOFFObjectFile(Type, MBR));
508 
509   uint64_t CurOffset = 0;
510   const auto *Base = Obj->base();
511   MemoryBufferRef Data = Obj->Data;
512 
513   // Parse file header.
514   auto FileHeaderOrErr =
515       getObject<void>(Data, Base + CurOffset, Obj->getFileHeaderSize());
516   if (Error E = FileHeaderOrErr.takeError())
517     return std::move(E);
518   Obj->FileHeader = FileHeaderOrErr.get();
519 
520   CurOffset += Obj->getFileHeaderSize();
521   // TODO FIXME we don't have support for an optional header yet, so just skip
522   // past it.
523   CurOffset += Obj->getOptionalHeaderSize();
524 
525   // Parse the section header table if it is present.
526   if (Obj->getNumberOfSections()) {
527     auto SecHeadersOrErr = getObject<void>(Data, Base + CurOffset,
528                                            Obj->getNumberOfSections() *
529                                                Obj->getSectionHeaderSize());
530     if (Error E = SecHeadersOrErr.takeError())
531       return std::move(E);
532     Obj->SectionHeaderTable = SecHeadersOrErr.get();
533   }
534 
535   // 64-bit object supports only file header and section headers for now.
536   if (Obj->is64Bit())
537     return std::move(Obj);
538 
539   // If there is no symbol table we are done parsing the memory buffer.
540   if (Obj->getLogicalNumberOfSymbolTableEntries32() == 0)
541     return std::move(Obj);
542 
543   // Parse symbol table.
544   CurOffset = Obj->fileHeader32()->SymbolTableOffset;
545   uint64_t SymbolTableSize = (uint64_t)(sizeof(XCOFFSymbolEntry)) *
546                              Obj->getLogicalNumberOfSymbolTableEntries32();
547   auto SymTableOrErr =
548       getObject<XCOFFSymbolEntry>(Data, Base + CurOffset, SymbolTableSize);
549   if (Error E = SymTableOrErr.takeError())
550     return std::move(E);
551   Obj->SymbolTblPtr = SymTableOrErr.get();
552   CurOffset += SymbolTableSize;
553 
554   // Parse String table.
555   Expected<XCOFFStringTable> StringTableOrErr =
556       parseStringTable(Obj.get(), CurOffset);
557   if (Error E = StringTableOrErr.takeError())
558     return std::move(E);
559   Obj->StringTable = StringTableOrErr.get();
560 
561   return std::move(Obj);
562 }
563 
564 Expected<std::unique_ptr<ObjectFile>>
565 ObjectFile::createXCOFFObjectFile(MemoryBufferRef MemBufRef,
566                                   unsigned FileType) {
567   return XCOFFObjectFile::create(FileType, MemBufRef);
568 }
569 
570 StringRef XCOFFSectionHeader32::getName() const {
571   return generateStringRef(Name, XCOFF::SectionNameSize);
572 }
573 
574 StringRef XCOFFSectionHeader64::getName() const {
575   return generateStringRef(Name, XCOFF::SectionNameSize);
576 }
577 
578 } // namespace object
579 } // namespace llvm
580