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

30#include

31#include

32#include

33

34namespace llvm {

35

37

39

48

50

52

53

56 const ObjectFile *OwningObject = nullptr;

57

58public:

61

63

65

69

70

71

72

74

77};

78

80

81

82

85

87 const ObjectFile *OwningObject = nullptr;

88

89public:

92

96

98

104

105

107

109

111

113

114 bool isBSS() const;

118

119

120

121

123

124

125

127

128

130

132

138

139

140

142

145};

146

153

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

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

158}

159

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

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

164}

165

167

168

169

172

173public:

182

188

190

191

193

194

195

197

198

202

203

204

206

208};

209

211public:

216

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

220 }

221

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

225 }

226};

227

228

229

230

232 virtual void anchor();

233

234protected:

236

238 return reinterpret_cast<const uint8_t *>(Data.getBufferStart());

239 }

240

241

242

243

244

245

246

247

248

250

261

262

264

277

287

288

296

301

303

304public:

308

311 if (!SymbolFlagsOrErr)

312

316 }

317

319 return std::vector();

320 }

321

326

329

334

336

337

338

340

346 return std::nullopt;

347 };

352

353

354 Triple makeTriple() const;

355

356

358

359

361

362

365 const;

366

367

368

369

370

373

376 bool InitContent = true);

381

383 return v->isObject();

384 }

385

388

390 createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType);

391

393 createELFObjectFile(MemoryBufferRef Object, bool InitContent = true);

394

398 size_t MachOFilesetEntryOffset = 0);

399

402

405

408};

409

410

411

413public:

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

418 scanPredicate();

419 }

422 ++Iterator;

423 scanPredicate();

424 return *this;

425 }

427 return Iterator != Other.Iterator;

428 }

429

430private:

431 void scanPredicate() {

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

433 ++Iterator;

434 }

435 }

439};

440

441

442

444public:

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

449 Object.section_end());

450 }

453 Object.section_end());

454 }

455

456private:

459};

460

461

464

468

472

476

480

484

488

492

497

498

501 : SectionPimpl(SectionP)

502 , OwningObject(Owner) {}

503

505 return OwningObject == Other.OwningObject &&

506 SectionPimpl == Other.SectionPimpl;

507}

508

510 return !(*this == Other);

511}

512

514 assert(OwningObject == Other.OwningObject);

515 return SectionPimpl < Other.SectionPimpl;

516}

517

519 return OwningObject->moveSectionNext(SectionPimpl);

520}

521

523 return OwningObject->getSectionName(SectionPimpl);

524}

525

527 return OwningObject->getSectionAddress(SectionPimpl);

528}

529

531 return OwningObject->getSectionIndex(SectionPimpl);

532}

533

535 return OwningObject->getSectionSize(SectionPimpl);

536}

537

540 OwningObject->getSectionContents(SectionPimpl);

541 if (!Res)

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

544}

545

547 return MaybeAlign(OwningObject->getSectionAlignment(SectionPimpl))

549}

550

552 return OwningObject->isSectionCompressed(SectionPimpl);

553}

554

556 return OwningObject->isSectionText(SectionPimpl);

557}

558

560 return OwningObject->isSectionData(SectionPimpl);

561}

562

564 return OwningObject->isSectionBSS(SectionPimpl);

565}

566

568 return OwningObject->isSectionVirtual(SectionPimpl);

569}

570

572 return OwningObject->isSectionBitcode(SectionPimpl);

573}

574

576 return OwningObject->isSectionStripped(SectionPimpl);

577}

578

580 return OwningObject->isBerkeleyText(SectionPimpl);

581}

582

584 return OwningObject->isBerkeleyData(SectionPimpl);

585}

586

588 return OwningObject->isDebugSection(SectionPimpl);

589}

590

592 return OwningObject->section_rel_begin(SectionPimpl);

593}

594

596 return OwningObject->section_rel_end(SectionPimpl);

597}

598

600 return OwningObject->getRelocatedSection(SectionPimpl);

601}

602

604 return SectionPimpl;

605}

606

608 return OwningObject;

609}

610

611

614 : RelocationPimpl(RelocationP)

615 , OwningObject(Owner) {}

616

618 return RelocationPimpl == Other.RelocationPimpl;

619}

620

622 return OwningObject->moveRelocationNext(RelocationPimpl);

623}

624

626 return OwningObject->getRelocationOffset(RelocationPimpl);

627}

628

630 return OwningObject->getRelocationSymbol(RelocationPimpl);

631}

632

634 return OwningObject->getRelocationType(RelocationPimpl);

635}

636

