LLVM: include/llvm/Object/ObjectFile.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_OBJECT_OBJECTFILE_H

14#define LLVM_OBJECT_OBJECTFILE_H

15

29#include

30#include

31#include

32

33namespace llvm {

34

35class SubtargetFeatures;

36

37namespace object {

38

39class COFFObjectFile;

40class MachOObjectFile;

42class SectionRef;

43class SymbolRef;

44class symbol_iterator;

45class WasmObjectFile;

46

48

50

51

54 const ObjectFile *OwningObject = nullptr;

55

56public:

59

61

63

67

68

69

70

72

75};

76

78

79

80

83

85 const ObjectFile *OwningObject = nullptr;

86

87public:

90

94

96

102

103

105

107

109

111

112 bool isBSS() const;

116

117

118

119

121

122

123

125

126

128

130

135 }

136

137

138

140

143};

144

147

150};

151

154 return std::tie(LHS.SectionIndex, LHS.Address) <

155 std::tie(RHS.SectionIndex, RHS.Address);

156}

157

160 return std::tie(LHS.SectionIndex, LHS.Address) ==

161 std::tie(RHS.SectionIndex, RHS.Address);

162}

163

165

166

167

170

171public:

179 };

180

185 }

186

188

189

191

192

193

195

196

200

201

202

204

206};

207

209public:

214

217 return static_cast<const SymbolRef*>(&P);

218 }

219

222 return static_cast<const SymbolRef&>(P);

223 }

224};

225

226

227

228

230 virtual void anchor();

231

232protected:

234

237 }

238

239

240

241

242

243

244

245

246

248

259

260

262

275

285

286

294

298 };

299

301

302public:

306

309 if (!SymbolFlagsOrErr)

310

314 }

315

317 return std::vector();

318 }

319

323 }

324

327

331 }

332

334

335

336

338

344 return std::nullopt;

345 };

349 };

350

351

353

354

356

357

359

360

363 const;

364

365

366

367

368

371

374 bool InitContent = true);

378 }

379

381 return v->isObject();

382 }

383

386

389

392

396 size_t MachOFilesetEntryOffset = 0);

397

400

403};

404

405

406

408public:

412 : Predicate(std::move(Pred)), Iterator(Begin), End(End) {

413 scanPredicate();

414 }

417 ++Iterator;

418 scanPredicate();

419 return *this;

420 }

422 return Iterator != Other.Iterator;

423 }

424

425private:

426 void scanPredicate() {

427 while (Iterator != End && !Predicate(*Iterator)) {

428 ++Iterator;

429 }

430 }

434};

435

436

437

439public:

441 : Predicate(std::move(Pred)), Object(Obj) {}

445 }

449 }

450

451private:

454};

455

456

459

462}

463

466}

467

470}

471

474}

475

478}

479

482}

483

486}

487

490 return cast(O);

491}

492

493

496 : SectionPimpl(SectionP)

497 , OwningObject(Owner) {}

498

500 return OwningObject == Other.OwningObject &&

501 SectionPimpl == Other.SectionPimpl;

502}

503

505 return !(*this == Other);

506}

507

509 assert(OwningObject == Other.OwningObject);

510 return SectionPimpl < Other.SectionPimpl;

511}

512

515}

516

519}

520

523}

524

527}

528

531}

532

536 if (!Res)

538 return StringRef(reinterpret_cast<const char *>(Res->data()), Res->size());

539}

540

544}

545

548}

549

551 return OwningObject->isSectionText(SectionPimpl);

552}

553

555 return OwningObject->isSectionData(SectionPimpl);

556}

557

559 return OwningObject->isSectionBSS(SectionPimpl);

560}

561

564}

565

568}

569

572}

573

576}

577

580}

581

584}

585

588}

589

592}

593

596}

597

599 return SectionPimpl;

600}

601

603 return OwningObject;

604}

605

606

609 : RelocationPimpl(RelocationP)

610 , OwningObject(Owner) {}

611

613 return RelocationPimpl == Other.RelocationPimpl;

614}

615

618}

619

622}

623

626}

627

630}

631

634}

635

637 return RelocationPimpl;

638}

639

641 return OwningObject;

642}

643

644}

645

649 return A == B;

650 }

653 }

656 TS.p = (uintptr_t)-1;

658 }

662 }

663};

664

665}

666

667#endif

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

Lightweight error class with error context and mandatory checking.

Tagged union holding either a T or a Error.

Error takeError()

Take ownership of the stored error.

const char * getBufferStart() const

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.

Triple - Helper class for working with autoconf configuration names.

The instances of the Type class are immutable: once they are created, they are never changed.

A range adaptor for a pair of iterators.

This is a value type class that represents a single symbol in the list of symbols in the object file.

const SymbolicFile * getObject() const

