LLVM 22.0.0git
ObjectFile.h
Go to the documentation of this file.
1//===- ObjectFile.h - File format independent object file -------*- 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 a file format independent ObjectFile class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_OBJECT_OBJECTFILE_H
14#define LLVM_OBJECT_OBJECTFILE_H
15
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/Hashing.h"
18#include "llvm/ADT/StringRef.h"
22#include "llvm/Object/Binary.h"
23#include "llvm/Object/Error.h"
27#include "llvm/Support/Error.h"
30#include <cassert>
31#include <cstdint>
32#include <memory>
33
34namespace llvm {
35
36class SubtargetFeatures;
37
38namespace object {
39
40class COFFObjectFile;
41class MachOObjectFile;
42class ObjectFile;
43class SectionRef;
44class SymbolRef;
45class symbol_iterator;
46class WasmObjectFile;
47class DXContainerObjectFile;
48
50
51typedef std::function<bool(const SectionRef &)> SectionFilterPredicate;
52/// This is a value type class that represents a single relocation in the list
53/// of relocations in the object file.
55 DataRefImpl RelocationPimpl;
56 const ObjectFile *OwningObject = nullptr;
57
58public:
59 RelocationRef() = default;
60 RelocationRef(DataRefImpl RelocationP, const ObjectFile *Owner);
61
62 bool operator==(const RelocationRef &Other) const;
63
64 void moveNext();
65
66 uint64_t getOffset() const;
68 uint64_t getType() const;
69
70 /// Get a string that represents the type of this relocation.
71 ///
72 /// This is for display purposes only.
73 void getTypeName(SmallVectorImpl<char> &Result) const;
74
76 const ObjectFile *getObject() const;
77};
78
80
81/// This is a value type class that represents a single section in the list of
82/// sections in the object file.
84 friend class SymbolRef;
85
86 DataRefImpl SectionPimpl;
87 const ObjectFile *OwningObject = nullptr;
88
89public:
90 SectionRef() = default;
91 SectionRef(DataRefImpl SectionP, const ObjectFile *Owner);
92
93 bool operator==(const SectionRef &Other) const;
94 bool operator!=(const SectionRef &Other) const;
95 bool operator<(const SectionRef &Other) const;
96
97 void moveNext();
98
100 uint64_t getAddress() const;
101 uint64_t getIndex() const;
102 uint64_t getSize() const;
104
105 /// Get the alignment of this section.
106 Align getAlignment() const;
107
108 bool isCompressed() const;
109 /// Whether this section contains instructions.
110 bool isText() const;
111 /// Whether this section contains data, not instructions.
112 bool isData() const;
113 /// Whether this section contains BSS uninitialized data.
114 bool isBSS() const;
115 bool isVirtual() const;
116 bool isBitcode() const;
117 bool isStripped() const;
118
119 /// Whether this section will be placed in the text segment, according to the
120 /// Berkeley size format. This is true if the section is allocatable, and
121 /// contains either code or readonly data.
122 bool isBerkeleyText() const;
123 /// Whether this section will be placed in the data segment, according to the
124 /// Berkeley size format. This is true if the section is allocatable and
125 /// contains data (e.g. PROGBITS), but is not text.
126 bool isBerkeleyData() const;
127
128 /// Whether this section is a debug section.
129 bool isDebugSection() const;
130
131 LLVM_ABI bool containsSymbol(SymbolRef S) const;
132
137 }
138
139 /// Returns the related section if this section contains relocations. The
140 /// returned section may or may not have applied its relocations.
142
144 const ObjectFile *getObject() const;
145};
146
149
152};
153
154inline bool operator<(const SectionedAddress &LHS,
155 const SectionedAddress &RHS) {
156 return std::tie(LHS.SectionIndex, LHS.Address) <
157 std::tie(RHS.SectionIndex, RHS.Address);
158}
159
160inline bool operator==(const SectionedAddress &LHS,
161 const SectionedAddress &RHS) {
162 return std::tie(LHS.SectionIndex, LHS.Address) ==
163 std::tie(RHS.SectionIndex, RHS.Address);
164}
165
167
168/// This is a value type class that represents a single symbol in the list of
169/// symbols in the object file.
170class SymbolRef : public BasicSymbolRef {
171 friend class SectionRef;
172
173public:
174 enum Type {
175 ST_Unknown, // Type not specified
181 };
182
183 SymbolRef() = default;
184 SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
186 assert(isa<ObjectFile>(BasicSymbolRef::getObject()));
187 }
188
190 /// Returns the symbol virtual address (i.e. address at which it will be
191 /// mapped).
193
194 /// Return the value of the symbol depending on the object this can be an
195 /// offset or a virtual address.
197
198 /// Get the alignment of this symbol as the actual value (not log 2).
199 uint32_t getAlignment() const;
200 uint64_t getCommonSize() const;
202
203 /// Get section this symbol is defined in reference to. Result is
204 /// section_end() if it is undefined or is an absolute symbol.
206
207 const ObjectFile *getObject() const;
208};
209
211public:
214 : basic_symbol_iterator(SymbolRef(B->getRawDataRefImpl(),
215 cast<ObjectFile>(B->getObject()))) {}
216
217 const SymbolRef *operator->() const {
219 return static_cast<const SymbolRef*>(&P);
220 }
221
222 const SymbolRef &operator*() const {
224 return static_cast<const SymbolRef&>(P);
225 }
226};
227
228/// This class is the base class for all object file types. Concrete instances
229/// of this object are created by createObjectFile, which figures out which type
230/// to create.
232 virtual void anchor();
233
234protected:
235 ObjectFile(unsigned int Type, MemoryBufferRef Source);
236
237 const uint8_t *base() const {
238 return reinterpret_cast<const uint8_t *>(Data.getBufferStart());
239 }
240
241 // These functions are for SymbolRef to call internally. The main goal of
242 // this is to allow SymbolRef::SymbolPimpl to point directly to the symbol
243 // entry in the memory mapped object file. SymbolPimpl cannot contain any
244 // virtual functions because then it could not point into the memory mapped
245 // file.
246 //
247 // Implementations assume that the DataRefImpl is valid and has not been
248 // modified externally. It's UB otherwise.
249 friend class SymbolRef;
250
252 Error printSymbolName(raw_ostream &OS,
253 DataRefImpl Symb) const override;
255 virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const = 0;
256 virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
261
262 // Same as above for SectionRef.
263 friend class SectionRef;
264
265 virtual void moveSectionNext(DataRefImpl &Sec) const = 0;
267 virtual uint64_t getSectionAddress(DataRefImpl Sec) const = 0;
268 virtual uint64_t getSectionIndex(DataRefImpl Sec) const = 0;
269 virtual uint64_t getSectionSize(DataRefImpl Sec) const = 0;
273 virtual bool isSectionCompressed(DataRefImpl Sec) const = 0;
274 virtual bool isSectionText(DataRefImpl Sec) const = 0;
275 virtual bool isSectionData(DataRefImpl Sec) const = 0;
276 virtual bool isSectionBSS(DataRefImpl Sec) const = 0;
277 // A section is 'virtual' if its contents aren't present in the object image.
278 virtual bool isSectionVirtual(DataRefImpl Sec) const = 0;
279 virtual bool isSectionBitcode(DataRefImpl Sec) const;
280 virtual bool isSectionStripped(DataRefImpl Sec) const;
281 virtual bool isBerkeleyText(DataRefImpl Sec) const;
282 virtual bool isBerkeleyData(DataRefImpl Sec) const;
283 virtual bool isDebugSection(DataRefImpl Sec) const;
286 virtual Expected<section_iterator> getRelocatedSection(DataRefImpl Sec) const;
287
288 // Same as above for RelocationRef.
289 friend class RelocationRef;
290 virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
293 virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
295 SmallVectorImpl<char> &Result) const = 0;
296
300 };
301
303
304public:
305 ObjectFile() = delete;
306 ObjectFile(const ObjectFile &other) = delete;
307 ObjectFile &operator=(const ObjectFile &other) = delete;
308
310 Expected<uint32_t> SymbolFlagsOrErr = getSymbolFlags(Symb);
311 if (!SymbolFlagsOrErr)
312 // TODO: Actually report errors helpfully.
313 report_fatal_error(SymbolFlagsOrErr.takeError());
314 assert(*SymbolFlagsOrErr & SymbolRef::SF_Common);
315 return getCommonSymbolSizeImpl(Symb);
316 }
317
318 virtual std::vector<SectionRef> dynamic_relocation_sections() const {
319 return std::vector<SectionRef>();
320 }
321
324 return symbol_iterator_range(symbol_begin(), symbol_end());
325 }
326
327 virtual section_iterator section_begin() const = 0;
328 virtual section_iterator section_end() const = 0;
329
332 return section_iterator_range(section_begin(), section_end());
333 }
334
335 virtual bool hasDebugInfo() const;
336
337 /// The number of bytes used to represent an address in this object
338 /// file format.
339 virtual uint8_t getBytesInAddress() const = 0;
340
341 virtual StringRef getFileFormatName() const = 0;
342 virtual Triple::ArchType getArch() const = 0;
343 virtual Triple::OSType getOS() const { return Triple::UnknownOS; }
345 virtual std::optional<StringRef> tryGetCPUName() const {
346 return std::nullopt;
347 };
348 virtual void setARMSubArch(Triple &TheTriple) const { }
350 return errorCodeToError(object_error::parse_failed);
351 };
352
353 /// Create a triple from the data in this object file.
354 Triple makeTriple() const;
355
356 /// Maps a debug section name to a standard DWARF section name.
358
359 /// True if this is a relocatable object (.o/.obj).
360 virtual bool isRelocatableObject() const = 0;
361
362 /// True if the reflection section can be stripped by the linker.
363 bool isReflectionSectionStrippable(
365 const;
366
367 /// @returns Pointer to ObjectFile subclass to handle this type of object.
368 /// @param ObjectPath The path to the object file. ObjectPath.isObject must
369 /// return true.
370 /// Create ObjectFile from path.
372 createObjectFile(StringRef ObjectPath);
373
375 createObjectFile(MemoryBufferRef Object, llvm::file_magic Type,
376 bool InitContent = true);
379 return createObjectFile(Object, llvm::file_magic::unknown);
380 }
381
382 static bool classof(const Binary *v) {
383 return v->isObject();
384 }
385
387 createCOFFObjectFile(MemoryBufferRef Object);
388
390 createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType);
391
393 createELFObjectFile(MemoryBufferRef Object, bool InitContent = true);
394
396 createMachOObjectFile(MemoryBufferRef Object, uint32_t UniversalCputype = 0,
397 uint32_t UniversalIndex = 0,
398 size_t MachOFilesetEntryOffset = 0);
399
401 createGOFFObjectFile(MemoryBufferRef Object);
402
404 createWasmObjectFile(MemoryBufferRef Object);
405
407 createDXContainerObjectFile(MemoryBufferRef Object);
408};
409
410/// A filtered iterator for SectionRefs that skips sections based on some given
411/// predicate.
413public:
415 const section_iterator &Begin,
416 const section_iterator &End)
417 : Predicate(std::move(Pred)), Iterator(Begin), End(End) {
418 scanPredicate();
419 }
420 const SectionRef &operator*() const { return *Iterator; }
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 }
437 section_iterator Iterator;
439};
440
441/// Creates an iterator range of SectionFilterIterators for a given Object and
442/// predicate.
444public:
446 : Predicate(std::move(Pred)), Object(Obj) {}
449 Object.section_end());
450 }
453 Object.section_end());
454 }
455
456private:
458 const ObjectFile &Object;
459};
460
461// Inline function definitions.
462inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
463 : BasicSymbolRef(SymbolP, Owner) {}
464
467}
468
471}
472
475}
476
479}
480
483}
484
487}
488
491}
492
493inline const ObjectFile *SymbolRef::getObject() const {
495 return cast<ObjectFile>(O);
496}
497
498/// SectionRef
500 const ObjectFile *Owner)
501 : SectionPimpl(SectionP)
502 , OwningObject(Owner) {}
503
504inline bool SectionRef::operator==(const SectionRef &Other) const {
505 return OwningObject == Other.OwningObject &&
506 SectionPimpl == Other.SectionPimpl;
507}
508
509inline bool SectionRef::operator!=(const SectionRef &Other) const {
510 return !(*this == Other);
511}
512
513inline bool SectionRef::operator<(const SectionRef &Other) const {
514 assert(OwningObject == Other.OwningObject);
515 return SectionPimpl < Other.SectionPimpl;
516}
517
518inline void SectionRef::moveNext() {
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)
542 return Res.takeError();
543 return StringRef(reinterpret_cast<const char *>(Res->data()), Res->size());
544}
545
547 return MaybeAlign(OwningObject->getSectionAlignment(SectionPimpl))
548 .valueOrOne();
549}
550
551inline bool SectionRef::isCompressed() const {
552 return OwningObject->isSectionCompressed(SectionPimpl);
553}
554
555inline bool SectionRef::isText() const {
556 return OwningObject->isSectionText(SectionPimpl);
557}
558
559inline bool SectionRef::isData() const {
560 return OwningObject->isSectionData(SectionPimpl);
561}
562
563inline bool SectionRef::isBSS() const {
564 return OwningObject->isSectionBSS(SectionPimpl);
565}
566
567inline bool SectionRef::isVirtual() const {
568 return OwningObject->isSectionVirtual(SectionPimpl);
569}
570
571inline bool SectionRef::isBitcode() const {
572 return OwningObject->isSectionBitcode(SectionPimpl);
573}
574
575inline bool SectionRef::isStripped() const {
576 return OwningObject->isSectionStripped(SectionPimpl);
577}
578
579inline bool SectionRef::isBerkeleyText() const {
580 return OwningObject->isBerkeleyText(SectionPimpl);
581}
582
583inline bool SectionRef::isBerkeleyData() const {
584 return OwningObject->isBerkeleyData(SectionPimpl);
585}
586
587inline bool SectionRef::isDebugSection() const {
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
607inline const ObjectFile *SectionRef::getObject() const {
608 return OwningObject;
609}
610
611/// RelocationRef
613 const ObjectFile *Owner)
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} // end namespace object
650
651template <> struct DenseMapInfo<object::SectionRef> {
652 static bool isEqual(const object::SectionRef &A,
653 const object::SectionRef &B) {
654 return A == B;
655 }
657 return object::SectionRef({}, nullptr);
658 }
661 TS.p = (uintptr_t)-1;
662 return object::SectionRef(TS, nullptr);
663 }
664 static unsigned getHashValue(const object::SectionRef &Sec) {
666 return hash_combine(Raw.p, Raw.d.a, Raw.d.b);
667 }
668};
669
670} // end namespace llvm
671
672#endif // LLVM_OBJECT_OBJECTFILE_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_ABI
Definition: Compiler.h:213
static bool hasDebugInfo(const MachineFunction *MF)
uint64_t Addr
std::string Name
static bool isDebugSection(const SectionBase &Sec)
Definition: ELFObjcopy.cpp:49
bool End
Definition: ELF_riscv.cpp:480
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define P(N)
raw_pwrite_stream & OS
static uint64_t getSymbolValue(const MCSymbolCOFF &Symbol, const MCAssembler &Asm)
Value * RHS
Value * LHS
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
Error takeError()
Take ownership of the stored error.
Definition: Error.h:612
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
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.
Definition: SymbolicFile.h:104
const SymbolicFile * getObject() const
Definition: SymbolicFile.h:215
DataRefImpl getRawDataRefImpl() const
Definition: SymbolicFile.h:211
This class is the base class for all object file types.
Definition: ObjectFile.h:231
virtual bool isBerkeleyText(DataRefImpl Sec) const
Definition: ObjectFile.cpp:90
virtual Expected< section_iterator > getRelocatedSection(DataRefImpl Sec) const
Definition: ObjectFile.cpp:106
uint64_t getCommonSymbolSize(DataRefImpl Symb) const
Definition: ObjectFile.h:309
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
Definition: ObjectFile.cpp:94
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.
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
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
Definition: ObjectFile.cpp:98
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
virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const
Definition: ObjectFile.cpp:78
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
Definition: ObjectFile.cpp:57
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
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
Definition: ObjectFile.cpp:88
virtual std::optional< StringRef > tryGetCPUName() const
Definition: ObjectFile.h:345
virtual bool isSectionBitcode(DataRefImpl Sec) const
Definition: ObjectFile.cpp:80
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
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...
Definition: ObjectFile.h:54
uint64_t getType() const
Definition: ObjectFile.h:633
bool operator==(const RelocationRef &Other) const
Definition: ObjectFile.h:617
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
Creates an iterator range of SectionFilterIterators for a given Object and predicate.
Definition: ObjectFile.h:443
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
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
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
Definition: ObjectFile.cpp:47
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
SymbolRef(const BasicSymbolRef &B)
Definition: ObjectFile.h:185
Expected< StringRef > getName() const
Definition: ObjectFile.h:465
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
const content_type & operator*() const
Definition: SymbolicFile.h:84
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.
Definition: raw_ostream.h:53
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define UINT64_MAX
Definition: DataTypes.h:77
Swift5ReflectionSectionKind
Definition: Swift.h:14
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
std::function< bool(const SectionRef &)> SectionFilterPredicate
Definition: ObjectFile.h:51
LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const SectionedAddress &Addr)
Definition: ObjectFile.cpp:35
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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.
Definition: TypeName.h:40
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
@ Other
Any other memory.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition: Casting.h:565
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:111
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:595
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
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...
Definition: DenseMapInfo.h:54
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Definition: Alignment.h:141
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
Definition: Magic.h:21
@ unknown
Unrecognized file.
Definition: Magic.h:23
static const uint64_t UndefSection
Definition: ObjectFile.h:148
struct llvm::object::DataRefImpl::@378 d