LLVM 19.0.0git
XCOFFObjectFile.h
Go to the documentation of this file.
1//===- XCOFFObjectFile.h - XCOFF object file implementation -----*- C++ -*-===//
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 declares the XCOFFObjectFile class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_OBJECT_XCOFFOBJECTFILE_H
14#define LLVM_OBJECT_XCOFFOBJECTFILE_H
15
21#include "llvm/Support/Endian.h"
22#include <limits>
23
24namespace llvm {
25namespace object {
26
27class xcoff_symbol_iterator;
28
32
33 // Unix time value, value of 0 indicates no timestamp.
34 // Negative values are reserved.
36
37 support::ubig32_t SymbolTableOffset; // File offset to symbol table.
41};
42
46
47 // Unix time value, value of 0 indicates no timestamp.
48 // Negative values are reserved.
50
51 support::ubig64_t SymbolTableOffset; // File offset to symbol table.
55};
56
57template <typename T> struct XCOFFAuxiliaryHeader {
58 static constexpr uint8_t AuxiHeaderFlagMask = 0xF0;
59 static constexpr uint8_t AuxiHeaderTDataAlignmentMask = 0x0F;
60
61public:
62 uint8_t getFlag() const {
63 return static_cast<const T *>(this)->FlagAndTDataAlignment &
65 }
66
67 uint8_t getTDataAlignment() const {
68 return static_cast<const T *>(this)->FlagAndTDataAlignment &
70 }
71
72 uint16_t getVersion() const { return static_cast<const T *>(this)->Version; }
73};
74
75struct XCOFFAuxiliaryHeader32 : XCOFFAuxiliaryHeader<XCOFFAuxiliaryHeader32> {
77 AuxMagic; ///< If the value of the o_vstamp field is greater than 1, the
78 ///< o_mflags field is reserved for future use and it should
79 ///< contain 0. Otherwise, this field is not used.
81 Version; ///< The valid values are 1 and 2. When the o_vstamp field is 2
82 ///< in an XCOFF32 file, the new interpretation of the n_type
83 ///< field in the symbol table entry is used.
100 uint8_t CpuFlag;
101 uint8_t CpuType;
102 support::ubig32_t MaxStackSize; ///< If the value is 0, the system default
103 ///< maximum stack size is used.
104 support::ubig32_t MaxDataSize; ///< If the value is 0, the system default
105 ///< maximum data size is used.
107 ReservedForDebugger; ///< This field should contain 0. When a loaded
108 ///< program is being debugged, the memory image of
109 ///< this field may be modified by a debugger to
110 ///< insert a trap instruction.
111 uint8_t TextPageSize; ///< Specifies the size of pages for the exec text. The
112 ///< default value is 0 (system-selected page size).
113 uint8_t DataPageSize; ///< Specifies the size of pages for the exec data. The
114 ///< default value is 0 (system-selected page size).
115 uint8_t StackPageSize; ///< Specifies the size of pages for the stack. The
116 ///< default value is 0 (system-selected page size).
120};
121
122struct XCOFFAuxiliaryHeader64 : XCOFFAuxiliaryHeader<XCOFFAuxiliaryHeader64> {
138 uint8_t CpuFlag;
139 uint8_t CpuType;
153};
154
155template <typename T> struct XCOFFSectionHeader {
156 // The section flags definitions are the same in both 32- and 64-bit objects.
157 // Least significant 3 bits are reserved.
158 static constexpr unsigned SectionFlagsReservedMask = 0x7;
159
160 // The low order 16 bits of section flags denotes the section type.
161 // The high order 16 bits of section flags denotes the section subtype.
162 // For now, this is only used for DWARF sections.
163 static constexpr unsigned SectionFlagsTypeMask = 0xffffu;
164
165public:
166 StringRef getName() const;
167 uint16_t getSectionType() const;
169 bool isReservedSectionType() const;
170};
171
172// Explicit extern template declarations.
175extern template struct XCOFFSectionHeader<XCOFFSectionHeader32>;
176extern template struct XCOFFSectionHeader<XCOFFSectionHeader64>;
177
189};
190
202 char Padding[4];
203};
204
209 support::big32_t IsNameInStrTbl; // Zero indicates name in string table.
211 };
212
213 char SymbolName[XCOFF::NameSize];
214 support::ubig32_t Value; // The virtual address of the symbol.
216 uint8_t SymbolType;
220
222 getSymbolName(const LoaderSectionHeader32 *LoaderSecHeader) const;
223};
224
226 support::ubig64_t Value; // The virtual address of the symbol.
229 uint8_t SymbolType;
233
235 getSymbolName(const LoaderSectionHeader64 *LoaderSecHeader) const;
236};
237
243};
244
250};
251
261
263 return NumberOfSymTabEnt == 0 ? 0 : sizeof(LoaderSectionHeader32);
264 }
265
267 // Relocation table is after Symbol table.
268 return NumberOfRelTabEnt == 0
269 ? 0
270 : sizeof(LoaderSectionHeader32) +
271 sizeof(LoaderSectionSymbolEntry32) * NumberOfSymTabEnt;
272 }
273};
274
286
287 uint64_t getOffsetToSymTbl() const { return OffsetToSymTbl; }
288 uint64_t getOffsetToRelEnt() const { return OffsetToRelEnt; }
289};
290
291template <typename AddressType> struct ExceptionSectionEntry {
292 union {
294 AddressType TrapInstAddr;
295 };
296 uint8_t LangId;
297 uint8_t Reason;
298
300 assert(Reason == 0 && "Get symbol table index of the function only when "
301 "the e_reason field is 0.");
302 return SymbolIdx;
303 }
304
306 assert(Reason != 0 && "Zero is not a valid trap exception reason code.");
307 return TrapInstAddr;
308 }
309 uint8_t getLangID() const { return LangId; }
310 uint8_t getReason() const { return Reason; }
311};
312
315
316// Explicit extern template declarations.
317extern template struct ExceptionSectionEntry<support::ubig32_t>;
318extern template struct ExceptionSectionEntry<support::ubig64_t>;
319
322 const char *Data;
323};
324
333};
334
342 uint8_t Pad;
344};
345
347public:
348 static constexpr uint8_t SymbolTypeMask = 0x07;
349 static constexpr uint8_t SymbolAlignmentMask = 0xF8;
350 static constexpr size_t SymbolAlignmentBitOffset = 3;
351
352 XCOFFCsectAuxRef(const XCOFFCsectAuxEnt32 *Entry32) : Entry32(Entry32) {}
353 XCOFFCsectAuxRef(const XCOFFCsectAuxEnt64 *Entry64) : Entry64(Entry64) {}
354
355 // For getSectionOrLength(),
356 // If the symbol type is XTY_SD or XTY_CM, the csect length.
357 // If the symbol type is XTY_LD, the symbol table
358 // index of the containing csect.
359 // If the symbol type is XTY_ER, 0.
361 return Entry32 ? getSectionOrLength32() : getSectionOrLength64();
362 }
363
365 assert(Entry32 && "32-bit interface called on 64-bit object file.");
366 return Entry32->SectionOrLength;
367 }
368
370 assert(Entry64 && "64-bit interface called on 32-bit object file.");
371 return (static_cast<uint64_t>(Entry64->SectionOrLengthHighByte) << 32) |
372 Entry64->SectionOrLengthLowByte;
373 }
374
375#define GETVALUE(X) Entry32 ? Entry32->X : Entry64->X
376
378 return GETVALUE(ParameterHashIndex);
379 }
380
381 uint16_t getTypeChkSectNum() const { return GETVALUE(TypeChkSectNum); }
382
385 }
386
387 uintptr_t getEntryAddress() const {
388 return Entry32 ? reinterpret_cast<uintptr_t>(Entry32)
389 : reinterpret_cast<uintptr_t>(Entry64);
390 }
391
393 return (getSymbolAlignmentAndType() & SymbolAlignmentMask) >>
394 SymbolAlignmentBitOffset;
395 }
396
397 uint8_t getSymbolType() const {
398 return getSymbolAlignmentAndType() & SymbolTypeMask;
399 }
400
401 bool isLabel() const { return getSymbolType() == XCOFF::XTY_LD; }
402
404 assert(Entry32 && "32-bit interface called on 64-bit object file.");
405 return Entry32->StabInfoIndex;
406 }
407
409 assert(Entry32 && "32-bit interface called on 64-bit object file.");
410 return Entry32->StabSectNum;
411 }
412
414 assert(Entry64 && "64-bit interface called on 32-bit object file.");
415 return Entry64->AuxType;
416 }
417
419 return GETVALUE(SymbolAlignmentAndType);
420 }
421
422#undef GETVALUE
423
424private:
425 const XCOFFCsectAuxEnt32 *Entry32 = nullptr;
426 const XCOFFCsectAuxEnt64 *Entry64 = nullptr;
427};
428
430 typedef struct {
431 support::big32_t Magic; // Zero indicates name in string table.
435 union {
438 };
440 uint8_t ReservedZeros[2];
441 XCOFF::SymbolAuxType AuxType; // 64-bit XCOFF file only.
442};
443
448 uint8_t Pad[10];
449}; // 32-bit XCOFF file only.
450
456 uint8_t Pad[2];
457};
458
463 uint8_t Pad;
464 XCOFF::SymbolAuxType AuxType; // Contains _AUX_FCN; Type of auxiliary entry
465};
466
471 uint8_t Pad;
472 XCOFF::SymbolAuxType AuxType; // Contains _AUX_EXCEPT; Type of auxiliary entry
473};
474
476 uint8_t ReservedZeros1[2];
479 uint8_t ReservedZeros2[12];
480};
481
484 uint8_t Pad[13];
485 XCOFF::SymbolAuxType AuxType; // Contains _AUX_SYM; Type of auxiliary entry
486};
487
490 uint8_t Pad1[4];
492 uint8_t Pad2[6];
493};
494
498 uint8_t Pad;
499 XCOFF::SymbolAuxType AuxType; // Contains _AUX_SECT; Type of Auxillary entry
500};
501
502template <typename AddressType> struct XCOFFRelocation {
503public:
504 AddressType VirtualAddress;
506
507 // Packed field, see XR_* masks for details of packing.
508 uint8_t Info;
509
511
512public:
513 bool isRelocationSigned() const;
514 bool isFixupIndicated() const;
515
516 // Returns the number of bits being relocated.
517 uint8_t getRelocatedLength() const;
518};
519
520extern template struct XCOFFRelocation<llvm::support::ubig32_t>;
521extern template struct XCOFFRelocation<llvm::support::ubig64_t>;
522
525
526class XCOFFSymbolRef;
527
529private:
530 const void *FileHeader = nullptr;
531 const void *AuxiliaryHeader = nullptr;
532 const void *SectionHeaderTable = nullptr;
533
534 const void *SymbolTblPtr = nullptr;
535 XCOFFStringTable StringTable = {0, nullptr};
536
537 const XCOFFSectionHeader32 *sectionHeaderTable32() const;
538 const XCOFFSectionHeader64 *sectionHeaderTable64() const;
539 template <typename T> const T *sectionHeaderTable() const;
540
541 size_t getFileHeaderSize() const;
542 size_t getSectionHeaderSize() const;
543
544 const XCOFFSectionHeader32 *toSection32(DataRefImpl Ref) const;
545 const XCOFFSectionHeader64 *toSection64(DataRefImpl Ref) const;
546 uintptr_t getSectionHeaderTableAddress() const;
547 uintptr_t getEndOfSymbolTableAddress() const;
548
549 DataRefImpl getSectionByType(XCOFF::SectionTypeFlags SectType) const;
550 uint64_t getSectionFileOffsetToRawData(DataRefImpl Sec) const;
551
552 // This returns a pointer to the start of the storage for the name field of
553 // the 32-bit or 64-bit SectionHeader struct. This string is *not* necessarily
554 // null-terminated.
555 const char *getSectionNameInternal(DataRefImpl Sec) const;
556
557 static bool isReservedSectionNumber(int16_t SectionNumber);
558
559 // Constructor and "create" factory function. The constructor is only a thin
560 // wrapper around the base constructor. The "create" function fills out the
561 // XCOFF-specific information and performs the error checking along the way.
562 XCOFFObjectFile(unsigned Type, MemoryBufferRef Object);
563 static Expected<std::unique_ptr<XCOFFObjectFile>> create(unsigned Type,
564 MemoryBufferRef MBR);
565
566 // Helper for parsing the StringTable. Returns an 'Error' if parsing failed
567 // and an XCOFFStringTable if parsing succeeded.
568 static Expected<XCOFFStringTable> parseStringTable(const XCOFFObjectFile *Obj,
570
571 // Make a friend so it can call the private 'create' function.
574
575 void checkSectionAddress(uintptr_t Addr, uintptr_t TableAddr) const;
576
577public:
578 static constexpr uint64_t InvalidRelocOffset =
579 std::numeric_limits<uint64_t>::max();
580
581 // Interface inherited from base classes.
582 void moveSymbolNext(DataRefImpl &Symb) const override;
583 Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
584 basic_symbol_iterator symbol_begin() const override;
585 basic_symbol_iterator symbol_end() const override;
586
588 xcoff_symbol_iterator_range symbols() const;
589
590 bool is64Bit() const override;
591 Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
592 Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
593 uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
594 uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
595 uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
597 Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
598
599 void moveSectionNext(DataRefImpl &Sec) const override;
601 uint64_t getSectionAddress(DataRefImpl Sec) const override;
602 uint64_t getSectionIndex(DataRefImpl Sec) const override;
603 uint64_t getSectionSize(DataRefImpl Sec) const override;
605 getSectionContents(DataRefImpl Sec) const override;
606 uint64_t getSectionAlignment(DataRefImpl Sec) const override;
607 bool isSectionCompressed(DataRefImpl Sec) const override;
608 bool isSectionText(DataRefImpl Sec) const override;
609 bool isSectionData(DataRefImpl Sec) const override;
610 bool isSectionBSS(DataRefImpl Sec) const override;
611 bool isDebugSection(DataRefImpl Sec) const override;
612
613 bool isSectionVirtual(DataRefImpl Sec) const override;
614 relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
615 relocation_iterator section_rel_end(DataRefImpl Sec) const override;
616
617 void moveRelocationNext(DataRefImpl &Rel) const override;
618
619 /// \returns the relocation offset with the base address of the containing
620 /// section as zero, or InvalidRelocOffset on errors (such as a relocation
621 /// that does not refer to an address in any section).
622 uint64_t getRelocationOffset(DataRefImpl Rel) const override;
623 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
624 uint64_t getRelocationType(DataRefImpl Rel) const override;
625 void getRelocationTypeName(DataRefImpl Rel,
626 SmallVectorImpl<char> &Result) const override;
627
628 section_iterator section_begin() const override;
629 section_iterator section_end() const override;
630 uint8_t getBytesInAddress() const override;
631 StringRef getFileFormatName() const override;
632 Triple::ArchType getArch() const override;
634 Expected<uint64_t> getStartAddress() const override;
635 StringRef mapDebugSectionName(StringRef Name) const override;
636 bool isRelocatableObject() const override;
637
638 // Below here is the non-inherited interface.
639
640 Expected<StringRef> getRawData(const char *Start, uint64_t Size,
641 StringRef Name) const;
642
643 const XCOFFAuxiliaryHeader32 *auxiliaryHeader32() const;
644 const XCOFFAuxiliaryHeader64 *auxiliaryHeader64() const;
645
646 const void *getPointerToSymbolTable() const { return SymbolTblPtr; }
647
648 Expected<StringRef> getSymbolSectionName(XCOFFSymbolRef Ref) const;
649 unsigned getSymbolSectionID(SymbolRef Sym) const;
650 XCOFFSymbolRef toSymbolRef(DataRefImpl Ref) const;
651
652 // File header related interfaces.
653 const XCOFFFileHeader32 *fileHeader32() const;
654 const XCOFFFileHeader64 *fileHeader64() const;
655 uint16_t getMagic() const;
656 uint16_t getNumberOfSections() const;
657 int32_t getTimeStamp() const;
658
659 // Symbol table offset and entry count are handled differently between
660 // XCOFF32 and XCOFF64.
661 uint32_t getSymbolTableOffset32() const;
662 uint64_t getSymbolTableOffset64() const;
663
664 // Note that this value is signed and might return a negative value. Negative
665 // values are reserved for future use.
666 int32_t getRawNumberOfSymbolTableEntries32() const;
667
668 // The sanitized value appropriate to use as an index into the symbol table.
669 uint32_t getLogicalNumberOfSymbolTableEntries32() const;
670
671 uint32_t getNumberOfSymbolTableEntries64() const;
672
673 // Return getLogicalNumberOfSymbolTableEntries32 or
674 // getNumberOfSymbolTableEntries64 depending on the object mode.
675 uint32_t getNumberOfSymbolTableEntries() const;
676
677 uint32_t getSymbolIndex(uintptr_t SymEntPtr) const;
678 uint64_t getSymbolSize(DataRefImpl Symb) const;
679 uintptr_t getSymbolByIndex(uint32_t Idx) const {
680 return reinterpret_cast<uintptr_t>(SymbolTblPtr) +
682 }
683 uintptr_t getSymbolEntryAddressByIndex(uint32_t SymbolTableIndex) const;
684 Expected<StringRef> getSymbolNameByIndex(uint32_t SymbolTableIndex) const;
685
686 Expected<StringRef> getCFileName(const XCOFFFileAuxEnt *CFileEntPtr) const;
687 uint16_t getOptionalHeaderSize() const;
688 uint16_t getFlags() const;
689
690 // Section header table related interfaces.
691 ArrayRef<XCOFFSectionHeader32> sections32() const;
692 ArrayRef<XCOFFSectionHeader64> sections64() const;
693
694 int32_t getSectionFlags(DataRefImpl Sec) const;
695 Expected<DataRefImpl> getSectionByNum(int16_t Num) const;
696
698 getSectionFileOffsetToRawData(XCOFF::SectionTypeFlags SectType) const;
699
700 void checkSymbolEntryPointer(uintptr_t SymbolEntPtr) const;
701
702 // Relocation-related interfaces.
703 template <typename T>
705 getNumberOfRelocationEntries(const XCOFFSectionHeader<T> &Sec) const;
706
707 template <typename Shdr, typename Reloc>
708 Expected<ArrayRef<Reloc>> relocations(const Shdr &Sec) const;
709
710 // Loader section related interfaces.
711 Expected<StringRef> getImportFileTable() const;
712
713 // Exception-related interface.
714 template <typename ExceptEnt>
715 Expected<ArrayRef<ExceptEnt>> getExceptionEntries() const;
716
717 // This function returns string table entry.
718 Expected<StringRef> getStringTableEntry(uint32_t Offset) const;
719
720 // This function returns the string table.
721 StringRef getStringTable() const;
722
723 const XCOFF::SymbolAuxType *getSymbolAuxType(uintptr_t AuxEntryAddress) const;
724
725 static uintptr_t getAdvancedSymbolEntryAddress(uintptr_t CurrentAddress,
726 uint32_t Distance);
727
728 static bool classof(const Binary *B) { return B->isXCOFF(); }
729
730 std::optional<StringRef> tryGetCPUName() const override;
731}; // XCOFFObjectFile
732
733typedef struct {
734 uint8_t LanguageId;
735 uint8_t CpuTypeId;
737
739 typedef struct {
740 support::big32_t Magic; // Zero indicates name in string table.
743
744 union {
747 };
748
749 support::ubig32_t Value; // Symbol value; storage class-dependent.
751
752 union {
755 };
756
759};
760
762 support::ubig64_t Value; // Symbol value; storage class-dependent.
765
766 union {
769 };
770
773};
774
775class XCOFFSymbolRef : public SymbolRef {
776public:
777 enum { NAME_IN_STR_TBL_MAGIC = 0x0 };
778
780 const XCOFFObjectFile *OwningObjectPtr)
781 : SymbolRef(SymEntDataRef, OwningObjectPtr) {
782 assert(OwningObjectPtr && "OwningObjectPtr cannot be nullptr!");
783 assert(SymEntDataRef.p != 0 &&
784 "Symbol table entry pointer cannot be nullptr!");
785 }
786
788 return reinterpret_cast<const XCOFFSymbolEntry32 *>(getRawDataRefImpl().p);
789 }
790
792 return reinterpret_cast<const XCOFFSymbolEntry64 *>(getRawDataRefImpl().p);
793 }
794
796 return getObject()->is64Bit() ? getValue64() : getValue32();
797 }
798
800 return reinterpret_cast<const XCOFFSymbolEntry32 *>(getRawDataRefImpl().p)
801 ->Value;
802 }
803
805 return reinterpret_cast<const XCOFFSymbolEntry64 *>(getRawDataRefImpl().p)
806 ->Value;
807 }
808
810 return getObject()->getSymbolSize(getRawDataRefImpl());
811 }
812
813#define GETVALUE(X) \
814 getObject()->is64Bit() \
815 ? reinterpret_cast<const XCOFFSymbolEntry64 *>(getRawDataRefImpl().p)->X \
816 : reinterpret_cast<const XCOFFSymbolEntry32 *>(getRawDataRefImpl().p)->X
817
818 int16_t getSectionNumber() const { return GETVALUE(SectionNumber); }
819
821
822 uint8_t getLanguageIdForCFile() const {
824 "This interface is for C_FILE only.");
825 return GETVALUE(CFileLanguageIdAndTypeId.LanguageId);
826 }
827
828 uint8_t getCPUTypeIddForCFile() const {
830 "This interface is for C_FILE only.");
831 return GETVALUE(CFileLanguageIdAndTypeId.CpuTypeId);
832 }
833
835
836 uint8_t getNumberOfAuxEntries() const { return GETVALUE(NumberOfAuxEntries); }
837
838#undef GETVALUE
839
840 uintptr_t getEntryAddress() const {
841 return getRawDataRefImpl().p;
842 }
843
846 bool isCsectSymbol() const;
848
849private:
850 const XCOFFObjectFile *getObject() const {
851 return cast<XCOFFObjectFile>(BasicSymbolRef::getObject());
852 }
853};
854
856public:
858 : symbol_iterator(B) {}
859
861 : symbol_iterator(*Symbol) {}
862
863 const XCOFFSymbolRef *operator->() const {
864 return static_cast<const XCOFFSymbolRef *>(symbol_iterator::operator->());
865 }
866
867 const XCOFFSymbolRef &operator*() const {
868 return static_cast<const XCOFFSymbolRef &>(symbol_iterator::operator*());
869 }
870};
871
873 uint16_t Data;
874 SmallString<32> VecParmsInfo;
875
876 TBVectorExt(StringRef TBvectorStrRef, Error &Err);
877
878public:
879 static Expected<TBVectorExt> create(StringRef TBvectorStrRef);
880 uint8_t getNumberOfVRSaved() const;
881 bool isVRSavedOnStack() const;
882 bool hasVarArgs() const;
883 uint8_t getNumberOfVectorParms() const;
884 bool hasVMXInstruction() const;
885 SmallString<32> getVectorParmsInfo() const { return VecParmsInfo; };
886};
887
888/// This class provides methods to extract traceback table data from a buffer.
889/// The various accessors may reference the buffer provided via the constructor.
890
892 const uint8_t *const TBPtr;
893 bool Is64BitObj;
894 std::optional<SmallString<32>> ParmsType;
895 std::optional<uint32_t> TraceBackTableOffset;
896 std::optional<uint32_t> HandlerMask;
897 std::optional<uint32_t> NumOfCtlAnchors;
898 std::optional<SmallVector<uint32_t, 8>> ControlledStorageInfoDisp;
899 std::optional<StringRef> FunctionName;
900 std::optional<uint8_t> AllocaRegister;
901 std::optional<TBVectorExt> VecExt;
902 std::optional<uint8_t> ExtensionTable;
903 std::optional<uint64_t> EhInfoDisp;
904
905 XCOFFTracebackTable(const uint8_t *Ptr, uint64_t &Size, Error &Err,
906 bool Is64Bit = false);
907
908public:
909 /// Parse an XCOFF Traceback Table from \a Ptr with \a Size bytes.
910 /// Returns an XCOFFTracebackTable upon successful parsing, otherwise an
911 /// Error is returned.
912 ///
913 /// \param[in] Ptr
914 /// A pointer that points just past the initial 4 bytes of zeros at the
915 /// beginning of an XCOFF Traceback Table.
916 ///
917 /// \param[in, out] Size
918 /// A pointer that points to the length of the XCOFF Traceback Table.
919 /// If the XCOFF Traceback Table is not parsed successfully or there are
920 /// extra bytes that are not recognized, \a Size will be updated to be the
921 /// size up to the end of the last successfully parsed field of the table.
923 create(const uint8_t *Ptr, uint64_t &Size, bool Is64Bits = false);
924 uint8_t getVersion() const;
925 uint8_t getLanguageID() const;
926
927 bool isGlobalLinkage() const;
928 bool isOutOfLineEpilogOrPrologue() const;
929 bool hasTraceBackTableOffset() const;
930 bool isInternalProcedure() const;
931 bool hasControlledStorage() const;
932 bool isTOCless() const;
933 bool isFloatingPointPresent() const;
935
936 bool isInterruptHandler() const;
937 bool isFuncNamePresent() const;
938 bool isAllocaUsed() const;
939 uint8_t getOnConditionDirective() const;
940 bool isCRSaved() const;
941 bool isLRSaved() const;
942
943 bool isBackChainStored() const;
944 bool isFixup() const;
945 uint8_t getNumOfFPRsSaved() const;
946
947 bool hasVectorInfo() const;
948 bool hasExtensionTable() const;
949 uint8_t getNumOfGPRsSaved() const;
950
951 uint8_t getNumberOfFixedParms() const;
952
953 uint8_t getNumberOfFPParms() const;
954 bool hasParmsOnStack() const;
955
956 const std::optional<SmallString<32>> &getParmsType() const {
957 return ParmsType;
958 }
959 const std::optional<uint32_t> &getTraceBackTableOffset() const {
960 return TraceBackTableOffset;
961 }
962 const std::optional<uint32_t> &getHandlerMask() const { return HandlerMask; }
963 const std::optional<uint32_t> &getNumOfCtlAnchors() {
964 return NumOfCtlAnchors;
965 }
966 const std::optional<SmallVector<uint32_t, 8>> &
968 return ControlledStorageInfoDisp;
969 }
970 const std::optional<StringRef> &getFunctionName() const {
971 return FunctionName;
972 }
973 const std::optional<uint8_t> &getAllocaRegister() const {
974 return AllocaRegister;
975 }
976 const std::optional<TBVectorExt> &getVectorExt() const { return VecExt; }
977 const std::optional<uint8_t> &getExtensionTable() const {
978 return ExtensionTable;
979 }
980 const std::optional<uint64_t> &getEhInfoDisp() const { return EhInfoDisp; }
981};
982
984} // namespace object
985} // namespace llvm
986
987#endif // LLVM_OBJECT_XCOFFOBJECTFILE_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static StringRef getSymbolName(SymbolKind SymKind)
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Elf_Shdr Shdr
uint64_t Addr
std::string Name
uint64_t Size
static bool isDebugSection(const SectionBase &Sec)
Definition: ELFObjcopy.cpp:54
Symbol * Sym
Definition: ELF_riscv.cpp:479
static FeatureBitset getFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS, ArrayRef< SubtargetSubTypeKV > ProcDesc, ArrayRef< SubtargetFeatureKV > ProcFeatures)
static uint32_t getSectionFlags(const MachOObjectFile &O, DataRefImpl Sec)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
This file defines the SmallVector class.
static unsigned getSymbolSectionID(const ObjectFile &O, SymbolRef Sym)
Definition: SymbolSize.cpp:39
static uint32_t getFlags(const Symbol *Sym)
Definition: TapiFile.cpp:27
static std::unique_ptr< PDBSymbol > getSymbolType(const PDBSymbol &Symbol)
Definition: UDTLayout.cpp:36
static bool is64Bit(const char *name)
#define GETVALUE(X)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
A range adaptor for a pair of iterators.
const SymbolicFile * getObject() const
Definition: SymbolicFile.h:214
DataRefImpl getRawDataRefImpl() const
Definition: SymbolicFile.h:210
This class is the base class for all object file types.
Definition: ObjectFile.h:229
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
SmallString< 32 > getVectorParmsInfo() const
uint8_t getNumberOfVectorParms() const
static Expected< TBVectorExt > create(StringRef TBvectorStrRef)
uint8_t getNumberOfVRSaved() const
XCOFF::StorageMappingClass getStorageMappingClass() const
XCOFFCsectAuxRef(const XCOFFCsectAuxEnt32 *Entry32)
uint32_t getSectionOrLength32() const
uint32_t getParameterHashIndex() const
XCOFFCsectAuxRef(const XCOFFCsectAuxEnt64 *Entry64)
uint64_t getSectionOrLength64() const
XCOFF::SymbolAuxType getAuxType64() const
uint8_t getSymbolAlignmentAndType() const
const void * getPointerToSymbolTable() const
static bool classof(const Binary *B)
uintptr_t getSymbolByIndex(uint32_t Idx) const
bool is64Bit() const override
uint64_t getSymbolSize(DataRefImpl Symb) const
Expected< XCOFFCsectAuxRef > getXCOFFCsectAuxRef() const
Expected< bool > isFunction() const
const XCOFFSymbolEntry64 * getSymbol64() const
XCOFFSymbolRef(DataRefImpl SymEntDataRef, const XCOFFObjectFile *OwningObjectPtr)
const XCOFFSymbolEntry32 * getSymbol32() const
Expected< StringRef > getName() const
uint8_t getCPUTypeIddForCFile() const
uint8_t getNumberOfAuxEntries() const
uintptr_t getEntryAddress() const
XCOFF::StorageClass getStorageClass() const
uint8_t getLanguageIdForCFile() const
This class provides methods to extract traceback table data from a buffer.
const std::optional< StringRef > & getFunctionName() const
const std::optional< uint64_t > & getEhInfoDisp() const
const std::optional< uint32_t > & getTraceBackTableOffset() const
const std::optional< SmallVector< uint32_t, 8 > > & getControlledStorageInfoDisp()
const std::optional< uint8_t > & getExtensionTable() const
const std::optional< SmallString< 32 > > & getParmsType() const
const std::optional< uint32_t > & getNumOfCtlAnchors()
const std::optional< uint32_t > & getHandlerMask() const
const std::optional< TBVectorExt > & getVectorExt() const
static Expected< XCOFFTracebackTable > create(const uint8_t *Ptr, uint64_t &Size, bool Is64Bits=false)
Parse an XCOFF Traceback Table from Ptr with Size bytes.
const std::optional< uint8_t > & getAllocaRegister() const
const SymbolRef * operator->() const
Definition: ObjectFile.h:215
const SymbolRef & operator*() const
Definition: ObjectFile.h:220
const XCOFFSymbolRef * operator->() const
const XCOFFSymbolRef & operator*() const
xcoff_symbol_iterator(const XCOFFSymbolRef *Symbol)
xcoff_symbol_iterator(const basic_symbol_iterator &B)
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
SymbolAuxType
Definition: XCOFF.h:342
RelocationType
Definition: XCOFF.h:262
constexpr size_t NameSize
Definition: XCOFF.h:29
CFileStringType
Definition: XCOFF.h:323
StorageClass
Definition: XCOFF.h:170
@ C_FILE
Definition: XCOFF.h:172
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:103
constexpr size_t SymbolTableEntrySize
Definition: XCOFF.h:38
constexpr size_t FileNamePadSize
Definition: XCOFF.h:28
@ XTY_LD
Label definition.
Definition: XCOFF.h:243
SectionTypeFlags
Definition: XCOFF.h:134
static constexpr const StringLiteral & getSectionName(DebugSectionKind SectionKind)
Return the name of the section.
bool doesXCOFFTracebackTableBegin(ArrayRef< uint8_t > Bytes)
ExceptionSectionEntry< support::ubig64_t > ExceptionSectionEntry64
ExceptionSectionEntry< support::ubig32_t > ExceptionSectionEntry32
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456
@ Ref
The access may reference the value stored in memory.
support::ubig32_t MaxStackSize
If the value is 0, the system default maximum stack size is used.
support::ubig16_t AuxMagic
If the value of the o_vstamp field is greater than 1, the o_mflags field is reserved for future use a...
uint8_t TextPageSize
Specifies the size of pages for the exec text.
uint8_t StackPageSize
Specifies the size of pages for the stack.
support::ubig32_t ReservedForDebugger
This field should contain 0.
support::ubig16_t Version
The valid values are 1 and 2.
uint8_t DataPageSize
Specifies the size of pages for the exec data.
support::ubig32_t MaxDataSize
If the value is 0, the system default maximum data size is used.
static constexpr uint8_t AuxiHeaderTDataAlignmentMask
static constexpr uint8_t AuxiHeaderFlagMask
XCOFF::StorageMappingClass StorageMappingClass
XCOFF::StorageMappingClass StorageMappingClass
support::ubig32_t SectionOrLengthLowByte
support::ubig32_t SectionOrLengthHighByte
XCOFF::SymbolAuxType AuxType
XCOFF::CFileStringType Type
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
support::ubig32_t FileOffsetToLineNumberInfo
support::ubig32_t FileOffsetToRelocationInfo
static constexpr unsigned SectionFlagsReservedMask
static constexpr unsigned SectionFlagsTypeMask
CFileLanguageIdAndTypeIdType CFileLanguageIdAndTypeId
char SymbolName[XCOFF::NameSize]
CFileLanguageIdAndTypeIdType CFileLanguageIdAndTypeId