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