RuntimeDyldImpl.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. //===-- RuntimeDyldImpl.h - Run-time dynamic linker for MC-JIT --*- 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. // Interface for the implementations of runtime dynamic linker facilities.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDIMPL_H
  13. #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDIMPL_H
  14. #include "llvm/ADT/SmallVector.h"
  15. #include "llvm/ADT/StringMap.h"
  16. #include "llvm/ADT/Triple.h"
  17. #include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
  18. #include "llvm/ExecutionEngine/RuntimeDyld.h"
  19. #include "llvm/ExecutionEngine/RuntimeDyldChecker.h"
  20. #include "llvm/Object/ObjectFile.h"
  21. #include "llvm/Support/Debug.h"
  22. #include "llvm/Support/ErrorHandling.h"
  23. #include "llvm/Support/Format.h"
  24. #include "llvm/Support/Host.h"
  25. #include "llvm/Support/Mutex.h"
  26. #include "llvm/Support/SwapByteOrder.h"
  27. #include <deque>
  28. #include <map>
  29. #include <system_error>
  30. #include <unordered_map>
  31. using namespace llvm;
  32. using namespace llvm::object;
  33. namespace llvm {
  34. #define UNIMPLEMENTED_RELOC(RelType) \
  35. case RelType: \
  36. return make_error<RuntimeDyldError>("Unimplemented relocation: " #RelType)
  37. /// SectionEntry - represents a section emitted into memory by the dynamic
  38. /// linker.
  39. class SectionEntry {
  40. /// Name - section name.
  41. std::string Name;
  42. /// Address - address in the linker's memory where the section resides.
  43. uint8_t *Address;
  44. /// Size - section size. Doesn't include the stubs.
  45. size_t Size;
  46. /// LoadAddress - the address of the section in the target process's memory.
  47. /// Used for situations in which JIT-ed code is being executed in the address
  48. /// space of a separate process. If the code executes in the same address
  49. /// space where it was JIT-ed, this just equals Address.
  50. uint64_t LoadAddress;
  51. /// StubOffset - used for architectures with stub functions for far
  52. /// relocations (like ARM).
  53. uintptr_t StubOffset;
  54. /// The total amount of space allocated for this section. This includes the
  55. /// section size and the maximum amount of space that the stubs can occupy.
  56. size_t AllocationSize;
  57. /// ObjAddress - address of the section in the in-memory object file. Used
  58. /// for calculating relocations in some object formats (like MachO).
  59. uintptr_t ObjAddress;
  60. public:
  61. SectionEntry(StringRef name, uint8_t *address, size_t size,
  62. size_t allocationSize, uintptr_t objAddress)
  63. : Name(std::string(name)), Address(address), Size(size),
  64. LoadAddress(reinterpret_cast<uintptr_t>(address)), StubOffset(size),
  65. AllocationSize(allocationSize), ObjAddress(objAddress) {
  66. // AllocationSize is used only in asserts, prevent an "unused private field"
  67. // warning:
  68. (void)AllocationSize;
  69. }
  70. StringRef getName() const { return Name; }
  71. uint8_t *getAddress() const { return Address; }
  72. /// Return the address of this section with an offset.
  73. uint8_t *getAddressWithOffset(unsigned OffsetBytes) const {
  74. assert(OffsetBytes <= AllocationSize && "Offset out of bounds!");
  75. return Address + OffsetBytes;
  76. }
  77. size_t getSize() const { return Size; }
  78. uint64_t getLoadAddress() const { return LoadAddress; }
  79. void setLoadAddress(uint64_t LA) { LoadAddress = LA; }
  80. /// Return the load address of this section with an offset.
  81. uint64_t getLoadAddressWithOffset(unsigned OffsetBytes) const {
  82. assert(OffsetBytes <= AllocationSize && "Offset out of bounds!");
  83. return LoadAddress + OffsetBytes;
  84. }
  85. uintptr_t getStubOffset() const { return StubOffset; }
  86. void advanceStubOffset(unsigned StubSize) {
  87. StubOffset += StubSize;
  88. assert(StubOffset <= AllocationSize && "Not enough space allocated!");
  89. }
  90. uintptr_t getObjAddress() const { return ObjAddress; }
  91. };
  92. /// RelocationEntry - used to represent relocations internally in the dynamic
  93. /// linker.
  94. class RelocationEntry {
  95. public:
  96. /// SectionID - the section this relocation points to.
  97. unsigned SectionID;
  98. /// Offset - offset into the section.
  99. uint64_t Offset;
  100. /// RelType - relocation type.
  101. uint32_t RelType;
  102. /// Addend - the relocation addend encoded in the instruction itself. Also
  103. /// used to make a relocation section relative instead of symbol relative.
  104. int64_t Addend;
  105. struct SectionPair {
  106. uint32_t SectionA;
  107. uint32_t SectionB;
  108. };
  109. /// SymOffset - Section offset of the relocation entry's symbol (used for GOT
  110. /// lookup).
  111. union {
  112. uint64_t SymOffset;
  113. SectionPair Sections;
  114. };
  115. /// True if this is a PCRel relocation (MachO specific).
  116. bool IsPCRel;
  117. /// The size of this relocation (MachO specific).
  118. unsigned Size;
  119. // ARM (MachO and COFF) specific.
  120. bool IsTargetThumbFunc = false;
  121. RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend)
  122. : SectionID(id), Offset(offset), RelType(type), Addend(addend),
  123. SymOffset(0), IsPCRel(false), Size(0), IsTargetThumbFunc(false) {}
  124. RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend,
  125. uint64_t symoffset)
  126. : SectionID(id), Offset(offset), RelType(type), Addend(addend),
  127. SymOffset(symoffset), IsPCRel(false), Size(0),
  128. IsTargetThumbFunc(false) {}
  129. RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend,
  130. bool IsPCRel, unsigned Size)
  131. : SectionID(id), Offset(offset), RelType(type), Addend(addend),
  132. SymOffset(0), IsPCRel(IsPCRel), Size(Size), IsTargetThumbFunc(false) {}
  133. RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend,
  134. unsigned SectionA, uint64_t SectionAOffset, unsigned SectionB,
  135. uint64_t SectionBOffset, bool IsPCRel, unsigned Size)
  136. : SectionID(id), Offset(offset), RelType(type),
  137. Addend(SectionAOffset - SectionBOffset + addend), IsPCRel(IsPCRel),
  138. Size(Size), IsTargetThumbFunc(false) {
  139. Sections.SectionA = SectionA;
  140. Sections.SectionB = SectionB;
  141. }
  142. RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend,
  143. unsigned SectionA, uint64_t SectionAOffset, unsigned SectionB,
  144. uint64_t SectionBOffset, bool IsPCRel, unsigned Size,
  145. bool IsTargetThumbFunc)
  146. : SectionID(id), Offset(offset), RelType(type),
  147. Addend(SectionAOffset - SectionBOffset + addend), IsPCRel(IsPCRel),
  148. Size(Size), IsTargetThumbFunc(IsTargetThumbFunc) {
  149. Sections.SectionA = SectionA;
  150. Sections.SectionB = SectionB;
  151. }
  152. };
  153. class RelocationValueRef {
  154. public:
  155. unsigned SectionID = 0;
  156. uint64_t Offset = 0;
  157. int64_t Addend = 0;
  158. const char *SymbolName = nullptr;
  159. bool IsStubThumb = false;
  160. inline bool operator==(const RelocationValueRef &Other) const {
  161. return SectionID == Other.SectionID && Offset == Other.Offset &&
  162. Addend == Other.Addend && SymbolName == Other.SymbolName &&
  163. IsStubThumb == Other.IsStubThumb;
  164. }
  165. inline bool operator<(const RelocationValueRef &Other) const {
  166. if (SectionID != Other.SectionID)
  167. return SectionID < Other.SectionID;
  168. if (Offset != Other.Offset)
  169. return Offset < Other.Offset;
  170. if (Addend != Other.Addend)
  171. return Addend < Other.Addend;
  172. if (IsStubThumb != Other.IsStubThumb)
  173. return IsStubThumb < Other.IsStubThumb;
  174. return SymbolName < Other.SymbolName;
  175. }
  176. };
  177. /// Symbol info for RuntimeDyld.
  178. class SymbolTableEntry {
  179. public:
  180. SymbolTableEntry() = default;
  181. SymbolTableEntry(unsigned SectionID, uint64_t Offset, JITSymbolFlags Flags)
  182. : Offset(Offset), SectionID(SectionID), Flags(Flags) {}
  183. unsigned getSectionID() const { return SectionID; }
  184. uint64_t getOffset() const { return Offset; }
  185. void setOffset(uint64_t NewOffset) { Offset = NewOffset; }
  186. JITSymbolFlags getFlags() const { return Flags; }
  187. private:
  188. uint64_t Offset = 0;
  189. unsigned SectionID = 0;
  190. JITSymbolFlags Flags = JITSymbolFlags::None;
  191. };
  192. typedef StringMap<SymbolTableEntry> RTDyldSymbolTable;
  193. class RuntimeDyldImpl {
  194. friend class RuntimeDyld::LoadedObjectInfo;
  195. protected:
  196. static const unsigned AbsoluteSymbolSection = ~0U;
  197. // The MemoryManager to load objects into.
  198. RuntimeDyld::MemoryManager &MemMgr;
  199. // The symbol resolver to use for external symbols.
  200. JITSymbolResolver &Resolver;
  201. // A list of all sections emitted by the dynamic linker. These sections are
  202. // referenced in the code by means of their index in this list - SectionID.
  203. // Because references may be kept while the list grows, use a container that
  204. // guarantees reference stability.
  205. typedef std::deque<SectionEntry> SectionList;
  206. SectionList Sections;
  207. typedef unsigned SID; // Type for SectionIDs
  208. #define RTDYLD_INVALID_SECTION_ID ((RuntimeDyldImpl::SID)(-1))
  209. // Keep a map of sections from object file to the SectionID which
  210. // references it.
  211. typedef std::map<SectionRef, unsigned> ObjSectionToIDMap;
  212. // A global symbol table for symbols from all loaded modules.
  213. RTDyldSymbolTable GlobalSymbolTable;
  214. // Keep a map of common symbols to their info pairs
  215. typedef std::vector<SymbolRef> CommonSymbolList;
  216. // For each symbol, keep a list of relocations based on it. Anytime
  217. // its address is reassigned (the JIT re-compiled the function, e.g.),
  218. // the relocations get re-resolved.
  219. // The symbol (or section) the relocation is sourced from is the Key
  220. // in the relocation list where it's stored.
  221. typedef SmallVector<RelocationEntry, 64> RelocationList;
  222. // Relocations to sections already loaded. Indexed by SectionID which is the
  223. // source of the address. The target where the address will be written is
  224. // SectionID/Offset in the relocation itself.
  225. std::unordered_map<unsigned, RelocationList> Relocations;
  226. // Relocations to external symbols that are not yet resolved. Symbols are
  227. // external when they aren't found in the global symbol table of all loaded
  228. // modules. This map is indexed by symbol name.
  229. StringMap<RelocationList> ExternalSymbolRelocations;
  230. typedef std::map<RelocationValueRef, uintptr_t> StubMap;
  231. Triple::ArchType Arch;
  232. bool IsTargetLittleEndian;
  233. bool IsMipsO32ABI;
  234. bool IsMipsN32ABI;
  235. bool IsMipsN64ABI;
  236. // True if all sections should be passed to the memory manager, false if only
  237. // sections containing relocations should be. Defaults to 'false'.
  238. bool ProcessAllSections;
  239. // This mutex prevents simultaneously loading objects from two different
  240. // threads. This keeps us from having to protect individual data structures
  241. // and guarantees that section allocation requests to the memory manager
  242. // won't be interleaved between modules. It is also used in mapSectionAddress
  243. // and resolveRelocations to protect write access to internal data structures.
  244. //
  245. // loadObject may be called on the same thread during the handling of of
  246. // processRelocations, and that's OK. The handling of the relocation lists
  247. // is written in such a way as to work correctly if new elements are added to
  248. // the end of the list while the list is being processed.
  249. sys::Mutex lock;
  250. using NotifyStubEmittedFunction =
  251. RuntimeDyld::NotifyStubEmittedFunction;
  252. NotifyStubEmittedFunction NotifyStubEmitted;
  253. virtual unsigned getMaxStubSize() const = 0;
  254. virtual Align getStubAlignment() = 0;
  255. bool HasError;
  256. std::string ErrorStr;
  257. void writeInt16BE(uint8_t *Addr, uint16_t Value) {
  258. llvm::support::endian::write<uint16_t, llvm::support::unaligned>(
  259. Addr, Value, IsTargetLittleEndian ? support::little : support::big);
  260. }
  261. void writeInt32BE(uint8_t *Addr, uint32_t Value) {
  262. llvm::support::endian::write<uint32_t, llvm::support::unaligned>(
  263. Addr, Value, IsTargetLittleEndian ? support::little : support::big);
  264. }
  265. void writeInt64BE(uint8_t *Addr, uint64_t Value) {
  266. llvm::support::endian::write<uint64_t, llvm::support::unaligned>(
  267. Addr, Value, IsTargetLittleEndian ? support::little : support::big);
  268. }
  269. virtual void setMipsABI(const ObjectFile &Obj) {
  270. IsMipsO32ABI = false;
  271. IsMipsN32ABI = false;
  272. IsMipsN64ABI = false;
  273. }
  274. /// Endian-aware read Read the least significant Size bytes from Src.
  275. uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const;
  276. /// Endian-aware write. Write the least significant Size bytes from Value to
  277. /// Dst.
  278. void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const;
  279. /// Generate JITSymbolFlags from a libObject symbol.
  280. virtual Expected<JITSymbolFlags> getJITSymbolFlags(const SymbolRef &Sym);
  281. /// Modify the given target address based on the given symbol flags.
  282. /// This can be used by subclasses to tweak addresses based on symbol flags,
  283. /// For example: the MachO/ARM target uses it to set the low bit if the target
  284. /// is a thumb symbol.
  285. virtual uint64_t modifyAddressBasedOnFlags(uint64_t Addr,
  286. JITSymbolFlags Flags) const {
  287. return Addr;
  288. }
  289. /// Given the common symbols discovered in the object file, emit a
  290. /// new section for them and update the symbol mappings in the object and
  291. /// symbol table.
  292. Error emitCommonSymbols(const ObjectFile &Obj,
  293. CommonSymbolList &CommonSymbols, uint64_t CommonSize,
  294. uint32_t CommonAlign);
  295. /// Emits section data from the object file to the MemoryManager.
  296. /// \param IsCode if it's true then allocateCodeSection() will be
  297. /// used for emits, else allocateDataSection() will be used.
  298. /// \return SectionID.
  299. Expected<unsigned> emitSection(const ObjectFile &Obj,
  300. const SectionRef &Section,
  301. bool IsCode);
  302. /// Find Section in LocalSections. If the secton is not found - emit
  303. /// it and store in LocalSections.
  304. /// \param IsCode if it's true then allocateCodeSection() will be
  305. /// used for emmits, else allocateDataSection() will be used.
  306. /// \return SectionID.
  307. Expected<unsigned> findOrEmitSection(const ObjectFile &Obj,
  308. const SectionRef &Section, bool IsCode,
  309. ObjSectionToIDMap &LocalSections);
  310. // Add a relocation entry that uses the given section.
  311. void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID);
  312. // Add a relocation entry that uses the given symbol. This symbol may
  313. // be found in the global symbol table, or it may be external.
  314. void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName);
  315. /// Emits long jump instruction to Addr.
  316. /// \return Pointer to the memory area for emitting target address.
  317. uint8_t *createStubFunction(uint8_t *Addr, unsigned AbiVariant = 0);
  318. /// Resolves relocations from Relocs list with address from Value.
  319. void resolveRelocationList(const RelocationList &Relocs, uint64_t Value);
  320. /// A object file specific relocation resolver
  321. /// \param RE The relocation to be resolved
  322. /// \param Value Target symbol address to apply the relocation action
  323. virtual void resolveRelocation(const RelocationEntry &RE, uint64_t Value) = 0;
  324. /// Parses one or more object file relocations (some object files use
  325. /// relocation pairs) and stores it to Relocations or SymbolRelocations
  326. /// (this depends on the object file type).
  327. /// \return Iterator to the next relocation that needs to be parsed.
  328. virtual Expected<relocation_iterator>
  329. processRelocationRef(unsigned SectionID, relocation_iterator RelI,
  330. const ObjectFile &Obj, ObjSectionToIDMap &ObjSectionToID,
  331. StubMap &Stubs) = 0;
  332. void applyExternalSymbolRelocations(
  333. const StringMap<JITEvaluatedSymbol> ExternalSymbolMap);
  334. /// Resolve relocations to external symbols.
  335. Error resolveExternalSymbols();
  336. // Compute an upper bound of the memory that is required to load all
  337. // sections
  338. Error computeTotalAllocSize(const ObjectFile &Obj, uint64_t &CodeSize,
  339. Align &CodeAlign, uint64_t &RODataSize,
  340. Align &RODataAlign, uint64_t &RWDataSize,
  341. Align &RWDataAlign);
  342. // Compute GOT size
  343. unsigned computeGOTSize(const ObjectFile &Obj);
  344. // Compute the stub buffer size required for a section
  345. unsigned computeSectionStubBufSize(const ObjectFile &Obj,
  346. const SectionRef &Section);
  347. // Implementation of the generic part of the loadObject algorithm.
  348. Expected<ObjSectionToIDMap> loadObjectImpl(const object::ObjectFile &Obj);
  349. // Return size of Global Offset Table (GOT) entry
  350. virtual size_t getGOTEntrySize() { return 0; }
  351. // Hook for the subclasses to do further processing when a symbol is added to
  352. // the global symbol table. This function may modify the symbol table entry.
  353. virtual void processNewSymbol(const SymbolRef &ObjSymbol, SymbolTableEntry& Entry) {}
  354. // Return true if the relocation R may require allocating a GOT entry.
  355. virtual bool relocationNeedsGot(const RelocationRef &R) const {
  356. return false;
  357. }
  358. // Return true if the relocation R may require allocating a stub.
  359. virtual bool relocationNeedsStub(const RelocationRef &R) const {
  360. return true; // Conservative answer
  361. }
  362. public:
  363. RuntimeDyldImpl(RuntimeDyld::MemoryManager &MemMgr,
  364. JITSymbolResolver &Resolver)
  365. : MemMgr(MemMgr), Resolver(Resolver),
  366. ProcessAllSections(false), HasError(false) {
  367. }
  368. virtual ~RuntimeDyldImpl();
  369. void setProcessAllSections(bool ProcessAllSections) {
  370. this->ProcessAllSections = ProcessAllSections;
  371. }
  372. virtual std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
  373. loadObject(const object::ObjectFile &Obj) = 0;
  374. uint64_t getSectionLoadAddress(unsigned SectionID) const {
  375. if (SectionID == AbsoluteSymbolSection)
  376. return 0;
  377. else
  378. return Sections[SectionID].getLoadAddress();
  379. }
  380. uint8_t *getSectionAddress(unsigned SectionID) const {
  381. if (SectionID == AbsoluteSymbolSection)
  382. return nullptr;
  383. else
  384. return Sections[SectionID].getAddress();
  385. }
  386. StringRef getSectionContent(unsigned SectionID) const {
  387. if (SectionID == AbsoluteSymbolSection)
  388. return {};
  389. else
  390. return StringRef(
  391. reinterpret_cast<char *>(Sections[SectionID].getAddress()),
  392. Sections[SectionID].getStubOffset() + getMaxStubSize());
  393. }
  394. uint8_t* getSymbolLocalAddress(StringRef Name) const {
  395. // FIXME: Just look up as a function for now. Overly simple of course.
  396. // Work in progress.
  397. RTDyldSymbolTable::const_iterator pos = GlobalSymbolTable.find(Name);
  398. if (pos == GlobalSymbolTable.end())
  399. return nullptr;
  400. const auto &SymInfo = pos->second;
  401. // Absolute symbols do not have a local address.
  402. if (SymInfo.getSectionID() == AbsoluteSymbolSection)
  403. return nullptr;
  404. return getSectionAddress(SymInfo.getSectionID()) + SymInfo.getOffset();
  405. }
  406. unsigned getSymbolSectionID(StringRef Name) const {
  407. auto GSTItr = GlobalSymbolTable.find(Name);
  408. if (GSTItr == GlobalSymbolTable.end())
  409. return ~0U;
  410. return GSTItr->second.getSectionID();
  411. }
  412. JITEvaluatedSymbol getSymbol(StringRef Name) const {
  413. // FIXME: Just look up as a function for now. Overly simple of course.
  414. // Work in progress.
  415. RTDyldSymbolTable::const_iterator pos = GlobalSymbolTable.find(Name);
  416. if (pos == GlobalSymbolTable.end())
  417. return nullptr;
  418. const auto &SymEntry = pos->second;
  419. uint64_t SectionAddr = 0;
  420. if (SymEntry.getSectionID() != AbsoluteSymbolSection)
  421. SectionAddr = getSectionLoadAddress(SymEntry.getSectionID());
  422. uint64_t TargetAddr = SectionAddr + SymEntry.getOffset();
  423. // FIXME: Have getSymbol should return the actual address and the client
  424. // modify it based on the flags. This will require clients to be
  425. // aware of the target architecture, which we should build
  426. // infrastructure for.
  427. TargetAddr = modifyAddressBasedOnFlags(TargetAddr, SymEntry.getFlags());
  428. return JITEvaluatedSymbol(TargetAddr, SymEntry.getFlags());
  429. }
  430. std::map<StringRef, JITEvaluatedSymbol> getSymbolTable() const {
  431. std::map<StringRef, JITEvaluatedSymbol> Result;
  432. for (const auto &KV : GlobalSymbolTable) {
  433. auto SectionID = KV.second.getSectionID();
  434. uint64_t SectionAddr = getSectionLoadAddress(SectionID);
  435. Result[KV.first()] =
  436. JITEvaluatedSymbol(SectionAddr + KV.second.getOffset(), KV.second.getFlags());
  437. }
  438. return Result;
  439. }
  440. void resolveRelocations();
  441. void resolveLocalRelocations();
  442. static void finalizeAsync(
  443. std::unique_ptr<RuntimeDyldImpl> This,
  444. unique_function<void(object::OwningBinary<object::ObjectFile>,
  445. std::unique_ptr<RuntimeDyld::LoadedObjectInfo>,
  446. Error)>
  447. OnEmitted,
  448. object::OwningBinary<object::ObjectFile> O,
  449. std::unique_ptr<RuntimeDyld::LoadedObjectInfo> Info);
  450. void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
  451. void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress);
  452. // Is the linker in an error state?
  453. bool hasError() { return HasError; }
  454. // Mark the error condition as handled and continue.
  455. void clearError() { HasError = false; }
  456. // Get the error message.
  457. StringRef getErrorString() { return ErrorStr; }
  458. virtual bool isCompatibleFile(const ObjectFile &Obj) const = 0;
  459. void setNotifyStubEmitted(NotifyStubEmittedFunction NotifyStubEmitted) {
  460. this->NotifyStubEmitted = std::move(NotifyStubEmitted);
  461. }
  462. virtual void registerEHFrames();
  463. void deregisterEHFrames();
  464. virtual Error finalizeLoad(const ObjectFile &ObjImg,
  465. ObjSectionToIDMap &SectionMap) {
  466. return Error::success();
  467. }
  468. };
  469. } // end namespace llvm
  470. #endif