LLVM  10.0.0svn
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 
17 #include "llvm/Object/ObjectFile.h"
18 
19 namespace llvm {
20 namespace object {
21 
25 
26  // Unix time value, value of 0 indicates no timestamp.
27  // Negative values are reserved.
29 
30  support::ubig32_t SymbolTableOffset; // File offset to symbol table.
34 };
35 
39 
40  // Unix time value, value of 0 indicates no timestamp.
41  // Negative values are reserved.
43 
44  support::ubig64_t SymbolTableOffset; // File offset to symbol table.
48 };
49 
61 
62  StringRef getName() const;
63 };
64 
76  char Padding[4];
77 
78  StringRef getName() const;
79 };
80 
82  enum { NAME_IN_STR_TBL_MAGIC = 0x0 };
83  typedef struct {
84  support::big32_t Magic; // Zero indicates name in string table.
87 
88  typedef struct {
89  uint8_t LanguageId;
90  uint8_t CpuTypeId;
92 
93  union {
96  };
97 
98  support::ubig32_t Value; // Symbol value; storage class-dependent.
100 
101  union {
104  };
105 
108 };
109 
112  const char *Data;
113 };
114 
123 };
124 
126  typedef struct {
127  support::big32_t Magic; // Zero indicates name in string table.
129  char NamePad[XCOFF::FileNamePadSize];
131  union {
134  };
136  uint8_t ReservedZeros[2];
137  uint8_t AuxType; // 64-bit XCOFF file only.
138 };
139 
144  uint8_t Pad[10];
145 };
146 
147 class XCOFFObjectFile : public ObjectFile {
148 private:
149  const void *FileHeader = nullptr;
150  const void *SectionHeaderTable = nullptr;
151 
152  const XCOFFSymbolEntry *SymbolTblPtr = nullptr;
153  XCOFFStringTable StringTable = {0, nullptr};
154 
155  const XCOFFFileHeader32 *fileHeader32() const;
156  const XCOFFFileHeader64 *fileHeader64() const;
157 
158  const XCOFFSectionHeader32 *sectionHeaderTable32() const;
159  const XCOFFSectionHeader64 *sectionHeaderTable64() const;
160 
161  size_t getFileHeaderSize() const;
162  size_t getSectionHeaderSize() const;
163 
164  const XCOFFSectionHeader32 *toSection32(DataRefImpl Ref) const;
165  const XCOFFSectionHeader64 *toSection64(DataRefImpl Ref) const;
166  uintptr_t getSectionHeaderTableAddress() const;
167  uintptr_t getEndOfSymbolTableAddress() const;
168 
169  // This returns a pointer to the start of the storage for the name field of
170  // the 32-bit or 64-bit SectionHeader struct. This string is *not* necessarily
171  // null-terminated.
172  const char *getSectionNameInternal(DataRefImpl Sec) const;
173 
174  // This function returns string table entry.
175  Expected<StringRef> getStringTableEntry(uint32_t Offset) const;
176 
177  static bool isReservedSectionNumber(int16_t SectionNumber);
178 
179  // Constructor and "create" factory function. The constructor is only a thin
180  // wrapper around the base constructor. The "create" function fills out the
181  // XCOFF-specific information and performs the error checking along the way.
182  XCOFFObjectFile(unsigned Type, MemoryBufferRef Object);
183  static Expected<std::unique_ptr<XCOFFObjectFile>> create(unsigned Type,
184  MemoryBufferRef MBR);
185 
186  // Helper for parsing the StringTable. Returns an 'Error' if parsing failed
187  // and an XCOFFStringTable if parsing succeeded.
188  static Expected<XCOFFStringTable> parseStringTable(const XCOFFObjectFile *Obj,
189  uint64_t Offset);
190 
191  // Make a friend so it can call the private 'create' function.
194 
195  void checkSectionAddress(uintptr_t Addr, uintptr_t TableAddr) const;
196 
197 public:
198  // Interface inherited from base classes.
199  void moveSymbolNext(DataRefImpl &Symb) const override;
200  uint32_t getSymbolFlags(DataRefImpl Symb) const override;
201  basic_symbol_iterator symbol_begin() const override;
202  basic_symbol_iterator symbol_end() const override;
203 
204  Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
205  Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
206  uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
207  uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
209  Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
210 
211  void moveSectionNext(DataRefImpl &Sec) const override;
212  Expected<StringRef> getSectionName(DataRefImpl Sec) const override;
213  uint64_t getSectionAddress(DataRefImpl Sec) const override;
214  uint64_t getSectionIndex(DataRefImpl Sec) const override;
215  uint64_t getSectionSize(DataRefImpl Sec) const override;
217  getSectionContents(DataRefImpl Sec) const override;
218  uint64_t getSectionAlignment(DataRefImpl Sec) const override;
219  bool isSectionCompressed(DataRefImpl Sec) const override;
220  bool isSectionText(DataRefImpl Sec) const override;
221  bool isSectionData(DataRefImpl Sec) const override;
222  bool isSectionBSS(DataRefImpl Sec) const override;
223 
224  bool isSectionVirtual(DataRefImpl Sec) const override;
225  relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
226  relocation_iterator section_rel_end(DataRefImpl Sec) const override;
227 
228  void moveRelocationNext(DataRefImpl &Rel) const override;
229  uint64_t getRelocationOffset(DataRefImpl Rel) const override;
230  symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
231  uint64_t getRelocationType(DataRefImpl Rel) const override;
232  void getRelocationTypeName(DataRefImpl Rel,
233  SmallVectorImpl<char> &Result) const override;
234 
235  section_iterator section_begin() const override;
236  section_iterator section_end() const override;
237  uint8_t getBytesInAddress() const override;
238  StringRef getFileFormatName() const override;
239  Triple::ArchType getArch() const override;
240  SubtargetFeatures getFeatures() const override;
241  Expected<uint64_t> getStartAddress() const override;
242  bool isRelocatableObject() const override;
243 
244  // Below here is the non-inherited interface.
245  bool is64Bit() const;
246 
248  assert(!is64Bit() && "Symbol table handling not supported yet.");
249  return SymbolTblPtr;
250  }
251 
253  getSymbolSectionName(const XCOFFSymbolEntry *SymEntPtr) const;
254 
255  const XCOFFSymbolEntry *toSymbolEntry(DataRefImpl Ref) const;
256 
257  // File header related interfaces.
258  uint16_t getMagic() const;
259  uint16_t getNumberOfSections() const;
260  int32_t getTimeStamp() const;
261 
262  // Symbol table offset and entry count are handled differently between
263  // XCOFF32 and XCOFF64.
264  uint32_t getSymbolTableOffset32() const;
265  uint64_t getSymbolTableOffset64() const;
266 
267  // Note that this value is signed and might return a negative value. Negative
268  // values are reserved for future use.
269  int32_t getRawNumberOfSymbolTableEntries32() const;
270 
271  // The sanitized value appropriate to use as an index into the symbol table.
272  uint32_t getLogicalNumberOfSymbolTableEntries32() const;
273 
274  uint32_t getNumberOfSymbolTableEntries64() const;
275  uint32_t getSymbolIndex(uintptr_t SymEntPtr) const;
276 
277  Expected<StringRef> getCFileName(const XCOFFFileAuxEnt *CFileEntPtr) const;
278  uint16_t getOptionalHeaderSize() const;
279  uint16_t getFlags() const;
280 
281  // Section header table related interfaces.
282  ArrayRef<XCOFFSectionHeader32> sections32() const;
283  ArrayRef<XCOFFSectionHeader64> sections64() const;
284 
285  int32_t getSectionFlags(DataRefImpl Sec) const;
286  Expected<DataRefImpl> getSectionByNum(int16_t Num) const;
287 
288  void checkSymbolEntryPointer(uintptr_t SymbolEntPtr) const;
289 }; // XCOFFObjectFile
290 
292  const DataRefImpl SymEntDataRef;
293  const XCOFFObjectFile *const OwningObjectPtr;
294 
295 public:
297  const XCOFFObjectFile *OwningObjectPtr)
298  : SymEntDataRef(SymEntDataRef), OwningObjectPtr(OwningObjectPtr){};
299 
300  XCOFF::StorageClass getStorageClass() const;
301  uint8_t getNumberOfAuxEntries() const;
302  const XCOFFCsectAuxEnt32 *getXCOFFCsectAuxEnt32() const;
303  uint16_t getType() const;
304  int16_t getSectionNumber() const;
305 
306  bool hasCsectAuxEnt() const;
307  bool isFunction() const;
308 };
309 
310 } // namespace object
311 } // namespace llvm
312 
313 #endif // LLVM_OBJECT_XCOFFOBJECTFILE_H
support::big64_t FileOffsetToLineNumberInfo
uint64_t getMagic()
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
XCOFF::StorageMappingClass StorageMappingClass
This class is the base class for all object file types.
Definition: ObjectFile.h:221
support::big32_t NumberOfSymTableEntries
static uint32_t getSectionFlags(const MachOObjectFile &O, DataRefImpl Sec)
static Expected< std::unique_ptr< ObjectFile > > createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType)
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
static StringRef getSymbolName(SymbolKind SymKind)
CFileLanguageIdAndTypeIdType CFileLanguageIdAndTypeId
The access may reference the value stored in memory.
static StringRef getName(Value *V)
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
bool isReservedSectionNumber(int32_t SectionNumber)
Definition: COFF.h:722
StorageClass
Definition: XCOFF.h:76
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
support::ubig32_t FileOffsetToRelocationInfo
support::ubig16_t NumberOfSections
support::big64_t FileOffsetToRelocationInfo
static FeatureBitset getFeatures(StringRef CPU, StringRef FS, ArrayRef< SubtargetSubTypeKV > ProcDesc, ArrayRef< SubtargetFeatureKV > ProcFeatures)
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:28
static bool is64Bit(const char *name)
XCOFF::StorageClass StorageClass
static wasm::ValType getType(const TargetRegisterClass *RC)
XCOFFSymbolRef(DataRefImpl SymEntDataRef, const XCOFFObjectFile *OwningObjectPtr)
FileType
Defines the file type this file represents.
Definition: InterfaceFile.h:65
const XCOFFSymbolEntry * getPointerToSymbolTable() const
support::ubig64_t SymbolTableOffset
static uint32_t getFlags(const Symbol *Sym)
Definition: TapiFile.cpp:28
support::ubig16_t NumberOfSections
Manages the enabling and disabling of subtarget specific features.
XCOFF::CFileStringType Type
static std::unique_ptr< PDBSymbol > getSymbolType(const PDBSymbol &Symbol)
Definition: UDTLayout.cpp:33
CFileStringType
Definition: XCOFF.h:174
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
support::ubig32_t SymbolTableOffset
support::ubig32_t NumberOfSymTableEntries
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
support::ubig32_t FileOffsetToLineNumberInfo