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"
19 #include "llvm/ADT/iterator_range.h"
20 #include "llvm/BinaryFormat/Magic.h"
21 #include "llvm/BinaryFormat/Swift.h"
22 #include "llvm/Object/Binary.h"
23 #include "llvm/Object/Error.h"
24 #include "llvm/Object/SymbolicFile.h"
25 #include "llvm/Support/Casting.h"
26 #include "llvm/Support/Error.h"
27 #include "llvm/Support/MemoryBufferRef.h"
28 #include "llvm/TargetParser/Triple.h"
29 #include <cassert>
30 #include <cstdint>
31 #include <memory>
32
33 namespace llvm {
34
35 class SubtargetFeatures;
36
37 namespace object {
38
39 class COFFObjectFile;
40 class MachOObjectFile;
41 class ObjectFile;
42 class SectionRef;
43 class SymbolRef;
44 class symbol_iterator;
45 class WasmObjectFile;
46
47 using section_iterator = content_iterator<SectionRef>;
48
49 typedef 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.
52 class RelocationRef {
53 DataRefImpl RelocationPimpl;
54 const ObjectFile *OwningObject = nullptr;
55
56 public:
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;
65 symbol_iterator getSymbol() 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
73 DataRefImpl getRawDataRefImpl() const;
74 const ObjectFile *getObject() const;
75 };
76
77 using relocation_iterator = content_iterator<RelocationRef>;
78
79 /// This is a value type class that represents a single section in the list of
80 /// sections in the object file.
81 class SectionRef {
82 friend class SymbolRef;
83
84 DataRefImpl SectionPimpl;
85 const ObjectFile *OwningObject = nullptr;
86
87 public:
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
97 Expected<StringRef> getName() const;
98 uint64_t getAddress() const;
99 uint64_t getIndex() const;
100 uint64_t getSize() const;
101 Expected<StringRef> getContents() 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
131 relocation_iterator relocation_begin() const;
132 relocation_iterator relocation_end() const;
relocations()133 iterator_range<relocation_iterator> relocations() const {
134 return make_range(relocation_begin(), relocation_end());
135 }
136
137 /// Returns the related section if this section contains relocations. The
138 /// returned section may or may not have applied its relocations.
139 Expected<section_iterator> getRelocatedSection() const;
140
141 DataRefImpl getRawDataRefImpl() const;
142 const ObjectFile *getObject() const;
143 };
144
145 struct SectionedAddress {
146 const static uint64_t UndefSection = UINT64_MAX;
147
148 uint64_t Address = 0;
149 uint64_t SectionIndex = UndefSection;
150 };
151
152 inline 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
158 inline 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
164 raw_ostream &operator<<(raw_ostream &OS, const SectionedAddress &Addr);
165
166 /// This is a value type class that represents a single symbol in the list of
167 /// symbols in the object file.
168 class SymbolRef : public BasicSymbolRef {
169 friend class SectionRef;
170
171 public:
172 enum Type {
173 ST_Unknown, // Type not specified
174 ST_Other,
175 ST_Data,
176 ST_Debug,
177 ST_File,
178 ST_Function,
179 };
180
181 SymbolRef() = default;
182 SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
SymbolRef(const BasicSymbolRef & B)183 SymbolRef(const BasicSymbolRef &B) : BasicSymbolRef(B) {
184 assert(isa<ObjectFile>(BasicSymbolRef::getObject()));
185 }
186
187 Expected<StringRef> getName() const;
188 /// Returns the symbol virtual address (i.e. address at which it will be
189 /// mapped).
190 Expected<uint64_t> getAddress() const;
191
192 /// Return the value of the symbol depending on the object this can be an
193 /// offset or a virtual address.
194 Expected<uint64_t> getValue() const;
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;
199 Expected<SymbolRef::Type> getType() 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.
203 Expected<section_iterator> getSection() const;
204
205 const ObjectFile *getObject() const;
206 };
207
208 class symbol_iterator : public basic_symbol_iterator {
209 public:
symbol_iterator(SymbolRef Sym)210 symbol_iterator(SymbolRef Sym) : basic_symbol_iterator(Sym) {}
symbol_iterator(const basic_symbol_iterator & B)211 symbol_iterator(const basic_symbol_iterator &B)
212 : basic_symbol_iterator(SymbolRef(B->getRawDataRefImpl(),
213 cast<ObjectFile>(B->getObject()))) {}
214
215 const SymbolRef *operator->() const {
216 const BasicSymbolRef &P = basic_symbol_iterator::operator *();
217 return static_cast<const SymbolRef*>(&P);
218 }
219
220 const SymbolRef &operator*() const {
221 const BasicSymbolRef &P = basic_symbol_iterator::operator *();
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.
229 class ObjectFile : public SymbolicFile {
230 virtual void anchor();
231
232 protected:
233 ObjectFile(unsigned int Type, MemoryBufferRef Source);
234
base()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
249 virtual Expected<StringRef> getSymbolName(DataRefImpl Symb) const = 0;
250 Error printSymbolName(raw_ostream &OS,
251 DataRefImpl Symb) const override;
252 virtual Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const = 0;
253 virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const = 0;
254 virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
255 virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0;
256 virtual Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const = 0;
257 virtual Expected<section_iterator>
258 getSymbolSection(DataRefImpl Symb) const = 0;
259
260 // Same as above for SectionRef.
261 friend class SectionRef;
262
263 virtual void moveSectionNext(DataRefImpl &Sec) const = 0;
264 virtual Expected<StringRef> getSectionName(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;
268 virtual Expected<ArrayRef<uint8_t>>
269 getSectionContents(DataRefImpl Sec) const = 0;
270 virtual uint64_t getSectionAlignment(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;
282 virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
283 virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0;
284 virtual Expected<section_iterator> getRelocatedSection(DataRefImpl Sec) const;
285
286 // Same as above for RelocationRef.
287 friend class RelocationRef;
288 virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
289 virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
290 virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
291 virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
292 virtual void getRelocationTypeName(DataRefImpl Rel,
293 SmallVectorImpl<char> &Result) const = 0;
294
295 virtual llvm::binaryformat::Swift5ReflectionSectionKind
mapReflectionSectionNameToEnumValue(StringRef SectionName)296 mapReflectionSectionNameToEnumValue(StringRef SectionName) const {
297 return llvm::binaryformat::Swift5ReflectionSectionKind::unknown;
298 };
299
300 Expected<uint64_t> getSymbolValue(DataRefImpl Symb) const;
301
302 public:
303 ObjectFile() = delete;
304 ObjectFile(const ObjectFile &other) = delete;
305
getCommonSymbolSize(DataRefImpl Symb)306 uint64_t getCommonSymbolSize(DataRefImpl Symb) const {
307 Expected<uint32_t> SymbolFlagsOrErr = getSymbolFlags(Symb);
308 if (!SymbolFlagsOrErr)
309 // TODO: Actually report errors helpfully.
310 report_fatal_error(SymbolFlagsOrErr.takeError());
311 assert(*SymbolFlagsOrErr & SymbolRef::SF_Common);
312 return getCommonSymbolSizeImpl(Symb);
313 }
314
dynamic_relocation_sections()315 virtual std::vector<SectionRef> dynamic_relocation_sections() const {
316 return std::vector<SectionRef>();
317 }
318
319 using symbol_iterator_range = iterator_range<symbol_iterator>;
symbols()320 symbol_iterator_range symbols() const {
321 return symbol_iterator_range(symbol_begin(), symbol_end());
322 }
323
324 virtual section_iterator section_begin() const = 0;
325 virtual section_iterator section_end() const = 0;
326
327 using section_iterator_range = iterator_range<section_iterator>;
sections()328 section_iterator_range sections() const {
329 return section_iterator_range(section_begin(), section_end());
330 }
331
332 virtual bool hasDebugInfo() const;
333
334 /// The number of bytes used to represent an address in this object
335 /// file format.
336 virtual uint8_t getBytesInAddress() const = 0;
337
338 virtual StringRef getFileFormatName() const = 0;
339 virtual Triple::ArchType getArch() const = 0;
340 virtual Expected<SubtargetFeatures> getFeatures() const = 0;
tryGetCPUName()341 virtual std::optional<StringRef> tryGetCPUName() const {
342 return std::nullopt;
343 };
setARMSubArch(Triple & TheTriple)344 virtual void setARMSubArch(Triple &TheTriple) const { }
getStartAddress()345 virtual Expected<uint64_t> getStartAddress() const {
346 return errorCodeToError(object_error::parse_failed);
347 };
348
349 /// Create a triple from the data in this object file.
350 Triple makeTriple() const;
351
352 /// Maps a debug section name to a standard DWARF section name.
mapDebugSectionName(StringRef Name)353 virtual StringRef mapDebugSectionName(StringRef Name) const { return Name; }
354
355 /// True if this is a relocatable object (.o/.obj).
356 virtual bool isRelocatableObject() const = 0;
357
358 /// True if the reflection section can be stripped by the linker.
359 bool isReflectionSectionStrippable(
360 llvm::binaryformat::Swift5ReflectionSectionKind ReflectionSectionKind)
361 const;
362
363 /// @returns Pointer to ObjectFile subclass to handle this type of object.
364 /// @param ObjectPath The path to the object file. ObjectPath.isObject must
365 /// return true.
366 /// Create ObjectFile from path.
367 static Expected<OwningBinary<ObjectFile>>
368 createObjectFile(StringRef ObjectPath);
369
370 static Expected<std::unique_ptr<ObjectFile>>
371 createObjectFile(MemoryBufferRef Object, llvm::file_magic Type,
372 bool InitContent = true);
373 static Expected<std::unique_ptr<ObjectFile>>
createObjectFile(MemoryBufferRef Object)374 createObjectFile(MemoryBufferRef Object) {
375 return createObjectFile(Object, llvm::file_magic::unknown);
376 }
377
classof(const Binary * v)378 static bool classof(const Binary *v) {
379 return v->isObject();
380 }
381
382 static Expected<std::unique_ptr<COFFObjectFile>>
383 createCOFFObjectFile(MemoryBufferRef Object);
384
385 static Expected<std::unique_ptr<ObjectFile>>
386 createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType);
387
388 static Expected<std::unique_ptr<ObjectFile>>
389 createELFObjectFile(MemoryBufferRef Object, bool InitContent = true);
390
391 static Expected<std::unique_ptr<MachOObjectFile>>
392 createMachOObjectFile(MemoryBufferRef Object, uint32_t UniversalCputype = 0,
393 uint32_t UniversalIndex = 0,
394 size_t MachOFilesetEntryOffset = 0);
395
396 static Expected<std::unique_ptr<ObjectFile>>
397 createGOFFObjectFile(MemoryBufferRef Object);
398
399 static Expected<std::unique_ptr<WasmObjectFile>>
400 createWasmObjectFile(MemoryBufferRef Object);
401 };
402
403 /// A filtered iterator for SectionRefs that skips sections based on some given
404 /// predicate.
405 class SectionFilterIterator {
406 public:
SectionFilterIterator(SectionFilterPredicate Pred,const section_iterator & Begin,const section_iterator & End)407 SectionFilterIterator(SectionFilterPredicate Pred,
408 const section_iterator &Begin,
409 const section_iterator &End)
410 : Predicate(std::move(Pred)), Iterator(Begin), End(End) {
411 scanPredicate();
412 }
413 const SectionRef &operator*() const { return *Iterator; }
414 SectionFilterIterator &operator++() {
415 ++Iterator;
416 scanPredicate();
417 return *this;
418 }
419 bool operator!=(const SectionFilterIterator &Other) const {
420 return Iterator != Other.Iterator;
421 }
422
423 private:
scanPredicate()424 void scanPredicate() {
425 while (Iterator != End && !Predicate(*Iterator)) {
426 ++Iterator;
427 }
428 }
429 SectionFilterPredicate Predicate;
430 section_iterator Iterator;
431 section_iterator End;
432 };
433
434 /// Creates an iterator range of SectionFilterIterators for a given Object and
435 /// predicate.
436 class SectionFilter {
437 public:
SectionFilter(SectionFilterPredicate Pred,const ObjectFile & Obj)438 SectionFilter(SectionFilterPredicate Pred, const ObjectFile &Obj)
439 : Predicate(std::move(Pred)), Object(Obj) {}
begin()440 SectionFilterIterator begin() {
441 return SectionFilterIterator(Predicate, Object.section_begin(),
442 Object.section_end());
443 }
end()444 SectionFilterIterator end() {
445 return SectionFilterIterator(Predicate, Object.section_end(),
446 Object.section_end());
447 }
448
449 private:
450 SectionFilterPredicate Predicate;
451 const ObjectFile &Object;
452 };
453
454 // Inline function definitions.
SymbolRef(DataRefImpl SymbolP,const ObjectFile * Owner)455 inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
456 : BasicSymbolRef(SymbolP, Owner) {}
457
getName()458 inline Expected<StringRef> SymbolRef::getName() const {
459 return getObject()->getSymbolName(getRawDataRefImpl());
460 }
461
getAddress()462 inline Expected<uint64_t> SymbolRef::getAddress() const {
463 return getObject()->getSymbolAddress(getRawDataRefImpl());
464 }
465
getValue()466 inline Expected<uint64_t> SymbolRef::getValue() const {
467 return getObject()->getSymbolValue(getRawDataRefImpl());
468 }
469
getAlignment()470 inline uint32_t SymbolRef::getAlignment() const {
471 return getObject()->getSymbolAlignment(getRawDataRefImpl());
472 }
473
getCommonSize()474 inline uint64_t SymbolRef::getCommonSize() const {
475 return getObject()->getCommonSymbolSize(getRawDataRefImpl());
476 }
477
getSection()478 inline Expected<section_iterator> SymbolRef::getSection() const {
479 return getObject()->getSymbolSection(getRawDataRefImpl());
480 }
481
getType()482 inline Expected<SymbolRef::Type> SymbolRef::getType() const {
483 return getObject()->getSymbolType(getRawDataRefImpl());
484 }
485
getObject()486 inline const ObjectFile *SymbolRef::getObject() const {
487 const SymbolicFile *O = BasicSymbolRef::getObject();
488 return cast<ObjectFile>(O);
489 }
490
491 /// SectionRef
SectionRef(DataRefImpl SectionP,const ObjectFile * Owner)492 inline SectionRef::SectionRef(DataRefImpl SectionP,
493 const ObjectFile *Owner)
494 : SectionPimpl(SectionP)
495 , OwningObject(Owner) {}
496
497 inline bool SectionRef::operator==(const SectionRef &Other) const {
498 return OwningObject == Other.OwningObject &&
499 SectionPimpl == Other.SectionPimpl;
500 }
501
502 inline bool SectionRef::operator!=(const SectionRef &Other) const {
503 return !(*this == Other);
504 }
505
506 inline bool SectionRef::operator<(const SectionRef &Other) const {
507 assert(OwningObject == Other.OwningObject);
508 return SectionPimpl < Other.SectionPimpl;
509 }
510
moveNext()511 inline void SectionRef::moveNext() {
512 return OwningObject->moveSectionNext(SectionPimpl);
513 }
514
getName()515 inline Expected<StringRef> SectionRef::getName() const {
516 return OwningObject->getSectionName(SectionPimpl);
517 }
518
getAddress()519 inline uint64_t SectionRef::getAddress() const {
520 return OwningObject->getSectionAddress(SectionPimpl);
521 }
522
getIndex()523 inline uint64_t SectionRef::getIndex() const {
524 return OwningObject->getSectionIndex(SectionPimpl);
525 }
526
getSize()527 inline uint64_t SectionRef::getSize() const {
528 return OwningObject->getSectionSize(SectionPimpl);
529 }
530
getContents()531 inline Expected<StringRef> SectionRef::getContents() const {
532 Expected<ArrayRef<uint8_t>> Res =
533 OwningObject->getSectionContents(SectionPimpl);
534 if (!Res)
535 return Res.takeError();
536 return StringRef(reinterpret_cast<const char *>(Res->data()), Res->size());
537 }
538
getAlignment()539 inline Align SectionRef::getAlignment() const {
540 return MaybeAlign(OwningObject->getSectionAlignment(SectionPimpl))
541 .valueOrOne();
542 }
543
isCompressed()544 inline bool SectionRef::isCompressed() const {
545 return OwningObject->isSectionCompressed(SectionPimpl);
546 }
547
isText()548 inline bool SectionRef::isText() const {
549 return OwningObject->isSectionText(SectionPimpl);
550 }
551
isData()552 inline bool SectionRef::isData() const {
553 return OwningObject->isSectionData(SectionPimpl);
554 }
555
isBSS()556 inline bool SectionRef::isBSS() const {
557 return OwningObject->isSectionBSS(SectionPimpl);
558 }
559
isVirtual()560 inline bool SectionRef::isVirtual() const {
561 return OwningObject->isSectionVirtual(SectionPimpl);
562 }
563
isBitcode()564 inline bool SectionRef::isBitcode() const {
565 return OwningObject->isSectionBitcode(SectionPimpl);
566 }
567
isStripped()568 inline bool SectionRef::isStripped() const {
569 return OwningObject->isSectionStripped(SectionPimpl);
570 }
571
isBerkeleyText()572 inline bool SectionRef::isBerkeleyText() const {
573 return OwningObject->isBerkeleyText(SectionPimpl);
574 }
575
isBerkeleyData()576 inline bool SectionRef::isBerkeleyData() const {
577 return OwningObject->isBerkeleyData(SectionPimpl);
578 }
579
isDebugSection()580 inline bool SectionRef::isDebugSection() const {
581 return OwningObject->isDebugSection(SectionPimpl);
582 }
583
relocation_begin()584 inline relocation_iterator SectionRef::relocation_begin() const {
585 return OwningObject->section_rel_begin(SectionPimpl);
586 }
587
relocation_end()588 inline relocation_iterator SectionRef::relocation_end() const {
589 return OwningObject->section_rel_end(SectionPimpl);
590 }
591
getRelocatedSection()592 inline Expected<section_iterator> SectionRef::getRelocatedSection() const {
593 return OwningObject->getRelocatedSection(SectionPimpl);
594 }
595
getRawDataRefImpl()596 inline DataRefImpl SectionRef::getRawDataRefImpl() const {
597 return SectionPimpl;
598 }
599
getObject()600 inline const ObjectFile *SectionRef::getObject() const {
601 return OwningObject;
602 }
603
604 /// RelocationRef
RelocationRef(DataRefImpl RelocationP,const ObjectFile * Owner)605 inline RelocationRef::RelocationRef(DataRefImpl RelocationP,
606 const ObjectFile *Owner)
607 : RelocationPimpl(RelocationP)
608 , OwningObject(Owner) {}
609
610 inline bool RelocationRef::operator==(const RelocationRef &Other) const {
611 return RelocationPimpl == Other.RelocationPimpl;
612 }
613
moveNext()614 inline void RelocationRef::moveNext() {
615 return OwningObject->moveRelocationNext(RelocationPimpl);
616 }
617
getOffset()618 inline uint64_t RelocationRef::getOffset() const {
619 return OwningObject->getRelocationOffset(RelocationPimpl);
620 }
621
getSymbol()622 inline symbol_iterator RelocationRef::getSymbol() const {
623 return OwningObject->getRelocationSymbol(RelocationPimpl);
624 }
625
getType()626 inline uint64_t RelocationRef::getType() const {
627 return OwningObject->getRelocationType(RelocationPimpl);
628 }
629
getTypeName(SmallVectorImpl<char> & Result)630 inline void RelocationRef::getTypeName(SmallVectorImpl<char> &Result) const {
631 return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
632 }
633
getRawDataRefImpl()634 inline DataRefImpl RelocationRef::getRawDataRefImpl() const {
635 return RelocationPimpl;
636 }
637
getObject()638 inline const ObjectFile *RelocationRef::getObject() const {
639 return OwningObject;
640 }
641
642 } // end namespace object
643
644 template <> struct DenseMapInfo<object::SectionRef> {
645 static bool isEqual(const object::SectionRef &A,
646 const object::SectionRef &B) {
647 return A == B;
648 }
649 static object::SectionRef getEmptyKey() {
650 return object::SectionRef({}, nullptr);
651 }
652 static object::SectionRef getTombstoneKey() {
653 object::DataRefImpl TS;
654 TS.p = (uintptr_t)-1;
655 return object::SectionRef(TS, nullptr);
656 }
657 static unsigned getHashValue(const object::SectionRef &Sec) {
658 object::DataRefImpl Raw = Sec.getRawDataRefImpl();
659 return hash_combine(Raw.p, Raw.d.a, Raw.d.b);
660 }
661 };
662
663 } // end namespace llvm
664
665 #endif // LLVM_OBJECT_OBJECTFILE_H
666