1 //===-- RuntimeDyld.h - Run-time dynamic linker for MC-JIT ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Interface for the runtime dynamic linker facilities of the MC-JIT.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_RUNTIME_DYLD_H
15 #define LLVM_RUNTIME_DYLD_H
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ExecutionEngine/ObjectBuffer.h"
19 #include "llvm/Support/Memory.h"
23 class RuntimeDyldImpl;
26 // RuntimeDyld clients often want to handle the memory management of
27 // what gets placed where. For JIT clients, this is an abstraction layer
28 // over the JITMemoryManager, which references objects by their source
29 // representations in LLVM IR.
30 // FIXME: As the RuntimeDyld fills out, additional routines will be needed
31 // for the varying types of objects to be allocated.
32 class RTDyldMemoryManager {
33 RTDyldMemoryManager(const RTDyldMemoryManager&) LLVM_DELETED_FUNCTION;
34 void operator=(const RTDyldMemoryManager&) LLVM_DELETED_FUNCTION;
36 RTDyldMemoryManager() {}
37 virtual ~RTDyldMemoryManager();
39 /// allocateCodeSection - Allocate a memory block of (at least) the given
40 /// size suitable for executable code.
41 virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
42 unsigned SectionID) = 0;
44 /// allocateDataSection - Allocate a memory block of (at least) the given
45 /// size suitable for data.
46 virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
47 unsigned SectionID) = 0;
49 virtual void *getPointerToNamedFunction(const std::string &Name,
50 bool AbortOnFailure = true) = 0;
54 RuntimeDyld(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
55 void operator=(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
57 // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
59 RuntimeDyldImpl *Dyld;
60 RTDyldMemoryManager *MM;
62 // Change the address associated with a section when resolving relocations.
63 // Any relocations already associated with the symbol will be re-resolved.
64 void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
66 RuntimeDyld(RTDyldMemoryManager *);
69 /// loadObject - prepare the object contained in the input buffer for
70 /// execution. Ownership of the input buffer is transferred to the
71 /// ObjectImage instance returned from this function if successful.
72 /// In the case of load failure, the input buffer will be deleted.
73 ObjectImage *loadObject(ObjectBuffer *InputBuffer);
75 /// Get the address of our local copy of the symbol. This may or may not
76 /// be the address used for relocation (clients can copy the data around
77 /// and resolve relocatons based on where they put it).
78 void *getSymbolAddress(StringRef Name);
80 /// Get the address of the target copy of the symbol. This is the address
81 /// used for relocation.
82 uint64_t getSymbolLoadAddress(StringRef Name);
84 /// Resolve the relocations for all symbols we currently know about.
85 void resolveRelocations();
87 /// mapSectionAddress - map a section to its target address space value.
88 /// Map the address of a JIT section as returned from the memory manager
89 /// to the address in the target process as the running code will see it.
90 /// This is the address which will be used for relocation resolution.
91 void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress);
93 StringRef getErrorString();
96 } // end namespace llvm