MCJIT: [cygming] Give noop to __main also in RecordingMemoryManger. It is emitted...
[oota-llvm.git] / tools / lli / RecordingMemoryManager.cpp
1 //===- RecordingMemoryManager.cpp - Recording memory manager --------------===//
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 // This memory manager allocates local storage and keeps a record of each
11 // allocation. Iterators are provided for all data and code allocations.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "RecordingMemoryManager.h"
16 using namespace llvm;
17
18 uint8_t *RecordingMemoryManager::
19 allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID) {
20   // The recording memory manager is just a local copy of the remote target.
21   // The alignment requirement is just stored here for later use. Regular
22   // heap storage is sufficient here.
23   void *Addr = malloc(Size);
24   assert(Addr && "malloc() failure!");
25   sys::MemoryBlock Block(Addr, Size);
26   AllocatedCodeMem.push_back(Allocation(Block, Alignment));
27   return (uint8_t*)Addr;
28 }
29
30 uint8_t *RecordingMemoryManager::
31 allocateDataSection(uintptr_t Size, unsigned Alignment,
32                     unsigned SectionID, bool IsReadOnly) {
33   // The recording memory manager is just a local copy of the remote target.
34   // The alignment requirement is just stored here for later use. Regular
35   // heap storage is sufficient here.
36   void *Addr = malloc(Size);
37   assert(Addr && "malloc() failure!");
38   sys::MemoryBlock Block(Addr, Size);
39   AllocatedDataMem.push_back(Allocation(Block, Alignment));
40   return (uint8_t*)Addr;
41 }
42 void RecordingMemoryManager::setMemoryWritable() { llvm_unreachable("Unexpected!"); }
43 void RecordingMemoryManager::setMemoryExecutable() { llvm_unreachable("Unexpected!"); }
44 void RecordingMemoryManager::setPoisonMemory(bool poison) { llvm_unreachable("Unexpected!"); }
45 void RecordingMemoryManager::AllocateGOT() { llvm_unreachable("Unexpected!"); }
46 uint8_t *RecordingMemoryManager::getGOTBase() const {
47   llvm_unreachable("Unexpected!");
48   return 0;
49 }
50 uint8_t *RecordingMemoryManager::startFunctionBody(const Function *F, uintptr_t &ActualSize){
51   llvm_unreachable("Unexpected!");
52   return 0;
53 }
54 uint8_t *RecordingMemoryManager::allocateStub(const GlobalValue* F, unsigned StubSize,
55                                               unsigned Alignment) {
56   llvm_unreachable("Unexpected!");
57   return 0;
58 }
59 void RecordingMemoryManager::endFunctionBody(const Function *F, uint8_t *FunctionStart,
60                                              uint8_t *FunctionEnd) {
61   llvm_unreachable("Unexpected!");
62 }
63 uint8_t *RecordingMemoryManager::allocateSpace(intptr_t Size, unsigned Alignment) {
64   llvm_unreachable("Unexpected!");
65   return 0;
66 }
67 uint8_t *RecordingMemoryManager::allocateGlobal(uintptr_t Size, unsigned Alignment) {
68   llvm_unreachable("Unexpected!");
69   return 0;
70 }
71 void RecordingMemoryManager::deallocateFunctionBody(void *Body) {
72   llvm_unreachable("Unexpected!");
73 }
74 uint8_t* RecordingMemoryManager::startExceptionTable(const Function* F, uintptr_t &ActualSize) {
75   llvm_unreachable("Unexpected!");
76   return 0;
77 }
78 void RecordingMemoryManager::endExceptionTable(const Function *F, uint8_t *TableStart,
79                                                uint8_t *TableEnd, uint8_t* FrameRegister) {
80   llvm_unreachable("Unexpected!");
81 }
82 void RecordingMemoryManager::deallocateExceptionTable(void *ET) {
83   llvm_unreachable("Unexpected!");
84 }
85
86 static int jit_noop() {
87   return 0;
88 }
89
90 void *RecordingMemoryManager::getPointerToNamedFunction(const std::string &Name,
91                                                         bool AbortOnFailure) {
92   // We should not invoke parent's ctors/dtors from generated main()!
93   // On Mingw and Cygwin, the symbol __main is resolved to
94   // callee's(eg. tools/lli) one, to invoke wrong duplicated ctors
95   // (and register wrong callee's dtors with atexit(3)).
96   // We expect ExecutionEngine::runStaticConstructorsDestructors()
97   // is called before ExecutionEngine::runFunctionAsMain() is called.
98   if (Name == "__main") return (void*)(intptr_t)&jit_noop;
99
100   return NULL;
101 }