DataRefImpl getRawDataRefImpl() const

This class is the base class for all object file types.

virtual bool isBerkeleyText(DataRefImpl Sec) const

virtual Expected< section_iterator > getRelocatedSection(DataRefImpl Sec) const

uint64_t getCommonSymbolSize(DataRefImpl Symb) const

virtual uint64_t getSectionIndex(DataRefImpl Sec) const =0

virtual Expected< StringRef > getSectionName(DataRefImpl Sec) const =0

virtual uint64_t getSectionAlignment(DataRefImpl Sec) const =0

virtual bool isBerkeleyData(DataRefImpl Sec) const

virtual bool isSectionBSS(DataRefImpl Sec) const =0

virtual Expected< StringRef > getSymbolName(DataRefImpl Symb) const =0

virtual void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const =0

virtual std::vector< SectionRef > dynamic_relocation_sections() const

static Expected< std::unique_ptr< MachOObjectFile > > createMachOObjectFile(MemoryBufferRef Object, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0, size_t MachOFilesetEntryOffset=0)

Create a MachOObjectFile instance from a given buffer.

static Expected< std::unique_ptr< COFFObjectFile > > createCOFFObjectFile(MemoryBufferRef Object)

virtual section_iterator section_end() const =0

virtual llvm::binaryformat::Swift5ReflectionSectionKind mapReflectionSectionNameToEnumValue(StringRef SectionName) const

virtual uint8_t getBytesInAddress() const =0

The number of bytes used to represent an address in this object file format.

Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override

virtual Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const =0

virtual Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const =0

virtual bool isSectionVirtual(DataRefImpl Sec) const =0

virtual uint64_t getRelocationType(DataRefImpl Rel) const =0

static Expected< std::unique_ptr< ObjectFile > > createELFObjectFile(MemoryBufferRef Object, bool InitContent=true)

virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const =0

virtual Expected< SubtargetFeatures > getFeatures() const =0

virtual bool isSectionCompressed(DataRefImpl Sec) const =0

virtual uint64_t getSectionSize(DataRefImpl Sec) const =0

Triple makeTriple() const

Create a triple from the data in this object file.

virtual bool isSectionText(DataRefImpl Sec) const =0

virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const =0

section_iterator_range sections() const

virtual StringRef getFileFormatName() const =0

virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const =0

virtual void moveSectionNext(DataRefImpl &Sec) const =0

virtual bool isDebugSection(DataRefImpl Sec) const

virtual void setARMSubArch(Triple &TheTriple) const

virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const =0

virtual uint64_t getSectionAddress(DataRefImpl Sec) const =0

static Expected< std::unique_ptr< WasmObjectFile > > createWasmObjectFile(MemoryBufferRef Object)

static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)

virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const

ObjectFile(const ObjectFile &other)=delete

virtual StringRef mapDebugSectionName(StringRef Name) const

Maps a debug section name to a standard DWARF section name.

symbol_iterator_range symbols() const

virtual bool isSectionData(DataRefImpl Sec) const =0

Expected< uint64_t > getSymbolValue(DataRefImpl Symb) const

iterator_range< section_iterator > section_iterator_range

virtual void moveRelocationNext(DataRefImpl &Rel) const =0

const uint8_t * base() const

virtual Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const =0

virtual bool isRelocatableObject() const =0

True if this is a relocatable object (.o/.obj).

virtual Triple::OSType getOS() const

bool isReflectionSectionStrippable(llvm::binaryformat::Swift5ReflectionSectionKind ReflectionSectionKind) const

True if the reflection section can be stripped by the linker.

virtual bool hasDebugInfo() const

static Expected< std::unique_ptr< ObjectFile > > createGOFFObjectFile(MemoryBufferRef Object)

static bool classof(const Binary *v)

static Expected< std::unique_ptr< ObjectFile > > createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType)

virtual Expected< uint64_t > getStartAddress() const

virtual relocation_iterator section_rel_end(DataRefImpl Sec) const =0

virtual Triple::ArchType getArch() const =0

ObjectFile & operator=(const ObjectFile &other)=delete

virtual bool isSectionStripped(DataRefImpl Sec) const

virtual std::optional< StringRef > tryGetCPUName() const

virtual bool isSectionBitcode(DataRefImpl Sec) const

iterator_range< symbol_iterator > symbol_iterator_range

virtual uint64_t getRelocationOffset(DataRefImpl Rel) const =0

static Expected< std::unique_ptr< ObjectFile > > createObjectFile(MemoryBufferRef Object)

virtual Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const =0

virtual section_iterator section_begin() const =0

This is a value type class that represents a single relocation in the list of relocations in the obje...

bool operator==(const RelocationRef &Other) const

uint64_t getOffset() const

symbol_iterator getSymbol() const

