Adding support and tests for multiple module handling in lli
[oota-llvm.git] / include / llvm / ExecutionEngine / RTDyldMemoryManager.h
1 //===-- RTDyldMemoryManager.cpp - Memory manager for MC-JIT -----*- 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 // Interface of the runtime dynamic memory manager base class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_EXECUTIONENGINE_RT_DYLD_MEMORY_MANAGER_H
15 #define LLVM_EXECUTIONENGINE_RT_DYLD_MEMORY_MANAGER_H
16
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/CBindingWrapping.h"
19 #include "llvm/Support/Memory.h"
20 #include "llvm-c/ExecutionEngine.h"
21
22 namespace llvm {
23
24 class ExecutionEngine;
25 class ObjectImage;
26
27 // RuntimeDyld clients often want to handle the memory management of
28 // what gets placed where. For JIT clients, this is the subset of
29 // JITMemoryManager required for dynamic loading of binaries.
30 //
31 // FIXME: As the RuntimeDyld fills out, additional routines will be needed
32 //        for the varying types of objects to be allocated.
33 class RTDyldMemoryManager {
34   RTDyldMemoryManager(const RTDyldMemoryManager&) LLVM_DELETED_FUNCTION;
35   void operator=(const RTDyldMemoryManager&) LLVM_DELETED_FUNCTION;
36 public:
37   RTDyldMemoryManager() {}
38   virtual ~RTDyldMemoryManager();
39
40   /// Allocate a memory block of (at least) the given size suitable for
41   /// executable code. The SectionID is a unique identifier assigned by the JIT
42   /// engine, and optionally recorded by the memory manager to access a loaded
43   /// section.
44   virtual uint8_t *allocateCodeSection(
45     uintptr_t Size, unsigned Alignment, unsigned SectionID,
46     StringRef SectionName) = 0;
47
48   /// Allocate a memory block of (at least) the given size suitable for data.
49   /// The SectionID is a unique identifier assigned by the JIT engine, and
50   /// optionally recorded by the memory manager to access a loaded section.
51   virtual uint8_t *allocateDataSection(
52     uintptr_t Size, unsigned Alignment, unsigned SectionID,
53     StringRef SectionName, bool IsReadOnly) = 0;
54
55   /// Register the EH frames with the runtime so that c++ exceptions work.
56   virtual void registerEHFrames(StringRef SectionData);
57
58   /// This method returns the address of the specified function or variable.
59   /// It is used to resolve symbols during module linking.
60   virtual uint64_t getSymbolAddress(const std::string &Name);
61
62   /// This method returns the address of the specified function. As such it is
63   /// only useful for resolving library symbols, not code generated symbols.
64   ///
65   /// If \p AbortOnFailure is false and no function with the given name is
66   /// found, this function returns a null pointer. Otherwise, it prints a
67   /// message to stderr and aborts.
68   ///
69   /// This function is deprecated for memory managers to be used with
70   /// MCJIT or RuntimeDyld.  Use getSymbolAddress instead.
71   virtual void *getPointerToNamedFunction(const std::string &Name,
72                                           bool AbortOnFailure = true);
73
74   /// This method is called after an object has been loaded into memory but
75   /// before relocations are applied to the loaded sections.  The object load
76   /// may have been initiated by MCJIT to resolve an external symbol for another
77   /// object that is being finalized.  In that case, the object about which
78   /// the memory manager is being notified will be finalized immediately after
79   /// the memory manager returns from this call.
80   ///
81   /// Memory managers which are preparing code for execution in an external
82   /// address space can use this call to remap the section addresses for the
83   /// newly loaded object.
84   virtual void notifyObjectLoaded(ExecutionEngine *EE,
85                                   const ObjectImage *) {}
86
87   /// This method is called when object loading is complete and section page
88   /// permissions can be applied.  It is up to the memory manager implementation
89   /// to decide whether or not to act on this method.  The memory manager will
90   /// typically allocate all sections as read-write and then apply specific
91   /// permissions when this method is called.  Code sections cannot be executed
92   /// until this function has been called.  In addition, any cache coherency
93   /// operations needed to reliably use the memory are also performed.
94   ///
95   /// Returns true if an error occurred, false otherwise.
96   virtual bool finalizeMemory(std::string *ErrMsg = 0) = 0;
97 };
98
99 // Create wrappers for C Binding types (see CBindingWrapping.h).
100 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(
101     RTDyldMemoryManager, LLVMMCJITMemoryManagerRef)
102
103 } // namespace llvm
104
105 #endif // LLVM_EXECUTIONENGINE_RT_DYLD_MEMORY_MANAGER_H