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/Support/Memory.h"
22 class RuntimeDyldImpl;
25 // RuntimeDyld clients often want to handle the memory management of
26 // what gets placed where. For JIT clients, this is an abstraction layer
27 // over the JITMemoryManager, which references objects by their source
28 // representations in LLVM IR.
29 // FIXME: As the RuntimeDyld fills out, additional routines will be needed
30 // for the varying types of objects to be allocated.
31 class RTDyldMemoryManager {
32 RTDyldMemoryManager(const RTDyldMemoryManager&); // DO NOT IMPLEMENT
33 void operator=(const RTDyldMemoryManager&); // DO NOT IMPLEMENT
35 RTDyldMemoryManager() {}
36 virtual ~RTDyldMemoryManager();
38 /// allocateCodeSection - Allocate a memory block of (at least) the given
39 /// size suitable for executable code.
40 virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
41 unsigned SectionID) = 0;
43 /// allocateDataSection - Allocate a memory block of (at least) the given
44 /// size suitable for data.
45 virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
46 unsigned SectionID) = 0;
48 // Allocate ActualSize bytes, or more, for the named function. Return
49 // a pointer to the allocated memory and update Size to reflect how much
50 // memory was acutally allocated.
51 virtual uint8_t *startFunctionBody(const char *Name, uintptr_t &Size) = 0;
53 // Mark the end of the function, including how much of the allocated
54 // memory was actually used.
55 virtual void endFunctionBody(const char *Name, uint8_t *FunctionStart,
56 uint8_t *FunctionEnd) = 0;
59 virtual void *getPointerToNamedFunction(const std::string &Name,
60 bool AbortOnFailure = true) = 0;
64 RuntimeDyld(const RuntimeDyld &); // DO NOT IMPLEMENT
65 void operator=(const RuntimeDyld &); // DO NOT IMPLEMENT
67 // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
69 RuntimeDyldImpl *Dyld;
70 RTDyldMemoryManager *MM;
72 // Change the address associated with a section when resolving relocations.
73 // Any relocations already associated with the symbol will be re-resolved.
74 void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
76 RuntimeDyld(RTDyldMemoryManager*);
79 bool loadObject(MemoryBuffer *InputBuffer);
80 // Get the address of our local copy of the symbol. This may or may not
81 // be the address used for relocation (clients can copy the data around
82 // and resolve relocatons based on where they put it).
83 void *getSymbolAddress(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(void *LocalAddress, uint64_t TargetAddress);
93 StringRef getErrorString();
96 } // end namespace llvm