ObjectFile.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. //===- ObjectFile.h - File format independent object file -------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file declares a file format independent ObjectFile class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_OBJECT_OBJECTFILE_H
  14. #define LLVM_OBJECT_OBJECTFILE_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include "llvm/Object/Binary.h"
  17. #include "llvm/Support/DataTypes.h"
  18. #include "llvm/Support/ErrorHandling.h"
  19. #include "llvm/Support/MemoryBuffer.h"
  20. #include <cstring>
  21. #include <vector>
  22. namespace llvm {
  23. namespace object {
  24. class ObjectFile;
  25. union DataRefImpl {
  26. // This entire union should probably be a
  27. // char[max(8, sizeof(uintptr_t))] and require the impl to cast.
  28. struct {
  29. uint32_t a, b;
  30. } d;
  31. uintptr_t p;
  32. DataRefImpl() {
  33. std::memset(this, 0, sizeof(DataRefImpl));
  34. }
  35. };
  36. template<class content_type>
  37. class content_iterator {
  38. content_type Current;
  39. public:
  40. content_iterator(content_type symb)
  41. : Current(symb) {}
  42. const content_type* operator->() const {
  43. return &Current;
  44. }
  45. const content_type &operator*() const {
  46. return Current;
  47. }
  48. bool operator==(const content_iterator &other) const {
  49. return Current == other.Current;
  50. }
  51. bool operator!=(const content_iterator &other) const {
  52. return !(*this == other);
  53. }
  54. content_iterator& increment(error_code &err) {
  55. content_type next;
  56. if (error_code ec = Current.getNext(next))
  57. err = ec;
  58. else
  59. Current = next;
  60. return *this;
  61. }
  62. };
  63. inline bool operator==(const DataRefImpl &a, const DataRefImpl &b) {
  64. // Check bitwise identical. This is the only legal way to compare a union w/o
  65. // knowing which member is in use.
  66. return std::memcmp(&a, &b, sizeof(DataRefImpl)) == 0;
  67. }
  68. inline bool operator<(const DataRefImpl &a, const DataRefImpl &b) {
  69. // Check bitwise identical. This is the only legal way to compare a union w/o
  70. // knowing which member is in use.
  71. return std::memcmp(&a, &b, sizeof(DataRefImpl)) < 0;
  72. }
  73. class SymbolRef;
  74. typedef content_iterator<SymbolRef> symbol_iterator;
  75. /// RelocationRef - This is a value type class that represents a single
  76. /// relocation in the list of relocations in the object file.
  77. class RelocationRef {
  78. DataRefImpl RelocationPimpl;
  79. const ObjectFile *OwningObject;
  80. public:
  81. RelocationRef() : OwningObject(NULL) { }
  82. RelocationRef(DataRefImpl RelocationP, const ObjectFile *Owner);
  83. bool operator==(const RelocationRef &Other) const;
  84. error_code getNext(RelocationRef &Result) const;
  85. error_code getAddress(uint64_t &Result) const;
  86. error_code getOffset(uint64_t &Result) const;
  87. symbol_iterator getSymbol() const;
  88. error_code getType(uint64_t &Result) const;
  89. /// @brief Indicates whether this relocation should hidden when listing
  90. /// relocations, usually because it is the trailing part of a multipart
  91. /// relocation that will be printed as part of the leading relocation.
  92. error_code getHidden(bool &Result) const;
  93. /// @brief Get a string that represents the type of this relocation.
  94. ///
  95. /// This is for display purposes only.
  96. error_code getTypeName(SmallVectorImpl<char> &Result) const;
  97. /// @brief Get a string that represents the calculation of the value of this
  98. /// relocation.
  99. ///
  100. /// This is for display purposes only.
  101. error_code getValueString(SmallVectorImpl<char> &Result) const;
  102. DataRefImpl getRawDataRefImpl() const;
  103. const ObjectFile *getObjectFile() const;
  104. };
  105. typedef content_iterator<RelocationRef> relocation_iterator;
  106. /// SectionRef - This is a value type class that represents a single section in
  107. /// the list of sections in the object file.
  108. class SectionRef;
  109. typedef content_iterator<SectionRef> section_iterator;
  110. class SectionRef {
  111. friend class SymbolRef;
  112. DataRefImpl SectionPimpl;
  113. const ObjectFile *OwningObject;
  114. public:
  115. SectionRef() : OwningObject(NULL) { }
  116. SectionRef(DataRefImpl SectionP, const ObjectFile *Owner);
  117. bool operator==(const SectionRef &Other) const;
  118. bool operator<(const SectionRef &Other) const;
  119. error_code getNext(SectionRef &Result) const;
  120. error_code getName(StringRef &Result) const;
  121. error_code getAddress(uint64_t &Result) const;
  122. error_code getSize(uint64_t &Result) const;
  123. error_code getContents(StringRef &Result) const;
  124. /// @brief Get the alignment of this section as the actual value (not log 2).
  125. error_code getAlignment(uint64_t &Result) const;
  126. // FIXME: Move to the normalization layer when it's created.
  127. error_code isText(bool &Result) const;
  128. error_code isData(bool &Result) const;
  129. error_code isBSS(bool &Result) const;
  130. error_code isRequiredForExecution(bool &Result) const;
  131. error_code isVirtual(bool &Result) const;
  132. error_code isZeroInit(bool &Result) const;
  133. error_code isReadOnlyData(bool &Result) const;
  134. error_code containsSymbol(SymbolRef S, bool &Result) const;
  135. relocation_iterator begin_relocations() const;
  136. relocation_iterator end_relocations() const;
  137. section_iterator getRelocatedSection() const;
  138. DataRefImpl getRawDataRefImpl() const;
  139. };
  140. /// SymbolRef - This is a value type class that represents a single symbol in
  141. /// the list of symbols in the object file.
  142. class SymbolRef {
  143. friend class SectionRef;
  144. DataRefImpl SymbolPimpl;
  145. const ObjectFile *OwningObject;
  146. public:
  147. SymbolRef() : OwningObject(NULL) { }
  148. enum Type {
  149. ST_Unknown, // Type not specified
  150. ST_Data,
  151. ST_Debug,
  152. ST_File,
  153. ST_Function,
  154. ST_Other
  155. };
  156. enum Flags LLVM_ENUM_INT_TYPE(unsigned) {
  157. SF_None = 0,
  158. SF_Undefined = 1U << 0, // Symbol is defined in another object file
  159. SF_Global = 1U << 1, // Global symbol
  160. SF_Weak = 1U << 2, // Weak symbol
  161. SF_Absolute = 1U << 3, // Absolute symbol
  162. SF_ThreadLocal = 1U << 4, // Thread local symbol
  163. SF_Common = 1U << 5, // Symbol has common linkage
  164. SF_FormatSpecific = 1U << 31 // Specific to the object file format
  165. // (e.g. section symbols)
  166. };
  167. SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
  168. bool operator==(const SymbolRef &Other) const;
  169. bool operator<(const SymbolRef &Other) const;
  170. error_code getNext(SymbolRef &Result) const;
  171. error_code getName(StringRef &Result) const;
  172. /// Returns the symbol virtual address (i.e. address at which it will be
  173. /// mapped).
  174. error_code getAddress(uint64_t &Result) const;
  175. error_code getFileOffset(uint64_t &Result) const;
  176. /// @brief Get the alignment of this symbol as the actual value (not log 2).
  177. error_code getAlignment(uint32_t &Result) const;
  178. error_code getSize(uint64_t &Result) const;
  179. error_code getType(SymbolRef::Type &Result) const;
  180. /// Get symbol flags (bitwise OR of SymbolRef::Flags)
  181. error_code getFlags(uint32_t &Result) const;
  182. /// @brief Get section this symbol is defined in reference to. Result is
  183. /// end_sections() if it is undefined or is an absolute symbol.
  184. error_code getSection(section_iterator &Result) const;
  185. /// @brief Get value of the symbol in the symbol table.
  186. error_code getValue(uint64_t &Val) const;
  187. DataRefImpl getRawDataRefImpl() const;
  188. };
  189. /// LibraryRef - This is a value type class that represents a single library in
  190. /// the list of libraries needed by a shared or dynamic object.
  191. class LibraryRef {
  192. friend class SectionRef;
  193. DataRefImpl LibraryPimpl;
  194. const ObjectFile *OwningObject;
  195. public:
  196. LibraryRef() : OwningObject(NULL) { }
  197. LibraryRef(DataRefImpl LibraryP, const ObjectFile *Owner);
  198. bool operator==(const LibraryRef &Other) const;
  199. bool operator<(const LibraryRef &Other) const;
  200. error_code getNext(LibraryRef &Result) const;
  201. // Get the path to this library, as stored in the object file.
  202. error_code getPath(StringRef &Result) const;
  203. DataRefImpl getRawDataRefImpl() const;
  204. };
  205. typedef content_iterator<LibraryRef> library_iterator;
  206. const uint64_t UnknownAddressOrSize = ~0ULL;
  207. /// ObjectFile - This class is the base class for all object file types.
  208. /// Concrete instances of this object are created by createObjectFile, which
  209. /// figures out which type to create.
  210. class ObjectFile : public Binary {
  211. virtual void anchor();
  212. ObjectFile() LLVM_DELETED_FUNCTION;
  213. ObjectFile(const ObjectFile &other) LLVM_DELETED_FUNCTION;
  214. protected:
  215. ObjectFile(unsigned int Type, MemoryBuffer *source);
  216. const uint8_t *base() const {
  217. return reinterpret_cast<const uint8_t *>(Data->getBufferStart());
  218. }
  219. // These functions are for SymbolRef to call internally. The main goal of
  220. // this is to allow SymbolRef::SymbolPimpl to point directly to the symbol
  221. // entry in the memory mapped object file. SymbolPimpl cannot contain any
  222. // virtual functions because then it could not point into the memory mapped
  223. // file.
  224. //
  225. // Implementations assume that the DataRefImpl is valid and has not been
  226. // modified externally. It's UB otherwise.
  227. friend class SymbolRef;
  228. virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const = 0;
  229. virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const = 0;
  230. virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const = 0;
  231. virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res)const=0;
  232. virtual error_code getSymbolAlignment(DataRefImpl Symb, uint32_t &Res) const;
  233. virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const = 0;
  234. virtual error_code getSymbolType(DataRefImpl Symb,
  235. SymbolRef::Type &Res) const = 0;
  236. virtual error_code getSymbolFlags(DataRefImpl Symb,
  237. uint32_t &Res) const = 0;
  238. virtual error_code getSymbolSection(DataRefImpl Symb,
  239. section_iterator &Res) const = 0;
  240. virtual error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const = 0;
  241. // Same as above for SectionRef.
  242. friend class SectionRef;
  243. virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const = 0;
  244. virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const = 0;
  245. virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const =0;
  246. virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const = 0;
  247. virtual error_code getSectionContents(DataRefImpl Sec, StringRef &Res)const=0;
  248. virtual error_code getSectionAlignment(DataRefImpl Sec, uint64_t &Res)const=0;
  249. virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const = 0;
  250. virtual error_code isSectionData(DataRefImpl Sec, bool &Res) const = 0;
  251. virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const = 0;
  252. virtual error_code isSectionRequiredForExecution(DataRefImpl Sec,
  253. bool &Res) const = 0;
  254. // A section is 'virtual' if its contents aren't present in the object image.
  255. virtual error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const = 0;
  256. virtual error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const = 0;
  257. virtual error_code isSectionReadOnlyData(DataRefImpl Sec, bool &Res) const =0;
  258. virtual error_code sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb,
  259. bool &Result) const = 0;
  260. virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
  261. virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0;
  262. virtual section_iterator getRelocatedSection(DataRefImpl Sec) const;
  263. // Same as above for RelocationRef.
  264. friend class RelocationRef;
  265. virtual error_code getRelocationNext(DataRefImpl Rel,
  266. RelocationRef &Res) const = 0;
  267. virtual error_code getRelocationAddress(DataRefImpl Rel,
  268. uint64_t &Res) const =0;
  269. virtual error_code getRelocationOffset(DataRefImpl Rel,
  270. uint64_t &Res) const =0;
  271. virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
  272. virtual error_code getRelocationType(DataRefImpl Rel,
  273. uint64_t &Res) const = 0;
  274. virtual error_code getRelocationTypeName(DataRefImpl Rel,
  275. SmallVectorImpl<char> &Result) const = 0;
  276. virtual error_code getRelocationValueString(DataRefImpl Rel,
  277. SmallVectorImpl<char> &Result) const = 0;
  278. virtual error_code getRelocationHidden(DataRefImpl Rel, bool &Result) const {
  279. Result = false;
  280. return object_error::success;
  281. }
  282. // Same for LibraryRef
  283. friend class LibraryRef;
  284. virtual error_code getLibraryNext(DataRefImpl Lib, LibraryRef &Res) const = 0;
  285. virtual error_code getLibraryPath(DataRefImpl Lib, StringRef &Res) const = 0;
  286. public:
  287. virtual symbol_iterator begin_symbols() const = 0;
  288. virtual symbol_iterator end_symbols() const = 0;
  289. virtual symbol_iterator begin_dynamic_symbols() const = 0;
  290. virtual symbol_iterator end_dynamic_symbols() const = 0;
  291. virtual section_iterator begin_sections() const = 0;
  292. virtual section_iterator end_sections() const = 0;
  293. virtual library_iterator begin_libraries_needed() const = 0;
  294. virtual library_iterator end_libraries_needed() const = 0;
  295. /// @brief The number of bytes used to represent an address in this object
  296. /// file format.
  297. virtual uint8_t getBytesInAddress() const = 0;
  298. virtual StringRef getFileFormatName() const = 0;
  299. virtual /* Triple::ArchType */ unsigned getArch() const = 0;
  300. /// For shared objects, returns the name which this object should be
  301. /// loaded from at runtime. This corresponds to DT_SONAME on ELF and
  302. /// LC_ID_DYLIB (install name) on MachO.
  303. virtual StringRef getLoadName() const = 0;
  304. /// @returns Pointer to ObjectFile subclass to handle this type of object.
  305. /// @param ObjectPath The path to the object file. ObjectPath.isObject must
  306. /// return true.
  307. /// @brief Create ObjectFile from path.
  308. static ErrorOr<ObjectFile *> createObjectFile(StringRef ObjectPath);
  309. static ErrorOr<ObjectFile *> createObjectFile(MemoryBuffer *Object);
  310. static inline bool classof(const Binary *v) {
  311. return v->isObject();
  312. }
  313. public:
  314. static ErrorOr<ObjectFile *> createCOFFObjectFile(MemoryBuffer *Object);
  315. static ErrorOr<ObjectFile *> createELFObjectFile(MemoryBuffer *Object);
  316. static ErrorOr<ObjectFile *> createMachOObjectFile(MemoryBuffer *Object);
  317. };
  318. // Inline function definitions.
  319. inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
  320. : SymbolPimpl(SymbolP)
  321. , OwningObject(Owner) {}
  322. inline bool SymbolRef::operator==(const SymbolRef &Other) const {
  323. return SymbolPimpl == Other.SymbolPimpl;
  324. }
  325. inline bool SymbolRef::operator<(const SymbolRef &Other) const {
  326. return SymbolPimpl < Other.SymbolPimpl;
  327. }
  328. inline error_code SymbolRef::getNext(SymbolRef &Result) const {
  329. return OwningObject->getSymbolNext(SymbolPimpl, Result);
  330. }
  331. inline error_code SymbolRef::getName(StringRef &Result) const {
  332. return OwningObject->getSymbolName(SymbolPimpl, Result);
  333. }
  334. inline error_code SymbolRef::getAddress(uint64_t &Result) const {
  335. return OwningObject->getSymbolAddress(SymbolPimpl, Result);
  336. }
  337. inline error_code SymbolRef::getFileOffset(uint64_t &Result) const {
  338. return OwningObject->getSymbolFileOffset(SymbolPimpl, Result);
  339. }
  340. inline error_code SymbolRef::getAlignment(uint32_t &Result) const {
  341. return OwningObject->getSymbolAlignment(SymbolPimpl, Result);
  342. }
  343. inline error_code SymbolRef::getSize(uint64_t &Result) const {
  344. return OwningObject->getSymbolSize(SymbolPimpl, Result);
  345. }
  346. inline error_code SymbolRef::getFlags(uint32_t &Result) const {
  347. return OwningObject->getSymbolFlags(SymbolPimpl, Result);
  348. }
  349. inline error_code SymbolRef::getSection(section_iterator &Result) const {
  350. return OwningObject->getSymbolSection(SymbolPimpl, Result);
  351. }
  352. inline error_code SymbolRef::getType(SymbolRef::Type &Result) const {
  353. return OwningObject->getSymbolType(SymbolPimpl, Result);
  354. }
  355. inline error_code SymbolRef::getValue(uint64_t &Val) const {
  356. return OwningObject->getSymbolValue(SymbolPimpl, Val);
  357. }
  358. inline DataRefImpl SymbolRef::getRawDataRefImpl() const {
  359. return SymbolPimpl;
  360. }
  361. /// SectionRef
  362. inline SectionRef::SectionRef(DataRefImpl SectionP,
  363. const ObjectFile *Owner)
  364. : SectionPimpl(SectionP)
  365. , OwningObject(Owner) {}
  366. inline bool SectionRef::operator==(const SectionRef &Other) const {
  367. return SectionPimpl == Other.SectionPimpl;
  368. }
  369. inline bool SectionRef::operator<(const SectionRef &Other) const {
  370. return SectionPimpl < Other.SectionPimpl;
  371. }
  372. inline error_code SectionRef::getNext(SectionRef &Result) const {
  373. return OwningObject->getSectionNext(SectionPimpl, Result);
  374. }
  375. inline error_code SectionRef::getName(StringRef &Result) const {
  376. return OwningObject->getSectionName(SectionPimpl, Result);
  377. }
  378. inline error_code SectionRef::getAddress(uint64_t &Result) const {
  379. return OwningObject->getSectionAddress(SectionPimpl, Result);
  380. }
  381. inline error_code SectionRef::getSize(uint64_t &Result) const {
  382. return OwningObject->getSectionSize(SectionPimpl, Result);
  383. }
  384. inline error_code SectionRef::getContents(StringRef &Result) const {
  385. return OwningObject->getSectionContents(SectionPimpl, Result);
  386. }
  387. inline error_code SectionRef::getAlignment(uint64_t &Result) const {
  388. return OwningObject->getSectionAlignment(SectionPimpl, Result);
  389. }
  390. inline error_code SectionRef::isText(bool &Result) const {
  391. return OwningObject->isSectionText(SectionPimpl, Result);
  392. }
  393. inline error_code SectionRef::isData(bool &Result) const {
  394. return OwningObject->isSectionData(SectionPimpl, Result);
  395. }
  396. inline error_code SectionRef::isBSS(bool &Result) const {
  397. return OwningObject->isSectionBSS(SectionPimpl, Result);
  398. }
  399. inline error_code SectionRef::isRequiredForExecution(bool &Result) const {
  400. return OwningObject->isSectionRequiredForExecution(SectionPimpl, Result);
  401. }
  402. inline error_code SectionRef::isVirtual(bool &Result) const {
  403. return OwningObject->isSectionVirtual(SectionPimpl, Result);
  404. }
  405. inline error_code SectionRef::isZeroInit(bool &Result) const {
  406. return OwningObject->isSectionZeroInit(SectionPimpl, Result);
  407. }
  408. inline error_code SectionRef::isReadOnlyData(bool &Result) const {
  409. return OwningObject->isSectionReadOnlyData(SectionPimpl, Result);
  410. }
  411. inline error_code SectionRef::containsSymbol(SymbolRef S, bool &Result) const {
  412. return OwningObject->sectionContainsSymbol(SectionPimpl, S.SymbolPimpl,
  413. Result);
  414. }
  415. inline relocation_iterator SectionRef::begin_relocations() const {
  416. return OwningObject->section_rel_begin(SectionPimpl);
  417. }
  418. inline relocation_iterator SectionRef::end_relocations() const {
  419. return OwningObject->section_rel_end(SectionPimpl);
  420. }
  421. inline section_iterator SectionRef::getRelocatedSection() const {
  422. return OwningObject->getRelocatedSection(SectionPimpl);
  423. }
  424. inline DataRefImpl SectionRef::getRawDataRefImpl() const {
  425. return SectionPimpl;
  426. }
  427. /// RelocationRef
  428. inline RelocationRef::RelocationRef(DataRefImpl RelocationP,
  429. const ObjectFile *Owner)
  430. : RelocationPimpl(RelocationP)
  431. , OwningObject(Owner) {}
  432. inline bool RelocationRef::operator==(const RelocationRef &Other) const {
  433. return RelocationPimpl == Other.RelocationPimpl;
  434. }
  435. inline error_code RelocationRef::getNext(RelocationRef &Result) const {
  436. return OwningObject->getRelocationNext(RelocationPimpl, Result);
  437. }
  438. inline error_code RelocationRef::getAddress(uint64_t &Result) const {
  439. return OwningObject->getRelocationAddress(RelocationPimpl, Result);
  440. }
  441. inline error_code RelocationRef::getOffset(uint64_t &Result) const {
  442. return OwningObject->getRelocationOffset(RelocationPimpl, Result);
  443. }
  444. inline symbol_iterator RelocationRef::getSymbol() const {
  445. return OwningObject->getRelocationSymbol(RelocationPimpl);
  446. }
  447. inline error_code RelocationRef::getType(uint64_t &Result) const {
  448. return OwningObject->getRelocationType(RelocationPimpl, Result);
  449. }
  450. inline error_code RelocationRef::getTypeName(SmallVectorImpl<char> &Result)
  451. const {
  452. return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
  453. }
  454. inline error_code RelocationRef::getValueString(SmallVectorImpl<char> &Result)
  455. const {
  456. return OwningObject->getRelocationValueString(RelocationPimpl, Result);
  457. }
  458. inline error_code RelocationRef::getHidden(bool &Result) const {
  459. return OwningObject->getRelocationHidden(RelocationPimpl, Result);
  460. }
  461. inline DataRefImpl RelocationRef::getRawDataRefImpl() const {
  462. return RelocationPimpl;
  463. }
  464. inline const ObjectFile *RelocationRef::getObjectFile() const {
  465. return OwningObject;
  466. }
  467. // Inline function definitions.
  468. inline LibraryRef::LibraryRef(DataRefImpl LibraryP, const ObjectFile *Owner)
  469. : LibraryPimpl(LibraryP)
  470. , OwningObject(Owner) {}
  471. inline bool LibraryRef::operator==(const LibraryRef &Other) const {
  472. return LibraryPimpl == Other.LibraryPimpl;
  473. }
  474. inline bool LibraryRef::operator<(const LibraryRef &Other) const {
  475. return LibraryPimpl < Other.LibraryPimpl;
  476. }
  477. inline error_code LibraryRef::getNext(LibraryRef &Result) const {
  478. return OwningObject->getLibraryNext(LibraryPimpl, Result);
  479. }
  480. inline error_code LibraryRef::getPath(StringRef &Result) const {
  481. return OwningObject->getLibraryPath(LibraryPimpl, Result);
  482. }
  483. } // end namespace object
  484. } // end namespace llvm
  485. #endif