const ObjectFile * getObject() const

void getTypeName(SmallVectorImpl< char > &Result) const

Get a string that represents the type of this relocation.

DataRefImpl getRawDataRefImpl() const

A filtered iterator for SectionRefs that skips sections based on some given predicate.

SectionFilterIterator & operator++()

const SectionRef & operator*() const

bool operator!=(const SectionFilterIterator &Other) const

SectionFilterIterator(SectionFilterPredicate Pred, const section_iterator &Begin, const section_iterator &End)

Creates an iterator range of SectionFilterIterators for a given Object and predicate.

SectionFilterIterator begin()

SectionFilter(SectionFilterPredicate Pred, const ObjectFile &Obj)

SectionFilterIterator end()

This is a value type class that represents a single section in the list of sections in the object fil...

uint64_t getIndex() const

bool operator<(const SectionRef &Other) const

DataRefImpl getRawDataRefImpl() const

bool operator!=(const SectionRef &Other) const

bool isDebugSection() const

Whether this section is a debug section.

iterator_range< relocation_iterator > relocations() const

bool isData() const

Whether this section contains data, not instructions.

Expected< StringRef > getContents() const

relocation_iterator relocation_end() const

bool isCompressed() const

bool isBSS() const

Whether this section contains BSS uninitialized data.

bool containsSymbol(SymbolRef S) const

bool operator==(const SectionRef &Other) const

uint64_t getAddress() const

bool isBerkeleyText() const

Whether this section will be placed in the text segment, according to the Berkeley size format.

bool isText() const

Whether this section contains instructions.

relocation_iterator relocation_begin() const

Align getAlignment() const

Get the alignment of this section.

bool isBerkeleyData() const

Whether this section will be placed in the data segment, according to the Berkeley size format.

const ObjectFile * getObject() const

Expected< StringRef > getName() const

Expected< section_iterator > getRelocatedSection() const

Returns the related section if this section contains relocations.

This is a value type class that represents a single symbol in the list of symbols in the object file.

Expected< SymbolRef::Type > getType() const

SymbolRef(const BasicSymbolRef &B)

Expected< StringRef > getName() const

uint32_t getAlignment() const

Get the alignment of this symbol as the actual value (not log 2).

const ObjectFile * getObject() const

Expected< uint64_t > getAddress() const

Returns the symbol virtual address (i.e.

Expected< uint64_t > getValue() const

Return the value of the symbol depending on the object this can be an offset or a virtual address.

Expected< section_iterator > getSection() const

Get section this symbol is defined in reference to.

uint64_t getCommonSize() const

virtual basic_symbol_iterator symbol_begin() const =0

virtual basic_symbol_iterator symbol_end() const =0

virtual Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const =0

const content_type & operator*() const

const SymbolRef * operator->() const

symbol_iterator(const basic_symbol_iterator &B)

const SymbolRef & operator*() const

symbol_iterator(SymbolRef Sym)

This class implements an extremely fast bulk output stream that can only output to a stream.

This provides a very simple, boring adaptor for a begin and end iterator into a range type.

Swift5ReflectionSectionKind

static Expected< const T * > getObject(MemoryBufferRef M, const void *Ptr, const uint64_t Size=sizeof(T))

bool operator<(const ELFSymbolRef &A, const ELFSymbolRef &B)

content_iterator< SectionRef > section_iterator

std::function< bool(const SectionRef &)> SectionFilterPredicate

raw_ostream & operator<<(raw_ostream &OS, const SectionedAddress &Addr)

This is an optimization pass for GlobalISel generic memory operations.

iterator_range< T > make_range(T x, T y)

Convenience function for iterating over sub-ranges.

bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)

void report_fatal_error(Error Err, bool gen_crash_diag=true)

Report a serious error, calling any installed error handler.

StringRef getTypeName()

We provide a function which tries to compute the (demangled) name of a type statically.

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

Error errorCodeToError(std::error_code EC)

Helper for converting an std::error_code to a Error.

hash_code hash_combine(const Ts &...args)

Combine values into a single hash_code.

Implement std::hash so that hash_code can be used in STL containers.

This struct is a compact representation of a valid (non-zero power of two) alignment.

static unsigned getHashValue(const object::SectionRef &Sec)

static object::SectionRef getEmptyKey()

static object::SectionRef getTombstoneKey()

static bool isEqual(const object::SectionRef &A, const object::SectionRef &B)

An information struct used to provide DenseMap with the various necessary components for a given valu...

This struct is a compact representation of a valid (power of two) or undefined (0) alignment.

Align valueOrOne() const

For convenience, returns a valid alignment or 1 if undefined.

file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...

@ unknown

Unrecognized file.

static const uint64_t UndefSection

struct llvm::object::DataRefImpl::@371 d