LLVM 19.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"
26#include "llvm/Support/Error.h"
29#include <cassert>
30#include <cstdint>
31#include <memory>
32
33namespace llvm {
34
35class SubtargetFeatures;
36
37namespace object {
38
39class COFFObjectFile;
40class MachOObjectFile;
41class ObjectFile;
42class SectionRef;
43class SymbolRef;
44class symbol_iterator;
45class WasmObjectFile;
46
48
49typedef std::function<bool(const SectionRef &)> SectionFilterPredicate;
50/// This is a value type class that represents a single relocation in the list
51/// of relocations in the object file.
53 DataRefImpl RelocationPimpl;
54 const ObjectFile *OwningObject = nullptr;
55
56public:
57 RelocationRef() = default;
58 RelocationRef(DataRefImpl RelocationP, const ObjectFile *Owner);
59
60 bool operator==(const RelocationRef &Other) const;
61
62 void moveNext();
63
64 uint64_t getOffset() const;
66 uint64_t getType() const;
67
68 /// Get a string that represents the type of this relocation.
69 ///
70 /// This is for display purposes only.
71 void getTypeName(SmallVectorImpl<char> &Result) const;
72
74 const ObjectFile *getObject() const;
75};
76
78
79/// This is a value type class that represents a single section in the list of
80/// sections in the object file.
82 friend class SymbolRef;
83
84 DataRefImpl SectionPimpl;
85 const ObjectFile *OwningObject = nullptr;
86
87public:
88 SectionRef() = default;
89 SectionRef(DataRefImpl SectionP, const ObjectFile *Owner);
90
91 bool operator==(const SectionRef &Other) const;
92 bool operator!=(const SectionRef &Other) const;
93 bool operator<(const SectionRef &Other) const;
94
95 void moveNext();
96
98 uint64_t getAddress() const;
99 uint64_t getIndex() const;
100 uint64_t getSize() const;
102
103 /// Get the alignment of this section.
104 Align getAlignment() const;
105
106 bool isCompressed() const;
107 /// Whether this section contains instructions.
108 bool isText() const;
109 /// Whether this section contains data, not instructions.
110 bool isData() const;
111 /// Whether this section contains BSS uninitialized data.
112 bool isBSS() const;
113 bool isVirtual() const;
114 bool isBitcode() const;
115 bool isStripped() const;
116
117 /// Whether this section will be placed in the text segment, according to the
118 /// Berkeley size format. This is true if the section is allocatable, and
119 /// contains either code or readonly data.
120 bool isBerkeleyText() const;
121 /// Whether this section will be placed in the data segment, according to the
122 /// Berkeley size format. This is true if the section is allocatable and
123 /// contains data (e.g. PROGBITS), but is not text.
124 bool isBerkeleyData() const;
125
126 /// Whether this section is a debug section.
127 bool isDebugSection() const;
128
129 bool containsSymbol(SymbolRef S) const;
130
135 }
136
137 /// Returns the related section if this section contains relocations. The
138 /// returned section may or may not have applied its relocations.
140
142 const ObjectFile *getObject() const;
143};
144
147
150};
151
152inline bool operator<(const SectionedAddress &LHS,
153 const SectionedAddress &RHS) {
154 return std::tie(LHS.SectionIndex, LHS.Address) <
155 std::tie(RHS.SectionIndex, RHS.Address);
156}
157
158inline bool operator==(const SectionedAddress &LHS,
159 const SectionedAddress &RHS) {
160 return std::tie(LHS.SectionIndex, LHS.Address) ==
161 std::tie(RHS.SectionIndex, RHS.Address);
162}
163
165
166/// This is a value type class that represents a single symbol in the list of
167/// symbols in the object file.
168class SymbolRef : public BasicSymbolRef {
169 friend class SectionRef;
170
171public:
172 enum Type {
173 ST_Unknown, // Type not specified
179 };
180
181 SymbolRef() = default;
182 SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
184 assert(isa<ObjectFile>(BasicSymbolRef::getObject()));
185 }
186
188 /// Returns the symbol virtual address (i.e. address at which it will be
189 /// mapped).
191
192 /// Return the value of the symbol depending on the object this can be an
193 /// offset or a virtual address.
195
196 /// Get the alignment of this symbol as the actual value (not log 2).
197 uint32_t getAlignment() const;
198 uint64_t getCommonSize() const;
200
201 /// Get section this symbol is defined in reference to. Result is
202 /// end_sections() if it is undefined or is an absolute symbol.
204
205 const ObjectFile *getObject() const;
206};
207
209public:
212 : basic_symbol_iterator(SymbolRef(B->getRawDataRefImpl(),
213 cast<ObjectFile>(B->getObject()))) {}
214
215 const SymbolRef *operator->() const {
217 return static_cast<const SymbolRef*>(&P);
218 }
219
220 const SymbolRef &operator*() const {
222 return static_cast<const SymbolRef&>(P);
223 }
224};
225
226/// This class is the base class for all object file types. Concrete instances
227/// of this object are created by createObjectFile, which figures out which type
228/// to create.
229class ObjectFile : public SymbolicFile {
230 virtual void anchor();
231
232protected:
233 ObjectFile(unsigned int Type, MemoryBufferRef Source);
234
235 const uint8_t *base() const {
236 return reinterpret_cast<const uint8_t *>(Data.getBufferStart());
237 }
238
239 // These functions are for SymbolRef to call internally. The main goal of
240 // this is to allow SymbolRef::SymbolPimpl to point directly to the symbol
241 // entry in the memory mapped object file. SymbolPimpl cannot contain any
242 // virtual functions because then it could not point into the memory mapped
243 // file.
244 //
245 // Implementations assume that the DataRefImpl is valid and has not been
246 // modified externally. It's UB otherwise.
247 friend class SymbolRef;
248
251 DataRefImpl Symb) const override;
253 virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const = 0;
254 virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
259
260 // Same as above for SectionRef.
261 friend class SectionRef;
262
263 virtual void moveSectionNext(DataRefImpl &Sec) const = 0;
265 virtual uint64_t getSectionAddress(DataRefImpl Sec) const = 0;
266 virtual uint64_t getSectionIndex(DataRefImpl Sec) const = 0;
267 virtual uint64_t getSectionSize(DataRefImpl Sec) const = 0;
271 virtual bool isSectionCompressed(DataRefImpl Sec) const = 0;
272 virtual bool isSectionText(DataRefImpl Sec) const = 0;
273 virtual bool isSectionData(DataRefImpl Sec) const = 0;
274 virtual bool isSectionBSS(DataRefImpl Sec) const = 0;
275 // A section is 'virtual' if its contents aren't present in the object image.
276 virtual bool isSectionVirtual(DataRefImpl Sec) const = 0;
277 virtual bool isSectionBitcode(DataRefImpl Sec) const;
278 virtual bool isSectionStripped(DataRefImpl Sec) const;
279 virtual bool isBerkeleyText(DataRefImpl Sec) const;
280 virtual bool isBerkeleyData(DataRefImpl Sec) const;
281 virtual bool isDebugSection(DataRefImpl Sec) const;
285
286 // Same as above for RelocationRef.
287 friend class RelocationRef;
288 virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
291 virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
293 SmallVectorImpl<char> &Result) const = 0;
294
298 };
299
301
302public:
303 ObjectFile() = delete;
304 ObjectFile(const ObjectFile &other) = delete;
305 ObjectFile &operator=(const ObjectFile &other) = delete;
306
308 Expected<uint32_t> SymbolFlagsOrErr = getSymbolFlags(Symb);
309 if (!SymbolFlagsOrErr)
310 // TODO: Actually report errors helpfully.
311 report_fatal_error(SymbolFlagsOrErr.takeError());
312 assert(*SymbolFlagsOrErr & SymbolRef::SF_Common);
313 return getCommonSymbolSizeImpl(Symb);
314 }
315
316 virtual std::vector<SectionRef> dynamic_relocation_sections() const {
317 return std::vector<SectionRef>();
318 }
319
323 }
324
325 virtual section_iterator section_begin() const = 0;
326 virtual section_iterator section_end() const = 0;
327
331 }
332
333 virtual bool hasDebugInfo() const;
334
335 /// The number of bytes used to represent an address in this object
336 /// file format.
337 virtual uint8_t getBytesInAddress() const = 0;
338
339 virtual StringRef getFileFormatName() const = 0;
340 virtual Triple::ArchType getArch() const = 0;
341 virtual Triple::OSType getOS() const { return Triple::UnknownOS; }
343 virtual std::optional<StringRef> tryGetCPUName() const {
344 return std::nullopt;
345 };
346 virtual void setARMSubArch(Triple &TheTriple) const { }
349 };
350
351 /// Create a triple from the data in this object file.
352 Triple makeTriple() const;
353
354 /// Maps a debug section name to a standard DWARF section name.
356
357 /// True if this is a relocatable object (.o/.obj).
358 virtual bool isRelocatableObject() const = 0;
359
360 /// True if the reflection section can be stripped by the linker.
363 const;
364
365 /// @returns Pointer to ObjectFile subclass to handle this type of object.
366 /// @param ObjectPath The path to the object file. ObjectPath.isObject must
367 /// return true.
368 /// Create ObjectFile from path.
370 createObjectFile(StringRef ObjectPath);
371
374 bool InitContent = true);
378 }
379
380 static bool classof(const Binary *v) {
381 return v->isObject();
382 }
383
386
388 createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType);
389
391 createELFObjectFile(MemoryBufferRef Object, bool InitContent = true);
392
394 createMachOObjectFile(MemoryBufferRef Object, uint32_t UniversalCputype = 0,
395 uint32_t UniversalIndex = 0,
396 size_t MachOFilesetEntryOffset = 0);
397
400
403};
404
405/// A filtered iterator for SectionRefs that skips sections based on some given
406/// predicate.
408public:
410 const section_iterator &Begin,
411 const section_iterator &End)
412 : Predicate(std::move(Pred)), Iterator(Begin), End(End) {
413 scanPredicate();
414 }
415 const SectionRef &operator*() const { return *Iterator; }
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 }
431 SectionFilterPredicate Predicate;
432 section_iterator Iterator;
434};
435
436/// Creates an iterator range of SectionFilterIterators for a given Object and
437/// predicate.
439public:
441 : Predicate(std::move(Pred)), Object(Obj) {}
443 return SectionFilterIterator(Predicate, Object.section_begin(),
444 Object.section_end());
445 }
447 return SectionFilterIterator(Predicate, Object.section_end(),
448 Object.section_end());
449 }
450
451private:
452 SectionFilterPredicate Predicate;
453 const ObjectFile &Object;
454};
455
456// Inline function definitions.
457inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
458 : BasicSymbolRef(SymbolP, Owner) {}
459
462}
463
466}
467
470}
471
474}
475
478}
479
482}
483
486}
487
488inline const ObjectFile *SymbolRef::getObject() const {
490 return cast<ObjectFile>(O);
491}
492
493/// SectionRef
495 const ObjectFile *Owner)
496 : SectionPimpl(SectionP)
497 , OwningObject(Owner) {}
498
499inline bool SectionRef::operator==(const SectionRef &Other) const {
500 return OwningObject == Other.OwningObject &&
501 SectionPimpl == Other.SectionPimpl;
502}
503
504inline bool SectionRef::operator!=(const SectionRef &Other) const {
505 return !(*this == Other);
506}
507
508inline bool SectionRef::operator<(const SectionRef &Other) const {
509 assert(OwningObject == Other.OwningObject);
510 return SectionPimpl < Other.SectionPimpl;
511}
512
513inline void SectionRef::moveNext() {
514 return OwningObject->moveSectionNext(SectionPimpl);
515}
516
518 return OwningObject->getSectionName(SectionPimpl);
519}
520
522 return OwningObject->getSectionAddress(SectionPimpl);
523}
524
526 return OwningObject->getSectionIndex(SectionPimpl);
527}
528
530 return OwningObject->getSectionSize(SectionPimpl);
531}
532
535 OwningObject->getSectionContents(SectionPimpl);
536 if (!Res)
537 return Res.takeError();
538 return StringRef(reinterpret_cast<const char *>(Res->data()), Res->size());
539}
540
542 return MaybeAlign(OwningObject->getSectionAlignment(SectionPimpl))
543 .valueOrOne();
544}
545
546inline bool SectionRef::isCompressed() const {
547 return OwningObject->isSectionCompressed(SectionPimpl);
548}
549
550inline bool SectionRef::isText() const {
551 return OwningObject->isSectionText(SectionPimpl);
552}
553
554inline bool SectionRef::isData() const {
555 return OwningObject->isSectionData(SectionPimpl);
556}
557
558inline bool SectionRef::isBSS() const {
559 return OwningObject->isSectionBSS(SectionPimpl);
560}
561
562inline bool SectionRef::isVirtual() const {
563 return OwningObject->isSectionVirtual(SectionPimpl);
564}
565
566inline bool SectionRef::isBitcode() const {
567 return OwningObject->isSectionBitcode(SectionPimpl);
568}
569
570inline bool SectionRef::isStripped() const {
571 return OwningObject->isSectionStripped(SectionPimpl);
572}
573
574inline bool SectionRef::isBerkeleyText() const {
575 return OwningObject->isBerkeleyText(SectionPimpl);
576}
577
578inline bool SectionRef::isBerkeleyData() const {
579 return OwningObject->isBerkeleyData(SectionPimpl);
580}
581
582inline bool SectionRef::isDebugSection() const {
583 return OwningObject->isDebugSection(SectionPimpl);
584}
585
587 return OwningObject->section_rel_begin(SectionPimpl);
588}
589
591 return OwningObject->section_rel_end(SectionPimpl);
592}
593
595 return OwningObject->getRelocatedSection(SectionPimpl);
596}
597
599 return SectionPimpl;
600}
601
602inline const ObjectFile *SectionRef::getObject() const {
603 return OwningObject;
604}
605
606/// RelocationRef
608 const ObjectFile *Owner)
609 : RelocationPimpl(RelocationP)
610 , OwningObject(Owner) {}
611
613 return RelocationPimpl == Other.RelocationPimpl;
614}
615
617 return OwningObject->moveRelocationNext(RelocationPimpl);
618}
619
621 return OwningObject->getRelocationOffset(RelocationPimpl);
622}
623
625 return OwningObject->getRelocationSymbol(RelocationPimpl);
626}
627
629 return OwningObject->getRelocationType(RelocationPimpl);
630}
631
633 return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
634}
635
637 return RelocationPimpl;
638}
639
641 return OwningObject;
642}
643
644} // end namespace object
645
646template <> struct DenseMapInfo<object::SectionRef> {
647 static bool isEqual(const object::SectionRef &A,
648 const object::SectionRef &B) {
649 return A == B;
650 }
652 return object::SectionRef({}, nullptr);
653 }
656 TS.p = (uintptr_t)-1;
657 return object::SectionRef(TS, nullptr);
658 }
659 static unsigned getHashValue(const object::SectionRef &Sec) {
661 return hash_combine(Raw.p, Raw.d.a, Raw.d.b);
662 }
663};
664
665} // end namespace llvm
666
667#endif // LLVM_OBJECT_OBJECTFILE_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
uint64_t Addr
std::string Name
bool End
Definition: ELF_riscv.cpp:480
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
Value * RHS
Value * LHS
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
Error takeError()
Take ownership of the stored error.
Definition: Error.h:608
const char * getBufferStart() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
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:103
const SymbolicFile * getObject() const
Definition: SymbolicFile.h:214
DataRefImpl getRawDataRefImpl() const
Definition: SymbolicFile.h:210
MemoryBufferRef Data
Definition: Binary.h:37
This class is the base class for all object file types.
Definition: ObjectFile.h:229
virtual bool isBerkeleyText(DataRefImpl Sec) const
Definition: ObjectFile.cpp:89
virtual Expected< section_iterator > getRelocatedSection(DataRefImpl Sec) const
Definition: ObjectFile.cpp:105
uint64_t getCommonSymbolSize(DataRefImpl Symb) const
Definition: ObjectFile.h:307
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:93
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:316
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
Definition: ObjectFile.h:296
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
Definition: ObjectFile.cpp:69
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.
Definition: ObjectFile.cpp:109
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:329
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:97
virtual void setARMSubArch(Triple &TheTriple) const
Definition: ObjectFile.h:346
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)
Definition: ObjectFile.cpp:209
virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const
Definition: ObjectFile.cpp:77
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:355
symbol_iterator_range symbols() const
Definition: ObjectFile.h:321
virtual bool isSectionData(DataRefImpl Sec) const =0
Expected< uint64_t > getSymbolValue(DataRefImpl Symb) const
Definition: ObjectFile.cpp:56
iterator_range< section_iterator > section_iterator_range
Definition: ObjectFile.h:328
virtual void moveRelocationNext(DataRefImpl &Rel) const =0
const uint8_t * base() const
Definition: ObjectFile.h:235
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:341
bool isReflectionSectionStrippable(llvm::binaryformat::Swift5ReflectionSectionKind ReflectionSectionKind) const
True if the reflection section can be stripped by the linker.
Definition: ObjectFile.cpp:225
virtual bool hasDebugInfo() const
Definition: ObjectFile.cpp:99
static Expected< std::unique_ptr< ObjectFile > > createGOFFObjectFile(MemoryBufferRef Object)
static bool classof(const Binary *v)
Definition: ObjectFile.h:380
static Expected< std::unique_ptr< ObjectFile > > createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType)
virtual Expected< uint64_t > getStartAddress() const
Definition: ObjectFile.h:347
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:87
virtual std::optional< StringRef > tryGetCPUName() const
Definition: ObjectFile.h:343
virtual bool isSectionBitcode(DataRefImpl Sec) const
Definition: ObjectFile.cpp:79
iterator_range< symbol_iterator > symbol_iterator_range
Definition: ObjectFile.h:320
virtual uint64_t getRelocationOffset(DataRefImpl Rel) const =0
static Expected< std::unique_ptr< ObjectFile > > createObjectFile(MemoryBufferRef Object)
Definition: ObjectFile.h:376
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:52
uint64_t getType() const
Definition: ObjectFile.h:628
bool operator==(const RelocationRef &Other) const
Definition: ObjectFile.h:612
uint64_t getOffset() const
Definition: ObjectFile.h:620
symbol_iterator getSymbol() const
Definition: ObjectFile.h:624
const ObjectFile * getObject() const
Definition: ObjectFile.h:640
void getTypeName(SmallVectorImpl< char > &Result) const
Get a string that represents the type of this relocation.
Definition: ObjectFile.h:632
DataRefImpl getRawDataRefImpl() const
Definition: ObjectFile.h:636
A filtered iterator for SectionRefs that skips sections based on some given predicate.
Definition: ObjectFile.h:407
SectionFilterIterator & operator++()
Definition: ObjectFile.h:416
const SectionRef & operator*() const
Definition: ObjectFile.h:415
bool operator!=(const SectionFilterIterator &Other) const
Definition: ObjectFile.h:421
SectionFilterIterator(SectionFilterPredicate Pred, const section_iterator &Begin, const section_iterator &End)
Definition: ObjectFile.h:409
Creates an iterator range of SectionFilterIterators for a given Object and predicate.
Definition: ObjectFile.h:438
SectionFilterIterator begin()
Definition: ObjectFile.h:442
SectionFilter(SectionFilterPredicate Pred, const ObjectFile &Obj)
Definition: ObjectFile.h:440
SectionFilterIterator end()
Definition: ObjectFile.h:446
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:81
uint64_t getIndex() const
Definition: ObjectFile.h:525
bool operator<(const SectionRef &Other) const
Definition: ObjectFile.h:508
DataRefImpl getRawDataRefImpl() const
Definition: ObjectFile.h:598
bool operator!=(const SectionRef &Other) const
Definition: ObjectFile.h:504
bool isDebugSection() const
Whether this section is a debug section.
Definition: ObjectFile.h:582
iterator_range< relocation_iterator > relocations() const
Definition: ObjectFile.h:133
bool isData() const
Whether this section contains data, not instructions.
Definition: ObjectFile.h:554
Expected< StringRef > getContents() const
Definition: ObjectFile.h:533
relocation_iterator relocation_end() const
Definition: ObjectFile.h:590
bool isCompressed() const
Definition: ObjectFile.h:546
bool isStripped() const
Definition: ObjectFile.h:570
bool isBSS() const
Whether this section contains BSS uninitialized data.
Definition: ObjectFile.h:558
uint64_t getSize() const
Definition: ObjectFile.h:529
bool containsSymbol(SymbolRef S) const
Definition: ObjectFile.cpp:46
bool operator==(const SectionRef &Other) const
Definition: ObjectFile.h:499
uint64_t getAddress() const
Definition: ObjectFile.h:521
bool isBerkeleyText() const
Whether this section will be placed in the text segment, according to the Berkeley size format.
Definition: ObjectFile.h:574
bool isVirtual() const
Definition: ObjectFile.h:562
bool isText() const
Whether this section contains instructions.
Definition: ObjectFile.h:550
relocation_iterator relocation_begin() const
Definition: ObjectFile.h:586
Align getAlignment() const
Get the alignment of this section.
Definition: ObjectFile.h:541
bool isBerkeleyData() const
Whether this section will be placed in the data segment, according to the Berkeley size format.
Definition: ObjectFile.h:578
const ObjectFile * getObject() const
Definition: ObjectFile.h:602
bool isBitcode() const
Definition: ObjectFile.h:566
Expected< StringRef > getName() const
Definition: ObjectFile.h:517
Expected< section_iterator > getRelocatedSection() const
Returns the related section if this section contains relocations.
Definition: ObjectFile.h:594
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition: ObjectFile.h:168
Expected< SymbolRef::Type > getType() const
Definition: ObjectFile.h:484
SymbolRef(const BasicSymbolRef &B)
Definition: ObjectFile.h:183
Expected< StringRef > getName() const
Definition: ObjectFile.h:460
uint32_t getAlignment() const
Get the alignment of this symbol as the actual value (not log 2).
Definition: ObjectFile.h:472
const ObjectFile * getObject() const
Definition: ObjectFile.h:488
Expected< uint64_t > getAddress() const
Returns the symbol virtual address (i.e.
Definition: ObjectFile.h:464
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:468
Expected< section_iterator > getSection() const
Get section this symbol is defined in reference to.
Definition: ObjectFile.h:480
uint64_t getCommonSize() const
Definition: ObjectFile.h:476
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
Definition: SymbolicFile.h:83
const SymbolRef * operator->() const
Definition: ObjectFile.h:215
symbol_iterator(const basic_symbol_iterator &B)
Definition: ObjectFile.h:211
const SymbolRef & operator*() const
Definition: ObjectFile.h:220
symbol_iterator(SymbolRef Sym)
Definition: ObjectFile.h:210
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
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:47
std::function< bool(const SectionRef &)> SectionFilterPredicate
Definition: ObjectFile.h:49
raw_ostream & operator<<(raw_ostream &OS, const SectionedAddress &Addr)
Definition: ObjectFile.cpp:34
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.
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.
Definition: Error.cpp:167
StringRef getTypeName()
We provide a function which tries to compute the (demangled) name of a type statically.
Definition: TypeName.h:27
@ 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:1849
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition: Casting.h:565
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:613
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
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:659
static object::SectionRef getEmptyKey()
Definition: ObjectFile.h:651
static object::SectionRef getTombstoneKey()
Definition: ObjectFile.h:654
static bool isEqual(const object::SectionRef &A, const object::SectionRef &B)
Definition: ObjectFile.h:647
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:52
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:20
@ unknown
Unrecognized file.
Definition: Magic.h:22
static const uint64_t UndefSection
Definition: ObjectFile.h:146
struct llvm::object::DataRefImpl::@359 d