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 the subset of
28 // JITMemoryManager required for dynamic loading of binaries.
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. The SectionID is a unique identifier
41 /// assigned by the JIT engine, and optionally recorded by the memory manager
42 /// to access a loaded section.
43 virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
44 unsigned SectionID) = 0;
46 /// allocateDataSection - Allocate a memory block of (at least) the given
47 /// size suitable for data. The SectionID is a unique identifier
48 /// assigned by the JIT engine, and optionally recorded by the memory manager
49 /// to access a loaded section.
50 virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
51 unsigned SectionID) = 0;
53 /// getPointerToNamedFunction - This method returns the address of the
54 /// specified function. As such it is only useful for resolving library
55 /// symbols, not code generated symbols.
57 /// If AbortOnFailure is false and no function with the given name is
58 /// found, this function returns a null pointer. Otherwise, it prints a
59 /// message to stderr and aborts.
60 virtual void *getPointerToNamedFunction(const std::string &Name,
61 bool AbortOnFailure = true) = 0;
65 RuntimeDyld(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
66 void operator=(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
68 // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
70 RuntimeDyldImpl *Dyld;
71 RTDyldMemoryManager *MM;
73 // Change the address associated with a section when resolving relocations.
74 // Any relocations already associated with the symbol will be re-resolved.
75 void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
77 RuntimeDyld(RTDyldMemoryManager *);
80 /// loadObject - prepare the object contained in the input buffer for
81 /// execution. Ownership of the input buffer is transferred to the
82 /// ObjectImage instance returned from this function if successful.
83 /// In the case of load failure, the input buffer will be deleted.
84 ObjectImage *loadObject(ObjectBuffer *InputBuffer);
86 /// Get the address of our local copy of the symbol. This may or may not
87 /// be the address used for relocation (clients can copy the data around
88 /// and resolve relocatons based on where they put it).
89 void *getSymbolAddress(StringRef Name);
91 /// Get the address of the target copy of the symbol. This is the address
92 /// used for relocation.
93 uint64_t getSymbolLoadAddress(StringRef Name);
95 /// Resolve the relocations for all symbols we currently know about.
96 void resolveRelocations();
98 /// mapSectionAddress - map a section to its target address space value.
99 /// Map the address of a JIT section as returned from the memory manager
100 /// to the address in the target process as the running code will see it.
101 /// This is the address which will be used for relocation resolution.
102 void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress);
104 StringRef getErrorString();
107 } // end namespace llvm