638 return OwningObject->getRelocationTypeName(RelocationPimpl, Result);

639}

640

642 return RelocationPimpl;

643}

644

646 return OwningObject;

647}

648

649}

650

661 TS.p = (uintptr_t)-1;

663 }

668};

669

670}

671

672#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

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

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

static ManagedStatic< DebugCounterOwner > Owner

static bool hasDebugInfo(const MachineFunction *MF)

static bool isDebugSection(const SectionBase &Sec)

static uint64_t getSymbolValue(const MCSymbolCOFF &Symbol, const MCAssembler &Asm)

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.

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.

Manages the enabling and disabling of subtarget specific features.

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.

Definition ObjectFile.h:231

virtual bool isBerkeleyText(DataRefImpl Sec) const

virtual Expected< section_iterator > getRelocatedSection(DataRefImpl Sec) const

uint64_t getCommonSymbolSize(DataRefImpl Symb) const

Definition ObjectFile.h:309

virtual uint64_t getSectionIndex(DataRefImpl Sec) const =0

friend class RelocationRef

Definition ObjectFile.h:289

friend class SymbolRef

Definition ObjectFile.h:249

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

Definition ObjectFile.h:318

virtual section_iterator section_end() const =0

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

Definition ObjectFile.h:298

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

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

virtual bool isSectionText(DataRefImpl Sec) const =0

virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const =0

section_iterator_range sections() const

Definition ObjectFile.h:331

friend class SectionRef

Definition ObjectFile.h:263

virtual StringRef getFileFormatName() const =0

virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const =0

virtual void moveSectionNext(DataRefImpl &Sec) const =0

virtual void setARMSubArch(Triple &TheTriple) const

Definition ObjectFile.h:348

virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const =0

virtual uint64_t getSectionAddress(DataRefImpl Sec) const =0

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.

Definition ObjectFile.h:357

symbol_iterator_range symbols() const

Definition ObjectFile.h:323

virtual bool isSectionData(DataRefImpl Sec) const =0

Expected< uint64_t > getSymbolValue(DataRefImpl Symb) const

iterator_range< section_iterator > section_iterator_range

Definition ObjectFile.h:330

virtual void moveRelocationNext(DataRefImpl &Rel) const =0

const uint8_t * base() const

Definition ObjectFile.h:237

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

Definition ObjectFile.h:343

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

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

static bool classof(const Binary *v)

Definition ObjectFile.h:382

virtual Expected< uint64_t > getStartAddress() const

Definition ObjectFile.h:349

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

Definition ObjectFile.h:345

virtual bool isSectionBitcode(DataRefImpl Sec) const

iterator_range< symbol_iterator > symbol_iterator_range

Definition ObjectFile.h:322

virtual uint64_t getRelocationOffset(DataRefImpl Rel) const =0

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

Definition ObjectFile.h:378

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

ObjectFile(unsigned int Type, MemoryBufferRef Source)

virtual section_iterator section_begin() const =0

uint64_t getType() const

Definition ObjectFile.h:633

bool operator==(const RelocationRef &Other) const

Definition ObjectFile.h:617

void moveNext()

Definition ObjectFile.h:621

uint64_t getOffset() const

Definition ObjectFile.h:625

symbol_iterator getSymbol() const

Definition ObjectFile.h:629

const ObjectFile * getObject() const

Definition ObjectFile.h:645

void getTypeName(SmallVectorImpl< char > &Result) const

Get a string that represents the type of this relocation.

Definition ObjectFile.h:637

DataRefImpl getRawDataRefImpl() const

Definition ObjectFile.h:641

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

Definition ObjectFile.h:412

SectionFilterIterator & operator++()

Definition ObjectFile.h:421

const SectionRef & operator*() const

Definition ObjectFile.h:420

bool operator!=(const SectionFilterIterator &Other) const

Definition ObjectFile.h:426

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

Definition ObjectFile.h:414

SectionFilterIterator begin()

Definition ObjectFile.h:447

SectionFilter(SectionFilterPredicate Pred, const ObjectFile &Obj)

Definition ObjectFile.h:445

SectionFilterIterator end()

Definition ObjectFile.h:451

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

Definition ObjectFile.h:83

void moveNext()

Definition ObjectFile.h:518

uint64_t getIndex() const

Definition ObjectFile.h:530

bool operator<(const SectionRef &Other) const

Definition ObjectFile.h:513

DataRefImpl getRawDataRefImpl() const

Definition ObjectFile.h:603

friend class SymbolRef

Definition ObjectFile.h:84

bool operator!=(const SectionRef &Other) const

