1//===- XCOFFObjectFile.h - XCOFF object file implementation -----*- C++ -*-===//
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
7//===----------------------------------------------------------------------===//
9// This file declares the XCOFFObjectFile class.
11//===----------------------------------------------------------------------===//
13#ifndef LLVM_OBJECT_XCOFFOBJECTFILE_H
14#define LLVM_OBJECT_XCOFFOBJECTFILE_H
34 // Unix time value, value of 0 indicates no timestamp.
35 // Negative values are reserved.
48 // Unix time value, value of 0 indicates no timestamp.
49 // Negative values are reserved.
64 return static_cast<const T *
>(
this)->FlagAndTDataAlignment &
69 return static_cast<const T *
>(
this)->FlagAndTDataAlignment &
75 return static_cast<const T *
>(
this)->EntryPointAddr;
81 AuxMagic;
///< If the value of the o_vstamp field is greater than 1, the
82 ///< o_mflags field is reserved for future use and it should
83 ///< contain 0. Otherwise, this field is not used.
85 Version;
///< The valid values are 1 and 2. When the o_vstamp field is 2
86 ///< in an XCOFF32 file, the new interpretation of the n_type
87 ///< field in the symbol table entry is used.
107 ///< maximum stack size is used.
109 ///< maximum data size is used.
112 ///< program is being debugged, the memory image of
113 ///< this field may be modified by a debugger to
114 ///< insert a trap instruction.
116 ///< default value is 0 (system-selected page size).
118 ///< default value is 0 (system-selected page size).
120 ///< default value is 0 (system-selected page size).
160 // The section flags definitions are the same in both 32- and 64-bit objects.
161 // Least significant 3 bits are reserved.
164 // The low order 16 bits of section flags denotes the section type.
165 // The high order 16 bits of section flags denotes the section subtype.
166 // For now, this is only used for DWARF sections.
176// Explicit extern template declarations.
273 // Relocation table is after Symbol table.
306 assert(
Reason == 0 &&
"Get symbol table index of the function only when "
307 "the e_reason field is 0.");
312 assert(
Reason != 0 &&
"Zero is not a valid trap exception reason code.");
322// Explicit extern template declarations.
363 // For getSectionOrLength(),
364 // If the symbol type is XTY_SD or XTY_CM, the csect length.
365 // If the symbol type is XTY_LD, the symbol table
366 // index of the containing csect.
367 // If the symbol type is XTY_ER, 0.
373 assert(Entry32 &&
"32-bit interface called on 64-bit object file.");
374 return Entry32->SectionOrLength;
378 assert(Entry64 &&
"64-bit interface called on 32-bit object file.");
379 return (
static_cast<uint64_t >(Entry64->SectionOrLengthHighByte) << 32) |
380 Entry64->SectionOrLengthLowByte;
383 #define GETVALUE(X) Entry32 ? Entry32->X : Entry64->X
386 return GETVALUE(ParameterHashIndex);
396 return Entry32 ?
reinterpret_cast<uintptr_t
>(Entry32)
397 :
reinterpret_cast<uintptr_t
>(Entry64);
412 assert(Entry32 &&
"32-bit interface called on 64-bit object file.");
413 return Entry32->StabInfoIndex;
417 assert(Entry32 &&
"32-bit interface called on 64-bit object file.");
418 return Entry32->StabSectNum;
422 assert(Entry64 &&
"64-bit interface called on 32-bit object file.");
423 return Entry64->AuxType;
427 return GETVALUE(SymbolAlignmentAndType);
457};
// 32-bit XCOFF file only.
515 // Packed field, see XR_* masks for details of packing.
524 // Returns the number of bits being relocated.
540 const void *FileHeader =
nullptr;
541 const void *AuxiliaryHeader =
nullptr;
542 const void *SectionHeaderTable =
nullptr;
544 const void *SymbolTblPtr =
nullptr;
549 template <
typename T>
const T *sectionHeaderTable()
const;
551 size_t getFileHeaderSize()
const;
552 size_t getSectionHeaderSize()
const;
556 uintptr_t getSectionHeaderTableAddress()
const;
557 uintptr_t getEndOfSymbolTableAddress()
const;
562 // This returns a pointer to the start of the storage for the name field of
563 // the 32-bit or 64-bit SectionHeader struct. This string is *not* necessarily
565 const char *getSectionNameInternal(
DataRefImpl Sec)
const;
567 static bool isReservedSectionNumber(int16_t SectionNumber);
569 // Constructor and "create" factory function. The constructor is only a thin
570 // wrapper around the base constructor. The "create" function fills out the
571 // XCOFF-specific information and performs the error checking along the way.
576 // Helper for parsing the StringTable. Returns an 'Error' if parsing failed
577 // and an XCOFFStringTable if parsing succeeded.
581 // Make a friend so it can call the private 'create' function.
585 void checkSectionAddress(uintptr_t Addr, uintptr_t TableAddr)
const;
589 std::numeric_limits<uint64_t>::max();
591 // Interface inherited from base classes.
629 /// \returns the relocation offset with the base address of the containing
630 /// section as zero, or InvalidRelocOffset on errors (such as a relocation
631 /// that does not refer to an address in any section).
648 // Below here is the non-inherited interface.
662 // File header related interfaces.
666 uint16_t getNumberOfSections()
const;
667 int32_t getTimeStamp()
const;
669 // Symbol table offset and entry count are handled differently between
670 // XCOFF32 and XCOFF64.
671 uint32_t getSymbolTableOffset32()
const;
672 uint64_t getSymbolTableOffset64()
const;
674 // Note that this value is signed and might return a negative value. Negative
675 // values are reserved for future use.
676 int32_t getRawNumberOfSymbolTableEntries32()
const;
678 // The sanitized value appropriate to use as an index into the symbol table.
679 uint32_t getLogicalNumberOfSymbolTableEntries32()
const;
681 uint32_t getNumberOfSymbolTableEntries64()
const;
683 // Return getLogicalNumberOfSymbolTableEntries32 or
684 // getNumberOfSymbolTableEntries64 depending on the object mode.
685 uint32_t getNumberOfSymbolTableEntries()
const;
687 uint32_t getSymbolIndex(uintptr_t SymEntPtr)
const;
690 return reinterpret_cast<uintptr_t
>(SymbolTblPtr) +
693 uintptr_t getSymbolEntryAddressByIndex(
uint32_t SymbolTableIndex)
const;
697 uint16_t getOptionalHeaderSize()
const;
700 // Section header table related interfaces.
710 void checkSymbolEntryPointer(uintptr_t SymbolEntPtr)
const;
712 // Relocation-related interfaces.
713 template <
typename T>
717 template <
typename Shdr,
typename Reloc>
720 // Loader section related interfaces.
723 // Exception-related interface.
724 template <
typename ExceptEnt>
727 // This function returns string table entry.
730 // This function returns the string table.
735 static uintptr_t getAdvancedSymbolEntryAddress(uintptr_t CurrentAddress,
740 std::optional<StringRef> tryGetCPUName()
const override;
798 :
SymbolRef(SymEntDataRef, OwningObjectPtr) {
799 assert(OwningObjectPtr &&
"OwningObjectPtr cannot be nullptr!");
801 "Symbol table entry pointer cannot be nullptr!");
831 getObject()->is64Bit() \
832 ? reinterpret_cast<const XCOFFSymbolEntry64 *>(getRawDataRefImpl().p)->X \
833 : reinterpret_cast<const XCOFFSymbolEntry32 *>(getRawDataRefImpl().p)->X
841 "This interface is for C_FILE only.");
842 return GETVALUE(CFileLanguageIdAndTypeId.LanguageId);
847 "This interface is for C_FILE only.");
848 return GETVALUE(CFileLanguageIdAndTypeId.CpuTypeId);
905/// This class provides methods to extract traceback table data from a buffer.
906/// The various accessors may reference the buffer provided via the constructor.
908 class XCOFFTracebackTable {
911 std::optional<SmallString<32>> ParmsType;
912 std::optional<uint32_t> TraceBackTableOffset;
913 std::optional<uint32_t> HandlerMask;
914 std::optional<uint32_t> NumOfCtlAnchors;
915 std::optional<SmallVector<uint32_t, 8>> ControlledStorageInfoDisp;
916 std::optional<StringRef> FunctionName;
917 std::optional<uint8_t> AllocaRegister;
918 std::optional<TBVectorExt> VecExt;
919 std::optional<uint8_t> ExtensionTable;
920 std::optional<uint64_t> EhInfoDisp;
923 bool Is64Bit =
false);
926 /// Parse an XCOFF Traceback Table from \a Ptr with \a Size bytes.
927 /// Returns an XCOFFTracebackTable upon successful parsing, otherwise an
928 /// Error is returned.
931 /// A pointer that points just past the initial 4 bytes of zeros at the
932 /// beginning of an XCOFF Traceback Table.
934 /// \param[in, out] Size
935 /// A pointer that points to the length of the XCOFF Traceback Table.
936 /// If the XCOFF Traceback Table is not parsed successfully or there are
937 /// extra bytes that are not recognized, \a Size will be updated to be the
938 /// size up to the end of the last successfully parsed field of the table.
977 return TraceBackTableOffset;
981 return NumOfCtlAnchors;
983 const std::optional<SmallVector<uint32_t, 8>> &
985 return ControlledStorageInfoDisp;
991 return AllocaRegister;
993 const std::optional<TBVectorExt> &
getVectorExt()
const {
return VecExt; }
995 return ExtensionTable;
1001}
// namespace object
1004#endif // LLVM_OBJECT_XCOFFOBJECTFILE_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static StringRef getSymbolName(SymbolKind SymKind)
#define LLVM_TEMPLATE_ABI
static bool isDebugSection(const SectionBase &Sec)
static FeatureBitset getFeatures(MCSubtargetInfo &STI, StringRef CPU, StringRef TuneCPU, StringRef FS, ArrayRef< StringRef > ProcNames, ArrayRef< SubtargetSubTypeKV > ProcDesc, ArrayRef< SubtargetFeatureKV > ProcFeatures)
static uint32_t getSectionFlags(const MachOObjectFile &O, DataRefImpl Sec)
This file defines the SmallString class.
This file defines the SmallVector class.
static unsigned getSymbolSectionID(const ObjectFile &O, SymbolRef Sym)
static uint32_t getFlags(const Symbol *Sym)
static std::unique_ptr< PDBSymbol > getSymbolType(const PDBSymbol &Symbol)
static bool is64Bit(const char *name)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
A range adaptor for a pair of iterators.
const SymbolicFile * getObject() const
DataRefImpl getRawDataRefImpl() const
static Expected< std::unique_ptr< ObjectFile > > createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType)
ObjectFile(unsigned int Type, MemoryBufferRef Source)
This is a value type class that represents a single symbol in the list of symbols in the object file.
const ObjectFile * getObject() const
virtual bool is64Bit() const =0
SmallString< 32 > getVectorParmsInfo() const
LLVM_ABI uint8_t getNumberOfVectorParms() const
static LLVM_ABI Expected< TBVectorExt > create(StringRef TBvectorStrRef)
LLVM_ABI bool isVRSavedOnStack() const
LLVM_ABI uint8_t getNumberOfVRSaved() const
LLVM_ABI bool hasVarArgs() const
LLVM_ABI bool hasVMXInstruction() const
XCOFF::StorageMappingClass getStorageMappingClass() const
XCOFFCsectAuxRef(const XCOFFCsectAuxEnt32 *Entry32)
uint32_t getSectionOrLength32() const
uint16_t getStabSectNum32() const
uint32_t getParameterHashIndex() const
uint8_t getSymbolType() const
static constexpr uint8_t SymbolTypeMask
uintptr_t getEntryAddress() const
uint64_t getSectionOrLength() const
uint16_t getAlignmentLog2() const
XCOFFCsectAuxRef(const XCOFFCsectAuxEnt64 *Entry64)
uint32_t getStabInfoIndex32() const
static constexpr size_t SymbolAlignmentBitOffset
uint64_t getSectionOrLength64() const
static constexpr uint8_t SymbolAlignmentMask
XCOFF::SymbolAuxType getAuxType64() const
uint16_t getTypeChkSectNum() const
uint8_t getSymbolAlignmentAndType() 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
relocation_iterator section_rel_end(DataRefImpl Sec) const override
const XCOFFAuxiliaryHeader32 * auxiliaryHeader32() const
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
Expected< uint64_t > getStartAddress() const override
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
bool isSectionVirtual(DataRefImpl Sec) const override
bool isSectionBSS(DataRefImpl Sec) const override
static bool classof(const Binary *B)
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
iterator_range< xcoff_symbol_iterator > xcoff_symbol_iterator_range
const XCOFFAuxiliaryHeader64 * auxiliaryHeader64() const
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
basic_symbol_iterator symbol_begin() const override
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
void moveRelocationNext(DataRefImpl &Rel) const override
StringRef getFileFormatName() const override
bool isSectionCompressed(DataRefImpl Sec) const override
static constexpr uint64_t InvalidRelocOffset
uintptr_t getSymbolByIndex(uint32_t Idx) const
uint64_t getSectionAddress(DataRefImpl Sec) const override
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
uint64_t getSectionAlignment(DataRefImpl Sec) const override
StringRef mapDebugSectionName(StringRef Name) const override
Maps a debug section name to a standard DWARF section name.
basic_symbol_iterator symbol_end() const override
Triple::ArchType getArch() const override
uint64_t getRelocationType(DataRefImpl Rel) const override
bool isSectionText(DataRefImpl Sec) const override
Expected< StringRef > getRawData(const char *Start, uint64_t Size, StringRef Name) 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
xcoff_symbol_iterator_range symbols() const
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
LLVM_ABI Expected< XCOFFCsectAuxRef > getXCOFFCsectAuxRef() const
LLVM_ABI Expected< bool > isFunction() const
int16_t getSectionNumber() const
LLVM_ABI bool isCsectSymbol() const
const XCOFFSymbolEntry64 * getSymbol64() const
XCOFFSymbolRef(DataRefImpl SymEntDataRef, const XCOFFObjectFile *OwningObjectPtr)
const XCOFFSymbolEntry32 * getSymbol32() const
uint16_t getSymbolType() const
uint32_t getValue32() const
uint64_t getValue() const
LLVM_ABI Expected< StringRef > getName() const
uint8_t getCPUTypeIddForCFile() const
uint64_t getValue64() const
uint8_t getNumberOfAuxEntries() const
uintptr_t getEntryAddress() const
XCOFF::StorageClass getStorageClass() const
uint8_t getLanguageIdForCFile() const
LLVM_ABI bool isOutOfLineEpilogOrPrologue() const
const std::optional< StringRef > & getFunctionName() const
const std::optional< uint64_t > & getEhInfoDisp() const
const std::optional< uint32_t > & getTraceBackTableOffset() const
LLVM_ABI uint8_t getNumOfGPRsSaved() const
LLVM_ABI bool hasTraceBackTableOffset() const
LLVM_ABI bool hasParmsOnStack() const
LLVM_ABI bool hasExtensionTable() const
const std::optional< SmallVector< uint32_t, 8 > > & getControlledStorageInfoDisp()
const std::optional< uint8_t > & getExtensionTable() const
const std::optional< SmallString< 32 > > & getParmsType() const
LLVM_ABI uint8_t getOnConditionDirective() const
LLVM_ABI uint8_t getLanguageID() const
LLVM_ABI uint8_t getNumOfFPRsSaved() const
LLVM_ABI bool isFloatingPointOperationLogOrAbortEnabled() const
LLVM_ABI bool isLRSaved() const
LLVM_ABI uint8_t getNumberOfFPParms() const
LLVM_ABI bool isFuncNamePresent() const
const std::optional< uint32_t > & getNumOfCtlAnchors()
LLVM_ABI bool isAllocaUsed() const
LLVM_ABI bool isGlobalLinkage() const
const std::optional< uint32_t > & getHandlerMask() const
LLVM_ABI bool isInternalProcedure() const
LLVM_ABI bool hasControlledStorage() const
LLVM_ABI bool isInterruptHandler() const
const std::optional< TBVectorExt > & getVectorExt() const
LLVM_ABI bool isFixup() const
LLVM_ABI bool isFloatingPointPresent() const
LLVM_ABI uint8_t getVersion() const
static LLVM_ABI Expected< XCOFFTracebackTable > create(const uint8_t *Ptr, uint64_t &Size, bool Is64Bits=false)
Parse an XCOFF Traceback Table from Ptr with Size bytes.
LLVM_ABI bool isBackChainStored() const
const std::optional< uint8_t > & getAllocaRegister() const
LLVM_ABI uint8_t getNumberOfFixedParms() const
LLVM_ABI bool isCRSaved() const
LLVM_ABI bool isTOCless() const
LLVM_ABI bool hasVectorInfo() const
const SymbolRef * operator->() const
const SymbolRef & operator*() const
symbol_iterator(SymbolRef Sym)
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.
constexpr size_t NameSize
StorageMappingClass
Storage Mapping Class definitions.
constexpr size_t SymbolTableEntrySize
constexpr size_t FileNamePadSize
@ XTY_LD
Label definition.
static constexpr const StringLiteral & getSectionName(DebugSectionKind SectionKind)
Return the name of the section.
LLVM_ABI bool doesXCOFFTracebackTableBegin(ArrayRef< uint8_t > Bytes)
content_iterator< SectionRef > section_iterator
content_iterator< BasicSymbolRef > basic_symbol_iterator
ExceptionSectionEntry< support::ubig64_t > ExceptionSectionEntry64
content_iterator< RelocationRef > relocation_iterator
ExceptionSectionEntry< support::ubig32_t > ExceptionSectionEntry32
detail::packed_endian_specific_integral< uint64_t, llvm::endianness::big, unaligned > ubig64_t
detail::packed_endian_specific_integral< int32_t, llvm::endianness::big, unaligned > big32_t
detail::packed_endian_specific_integral< uint16_t, llvm::endianness::big, unaligned > ubig16_t
detail::packed_endian_specific_integral< int16_t, llvm::endianness::big, unaligned > big16_t
detail::packed_endian_specific_integral< uint32_t, llvm::endianness::big, unaligned > ubig32_t
detail::packed_endian_specific_integral< int64_t, llvm::endianness::big, unaligned > big64_t
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
@ Ref
The access may reference the value stored in memory.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
support::ubig32_t SymbolIdx
support::ubig32_t TrapInstAddr
uint8_t getReason() const
uint64_t getTrapInstAddr() const
uint8_t getLangID() const
uint32_t getSymbolIndex() const
support::big32_t SymbolIndex
support::ubig32_t VirtualAddr
support::big16_t SectionNum
support::ubig64_t VirtualAddr
support::big16_t SectionNum
support::big32_t SymbolIndex
support::big32_t IsNameInStrTbl
XCOFF::StorageClass StorageClass
support::big16_t SectionNumber
char SymbolName[XCOFF::NameSize]
support::ubig32_t ParameterTypeCheck
support::ubig32_t ImportFileID
support::ubig32_t ParameterTypeCheck
XCOFF::StorageClass StorageClass
support::big16_t SectionNumber
support::ubig32_t ImportFileID
uint8_t ReservedZeros1[2]
support::ubig16_t LineNumLo
support::ubig16_t LineNumHi
uint8_t ReservedZeros2[12]
XCOFF::SymbolAuxType AuxType
support::ubig32_t LineNum
support::ubig16_t TypeChkSectNum
support::ubig16_t StabSectNum
support::ubig32_t ParameterHashIndex
support::ubig32_t SectionOrLength
support::ubig32_t StabInfoIndex
XCOFF::StorageMappingClass StorageMappingClass
uint8_t SymbolAlignmentAndType
XCOFF::StorageMappingClass StorageMappingClass
support::ubig32_t SectionOrLengthLowByte
support::ubig16_t TypeChkSectNum
support::ubig32_t SectionOrLengthHighByte
support::ubig32_t ParameterHashIndex
uint8_t SymbolAlignmentAndType
XCOFF::SymbolAuxType AuxType
support::ubig32_t SizeOfFunction
support::big32_t SymIdxOfNextBeyond
support::ubig64_t OffsetToExceptionTbl
XCOFF::SymbolAuxType AuxType
char NamePad[XCOFF::FileNamePadSize]
NameInStrTblType NameInStrTbl
XCOFF::SymbolAuxType AuxType
XCOFF::CFileStringType Type
char Name[XCOFF::NameSize+XCOFF::FileNamePadSize]
support::ubig32_t SizeOfFunction
support::ubig32_t PtrToLineNum
support::ubig32_t OffsetToExceptionTbl
support::big32_t SymIdxOfNextBeyond
support::big32_t SymIdxOfNextBeyond
support::ubig64_t PtrToLineNum
XCOFF::SymbolAuxType AuxType
support::ubig32_t SizeOfFunction
XCOFF::RelocationType Type
AddressType VirtualAddress
bool isFixupIndicated() const
support::ubig32_t SymbolIndex
uint8_t getRelocatedLength() const
bool isRelocationSigned() const
support::ubig32_t LengthOfSectionPortion
support::ubig32_t NumberOfRelocEnt
XCOFF::SymbolAuxType AuxType
support::ubig64_t LengthOfSectionPortion
support::ubig64_t NumberOfRelocEnt
support::ubig32_t SectionLength
support::ubig16_t NumberOfLineNum
support::ubig16_t NumberOfRelocEnt
uint8_t NumberOfAuxEntries
support::ubig16_t SymbolType
CFileLanguageIdAndTypeIdType CFileLanguageIdAndTypeId
XCOFF::StorageClass StorageClass
NameInStrTblType NameInStrTbl
char SymbolName[XCOFF::NameSize]
support::big16_t SectionNumber
support::big16_t SectionNumber
uint8_t NumberOfAuxEntries
support::ubig16_t SymbolType
CFileLanguageIdAndTypeIdType CFileLanguageIdAndTypeId
XCOFF::StorageClass StorageClass