LLVM 20.0.0git
XCOFFObjectFile.cpp
Go to the documentation of this file.
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
18#include <cstddef>
19#include <cstring>
20
21namespace llvm {
22
23using namespace XCOFF;
24
25namespace object {
26
27static const uint8_t FunctionSym = 0x20;
28static const uint16_t NoRelMask = 0x0001;
29static const size_t SymbolAuxTypeOffset = 17;
30
31// Checks that [Ptr, Ptr + Size) bytes fall inside the memory buffer
32// 'M'. Returns a pointer to the underlying object on success.
33template <typename T>
35 const uint64_t Size = sizeof(T)) {
36 uintptr_t Addr = reinterpret_cast<uintptr_t>(Ptr);
38 return std::move(E);
39 return reinterpret_cast<const T *>(Addr);
40}
41
42static uintptr_t getWithOffset(uintptr_t Base, ptrdiff_t Offset) {
43 return reinterpret_cast<uintptr_t>(reinterpret_cast<const char *>(Base) +
44 Offset);
45}
46
47template <typename T> static const T *viewAs(uintptr_t in) {
48 return reinterpret_cast<const T *>(in);
49}
50
52 auto NulCharPtr =
53 static_cast<const char *>(memchr(Name, '\0', XCOFF::NameSize));
54 return NulCharPtr ? StringRef(Name, NulCharPtr - Name)
56}
57
58template <typename T> StringRef XCOFFSectionHeader<T>::getName() const {
59 const T &DerivedXCOFFSectionHeader = static_cast<const T &>(*this);
60 return generateXCOFFFixedNameStringRef(DerivedXCOFFSectionHeader.Name);
61}
62
63template <typename T> uint16_t XCOFFSectionHeader<T>::getSectionType() const {
64 const T &DerivedXCOFFSectionHeader = static_cast<const T &>(*this);
65 return DerivedXCOFFSectionHeader.Flags & SectionFlagsTypeMask;
66}
67
68template <typename T>
70 const T &DerivedXCOFFSectionHeader = static_cast<const T &>(*this);
71 return DerivedXCOFFSectionHeader.Flags & ~SectionFlagsTypeMask;
72}
73
74template <typename T>
76 return getSectionType() & SectionFlagsReservedMask;
77}
78
79template <typename AddressType>
82}
83
84template <typename AddressType>
87}
88
89template <typename AddressType>
91 // The relocation encodes the bit length being relocated minus 1. Add back
92 // the 1 to get the actual length being relocated.
93 return (Info & XR_BIASED_LENGTH_MASK) + 1;
94}
95
98
99template <typename T>
102 if (LoaderSecHeader->LengthOfStrTbl > Offset)
103 return (reinterpret_cast<const char *>(LoaderSecHeader) +
104 LoaderSecHeader->OffsetToStrTbl + Offset);
105
106 return createError("entry with offset 0x" + Twine::utohexstr(Offset) +
107 " in the loader section's string table with size 0x" +
108 Twine::utohexstr(LoaderSecHeader->LengthOfStrTbl) +
109 " is invalid");
110}
111
113 const LoaderSectionHeader32 *LoaderSecHeader32) const {
114 const NameOffsetInStrTbl *NameInStrTbl =
115 reinterpret_cast<const NameOffsetInStrTbl *>(SymbolName);
118
119 return getLoaderSecSymNameInStrTbl(LoaderSecHeader32, NameInStrTbl->Offset);
120}
121
123 const LoaderSectionHeader64 *LoaderSecHeader64) const {
124 return getLoaderSecSymNameInStrTbl(LoaderSecHeader64, Offset);
125}
126
127uintptr_t
129 uint32_t Distance) {
130 return getWithOffset(CurrentAddress, Distance * XCOFF::SymbolTableEntrySize);
131}
132
134XCOFFObjectFile::getSymbolAuxType(uintptr_t AuxEntryAddress) const {
135 assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
136 return viewAs<XCOFF::SymbolAuxType>(
137 getWithOffset(AuxEntryAddress, SymbolAuxTypeOffset));
138}
139
140void XCOFFObjectFile::checkSectionAddress(uintptr_t Addr,
141 uintptr_t TableAddress) const {
142 if (Addr < TableAddress)
143 report_fatal_error("Section header outside of section header table.");
144
145 uintptr_t Offset = Addr - TableAddress;
146 if (Offset >= getSectionHeaderSize() * getNumberOfSections())
147 report_fatal_error("Section header outside of section header table.");
148
149 if (Offset % getSectionHeaderSize() != 0)
151 "Section header pointer does not point to a valid section header.");
152}
153
154const XCOFFSectionHeader32 *
155XCOFFObjectFile::toSection32(DataRefImpl Ref) const {
156 assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
157#ifndef NDEBUG
158 checkSectionAddress(Ref.p, getSectionHeaderTableAddress());
159#endif
160 return viewAs<XCOFFSectionHeader32>(Ref.p);
161}
162
163const XCOFFSectionHeader64 *
164XCOFFObjectFile::toSection64(DataRefImpl Ref) const {
165 assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
166#ifndef NDEBUG
167 checkSectionAddress(Ref.p, getSectionHeaderTableAddress());
168#endif
169 return viewAs<XCOFFSectionHeader64>(Ref.p);
173 assert(Ref.p != 0 && "Symbol table pointer can not be nullptr!");
174#ifndef NDEBUG
176#endif
177 return XCOFFSymbolRef(Ref, this);
178}
179
181 assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
182 return static_cast<const XCOFFFileHeader32 *>(FileHeader);
183}
184
186 assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
187 return static_cast<const XCOFFFileHeader64 *>(FileHeader);
188}
189
191 assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
192 return static_cast<const XCOFFAuxiliaryHeader32 *>(AuxiliaryHeader);
193}
194
196 assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
197 return static_cast<const XCOFFAuxiliaryHeader64 *>(AuxiliaryHeader);
198}
199
200template <typename T> const T *XCOFFObjectFile::sectionHeaderTable() const {
201 return static_cast<const T *>(SectionHeaderTable);
202}
203
204const XCOFFSectionHeader32 *
205XCOFFObjectFile::sectionHeaderTable32() const {
206 assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
207 return static_cast<const XCOFFSectionHeader32 *>(SectionHeaderTable);
208}
209
210const XCOFFSectionHeader64 *
211XCOFFObjectFile::sectionHeaderTable64() const {
212 assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
213 return static_cast<const XCOFFSectionHeader64 *>(SectionHeaderTable);
214}
215
217 uintptr_t NextSymbolAddr = getAdvancedSymbolEntryAddress(
218 Symb.p, toSymbolRef(Symb).getNumberOfAuxEntries() + 1);
219#ifndef NDEBUG
220 // This function is used by basic_symbol_iterator, which allows to
221 // point to the end-of-symbol-table address.
222 if (NextSymbolAddr != getEndOfSymbolTableAddress())
223 checkSymbolEntryPointer(NextSymbolAddr);
224#endif
225 Symb.p = NextSymbolAddr;
226}
227
230 // The byte offset is relative to the start of the string table.
231 // A byte offset value of 0 is a null or zero-length symbol
232 // name. A byte offset in the range 1 to 3 (inclusive) points into the length
233 // field; as a soft-error recovery mechanism, we treat such cases as having an
234 // offset of 0.
235 if (Offset < 4)
236 return StringRef(nullptr, 0);
237
238 if (StringTable.Data != nullptr && StringTable.Size > Offset)
239 return (StringTable.Data + Offset);
240
241 return createError("entry with offset 0x" + Twine::utohexstr(Offset) +
242 " in a string table with size 0x" +
243 Twine::utohexstr(StringTable.Size) + " is invalid");
244}
245
247 // If the size is less than or equal to 4, then the string table contains no
248 // string data.
249 return StringRef(StringTable.Data,
250 StringTable.Size <= 4 ? 0 : StringTable.Size);
251}
252
256 return generateXCOFFFixedNameStringRef(CFileEntPtr->Name);
257 return getStringTableEntry(CFileEntPtr->NameInStrTbl.Offset);
258}
259
261 return toSymbolRef(Symb).getName();
262}
263
265 return toSymbolRef(Symb).getValue();
266}
267
269 return toSymbolRef(Symb).getValue();
270}
271
273 uint64_t Result = 0;
274 XCOFFSymbolRef XCOFFSym = toSymbolRef(Symb);
275 if (XCOFFSym.isCsectSymbol()) {
276 Expected<XCOFFCsectAuxRef> CsectAuxRefOrError =
277 XCOFFSym.getXCOFFCsectAuxRef();
278 if (!CsectAuxRefOrError)
279 // TODO: report the error up the stack.
280 consumeError(CsectAuxRefOrError.takeError());
281 else
282 Result = 1ULL << CsectAuxRefOrError.get().getAlignmentLog2();
283 }
284 return Result;
285}
286
288 uint64_t Result = 0;
289 XCOFFSymbolRef XCOFFSym = toSymbolRef(Symb);
290 if (XCOFFSym.isCsectSymbol()) {
291 Expected<XCOFFCsectAuxRef> CsectAuxRefOrError =
292 XCOFFSym.getXCOFFCsectAuxRef();
293 if (!CsectAuxRefOrError)
294 // TODO: report the error up the stack.
295 consumeError(CsectAuxRefOrError.takeError());
296 else {
297 XCOFFCsectAuxRef CsectAuxRef = CsectAuxRefOrError.get();
298 assert(CsectAuxRef.getSymbolType() == XCOFF::XTY_CM);
299 Result = CsectAuxRef.getSectionOrLength();
300 }
301 }
302 return Result;
303}
304
307 XCOFFSymbolRef XCOFFSym = toSymbolRef(Symb);
308
309 Expected<bool> IsFunction = XCOFFSym.isFunction();
310 if (!IsFunction)
311 return IsFunction.takeError();
312
313 if (*IsFunction)
315
316 if (XCOFF::C_FILE == XCOFFSym.getStorageClass())
317 return SymbolRef::ST_File;
318
319 int16_t SecNum = XCOFFSym.getSectionNumber();
320 if (SecNum <= 0)
321 return SymbolRef::ST_Other;
322
323 Expected<DataRefImpl> SecDRIOrErr =
325
326 if (!SecDRIOrErr)
327 return SecDRIOrErr.takeError();
328
329 DataRefImpl SecDRI = SecDRIOrErr.get();
330
331 Expected<StringRef> SymNameOrError = XCOFFSym.getName();
332 if (SymNameOrError) {
333 // The "TOC" symbol is treated as SymbolRef::ST_Other.
334 if (SymNameOrError.get() == "TOC")
335 return SymbolRef::ST_Other;
336
337 // The symbol for a section name is treated as SymbolRef::ST_Other.
338 StringRef SecName;
339 if (is64Bit())
340 SecName = XCOFFObjectFile::toSection64(SecDRIOrErr.get())->getName();
341 else
342 SecName = XCOFFObjectFile::toSection32(SecDRIOrErr.get())->getName();
343
344 if (SecName == SymNameOrError.get())
345 return SymbolRef::ST_Other;
346 } else
347 return SymNameOrError.takeError();
348
349 if (isSectionData(SecDRI) || isSectionBSS(SecDRI))
350 return SymbolRef::ST_Data;
351
352 if (isDebugSection(SecDRI))
353 return SymbolRef::ST_Debug;
354
355 return SymbolRef::ST_Other;
356}
357
360 const int16_t SectNum = toSymbolRef(Symb).getSectionNumber();
361
362 if (isReservedSectionNumber(SectNum))
363 return section_end();
364
365 Expected<DataRefImpl> ExpSec = getSectionByNum(SectNum);
366 if (!ExpSec)
367 return ExpSec.takeError();
368
369 return section_iterator(SectionRef(ExpSec.get(), this));
370}
371
373 const char *Ptr = reinterpret_cast<const char *>(Sec.p);
374 Sec.p = reinterpret_cast<uintptr_t>(Ptr + getSectionHeaderSize());
375}
376
378 return generateXCOFFFixedNameStringRef(getSectionNameInternal(Sec));
379}
380
382 // Avoid ternary due to failure to convert the ubig32_t value to a unit64_t
383 // with MSVC.
384 if (is64Bit())
385 return toSection64(Sec)->VirtualAddress;
386
387 return toSection32(Sec)->VirtualAddress;
388}
389
391 // Section numbers in XCOFF are numbered beginning at 1. A section number of
392 // zero is used to indicate that a symbol is being imported or is undefined.
393 if (is64Bit())
394 return toSection64(Sec) - sectionHeaderTable64() + 1;
395 else
396 return toSection32(Sec) - sectionHeaderTable32() + 1;
397}
398
400 // Avoid ternary due to failure to convert the ubig32_t value to a unit64_t
401 // with MSVC.
402 if (is64Bit())
403 return toSection64(Sec)->SectionSize;
404
405 return toSection32(Sec)->SectionSize;
406}
407
410 if (isSectionVirtual(Sec))
411 return ArrayRef<uint8_t>();
412
413 uint64_t OffsetToRaw;
414 if (is64Bit())
415 OffsetToRaw = toSection64(Sec)->FileOffsetToRawData;
416 else
417 OffsetToRaw = toSection32(Sec)->FileOffsetToRawData;
418
419 const uint8_t * ContentStart = base() + OffsetToRaw;
420 uint64_t SectionSize = getSectionSize(Sec);
422 Data, reinterpret_cast<uintptr_t>(ContentStart), SectionSize))
423 return createError(
424 toString(std::move(E)) + ": section data with offset 0x" +
425 Twine::utohexstr(OffsetToRaw) + " and size 0x" +
426 Twine::utohexstr(SectionSize) + " goes past the end of the file");
427
428 return ArrayRef(ContentStart, SectionSize);
429}
430
432 uint64_t Result = 0;
433 llvm_unreachable("Not yet implemented!");
434 return Result;
435}
436
437uint64_t XCOFFObjectFile::getSectionFileOffsetToRawData(DataRefImpl Sec) const {
438 if (is64Bit())
439 return toSection64(Sec)->FileOffsetToRawData;
440
441 return toSection32(Sec)->FileOffsetToRawData;
442}
443
444Expected<uintptr_t> XCOFFObjectFile::getSectionFileOffsetToRawData(
445 XCOFF::SectionTypeFlags SectType) const {
446 DataRefImpl DRI = getSectionByType(SectType);
447
448 if (DRI.p == 0) // No section is not an error.
449 return 0;
450
451 uint64_t SectionOffset = getSectionFileOffsetToRawData(DRI);
452 uint64_t SizeOfSection = getSectionSize(DRI);
453
454 uintptr_t SectionStart = reinterpret_cast<uintptr_t>(base() + SectionOffset);
455 if (Error E = Binary::checkOffset(Data, SectionStart, SizeOfSection)) {
456 SmallString<32> UnknownType;
457 Twine(("<Unknown:") + Twine::utohexstr(SectType) + ">")
458 .toVector(UnknownType);
459 const char *SectionName = UnknownType.c_str();
460
461 switch (SectType) {
462#define ECASE(Value, String) \
463 case XCOFF::Value: \
464 SectionName = String; \
465 break
466
467 ECASE(STYP_PAD, "pad");
468 ECASE(STYP_DWARF, "dwarf");
469 ECASE(STYP_TEXT, "text");
470 ECASE(STYP_DATA, "data");
471 ECASE(STYP_BSS, "bss");
472 ECASE(STYP_EXCEPT, "expect");
473 ECASE(STYP_INFO, "info");
474 ECASE(STYP_TDATA, "tdata");
475 ECASE(STYP_TBSS, "tbss");
476 ECASE(STYP_LOADER, "loader");
477 ECASE(STYP_DEBUG, "debug");
478 ECASE(STYP_TYPCHK, "typchk");
479 ECASE(STYP_OVRFLO, "ovrflo");
480#undef ECASE
481 }
482 return createError(toString(std::move(E)) + ": " + SectionName +
483 " section with offset 0x" +
484 Twine::utohexstr(SectionOffset) + " and size 0x" +
485 Twine::utohexstr(SizeOfSection) +
486 " goes past the end of the file");
487 }
488 return SectionStart;
489}
490
492 return false;
493}
494
496 return getSectionFlags(Sec) & XCOFF::STYP_TEXT;
497}
498
500 uint32_t Flags = getSectionFlags(Sec);
501 return Flags & (XCOFF::STYP_DATA | XCOFF::STYP_TDATA);
502}
503
505 uint32_t Flags = getSectionFlags(Sec);
506 return Flags & (XCOFF::STYP_BSS | XCOFF::STYP_TBSS);
507}
508
510 uint32_t Flags = getSectionFlags(Sec);
511 return Flags & (XCOFF::STYP_DEBUG | XCOFF::STYP_DWARF);
512}
513
515 return is64Bit() ? toSection64(Sec)->FileOffsetToRawData == 0
516 : toSection32(Sec)->FileOffsetToRawData == 0;
520 DataRefImpl Ret;
521 if (is64Bit()) {
522 const XCOFFSectionHeader64 *SectionEntPtr = toSection64(Sec);
523 auto RelocationsOrErr =
524 relocations<XCOFFSectionHeader64, XCOFFRelocation64>(*SectionEntPtr);
525 if (Error E = RelocationsOrErr.takeError()) {
526 // TODO: report the error up the stack.
527 consumeError(std::move(E));
529 }
530 Ret.p = reinterpret_cast<uintptr_t>(&*RelocationsOrErr.get().begin());
531 } else {
532 const XCOFFSectionHeader32 *SectionEntPtr = toSection32(Sec);
533 auto RelocationsOrErr =
534 relocations<XCOFFSectionHeader32, XCOFFRelocation32>(*SectionEntPtr);
535 if (Error E = RelocationsOrErr.takeError()) {
536 // TODO: report the error up the stack.
537 consumeError(std::move(E));
539 }
540 Ret.p = reinterpret_cast<uintptr_t>(&*RelocationsOrErr.get().begin());
541 }
542 return relocation_iterator(RelocationRef(Ret, this));
543}
544
546 DataRefImpl Ret;
547 if (is64Bit()) {
548 const XCOFFSectionHeader64 *SectionEntPtr = toSection64(Sec);
549 auto RelocationsOrErr =
550 relocations<XCOFFSectionHeader64, XCOFFRelocation64>(*SectionEntPtr);
551 if (Error E = RelocationsOrErr.takeError()) {
552 // TODO: report the error up the stack.
553 consumeError(std::move(E));
555 }
556 Ret.p = reinterpret_cast<uintptr_t>(&*RelocationsOrErr.get().end());
557 } else {
558 const XCOFFSectionHeader32 *SectionEntPtr = toSection32(Sec);
559 auto RelocationsOrErr =
560 relocations<XCOFFSectionHeader32, XCOFFRelocation32>(*SectionEntPtr);
561 if (Error E = RelocationsOrErr.takeError()) {
562 // TODO: report the error up the stack.
563 consumeError(std::move(E));
565 }
566 Ret.p = reinterpret_cast<uintptr_t>(&*RelocationsOrErr.get().end());
567 }
568 return relocation_iterator(RelocationRef(Ret, this));
569}
570
572 if (is64Bit())
573 Rel.p = reinterpret_cast<uintptr_t>(viewAs<XCOFFRelocation64>(Rel.p) + 1);
574 else
575 Rel.p = reinterpret_cast<uintptr_t>(viewAs<XCOFFRelocation32>(Rel.p) + 1);
576}
577
579 if (is64Bit()) {
580 const XCOFFRelocation64 *Reloc = viewAs<XCOFFRelocation64>(Rel.p);
581 const XCOFFSectionHeader64 *Sec64 = sectionHeaderTable64();
582 const uint64_t RelocAddress = Reloc->VirtualAddress;
583 const uint16_t NumberOfSections = getNumberOfSections();
584 for (uint16_t I = 0; I < NumberOfSections; ++I) {
585 // Find which section this relocation belongs to, and get the
586 // relocation offset relative to the start of the section.
587 if (Sec64->VirtualAddress <= RelocAddress &&
588 RelocAddress < Sec64->VirtualAddress + Sec64->SectionSize) {
589 return RelocAddress - Sec64->VirtualAddress;
590 }
591 ++Sec64;
592 }
593 } else {
594 const XCOFFRelocation32 *Reloc = viewAs<XCOFFRelocation32>(Rel.p);
595 const XCOFFSectionHeader32 *Sec32 = sectionHeaderTable32();
596 const uint32_t RelocAddress = Reloc->VirtualAddress;
597 const uint16_t NumberOfSections = getNumberOfSections();
598 for (uint16_t I = 0; I < NumberOfSections; ++I) {
599 // Find which section this relocation belongs to, and get the
600 // relocation offset relative to the start of the section.
601 if (Sec32->VirtualAddress <= RelocAddress &&
602 RelocAddress < Sec32->VirtualAddress + Sec32->SectionSize) {
603 return RelocAddress - Sec32->VirtualAddress;
604 }
605 ++Sec32;
606 }
607 }
608 return InvalidRelocOffset;
609}
610
613 if (is64Bit()) {
614 const XCOFFRelocation64 *Reloc = viewAs<XCOFFRelocation64>(Rel.p);
615 Index = Reloc->SymbolIndex;
616
618 return symbol_end();
619 } else {
620 const XCOFFRelocation32 *Reloc = viewAs<XCOFFRelocation32>(Rel.p);
621 Index = Reloc->SymbolIndex;
622
624 return symbol_end();
625 }
626 DataRefImpl SymDRI;
628 return symbol_iterator(SymbolRef(SymDRI, this));
629}
630
632 if (is64Bit())
633 return viewAs<XCOFFRelocation64>(Rel.p)->Type;
634 return viewAs<XCOFFRelocation32>(Rel.p)->Type;
635}
636
638 DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
639 StringRef Res;
640 if (is64Bit()) {
641 const XCOFFRelocation64 *Reloc = viewAs<XCOFFRelocation64>(Rel.p);
643 } else {
644 const XCOFFRelocation32 *Reloc = viewAs<XCOFFRelocation32>(Rel.p);
646 }
647 Result.append(Res.begin(), Res.end());
648}
649
651 XCOFFSymbolRef XCOFFSym = toSymbolRef(Symb);
653
654 if (XCOFFSym.getSectionNumber() == XCOFF::N_ABS)
655 Result |= SymbolRef::SF_Absolute;
656
657 XCOFF::StorageClass SC = XCOFFSym.getStorageClass();
658 if (XCOFF::C_EXT == SC || XCOFF::C_WEAKEXT == SC)
659 Result |= SymbolRef::SF_Global;
660
661 if (XCOFF::C_WEAKEXT == SC)
662 Result |= SymbolRef::SF_Weak;
663
664 if (XCOFFSym.isCsectSymbol()) {
665 Expected<XCOFFCsectAuxRef> CsectAuxEntOrErr =
666 XCOFFSym.getXCOFFCsectAuxRef();
667 if (CsectAuxEntOrErr) {
668 if (CsectAuxEntOrErr.get().getSymbolType() == XCOFF::XTY_CM)
669 Result |= SymbolRef::SF_Common;
670 } else
671 return CsectAuxEntOrErr.takeError();
672 }
673
674 if (XCOFFSym.getSectionNumber() == XCOFF::N_UNDEF)
675 Result |= SymbolRef::SF_Undefined;
676
677 // There is no visibility in old 32 bit XCOFF object file interpret.
678 if (is64Bit() || (auxiliaryHeader32() && (auxiliaryHeader32()->getVersion() ==
680 uint16_t SymType = XCOFFSym.getSymbolType();
681 if ((SymType & VISIBILITY_MASK) == SYM_V_HIDDEN)
682 Result |= SymbolRef::SF_Hidden;
683
684 if ((SymType & VISIBILITY_MASK) == SYM_V_EXPORTED)
685 Result |= SymbolRef::SF_Exported;
686 }
687 return Result;
688}
689
691 DataRefImpl SymDRI;
692 SymDRI.p = reinterpret_cast<uintptr_t>(SymbolTblPtr);
693 return basic_symbol_iterator(SymbolRef(SymDRI, this));
694}
695
697 DataRefImpl SymDRI;
698 const uint32_t NumberOfSymbolTableEntries = getNumberOfSymbolTableEntries();
699 SymDRI.p = getSymbolEntryAddressByIndex(NumberOfSymbolTableEntries);
700 return basic_symbol_iterator(SymbolRef(SymDRI, this));
701}
702
705}
706
708 DataRefImpl DRI;
709 DRI.p = getSectionHeaderTableAddress();
710 return section_iterator(SectionRef(DRI, this));
711}
712
714 DataRefImpl DRI;
715 DRI.p = getWithOffset(getSectionHeaderTableAddress(),
716 getNumberOfSections() * getSectionHeaderSize());
717 return section_iterator(SectionRef(DRI, this));
718}
719
721
723 return is64Bit() ? "aix5coff64-rs6000" : "aixcoff-rs6000";
724}
725
727 return is64Bit() ? Triple::ppc64 : Triple::ppc;
728}
729
731 return SubtargetFeatures();
732}
733
735 if (is64Bit())
736 return !(fileHeader64()->Flags & NoRelMask);
737 return !(fileHeader32()->Flags & NoRelMask);
738}
739
741 if (AuxiliaryHeader == nullptr)
742 return 0;
743
746}
747
750 .Case("dwinfo", "debug_info")
751 .Case("dwline", "debug_line")
752 .Case("dwpbnms", "debug_pubnames")
753 .Case("dwpbtyp", "debug_pubtypes")
754 .Case("dwarnge", "debug_aranges")
755 .Case("dwabrev", "debug_abbrev")
756 .Case("dwstr", "debug_str")
757 .Case("dwrnges", "debug_ranges")
758 .Case("dwloc", "debug_loc")
759 .Case("dwframe", "debug_frame")
760 .Case("dwmac", "debug_macinfo")
761 .Default(Name);
762}
763
764size_t XCOFFObjectFile::getFileHeaderSize() const {
765 return is64Bit() ? sizeof(XCOFFFileHeader64) : sizeof(XCOFFFileHeader32);
766}
767
768size_t XCOFFObjectFile::getSectionHeaderSize() const {
769 return is64Bit() ? sizeof(XCOFFSectionHeader64) :
770 sizeof(XCOFFSectionHeader32);
771}
772
774 return Binary::ID_XCOFF64 == getType();
775}
776
779 StringRef Name) const {
780 uintptr_t StartPtr = reinterpret_cast<uintptr_t>(Start);
781 // TODO: this path is untested.
782 if (Error E = Binary::checkOffset(Data, StartPtr, Size))
783 return createError(toString(std::move(E)) + ": " + Name.data() +
784 " data with offset 0x" + Twine::utohexstr(StartPtr) +
785 " and size 0x" + Twine::utohexstr(Size) +
786 " goes past the end of the file");
787 return StringRef(Start, Size);
788}
789
791 return is64Bit() ? fileHeader64()->Magic : fileHeader32()->Magic;
792}
793
795 if (Num <= 0 || Num > getNumberOfSections())
797 "the section index (" + Twine(Num) +
798 ") is invalid");
799
800 DataRefImpl DRI;
801 DRI.p = getWithOffset(getSectionHeaderTableAddress(),
802 getSectionHeaderSize() * (Num - 1));
803 return DRI;
804}
805
807XCOFFObjectFile::getSectionByType(XCOFF::SectionTypeFlags SectType) const {
808 DataRefImpl DRI;
809 auto GetSectionAddr = [&](const auto &Sections) -> uintptr_t {
810 for (const auto &Sec : Sections)
811 if (Sec.getSectionType() == SectType)
812 return reinterpret_cast<uintptr_t>(&Sec);
813 return uintptr_t(0);
814 };
815 if (is64Bit())
816 DRI.p = GetSectionAddr(sections64());
817 else
818 DRI.p = GetSectionAddr(sections32());
819 return DRI;
820}
821
822Expected<StringRef>
824 const int16_t SectionNum = SymEntPtr.getSectionNumber();
825
826 switch (SectionNum) {
827 case XCOFF::N_DEBUG:
828 return "N_DEBUG";
829 case XCOFF::N_ABS:
830 return "N_ABS";
831 case XCOFF::N_UNDEF:
832 return "N_UNDEF";
833 default:
834 Expected<DataRefImpl> SecRef = getSectionByNum(SectionNum);
835 if (SecRef)
837 getSectionNameInternal(SecRef.get()));
838 return SecRef.takeError();
839 }
840}
841
843 XCOFFSymbolRef XCOFFSymRef(Sym.getRawDataRefImpl(), this);
844 return XCOFFSymRef.getSectionNumber();
845}
846
847bool XCOFFObjectFile::isReservedSectionNumber(int16_t SectionNumber) {
848 return (SectionNumber <= 0 && SectionNumber >= -2);
849}
850
854}
855
858}
859
863}
864
867}
868
870 // As far as symbol table size is concerned, if this field is negative it is
871 // to be treated as a 0. However since this field is also used for printing we
872 // don't want to truncate any negative values.
874}
875
877 return (fileHeader32()->NumberOfSymTableEntries >= 0
878 ? fileHeader32()->NumberOfSymTableEntries
879 : 0);
880}
881
884}
885
888}
889
893}
894
895uintptr_t XCOFFObjectFile::getEndOfSymbolTableAddress() const {
896 const uint32_t NumberOfSymTableEntries = getNumberOfSymbolTableEntries();
897 return getWithOffset(reinterpret_cast<uintptr_t>(SymbolTblPtr),
898 XCOFF::SymbolTableEntrySize * NumberOfSymTableEntries);
899}
900
901void XCOFFObjectFile::checkSymbolEntryPointer(uintptr_t SymbolEntPtr) const {
902 if (SymbolEntPtr < reinterpret_cast<uintptr_t>(SymbolTblPtr))
903 report_fatal_error("Symbol table entry is outside of symbol table.");
904
905 if (SymbolEntPtr >= getEndOfSymbolTableAddress())
906 report_fatal_error("Symbol table entry is outside of symbol table.");
907
908 ptrdiff_t Offset = reinterpret_cast<const char *>(SymbolEntPtr) -
909 reinterpret_cast<const char *>(SymbolTblPtr);
910
913 "Symbol table entry position is not valid inside of symbol table.");
914}
915
916uint32_t XCOFFObjectFile::getSymbolIndex(uintptr_t SymbolEntPtr) const {
917 return (reinterpret_cast<const char *>(SymbolEntPtr) -
918 reinterpret_cast<const char *>(SymbolTblPtr)) /
920}
921
923 uint64_t Result = 0;
924 XCOFFSymbolRef XCOFFSym = toSymbolRef(Symb);
925 if (XCOFFSym.isCsectSymbol()) {
926 Expected<XCOFFCsectAuxRef> CsectAuxRefOrError =
927 XCOFFSym.getXCOFFCsectAuxRef();
928 if (!CsectAuxRefOrError)
929 // TODO: report the error up the stack.
930 consumeError(CsectAuxRefOrError.takeError());
931 else {
932 XCOFFCsectAuxRef CsectAuxRef = CsectAuxRefOrError.get();
933 uint8_t SymType = CsectAuxRef.getSymbolType();
934 if (SymType == XCOFF::XTY_SD || SymType == XCOFF::XTY_CM)
935 Result = CsectAuxRef.getSectionOrLength();
936 }
937 }
938 return Result;
939}
940
943 reinterpret_cast<uintptr_t>(getPointerToSymbolTable()), Index);
944}
945
948 const uint32_t NumberOfSymTableEntries = getNumberOfSymbolTableEntries();
949
950 if (Index >= NumberOfSymTableEntries)
951 return createError("symbol index " + Twine(Index) +
952 " exceeds symbol count " +
953 Twine(NumberOfSymTableEntries));
954
955 DataRefImpl SymDRI;
957 return getSymbolName(SymDRI);
958}
959
961 return is64Bit() ? fileHeader64()->Flags : fileHeader32()->Flags;
962}
963
964const char *XCOFFObjectFile::getSectionNameInternal(DataRefImpl Sec) const {
965 return is64Bit() ? toSection64(Sec)->Name : toSection32(Sec)->Name;
966}
967
968uintptr_t XCOFFObjectFile::getSectionHeaderTableAddress() const {
969 return reinterpret_cast<uintptr_t>(SectionHeaderTable);
970}
971
973 return is64Bit() ? toSection64(Sec)->Flags : toSection32(Sec)->Flags;
974}
975
976XCOFFObjectFile::XCOFFObjectFile(unsigned int Type, MemoryBufferRef Object)
977 : ObjectFile(Type, Object) {
979}
980
982 assert(is64Bit() && "64-bit interface called for non 64-bit file.");
983 const XCOFFSectionHeader64 *TablePtr = sectionHeaderTable64();
984 return ArrayRef<XCOFFSectionHeader64>(TablePtr,
985 TablePtr + getNumberOfSections());
986}
987
989 assert(!is64Bit() && "32-bit interface called for non 32-bit file.");
990 const XCOFFSectionHeader32 *TablePtr = sectionHeaderTable32();
991 return ArrayRef<XCOFFSectionHeader32>(TablePtr,
992 TablePtr + getNumberOfSections());
993}
994
995// In an XCOFF32 file, when the field value is 65535, then an STYP_OVRFLO
996// section header contains the actual count of relocation entries in the s_paddr
997// field. STYP_OVRFLO headers contain the section index of their corresponding
998// sections as their raw "NumberOfRelocations" field value.
999template <typename T>
1001 const XCOFFSectionHeader<T> &Sec) const {
1002 const T &Section = static_cast<const T &>(Sec);
1003 if (is64Bit())
1004 return Section.NumberOfRelocations;
1005
1006 uint16_t SectionIndex = &Section - sectionHeaderTable<T>() + 1;
1007 if (Section.NumberOfRelocations < XCOFF::RelocOverflow)
1008 return Section.NumberOfRelocations;
1009 for (const auto &Sec : sections32()) {
1010 if (Sec.Flags == XCOFF::STYP_OVRFLO &&
1011 Sec.NumberOfRelocations == SectionIndex)
1012 return Sec.PhysicalAddress;
1013 }
1015}
1016
1017template <typename Shdr, typename Reloc>
1019 uintptr_t RelocAddr = getWithOffset(reinterpret_cast<uintptr_t>(FileHeader),
1020 Sec.FileOffsetToRelocationInfo);
1021 auto NumRelocEntriesOrErr = getNumberOfRelocationEntries(Sec);
1022 if (Error E = NumRelocEntriesOrErr.takeError())
1023 return std::move(E);
1024
1025 uint32_t NumRelocEntries = NumRelocEntriesOrErr.get();
1026 static_assert((sizeof(Reloc) == XCOFF::RelocationSerializationSize64 ||
1027 sizeof(Reloc) == XCOFF::RelocationSerializationSize32),
1028 "Relocation structure is incorrect");
1029 auto RelocationOrErr =
1030 getObject<Reloc>(Data, reinterpret_cast<void *>(RelocAddr),
1031 NumRelocEntries * sizeof(Reloc));
1032 if (!RelocationOrErr)
1033 return createError(
1034 toString(RelocationOrErr.takeError()) + ": relocations with offset 0x" +
1035 Twine::utohexstr(Sec.FileOffsetToRelocationInfo) + " and size 0x" +
1036 Twine::utohexstr(NumRelocEntries * sizeof(Reloc)) +
1037 " go past the end of the file");
1038
1039 const Reloc *StartReloc = RelocationOrErr.get();
1040
1041 return ArrayRef<Reloc>(StartReloc, StartReloc + NumRelocEntries);
1042}
1043
1044template <typename ExceptEnt>
1046 assert((is64Bit() && sizeof(ExceptEnt) == sizeof(ExceptionSectionEntry64)) ||
1047 (!is64Bit() && sizeof(ExceptEnt) == sizeof(ExceptionSectionEntry32)));
1048
1049 Expected<uintptr_t> ExceptionSectOrErr =
1050 getSectionFileOffsetToRawData(XCOFF::STYP_EXCEPT);
1051 if (!ExceptionSectOrErr)
1052 return ExceptionSectOrErr.takeError();
1053
1054 DataRefImpl DRI = getSectionByType(XCOFF::STYP_EXCEPT);
1055 if (DRI.p == 0)
1056 return ArrayRef<ExceptEnt>();
1057
1058 ExceptEnt *ExceptEntStart =
1059 reinterpret_cast<ExceptEnt *>(*ExceptionSectOrErr);
1060 return ArrayRef<ExceptEnt>(
1061 ExceptEntStart, ExceptEntStart + getSectionSize(DRI) / sizeof(ExceptEnt));
1062}
1063
1064template LLVM_EXPORT_TEMPLATE Expected<ArrayRef<ExceptionSectionEntry32>>
1066template LLVM_EXPORT_TEMPLATE Expected<ArrayRef<ExceptionSectionEntry64>>
1068
1070XCOFFObjectFile::parseStringTable(const XCOFFObjectFile *Obj, uint64_t Offset) {
1071 // If there is a string table, then the buffer must contain at least 4 bytes
1072 // for the string table's size. Not having a string table is not an error.
1074 Obj->Data, reinterpret_cast<uintptr_t>(Obj->base() + Offset), 4)) {
1075 consumeError(std::move(E));
1076 return XCOFFStringTable{0, nullptr};
1077 }
1078
1079 // Read the size out of the buffer.
1081
1082 // If the size is less then 4, then the string table is just a size and no
1083 // string data.
1084 if (Size <= 4)
1085 return XCOFFStringTable{4, nullptr};
1086
1087 auto StringTableOrErr =
1088 getObject<char>(Obj->Data, Obj->base() + Offset, Size);
1089 if (!StringTableOrErr)
1090 return createError(toString(StringTableOrErr.takeError()) +
1091 ": string table with offset 0x" +
1092 Twine::utohexstr(Offset) + " and size 0x" +
1094 " goes past the end of the file");
1095
1096 const char *StringTablePtr = StringTableOrErr.get();
1097 if (StringTablePtr[Size - 1] != '\0')
1099
1100 return XCOFFStringTable{Size, StringTablePtr};
1101}
1102
1103// This function returns the import file table. Each entry in the import file
1104// table consists of: "path_name\0base_name\0archive_member_name\0".
1106 Expected<uintptr_t> LoaderSectionAddrOrError =
1107 getSectionFileOffsetToRawData(XCOFF::STYP_LOADER);
1108 if (!LoaderSectionAddrOrError)
1109 return LoaderSectionAddrOrError.takeError();
1110
1111 uintptr_t LoaderSectionAddr = LoaderSectionAddrOrError.get();
1112 if (!LoaderSectionAddr)
1113 return StringRef();
1114
1115 uint64_t OffsetToImportFileTable = 0;
1116 uint64_t LengthOfImportFileTable = 0;
1117 if (is64Bit()) {
1118 const LoaderSectionHeader64 *LoaderSec64 =
1119 viewAs<LoaderSectionHeader64>(LoaderSectionAddr);
1120 OffsetToImportFileTable = LoaderSec64->OffsetToImpid;
1121 LengthOfImportFileTable = LoaderSec64->LengthOfImpidStrTbl;
1122 } else {
1123 const LoaderSectionHeader32 *LoaderSec32 =
1124 viewAs<LoaderSectionHeader32>(LoaderSectionAddr);
1125 OffsetToImportFileTable = LoaderSec32->OffsetToImpid;
1126 LengthOfImportFileTable = LoaderSec32->LengthOfImpidStrTbl;
1127 }
1128
1129 auto ImportTableOrErr = getObject<char>(
1130 Data,
1131 reinterpret_cast<void *>(LoaderSectionAddr + OffsetToImportFileTable),
1132 LengthOfImportFileTable);
1133 if (!ImportTableOrErr)
1134 return createError(
1135 toString(ImportTableOrErr.takeError()) +
1136 ": import file table with offset 0x" +
1137 Twine::utohexstr(LoaderSectionAddr + OffsetToImportFileTable) +
1138 " and size 0x" + Twine::utohexstr(LengthOfImportFileTable) +
1139 " goes past the end of the file");
1140
1141 const char *ImportTablePtr = ImportTableOrErr.get();
1142 if (ImportTablePtr[LengthOfImportFileTable - 1] != '\0')
1143 return createError(
1144 ": import file name table with offset 0x" +
1145 Twine::utohexstr(LoaderSectionAddr + OffsetToImportFileTable) +
1146 " and size 0x" + Twine::utohexstr(LengthOfImportFileTable) +
1147 " must end with a null terminator");
1148
1149 return StringRef(ImportTablePtr, LengthOfImportFileTable);
1150}
1151
1153XCOFFObjectFile::create(unsigned Type, MemoryBufferRef MBR) {
1154 // Can't use std::make_unique because of the private constructor.
1155 std::unique_ptr<XCOFFObjectFile> Obj;
1156 Obj.reset(new XCOFFObjectFile(Type, MBR));
1157
1158 uint64_t CurOffset = 0;
1159 const auto *Base = Obj->base();
1160 MemoryBufferRef Data = Obj->Data;
1161
1162 // Parse file header.
1163 auto FileHeaderOrErr =
1164 getObject<void>(Data, Base + CurOffset, Obj->getFileHeaderSize());
1165 if (Error E = FileHeaderOrErr.takeError())
1166 return std::move(E);
1167 Obj->FileHeader = FileHeaderOrErr.get();
1168
1169 CurOffset += Obj->getFileHeaderSize();
1170
1171 if (Obj->getOptionalHeaderSize()) {
1172 auto AuxiliaryHeaderOrErr =
1173 getObject<void>(Data, Base + CurOffset, Obj->getOptionalHeaderSize());
1174 if (Error E = AuxiliaryHeaderOrErr.takeError())
1175 return std::move(E);
1176 Obj->AuxiliaryHeader = AuxiliaryHeaderOrErr.get();
1177 }
1178
1179 CurOffset += Obj->getOptionalHeaderSize();
1180
1181 // Parse the section header table if it is present.
1182 if (Obj->getNumberOfSections()) {
1183 uint64_t SectionHeadersSize =
1184 Obj->getNumberOfSections() * Obj->getSectionHeaderSize();
1185 auto SecHeadersOrErr =
1186 getObject<void>(Data, Base + CurOffset, SectionHeadersSize);
1187 if (!SecHeadersOrErr)
1188 return createError(toString(SecHeadersOrErr.takeError()) +
1189 ": section headers with offset 0x" +
1190 Twine::utohexstr(CurOffset) + " and size 0x" +
1191 Twine::utohexstr(SectionHeadersSize) +
1192 " go past the end of the file");
1193
1194 Obj->SectionHeaderTable = SecHeadersOrErr.get();
1195 }
1196
1197 const uint32_t NumberOfSymbolTableEntries =
1198 Obj->getNumberOfSymbolTableEntries();
1199
1200 // If there is no symbol table we are done parsing the memory buffer.
1201 if (NumberOfSymbolTableEntries == 0)
1202 return std::move(Obj);
1203
1204 // Parse symbol table.
1205 CurOffset = Obj->is64Bit() ? Obj->getSymbolTableOffset64()
1206 : Obj->getSymbolTableOffset32();
1207 const uint64_t SymbolTableSize =
1209 NumberOfSymbolTableEntries;
1210 auto SymTableOrErr =
1211 getObject<void *>(Data, Base + CurOffset, SymbolTableSize);
1212 if (!SymTableOrErr)
1213 return createError(
1214 toString(SymTableOrErr.takeError()) + ": symbol table with offset 0x" +
1215 Twine::utohexstr(CurOffset) + " and size 0x" +
1216 Twine::utohexstr(SymbolTableSize) + " goes past the end of the file");
1217
1218 Obj->SymbolTblPtr = SymTableOrErr.get();
1219 CurOffset += SymbolTableSize;
1220
1221 // Parse String table.
1222 Expected<XCOFFStringTable> StringTableOrErr =
1223 parseStringTable(Obj.get(), CurOffset);
1224 if (Error E = StringTableOrErr.takeError())
1225 return std::move(E);
1226 Obj->StringTable = StringTableOrErr.get();
1227
1228 return std::move(Obj);
1229}
1230
1231Expected<std::unique_ptr<ObjectFile>>
1233 unsigned FileType) {
1234 return XCOFFObjectFile::create(FileType, MemBufRef);
1235}
1236
1237std::optional<StringRef> XCOFFObjectFile::tryGetCPUName() const {
1238 return StringRef("future");
1239}
1240
1242 if (!isCsectSymbol())
1243 return false;
1244
1245 if (getSymbolType() & FunctionSym)
1246 return true;
1247
1249 if (!ExpCsectAuxEnt)
1250 return ExpCsectAuxEnt.takeError();
1251
1252 const XCOFFCsectAuxRef CsectAuxRef = ExpCsectAuxEnt.get();
1253
1254 if (CsectAuxRef.getStorageMappingClass() != XCOFF::XMC_PR &&
1255 CsectAuxRef.getStorageMappingClass() != XCOFF::XMC_GL)
1256 return false;
1257
1258 // A function definition should not be a common type symbol or an external
1259 // symbol.
1260 if (CsectAuxRef.getSymbolType() == XCOFF::XTY_CM ||
1261 CsectAuxRef.getSymbolType() == XCOFF::XTY_ER)
1262 return false;
1263
1264 // If the next symbol is an XTY_LD type symbol with the same address, this
1265 // XTY_SD symbol is not a function. Otherwise this is a function symbol for
1266 // -ffunction-sections.
1267 if (CsectAuxRef.getSymbolType() == XCOFF::XTY_SD) {
1268 // If this is a csect with size 0, it won't be a function definition.
1269 // This is used to work around the fact that LLVM always generates below
1270 // symbol for -ffunction-sections:
1271 // m 0x00000000 .text 1 unamex **No Symbol**
1272 // a4 0x00000000 0 0 SD PR 0 0
1273 // FIXME: remove or replace this meaningless symbol.
1274 if (getSize() == 0)
1275 return false;
1276
1277 xcoff_symbol_iterator NextIt(this);
1278 // If this is the last main symbol table entry, there won't be an XTY_LD
1279 // type symbol below.
1280 if (++NextIt == getObject()->symbol_end())
1281 return true;
1282
1283 if (cantFail(getAddress()) != cantFail(NextIt->getAddress()))
1284 return true;
1285
1286 // Check next symbol is XTY_LD. If so, this symbol is not a function.
1287 Expected<XCOFFCsectAuxRef> NextCsectAuxEnt = NextIt->getXCOFFCsectAuxRef();
1288 if (!NextCsectAuxEnt)
1289 return NextCsectAuxEnt.takeError();
1290
1291 if (NextCsectAuxEnt.get().getSymbolType() == XCOFF::XTY_LD)
1292 return false;
1293
1294 return true;
1295 }
1296
1297 if (CsectAuxRef.getSymbolType() == XCOFF::XTY_LD)
1298 return true;
1299
1300 return createError(
1301 "symbol csect aux entry with index " +
1302 Twine(getObject()->getSymbolIndex(CsectAuxRef.getEntryAddress())) +
1303 " has invalid symbol type " +
1304 Twine::utohexstr(CsectAuxRef.getSymbolType()));
1305}
1306
1309 return (SC == XCOFF::C_EXT || SC == XCOFF::C_WEAKEXT ||
1310 SC == XCOFF::C_HIDEXT);
1311}
1312
1315 "Calling csect symbol interface with a non-csect symbol.");
1316
1317 uint8_t NumberOfAuxEntries = getNumberOfAuxEntries();
1318
1319 Expected<StringRef> NameOrErr = getName();
1320 if (auto Err = NameOrErr.takeError())
1321 return std::move(Err);
1322
1323 uint32_t SymbolIdx = getObject()->getSymbolIndex(getEntryAddress());
1324 if (!NumberOfAuxEntries) {
1325 return createError("csect symbol \"" + *NameOrErr + "\" with index " +
1326 Twine(SymbolIdx) + " contains no auxiliary entry");
1327 }
1328
1329 if (!getObject()->is64Bit()) {
1330 // In XCOFF32, the csect auxilliary entry is always the last auxiliary
1331 // entry for the symbol.
1333 getEntryAddress(), NumberOfAuxEntries);
1334 return XCOFFCsectAuxRef(viewAs<XCOFFCsectAuxEnt32>(AuxAddr));
1335 }
1336
1337 // XCOFF64 uses SymbolAuxType to identify the auxiliary entry type.
1338 // We need to iterate through all the auxiliary entries to find it.
1339 for (uint8_t Index = NumberOfAuxEntries; Index > 0; --Index) {
1342 if (*getObject()->getSymbolAuxType(AuxAddr) ==
1344#ifndef NDEBUG
1345 getObject()->checkSymbolEntryPointer(AuxAddr);
1346#endif
1347 return XCOFFCsectAuxRef(viewAs<XCOFFCsectAuxEnt64>(AuxAddr));
1348 }
1349 }
1350
1351 return createError(
1352 "a csect auxiliary entry has not been found for symbol \"" + *NameOrErr +
1353 "\" with index " + Twine(SymbolIdx));
1354}
1355
1357 // A storage class value with the high-order bit on indicates that the name is
1358 // a symbolic debugger stabstring.
1359 if (getStorageClass() & 0x80)
1360 return StringRef("Unimplemented Debug Name");
1361
1362 if (!getObject()->is64Bit()) {
1363 if (getSymbol32()->NameInStrTbl.Magic !=
1365 return generateXCOFFFixedNameStringRef(getSymbol32()->SymbolName);
1366
1367 return getObject()->getStringTableEntry(getSymbol32()->NameInStrTbl.Offset);
1368 }
1369
1370 return getObject()->getStringTableEntry(getSymbol64()->Offset);
1371}
1372
1373// Explicitly instantiate template classes.
1376
1379
1380template LLVM_EXPORT_TEMPLATE
1385template LLVM_EXPORT_TEMPLATE
1390
1392 if (Bytes.size() < 4)
1393 return false;
1394
1395 return support::endian::read32be(Bytes.data()) == 0;
1396}
1397
1398#define GETVALUEWITHMASK(X) (Data & (TracebackTable::X))
1399#define GETVALUEWITHMASKSHIFT(X, S) \
1400 ((Data & (TracebackTable::X)) >> (TracebackTable::S))
1401
1403 Error Err = Error::success();
1404 TBVectorExt TBTVecExt(TBvectorStrRef, Err);
1405 if (Err)
1406 return std::move(Err);
1407 return TBTVecExt;
1408}
1409
1410TBVectorExt::TBVectorExt(StringRef TBvectorStrRef, Error &Err) {
1411 const uint8_t *Ptr = reinterpret_cast<const uint8_t *>(TBvectorStrRef.data());
1413 uint32_t VecParmsTypeValue = support::endian::read32be(Ptr + 2);
1414 unsigned ParmsNum =
1415 GETVALUEWITHMASKSHIFT(NumberOfVectorParmsMask, NumberOfVectorParmsShift);
1416
1417 ErrorAsOutParameter EAO(Err);
1418 Expected<SmallString<32>> VecParmsTypeOrError =
1419 parseVectorParmsType(VecParmsTypeValue, ParmsNum);
1420 if (!VecParmsTypeOrError)
1421 Err = VecParmsTypeOrError.takeError();
1422 else
1423 VecParmsInfo = VecParmsTypeOrError.get();
1424}
1425
1427 return GETVALUEWITHMASKSHIFT(NumberOfVRSavedMask, NumberOfVRSavedShift);
1428}
1429
1431 return GETVALUEWITHMASK(IsVRSavedOnStackMask);
1432}
1433
1435 return GETVALUEWITHMASK(HasVarArgsMask);
1436}
1437
1439 return GETVALUEWITHMASKSHIFT(NumberOfVectorParmsMask,
1440 NumberOfVectorParmsShift);
1441}
1442
1444 return GETVALUEWITHMASK(HasVMXInstructionMask);
1445}
1446#undef GETVALUEWITHMASK
1447#undef GETVALUEWITHMASKSHIFT
1448
1451 Error Err = Error::success();
1452 XCOFFTracebackTable TBT(Ptr, Size, Err, Is64Bit);
1453 if (Err)
1454 return std::move(Err);
1455 return TBT;
1456}
1457
1458XCOFFTracebackTable::XCOFFTracebackTable(const uint8_t *Ptr, uint64_t &Size,
1459 Error &Err, bool Is64Bit)
1460 : TBPtr(Ptr), Is64BitObj(Is64Bit) {
1461 ErrorAsOutParameter EAO(Err);
1462 DataExtractor DE(ArrayRef<uint8_t>(Ptr, Size), /*IsLittleEndian=*/false,
1463 /*AddressSize=*/0);
1464 DataExtractor::Cursor Cur(/*Offset=*/0);
1465
1466 // Skip 8 bytes of mandatory fields.
1467 DE.getU64(Cur);
1468
1469 unsigned FixedParmsNum = getNumberOfFixedParms();
1470 unsigned FloatingParmsNum = getNumberOfFPParms();
1471 uint32_t ParamsTypeValue = 0;
1472
1473 // Begin to parse optional fields.
1474 if (Cur && (FixedParmsNum + FloatingParmsNum) > 0)
1475 ParamsTypeValue = DE.getU32(Cur);
1476
1477 if (Cur && hasTraceBackTableOffset())
1478 TraceBackTableOffset = DE.getU32(Cur);
1479
1480 if (Cur && isInterruptHandler())
1481 HandlerMask = DE.getU32(Cur);
1482
1483 if (Cur && hasControlledStorage()) {
1484 NumOfCtlAnchors = DE.getU32(Cur);
1485 if (Cur && NumOfCtlAnchors) {
1487 Disp.reserve(*NumOfCtlAnchors);
1488 for (uint32_t I = 0; I < NumOfCtlAnchors && Cur; ++I)
1489 Disp.push_back(DE.getU32(Cur));
1490 if (Cur)
1491 ControlledStorageInfoDisp = std::move(Disp);
1492 }
1493 }
1494
1495 if (Cur && isFuncNamePresent()) {
1496 uint16_t FunctionNameLen = DE.getU16(Cur);
1497 if (Cur)
1498 FunctionName = DE.getBytes(Cur, FunctionNameLen);
1499 }
1500
1501 if (Cur && isAllocaUsed())
1502 AllocaRegister = DE.getU8(Cur);
1503
1504 unsigned VectorParmsNum = 0;
1505 if (Cur && hasVectorInfo()) {
1506 StringRef VectorExtRef = DE.getBytes(Cur, 6);
1507 if (Cur) {
1508 Expected<TBVectorExt> TBVecExtOrErr = TBVectorExt::create(VectorExtRef);
1509 if (!TBVecExtOrErr) {
1510 Err = TBVecExtOrErr.takeError();
1511 return;
1512 }
1513 VecExt = TBVecExtOrErr.get();
1514 VectorParmsNum = VecExt->getNumberOfVectorParms();
1515 // Skip two bytes of padding after vector info.
1516 DE.skip(Cur, 2);
1517 }
1518 }
1519
1520 // As long as there is no fixed-point or floating-point parameter, this
1521 // field remains not present even when hasVectorInfo gives true and
1522 // indicates the presence of vector parameters.
1523 if (Cur && (FixedParmsNum + FloatingParmsNum) > 0) {
1524 Expected<SmallString<32>> ParmsTypeOrError =
1526 ? parseParmsTypeWithVecInfo(ParamsTypeValue, FixedParmsNum,
1527 FloatingParmsNum, VectorParmsNum)
1528 : parseParmsType(ParamsTypeValue, FixedParmsNum, FloatingParmsNum);
1529
1530 if (!ParmsTypeOrError) {
1531 Err = ParmsTypeOrError.takeError();
1532 return;
1533 }
1534 ParmsType = ParmsTypeOrError.get();
1535 }
1536
1537 if (Cur && hasExtensionTable()) {
1538 ExtensionTable = DE.getU8(Cur);
1539
1540 if (*ExtensionTable & ExtendedTBTableFlag::TB_EH_INFO) {
1541 // eh_info displacement must be 4-byte aligned.
1542 Cur.seek(alignTo(Cur.tell(), 4));
1543 EhInfoDisp = Is64BitObj ? DE.getU64(Cur) : DE.getU32(Cur);
1544 }
1545 }
1546 if (!Cur)
1547 Err = Cur.takeError();
1548
1549 Size = Cur.tell();
1550}
1551
1552#define GETBITWITHMASK(P, X) \
1553 (support::endian::read32be(TBPtr + (P)) & (TracebackTable::X))
1554#define GETBITWITHMASKSHIFT(P, X, S) \
1555 ((support::endian::read32be(TBPtr + (P)) & (TracebackTable::X)) >> \
1556 (TracebackTable::S))
1557
1559 return GETBITWITHMASKSHIFT(0, VersionMask, VersionShift);
1560}
1561
1563 return GETBITWITHMASKSHIFT(0, LanguageIdMask, LanguageIdShift);
1564}
1565
1567 return GETBITWITHMASK(0, IsGlobaLinkageMask);
1568}
1569
1571 return GETBITWITHMASK(0, IsOutOfLineEpilogOrPrologueMask);
1572}
1573
1575 return GETBITWITHMASK(0, HasTraceBackTableOffsetMask);
1576}
1577
1579 return GETBITWITHMASK(0, IsInternalProcedureMask);
1580}
1581
1583 return GETBITWITHMASK(0, HasControlledStorageMask);
1584}
1585
1587 return GETBITWITHMASK(0, IsTOClessMask);
1588}
1589
1591 return GETBITWITHMASK(0, IsFloatingPointPresentMask);
1592}
1593
1595 return GETBITWITHMASK(0, IsFloatingPointOperationLogOrAbortEnabledMask);
1596}
1597
1599 return GETBITWITHMASK(0, IsInterruptHandlerMask);
1600}
1601
1603 return GETBITWITHMASK(0, IsFunctionNamePresentMask);
1604}
1605
1607 return GETBITWITHMASK(0, IsAllocaUsedMask);
1608}
1609
1611 return GETBITWITHMASKSHIFT(0, OnConditionDirectiveMask,
1612 OnConditionDirectiveShift);
1613}
1614
1616 return GETBITWITHMASK(0, IsCRSavedMask);
1617}
1618
1620 return GETBITWITHMASK(0, IsLRSavedMask);
1621}
1622
1624 return GETBITWITHMASK(4, IsBackChainStoredMask);
1625}
1626
1628 return GETBITWITHMASK(4, IsFixupMask);
1629}
1630
1632 return GETBITWITHMASKSHIFT(4, FPRSavedMask, FPRSavedShift);
1633}
1634
1636 return GETBITWITHMASK(4, HasExtensionTableMask);
1637}
1638
1640 return GETBITWITHMASK(4, HasVectorInfoMask);
1641}
1642
1644 return GETBITWITHMASKSHIFT(4, GPRSavedMask, GPRSavedShift);
1645}
1646
1648 return GETBITWITHMASKSHIFT(4, NumberOfFixedParmsMask,
1649 NumberOfFixedParmsShift);
1650}
1651
1653 return GETBITWITHMASKSHIFT(4, NumberOfFloatingPointParmsMask,
1654 NumberOfFloatingPointParmsShift);
1655}
1656
1658 return GETBITWITHMASK(4, HasParmsOnStackMask);
1659}
1660
1661#undef GETBITWITHMASK
1662#undef GETBITWITHMASKSHIFT
1663} // namespace object
1664} // namespace llvm
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
Elf_Shdr Shdr
uint64_t Addr
std::string Name
uint32_t Index
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define I(x, y, z)
Definition: MD5.cpp:58
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static bool is64Bit(const char *name)
#define GETVALUEWITHMASKSHIFT(X, S)
#define GETVALUEWITHMASK(X)
#define GETBITWITHMASKSHIFT(P, X, S)
#define GETBITWITHMASK(P, X)
#define ECASE(Value, String)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:168
const T * data() const
Definition: ArrayRef.h:165
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Definition: DataExtractor.h:54
Helper for Errors used as out-parameters.
Definition: Error.h:1130
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Tagged union holding either a T or a Error.
Definition: Error.h:481
Error takeError()
Take ownership of the stored error.
Definition: Error.h:608
reference get()
Returns a reference to the stored T value.
Definition: Error.h:578
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
const char * c_str()
Definition: SmallString.h:259
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
void reserve(size_type N)
Definition: SmallVector.h:663
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
iterator begin() const
Definition: StringRef.h:116
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:144
iterator end() const
Definition: StringRef.h:118
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
A table of densely packed, null-terminated strings indexed by offset.
Definition: StringTable.h:31
Manages the enabling and disabling of subtarget specific features.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:416
void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
Definition: Twine.cpp:32
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
A range adaptor for a pair of iterators.
MemoryBufferRef Data
Definition: Binary.h:37
unsigned int getType() const
Definition: Binary.h:104
static Error checkOffset(MemoryBufferRef M, uintptr_t Addr, const uint64_t Size)
Definition: Binary.h:175
This class is the base class for all object file types.
Definition: ObjectFile.h:229
friend class RelocationRef
Definition: ObjectFile.h:287
friend class SymbolRef
Definition: ObjectFile.h:247
friend class SectionRef
Definition: ObjectFile.h:261
const uint8_t * base() const
Definition: ObjectFile.h:235
static Expected< std::unique_ptr< ObjectFile > > createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType)
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition: ObjectFile.h:168
Expected< uint64_t > getAddress() const
Returns the symbol virtual address (i.e.
Definition: ObjectFile.h:464
uint8_t getNumberOfVectorParms() const
static Expected< TBVectorExt > create(StringRef TBvectorStrRef)
uint8_t getNumberOfVRSaved() const
XCOFF::StorageMappingClass getStorageMappingClass() const
Expected< DataRefImpl > getSectionByNum(int16_t Num) const
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
const void * getPointerToSymbolTable() const
section_iterator section_begin() const override
uint32_t getSymbolIndex(uintptr_t SymEntPtr) const
relocation_iterator section_rel_end(DataRefImpl Sec) const override
Expected< StringRef > getCFileName(const XCOFFFileAuxEnt *CFileEntPtr) const
uintptr_t getSymbolEntryAddressByIndex(uint32_t SymbolTableIndex) const
bool isDebugSection(DataRefImpl Sec) const override
const XCOFFAuxiliaryHeader32 * auxiliaryHeader32() const
ArrayRef< XCOFFSectionHeader32 > sections32() const
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
const XCOFFFileHeader64 * fileHeader64() const
ArrayRef< XCOFFSectionHeader64 > sections64() const
Expected< uint64_t > getStartAddress() const override
Expected< ArrayRef< ExceptEnt > > getExceptionEntries() const
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
uint32_t getSymbolTableOffset32() const
bool isSectionVirtual(DataRefImpl Sec) const override
bool isSectionBSS(DataRefImpl Sec) const override
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
uint32_t getNumberOfSymbolTableEntries() const
bool isSectionData(DataRefImpl Sec) const override
uint64_t getRelocationOffset(DataRefImpl Rel) const override
uint64_t getSectionSize(DataRefImpl Sec) const override
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
int32_t getSectionFlags(DataRefImpl Sec) const
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
const XCOFFFileHeader32 * fileHeader32() const
int32_t getRawNumberOfSymbolTableEntries32() const
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
uint32_t getNumberOfSymbolTableEntries64() const
iterator_range< xcoff_symbol_iterator > xcoff_symbol_iterator_range
const XCOFFAuxiliaryHeader64 * auxiliaryHeader64() const
uint16_t getOptionalHeaderSize() const
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
XCOFFSymbolRef toSymbolRef(DataRefImpl Ref) const
basic_symbol_iterator symbol_begin() const override
Expected< StringRef > getSymbolNameByIndex(uint32_t SymbolTableIndex) const
unsigned getSymbolSectionID(SymbolRef Sym) const
uint64_t getSymbolTableOffset64() const
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
void moveRelocationNext(DataRefImpl &Rel) const override
Expected< StringRef > getImportFileTable() const
StringRef getFileFormatName() const override
Expected< uint32_t > getNumberOfRelocationEntries(const XCOFFSectionHeader< T > &Sec) const
bool isSectionCompressed(DataRefImpl Sec) const override
Expected< StringRef > getSymbolSectionName(XCOFFSymbolRef Ref) const
Expected< StringRef > getStringTableEntry(uint32_t Offset) const
static constexpr uint64_t InvalidRelocOffset
uint64_t getSectionAddress(DataRefImpl Sec) const override
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
Expected< SubtargetFeatures > getFeatures() const override
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
uint64_t getSectionAlignment(DataRefImpl Sec) const override
void checkSymbolEntryPointer(uintptr_t SymbolEntPtr) const
StringRef mapDebugSectionName(StringRef Name) const override
Maps a debug section name to a standard DWARF section name.
basic_symbol_iterator symbol_end() const override
static uintptr_t getAdvancedSymbolEntryAddress(uintptr_t CurrentAddress, uint32_t Distance)
bool is64Bit() const override
const XCOFF::SymbolAuxType * getSymbolAuxType(uintptr_t AuxEntryAddress) const
Triple::ArchType getArch() const override
uint64_t getRelocationType(DataRefImpl Rel) const override
std::optional< StringRef > tryGetCPUName() const override
bool isSectionText(DataRefImpl Sec) const override
Expected< StringRef > getRawData(const char *Start, uint64_t Size, StringRef Name) const
uint64_t getSymbolSize(DataRefImpl Symb) const
void moveSymbolNext(DataRefImpl &Symb) const override
Expected< ArrayRef< Reloc > > relocations(const Shdr &Sec) const
uint64_t getSectionIndex(DataRefImpl Sec) const override
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
void moveSectionNext(DataRefImpl &Sec) const override
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
section_iterator section_end() const override
uint32_t getLogicalNumberOfSymbolTableEntries32() const
xcoff_symbol_iterator_range symbols() const
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
Expected< XCOFFCsectAuxRef > getXCOFFCsectAuxRef() const
Expected< bool > isFunction() const
const XCOFFSymbolEntry64 * getSymbol64() const
const XCOFFSymbolEntry32 * getSymbol32() const
Expected< StringRef > getName() const
uint8_t getNumberOfAuxEntries() const
uintptr_t getEntryAddress() const
XCOFF::StorageClass getStorageClass() const
This class provides methods to extract traceback table data from a buffer.
static Expected< XCOFFTracebackTable > create(const uint8_t *Ptr, uint64_t &Size, bool Is64Bits=false)
Parse an XCOFF Traceback Table from Ptr with Size bytes.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static constexpr uint8_t XR_BIASED_LENGTH_MASK
Definition: XCOFF.h:60
constexpr size_t RelocationSerializationSize32
Definition: XCOFF.h:39
static constexpr uint8_t XR_FIXUP_INDICATOR_MASK
Definition: XCOFF.h:57
constexpr uint16_t VISIBILITY_MASK
Definition: XCOFF.h:259
Expected< SmallString< 32 > > parseParmsTypeWithVecInfo(uint32_t Value, unsigned FixedParmsNum, unsigned FloatingParmsNum, unsigned VectorParmsNum)
Definition: XCOFF.cpp:247
static constexpr uint8_t XR_SIGN_INDICATOR_MASK
Definition: XCOFF.h:54
StringRef getRelocationTypeString(XCOFF::RelocationType Type)
Definition: XCOFF.cpp:55
Expected< SmallString< 32 > > parseParmsType(uint32_t Value, unsigned FixedParmsNum, unsigned FloatingParmsNum)
Definition: XCOFF.cpp:169
constexpr size_t RelocationSerializationSize64
Definition: XCOFF.h:40
Expected< SmallString< 32 > > parseVectorParmsType(uint32_t Value, unsigned ParmsNum)
Definition: XCOFF.cpp:299
SymbolAuxType
Definition: XCOFF.h:365
@ AUX_CSECT
Identifies a csect auxiliary entry.
Definition: XCOFF.h:370
@ SYM_V_HIDDEN
Definition: XCOFF.h:254
@ SYM_V_EXPORTED
Definition: XCOFF.h:256
constexpr size_t NameSize
Definition: XCOFF.h:29
constexpr uint16_t RelocOverflow
Definition: XCOFF.h:43
@ N_DEBUG
Definition: XCOFF.h:46
@ N_UNDEF
Definition: XCOFF.h:46
@ N_ABS
Definition: XCOFF.h:46
StorageClass
Definition: XCOFF.h:170
@ C_WEAKEXT
Definition: XCOFF.h:199
@ C_FILE
Definition: XCOFF.h:172
@ C_HIDEXT
Definition: XCOFF.h:206
@ XMC_GL
Global Linkage (Interfile Interface Code)
Definition: XCOFF.h:108
@ XMC_PR
Program Code.
Definition: XCOFF.h:105
@ NEW_XCOFF_INTERPRET
Definition: XCOFF.h:75
constexpr size_t SymbolTableEntrySize
Definition: XCOFF.h:38
@ XTY_CM
Common csect definition. For uninitialized storage.
Definition: XCOFF.h:245
@ XTY_SD
Csect definition for initialized storage.
Definition: XCOFF.h:242
@ XTY_LD
Label definition.
Definition: XCOFF.h:243
@ XTY_ER
External reference.
Definition: XCOFF.h:241
SectionTypeFlags
Definition: XCOFF.h:134
@ STYP_TYPCHK
Definition: XCOFF.h:146
@ STYP_LOADER
Definition: XCOFF.h:144
@ STYP_DWARF
Definition: XCOFF.h:136
@ STYP_DATA
Definition: XCOFF.h:138
@ STYP_INFO
Definition: XCOFF.h:141
@ STYP_TDATA
Definition: XCOFF.h:142
@ STYP_TEXT
Definition: XCOFF.h:137
@ STYP_DEBUG
Definition: XCOFF.h:145
@ STYP_PAD
Definition: XCOFF.h:135
@ STYP_EXCEPT
Definition: XCOFF.h:140
@ STYP_OVRFLO
Definition: XCOFF.h:147
@ STYP_BSS
Definition: XCOFF.h:139
@ STYP_TBSS
Definition: XCOFF.h:143
static Expected< const T * > getObject(MemoryBufferRef M, const void *Ptr, const uint64_t Size=sizeof(T))
bool doesXCOFFTracebackTableBegin(ArrayRef< uint8_t > Bytes)
Error createError(const Twine &Err)
Definition: Error.h:84
Expected< StringRef > getLoaderSecSymNameInStrTbl(const T *LoaderSecHeader, uint64_t Offset)
static const size_t SymbolAuxTypeOffset
static const uint16_t NoRelMask
content_iterator< SectionRef > section_iterator
Definition: ObjectFile.h:47
static const uint8_t FunctionSym
content_iterator< RelocationRef > relocation_iterator
Definition: ObjectFile.h:77
content_iterator< BasicSymbolRef > basic_symbol_iterator
Definition: SymbolicFile.h:143
static uintptr_t getWithOffset(uintptr_t Base, ptrdiff_t Offset)
static StringRef generateXCOFFFixedNameStringRef(const char *Name)
static const T * viewAs(uintptr_t in)
uint32_t read32be(const void *P)
Definition: Endian.h:434
uint16_t read16be(const void *P)
Definition: Endian.h:431
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1291
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
@ Ref
The access may reference the value stored in memory.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:756
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
const char * toString(DWARFSectionKind Kind)
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:111
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1069
Expected< StringRef > getSymbolName(const LoaderSectionHeader32 *LoaderSecHeader) const
Expected< StringRef > getSymbolName(const LoaderSectionHeader64 *LoaderSecHeader) const
char Name[XCOFF::NameSize+XCOFF::FileNamePadSize]
support::big32_t NumberOfSymTableEntries
support::ubig16_t NumberOfSections
support::ubig32_t SymbolTableOffset
support::ubig64_t SymbolTableOffset
support::ubig32_t NumberOfSymTableEntries
support::ubig16_t NumberOfSections
XCOFF::RelocationType Type