Definition ObjectFile.h:509

bool isDebugSection() const

Whether this section is a debug section.

Definition ObjectFile.h:587

iterator_range< relocation_iterator > relocations() const

Definition ObjectFile.h:135

bool isData() const

Whether this section contains data, not instructions.

Definition ObjectFile.h:559

Expected< StringRef > getContents() const

Definition ObjectFile.h:538

relocation_iterator relocation_end() const

Definition ObjectFile.h:595

bool isCompressed() const

Definition ObjectFile.h:551

bool isStripped() const

Definition ObjectFile.h:575

bool isBSS() const

Whether this section contains BSS uninitialized data.

Definition ObjectFile.h:563

uint64_t getSize() const

Definition ObjectFile.h:534

LLVM_ABI bool containsSymbol(SymbolRef S) const

bool operator==(const SectionRef &Other) const

Definition ObjectFile.h:504

uint64_t getAddress() const

Definition ObjectFile.h:526

bool isBerkeleyText() const

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

Definition ObjectFile.h:579

bool isVirtual() const

Definition ObjectFile.h:567

bool isText() const

Whether this section contains instructions.

Definition ObjectFile.h:555

relocation_iterator relocation_begin() const

Definition ObjectFile.h:591

Align getAlignment() const

Get the alignment of this section.

Definition ObjectFile.h:546

bool isBerkeleyData() const

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

Definition ObjectFile.h:583

const ObjectFile * getObject() const

Definition ObjectFile.h:607

bool isBitcode() const

Definition ObjectFile.h:571

Expected< StringRef > getName() const

Definition ObjectFile.h:522

Expected< section_iterator > getRelocatedSection() const

Returns the related section if this section contains relocations.

Definition ObjectFile.h:599

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

Definition ObjectFile.h:170

Expected< SymbolRef::Type > getType() const

Definition ObjectFile.h:489

Type

Definition ObjectFile.h:174

@ ST_Other

Definition ObjectFile.h:176

@ ST_Unknown

Definition ObjectFile.h:175

@ ST_Function

Definition ObjectFile.h:180

@ ST_File

Definition ObjectFile.h:179

@ ST_Data

Definition ObjectFile.h:177

@ ST_Debug

Definition ObjectFile.h:178

SymbolRef(const BasicSymbolRef &B)

Definition ObjectFile.h:185

Expected< StringRef > getName() const

Definition ObjectFile.h:465

friend class SectionRef

Definition ObjectFile.h:171

uint32_t getAlignment() const

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

Definition ObjectFile.h:477

const ObjectFile * getObject() const

Definition ObjectFile.h:493

Expected< uint64_t > getAddress() const

Returns the symbol virtual address (i.e.

Definition ObjectFile.h:469

Expected< uint64_t > getValue() const

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

Definition ObjectFile.h:473

Expected< section_iterator > getSection() const

Get section this symbol is defined in reference to.

Definition ObjectFile.h:485

uint64_t getCommonSize() const

Definition ObjectFile.h:481

virtual basic_symbol_iterator symbol_begin() const =0

virtual basic_symbol_iterator symbol_end() const =0

SymbolicFile(unsigned int Type, MemoryBufferRef Source)

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

const BasicSymbolRef & operator*() const

Definition ObjectFile.h:210

const SymbolRef * operator->() const

Definition ObjectFile.h:217

symbol_iterator(const basic_symbol_iterator &B)

Definition ObjectFile.h:213

const SymbolRef & operator*() const

Definition ObjectFile.h:222

symbol_iterator(SymbolRef Sym)

Definition ObjectFile.h:212

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

Definition ObjectFile.h:49

content_iterator< BasicSymbolRef > basic_symbol_iterator

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

Definition ObjectFile.h:160

content_iterator< RelocationRef > relocation_iterator

Definition ObjectFile.h:79

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

Definition ObjectFile.h:51

LLVM_ABI 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.

LLVM_GET_TYPE_NAME_CONSTEXPR StringRef getTypeName()

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

LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

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.

LLVM_ABI 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)

Definition ObjectFile.h:664

static object::SectionRef getEmptyKey()

Definition ObjectFile.h:656

static object::SectionRef getTombstoneKey()

Definition ObjectFile.h:659

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

Definition ObjectFile.h:652

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.

Definition ObjectFile.h:147

uint64_t Address

Definition ObjectFile.h:150

static const uint64_t UndefSection

Definition ObjectFile.h:148

uint64_t SectionIndex

Definition ObjectFile.h:151

struct llvm::object::DataRefImpl::@005117267142344013370254144343227032034000327225 d