ObjectFile.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ObjectFile.h - File format independent object file -------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares a file format independent ObjectFile class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_OBJECT_OBJECTFILE_H
  18. #define LLVM_OBJECT_OBJECTFILE_H
  19. #include "llvm/ADT/ArrayRef.h"
  20. #include "llvm/ADT/Hashing.h"
  21. #include "llvm/ADT/StringRef.h"
  22. #include "llvm/ADT/Triple.h"
  23. #include "llvm/ADT/iterator_range.h"
  24. #include "llvm/BinaryFormat/Magic.h"
  25. #include "llvm/BinaryFormat/Swift.h"
  26. #include "llvm/Object/Binary.h"
  27. #include "llvm/Object/Error.h"
  28. #include "llvm/Object/SymbolicFile.h"
  29. #include "llvm/Support/Casting.h"
  30. #include "llvm/Support/Error.h"
  31. #include "llvm/Support/MemoryBufferRef.h"
  32. #include <cassert>
  33. #include <cstdint>
  34. #include <memory>
  35. namespace llvm {
  36. class SubtargetFeatures;
  37. namespace object {
  38. class COFFObjectFile;
  39. class MachOObjectFile;
  40. class ObjectFile;
  41. class SectionRef;
  42. class SymbolRef;
  43. class symbol_iterator;
  44. class WasmObjectFile;
  45. using section_iterator = content_iterator<SectionRef>;
  46. /// This is a value type class that represents a single relocation in the list
  47. /// of relocations in the object file.
  48. class RelocationRef {
  49. DataRefImpl RelocationPimpl;
  50. const ObjectFile *OwningObject = nullptr;
  51. public:
  52. RelocationRef() = default;
  53. RelocationRef(DataRefImpl RelocationP, const ObjectFile *Owner);
  54. bool operator==(const RelocationRef &Other) const;
  55. void moveNext();
  56. uint64_t getOffset() const;
  57. symbol_iterator getSymbol() const;
  58. uint64_t getType() const;
  59. /// Get a string that represents the type of this relocation.
  60. ///
  61. /// This is for display purposes only.
  62. void getTypeName(SmallVectorImpl<char> &Result) const;
  63. DataRefImpl getRawDataRefImpl() const;
  64. const ObjectFile *getObject() const;
  65. };
  66. using relocation_iterator = content_iterator<RelocationRef>;
  67. /// This is a value type class that represents a single section in the list of
  68. /// sections in the object file.
  69. class SectionRef {
  70. friend class SymbolRef;
  71. DataRefImpl SectionPimpl;
  72. const ObjectFile *OwningObject = nullptr;
  73. public:
  74. SectionRef() = default;
  75. SectionRef(DataRefImpl SectionP, const ObjectFile *Owner);
  76. bool operator==(const SectionRef &Other) const;
  77. bool operator!=(const SectionRef &Other) const;
  78. bool operator<(const SectionRef &Other) const;
  79. void moveNext();
  80. Expected<StringRef> getName() const;
  81. uint64_t getAddress() const;
  82. uint64_t getIndex() const;
  83. uint64_t getSize() const;
  84. Expected<StringRef> getContents() const;
  85. /// Get the alignment of this section.
  86. Align getAlignment() const;
  87. bool isCompressed() const;
  88. /// Whether this section contains instructions.
  89. bool isText() const;
  90. /// Whether this section contains data, not instructions.
  91. bool isData() const;
  92. /// Whether this section contains BSS uninitialized data.
  93. bool isBSS() const;
  94. bool isVirtual() const;
  95. bool isBitcode() const;
  96. bool isStripped() const;
  97. /// Whether this section will be placed in the text segment, according to the
  98. /// Berkeley size format. This is true if the section is allocatable, and
  99. /// contains either code or readonly data.
  100. bool isBerkeleyText() const;
  101. /// Whether this section will be placed in the data segment, according to the
  102. /// Berkeley size format. This is true if the section is allocatable and
  103. /// contains data (e.g. PROGBITS), but is not text.
  104. bool isBerkeleyData() const;
  105. /// Whether this section is a debug section.
  106. bool isDebugSection() const;
  107. bool containsSymbol(SymbolRef S) const;
  108. relocation_iterator relocation_begin() const;
  109. relocation_iterator relocation_end() const;
  110. iterator_range<relocation_iterator> relocations() const {
  111. return make_range(relocation_begin(), relocation_end());
  112. }
  113. /// Returns the related section if this section contains relocations. The
  114. /// returned section may or may not have applied its relocations.
  115. Expected<section_iterator> getRelocatedSection() const;
  116. DataRefImpl getRawDataRefImpl() const;
  117. const ObjectFile *getObject() const;
  118. };
  119. struct SectionedAddress {
  120. const static uint64_t UndefSection = UINT64_MAX;
  121. uint64_t Address = 0;
  122. uint64_t SectionIndex = UndefSection;
  123. };
  124. inline bool operator<(const SectionedAddress &LHS,
  125. const SectionedAddress &RHS) {
  126. return std::tie(LHS.SectionIndex, LHS.Address) <
  127. std::tie(RHS.SectionIndex, RHS.Address);
  128. }
  129. inline bool operator==(const SectionedAddress &LHS,
  130. const SectionedAddress &RHS) {
  131. return std::tie(LHS.SectionIndex, LHS.Address) ==
  132. std::tie(RHS.SectionIndex, RHS.Address);
  133. }
  134. raw_ostream &operator<<(raw_ostream &OS, const SectionedAddress &Addr);
  135. /// This is a value type class that represents a single symbol in the list of
  136. /// symbols in the object file.
  137. class SymbolRef : public BasicSymbolRef {
  138. friend class SectionRef;
  139. public:
  140. enum Type {
  141. ST_Unknown, // Type not specified
  142. ST_Other,
  143. ST_Data,
  144. ST_Debug,
  145. ST_File,
  146. ST_Function,
  147. };
  148. SymbolRef() = default;
  149. SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
  150. SymbolRef(const BasicSymbolRef &B) : BasicSymbolRef(B) {
  151. assert(isa<ObjectFile>(BasicSymbolRef::getObject()));
  152. }
  153. Expected<StringRef> getName() const;
  154. /// Returns the symbol virtual address (i.e. address at which it will be
  155. /// mapped).
  156. Expected<uint64_t> getAddress() const;
  157. /// Return the value of the symbol depending on the object this can be an
  158. /// offset or a virtual address.
  159. Expected<uint64_t> getValue() const;
  160. /// Get the alignment of this symbol as the actual value (not log 2).
  161. uint32_t getAlignment() const;
  162. uint64_t getCommonSize() const;
  163. Expected<SymbolRef::Type> getType() const;
  164. /// Get section this symbol is defined in reference to. Result is
  165. /// end_sections() if it is undefined or is an absolute symbol.
  166. Expected<section_iterator> getSection() const;
  167. const ObjectFile *getObject() const;
  168. };
  169. class symbol_iterator : public basic_symbol_iterator {
  170. public:
  171. symbol_iterator(SymbolRef Sym) : basic_symbol_iterator(Sym) {}
  172. symbol_iterator(const basic_symbol_iterator &B)
  173. : basic_symbol_iterator(SymbolRef(B->getRawDataRefImpl(),
  174. cast<ObjectFile>(B->getObject()))) {}
  175. const SymbolRef *operator->() const {
  176. const BasicSymbolRef &P = basic_symbol_iterator::operator *();
  177. return static_cast<const SymbolRef*>(&P);
  178. }
  179. const SymbolRef &operator*() const {
  180. const BasicSymbolRef &P = basic_symbol_iterator::operator *();
  181. return static_cast<const SymbolRef&>(P);
  182. }
  183. };
  184. /// This class is the base class for all object file types. Concrete instances
  185. /// of this object are created by createObjectFile, which figures out which type
  186. /// to create.
  187. class ObjectFile : public SymbolicFile {
  188. virtual void anchor();
  189. protected:
  190. ObjectFile(unsigned int Type, MemoryBufferRef Source);
  191. const uint8_t *base() const {
  192. return reinterpret_cast<const uint8_t *>(Data.getBufferStart());
  193. }
  194. // These functions are for SymbolRef to call internally. The main goal of
  195. // this is to allow SymbolRef::SymbolPimpl to point directly to the symbol
  196. // entry in the memory mapped object file. SymbolPimpl cannot contain any
  197. // virtual functions because then it could not point into the memory mapped
  198. // file.
  199. //
  200. // Implementations assume that the DataRefImpl is valid and has not been
  201. // modified externally. It's UB otherwise.
  202. friend class SymbolRef;
  203. virtual Expected<StringRef> getSymbolName(DataRefImpl Symb) const = 0;
  204. Error printSymbolName(raw_ostream &OS,
  205. DataRefImpl Symb) const override;
  206. virtual Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const = 0;
  207. virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const = 0;
  208. virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
  209. virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0;
  210. virtual Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const = 0;
  211. virtual Expected<section_iterator>
  212. getSymbolSection(DataRefImpl Symb) const = 0;
  213. // Same as above for SectionRef.
  214. friend class SectionRef;
  215. virtual void moveSectionNext(DataRefImpl &Sec) const = 0;
  216. virtual Expected<StringRef> getSectionName(DataRefImpl Sec) const = 0;
  217. virtual uint64_t getSectionAddress(DataRefImpl Sec) const = 0;
  218. virtual uint64_t getSectionIndex(DataRefImpl Sec) const = 0;
  219. virtual uint64_t getSectionSize(DataRefImpl Sec) const = 0;
  220. virtual Expected<ArrayRef<uint8_t>>
  221. getSectionContents(DataRefImpl Sec) const = 0;
  222. virtual uint64_t getSectionAlignment(DataRefImpl Sec) const = 0;
  223. virtual bool isSectionCompressed(DataRefImpl Sec) const = 0;
  224. virtual bool isSectionText(DataRefImpl Sec) const = 0;
  225. virtual bool isSectionData(DataRefImpl Sec) const = 0;
  226. virtual bool isSectionBSS(DataRefImpl Sec) const = 0;
  227. // A section is 'virtual' if its contents aren't present in the object image.
  228. virtual bool isSectionVirtual(DataRefImpl Sec) const = 0;
  229. virtual bool isSectionBitcode(DataRefImpl Sec) const;
  230. virtual bool isSectionStripped(DataRefImpl Sec) const;
  231. virtual bool isBerkeleyText(DataRefImpl Sec) const;
  232. virtual bool isBerkeleyData(DataRefImpl Sec) const;
  233. virtual bool isDebugSection(DataRefImpl Sec) const;
  234. virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
  235. virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0;
  236. virtual Expected<section_iterator> getRelocatedSection(DataRefImpl Sec) const;
  237. // Same as above for RelocationRef.
  238. friend class RelocationRef;
  239. virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
  240. virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
  241. virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
  242. virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
  243. virtual void getRelocationTypeName(DataRefImpl Rel,
  244. SmallVectorImpl<char> &Result) const = 0;
  245. virtual llvm::binaryformat::Swift5ReflectionSectionKind
  246. mapReflectionSectionNameToEnumValue(StringRef SectionName) const {
  247. return llvm::binaryformat::Swift5ReflectionSectionKind::unknown;
  248. };
  249. Expected<uint64_t> getSymbolValue(DataRefImpl Symb) const;
  250. public:
  251. ObjectFile() = delete;
  252. ObjectFile(const ObjectFile &other) = delete;
  253. uint64_t getCommonSymbolSize(DataRefImpl Symb) const {
  254. Expected<uint32_t> SymbolFlagsOrErr = getSymbolFlags(Symb);
  255. if (!SymbolFlagsOrErr)
  256. // TODO: Actually report errors helpfully.
  257. report_fatal_error(SymbolFlagsOrErr.takeError());
  258. assert(*SymbolFlagsOrErr & SymbolRef::SF_Common);
  259. return getCommonSymbolSizeImpl(Symb);
  260. }
  261. virtual std::vector<SectionRef> dynamic_relocation_sections() const {
  262. return std::vector<SectionRef>();
  263. }
  264. using symbol_iterator_range = iterator_range<symbol_iterator>;
  265. symbol_iterator_range symbols() const {
  266. return symbol_iterator_range(symbol_begin(), symbol_end());
  267. }
  268. virtual section_iterator section_begin() const = 0;
  269. virtual section_iterator section_end() const = 0;
  270. using section_iterator_range = iterator_range<section_iterator>;
  271. section_iterator_range sections() const {
  272. return section_iterator_range(section_begin(), section_end());
  273. }
  274. virtual bool hasDebugInfo() const;
  275. /// The number of bytes used to represent an address in this object
  276. /// file format.
  277. virtual uint8_t getBytesInAddress() const = 0;
  278. virtual StringRef getFileFormatName() const = 0;
  279. virtual Triple::ArchType getArch() const = 0;
  280. virtual Expected<SubtargetFeatures> getFeatures() const = 0;
  281. virtual std::optional<StringRef> tryGetCPUName() const {
  282. return std::nullopt;
  283. };
  284. virtual void setARMSubArch(Triple &TheTriple) const { }
  285. virtual Expected<uint64_t> getStartAddress() const {
  286. return errorCodeToError(object_error::parse_failed);
  287. };
  288. /// Create a triple from the data in this object file.
  289. Triple makeTriple() const;
  290. /// Maps a debug section name to a standard DWARF section name.
  291. virtual StringRef mapDebugSectionName(StringRef Name) const { return Name; }
  292. /// True if this is a relocatable object (.o/.obj).
  293. virtual bool isRelocatableObject() const = 0;
  294. /// True if the reflection section can be stripped by the linker.
  295. bool isReflectionSectionStrippable(
  296. llvm::binaryformat::Swift5ReflectionSectionKind ReflectionSectionKind)
  297. const;
  298. /// @returns Pointer to ObjectFile subclass to handle this type of object.
  299. /// @param ObjectPath The path to the object file. ObjectPath.isObject must
  300. /// return true.
  301. /// Create ObjectFile from path.
  302. static Expected<OwningBinary<ObjectFile>>
  303. createObjectFile(StringRef ObjectPath);
  304. static Expected<std::unique_ptr<ObjectFile>>
  305. createObjectFile(MemoryBufferRef Object, llvm::file_magic Type,
  306. bool InitContent = true);
  307. static Expected<std::unique_ptr<ObjectFile>>
  308. createObjectFile(MemoryBufferRef Object) {
  309. return createObjectFile(Object, llvm::file_magic::unknown);
  310. }
  311. static bool classof(const Binary *v) {
  312. return v->isObject();
  313. }
  314. static Expected<std::unique_ptr<COFFObjectFile>>
  315. createCOFFObjectFile(MemoryBufferRef Object);
  316. static Expected<std::unique_ptr<ObjectFile>>
  317. createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType);
  318. static Expected<std::unique_ptr<ObjectFile>>
  319. createELFObjectFile(MemoryBufferRef Object, bool InitContent = true);
  320. static Expected<std::unique_ptr<MachOObjectFile>>
  321. createMachOObjectFile(MemoryBufferRef Object,
  322. uint32_t UniversalCputype = 0,
  323. uint32_t UniversalIndex = 0);
  324. static Expected<std::unique_ptr<WasmObjectFile>>
  325. createWasmObjectFile(MemoryBufferRef Object);
  326. };
  327. // Inline function definitions.
  328. inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
  329. : BasicSymbolRef(SymbolP, Owner) {}
  330. inline Expected<StringRef> SymbolRef::getName() const {
  331. return getObject()->getSymbolName(getRawDataRefImpl());
  332. }
  333. inline Expected<uint64_t> SymbolRef::getAddress() const {
  334. return getObject()->getSymbolAddress(getRawDataRefImpl());
  335. }
  336. inline Expected<uint64_t> SymbolRef::getValue() const {
  337. return getObject()->getSymbolValue(getRawDataRefImpl());
  338. }
  339. inline uint32_t SymbolRef::getAlignment() const {
  340. return getObject()->getSymbolAlignment(getRawDataRefImpl());
  341. }
  342. inline uint64_t SymbolRef::getCommonSize() const {
  343. return getObject()->getCommonSymbolSize(getRawDataRefImpl());
  344. }
  345. inline Expected<section_iterator> SymbolRef::getSection() const {
  346. return getObject()->getSymbolSection(getRawDataRefImpl());
  347. }
  348. inline Expected<SymbolRef::Type> SymbolRef::getType() const {
  349. return getObject()->getSymbolType(getRawDataRefImpl());
  350. }
  351. inline const ObjectFile *SymbolRef::getObject() const {
  352. const SymbolicFile *O = BasicSymbolRef::getObject();
  353. return cast<ObjectFile>(O);
  354. }
  355. /// SectionRef
  356. inline SectionRef::SectionRef(DataRefImpl SectionP,
  357. const ObjectFile *Owner)
  358. : SectionPimpl(SectionP)
  359. , OwningObject(Owner) {}
  360. inline bool SectionRef::operator==(const SectionRef &Other) const {
  361. return OwningObject == Other.OwningObject &&
  362. SectionPimpl == Other.SectionPimpl;
  363. }
  364. inline bool SectionRef::operator!=(const SectionRef &Other) const {
  365. return !(*this == Other);
  366. }
  367. inline bool SectionRef::operator<(const SectionRef &Other) const {
  368. assert(OwningObject == Other.OwningObject);
  369. return SectionPimpl < Other.SectionPimpl;
  370. }
  371. inline void SectionRef::moveNext() {
  372. return OwningObject->moveSectionNext(SectionPimpl);
  373. }
  374. inline Expected<StringRef> SectionRef::getName() const {
  375. return OwningObject->getSectionName(SectionPimpl);
  376. }
  377. inline uint64_t SectionRef::getAddress() const {
  378. return OwningObject->getSectionAddress(SectionPimpl);
  379. }
  380. inline uint64_t SectionRef::getIndex() const {
  381. return OwningObject->getSectionIndex(SectionPimpl);
  382. }
  383. inline uint64_t SectionRef::getSize() const {
  384. return OwningObject->getSectionSize(SectionPimpl);
  385. }
  386. inline Expected<StringRef> SectionRef::getContents() const {
  387. Expected<ArrayRef<uint8_t>> Res =
  388. OwningObject->getSectionContents(SectionPimpl);
  389. if (!Res)
  390. return Res.takeError();
  391. return StringRef(reinterpret_cast<const char *>(Res->data()), Res->size());
  392. }
  393. inline Align SectionRef::getAlignment() const {
  394. return MaybeAlign(OwningObject->getSectionAlignment(SectionPimpl))
  395. .valueOrOne();
  396. }
  397. inline bool SectionRef::isCompressed() const {
  398. return OwningObject->isSectionCompressed(SectionPimpl);
  399. }
  400. inline bool SectionRef::isText() const {
  401. return OwningObject->isSectionText(SectionPimpl);
  402. }
  403. inline bool SectionRef::isData() const {
  404. return OwningObject->isSectionData(SectionPimpl);
  405. }
  406. inline bool SectionRef::isBSS() const {
  407. return OwningObject->isSectionBSS(SectionPimpl);
  408. }
  409. inline bool SectionRef::isVirtual() const {
  410. return OwningObject->isSectionVirtual(SectionPimpl);
  411. }
  412. inline bool SectionRef::isBitcode() const {
  413. return OwningObject->isSectionBitcode(SectionPimpl);
  414. }
  415. inline bool SectionRef::isStripped() const {
  416. return OwningObject->isSectionStripped(SectionPimpl);
  417. }
  418. inline bool SectionRef::isBerkeleyText() const {
  419. return OwningObject->isBerkeleyText(SectionPimpl);
  420. }
  421. inline bool SectionRef::isBerkeleyData() const {
  422. return OwningObject->isBerkeleyData(SectionPimpl);
  423. }
  424. inline bool SectionRef::isDebugSection() const {
  425. return OwningObject->isDebugSection(SectionPimpl);
  426. }
  427. inline relocation_iterator SectionRef::relocation_begin() const {
  428. return OwningObject->section_rel_begin(SectionPimpl);
  429. }
  430. inline relocation_iterator SectionRef::relocation_end() const {
  431. return OwningObject->section_rel_end(SectionPimpl);
  432. }
  433. inline Expected<section_iterator> SectionRef::getRelocatedSection() const {
  434. return OwningObject->getRelocatedSection(SectionPimpl);
  435. }
  436. inline DataRefImpl SectionRef::getRawDataRefImpl() const {
  437. return SectionPimpl;
  438. }
  439. inline const ObjectFile *SectionRef::getObject() const {
  440. return OwningObject;
  441. }
  442. /// RelocationRef
  443. inline RelocationRef::RelocationRef(DataRefImpl RelocationP,
  444. const ObjectFile *Owner)
  445. : RelocationPimpl(RelocationP)
  446. , OwningObject(Owner) {}
  447. inline bool RelocationRef::operator==(const RelocationRef &Other) const {
  448. return RelocationPimpl == Other.RelocationPimpl;
  449. }
  450. inline void RelocationRef::moveNext() {
  451. return OwningObject->moveRelocationNext(RelocationPimpl);
  452. }
  453. inline uint64_t RelocationRef::getOffset() const {
  454. return OwningObject->getRelocationOffset(RelocationPimpl);
  455. }
  456. inline symbol_iterator RelocationRef::getSymbol() const {
  457. return OwningObject->getRelocationSymbol(RelocationPimpl);
  458. }
  459. inline uint64_t RelocationRef::getType() const {
  460. return OwningObject->getRelocationType(RelocationPimpl);
  461. }
  462. inline void RelocationRef::getTypeName(SmallVectorImpl<char> &Result) const {
  463. return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
  464. }
  465. inline DataRefImpl RelocationRef::getRawDataRefImpl() const {
  466. return RelocationPimpl;
  467. }
  468. inline const ObjectFile *RelocationRef::getObject() const {
  469. return OwningObject;
  470. }
  471. } // end namespace object
  472. template <> struct DenseMapInfo<object::SectionRef> {
  473. static bool isEqual(const object::SectionRef &A,
  474. const object::SectionRef &B) {
  475. return A == B;
  476. }
  477. static object::SectionRef getEmptyKey() {
  478. return object::SectionRef({}, nullptr);
  479. }
  480. static object::SectionRef getTombstoneKey() {
  481. object::DataRefImpl TS;
  482. TS.p = (uintptr_t)-1;
  483. return object::SectionRef(TS, nullptr);
  484. }
  485. static unsigned getHashValue(const object::SectionRef &Sec) {
  486. object::DataRefImpl Raw = Sec.getRawDataRefImpl();
  487. return hash_combine(Raw.p, Raw.d.a, Raw.d.b);
  488. }
  489. };
  490. } // end namespace llvm
  491. #endif // LLVM_OBJECT_OBJECTFILE_H
  492. #ifdef __GNUC__
  493. #pragma GCC diagnostic pop
  494. #endif