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