llvm.org GIT mirror llvm / 7803ec3
Based on this discussion: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120305/138477.html 1. Declare a virtual function getPointerToNamedFunction() in JITMemoryManager 2. Move the implementation of getPointerToNamedFunction() form JIT/MCJIT to DefaultJITMemoryManager. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153205 91177308-0d34-0410-b5e6-96231b3b80d8 Danil Malyshev 8 years ago
11 changed file(s) with 215 addition(s) and 329 deletion(s). Raw diff Collapse all Expand all
4545 /// garbage values over freed memory. This is useful for testing and
4646 /// debugging, and may be turned on by default in debug mode.
4747 virtual void setPoisonMemory(bool poison) = 0;
48
49 /// getPointerToNamedFunction - This method returns the address of the
50 /// specified function by using the dlsym function call. As such it is only
51 /// useful for resolving library symbols, not code generated symbols.
52 ///
53 /// If AbortOnFailure is false and no function with the given name is
54 /// found, this function silently returns a null pointer. Otherwise,
55 /// it prints a message to stderr and aborts.
56 ///
57 virtual void *getPointerToNamedFunction(const std::string &Name,
58 bool AbortOnFailure = true) = 0;
4859
4960 //===--------------------------------------------------------------------===//
5061 // Global Offset Table Management
11 add_definitions(-DENABLE_X86_JIT)
22
33 add_llvm_library(LLVMJIT
4 Intercept.cpp
54 JIT.cpp
65 JITDwarfEmitter.cpp
76 JITEmitter.cpp
+0
-162
lib/ExecutionEngine/JIT/Intercept.cpp less more
None //===-- Intercept.cpp - System function interception routines -------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // If a function call occurs to an external function, the JIT is designed to use
10 // the dynamic loader interface to find a function to call. This is useful for
11 // calling system calls and library functions that are not available in LLVM.
12 // Some system calls, however, need to be handled specially. For this reason,
13 // we intercept some of them here and use our own stubs to handle them.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #include "JIT.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/DynamicLibrary.h"
20 #include "llvm/Config/config.h"
21 using namespace llvm;
22
23 // AtExitHandlers - List of functions to call when the program exits,
24 // registered with the atexit() library function.
25 static std::vector AtExitHandlers;
26
27 /// runAtExitHandlers - Run any functions registered by the program's
28 /// calls to atexit(3), which we intercept and store in
29 /// AtExitHandlers.
30 ///
31 static void runAtExitHandlers() {
32 while (!AtExitHandlers.empty()) {
33 void (*Fn)() = AtExitHandlers.back();
34 AtExitHandlers.pop_back();
35 Fn();
36 }
37 }
38
39 //===----------------------------------------------------------------------===//
40 // Function stubs that are invoked instead of certain library calls
41 //===----------------------------------------------------------------------===//
42
43 // Force the following functions to be linked in to anything that uses the
44 // JIT. This is a hack designed to work around the all-too-clever Glibc
45 // strategy of making these functions work differently when inlined vs. when
46 // not inlined, and hiding their real definitions in a separate archive file
47 // that the dynamic linker can't see. For more info, search for
48 // 'libc_nonshared.a' on Google, or read http://llvm.org/PR274.
49 #if defined(__linux__)
50 #if defined(HAVE_SYS_STAT_H)
51 #include
52 #endif
53 #include
54 #include
55 /* stat functions are redirecting to __xstat with a version number. On x86-64
56 * linking with libc_nonshared.a and -Wl,--export-dynamic doesn't make 'stat'
57 * available as an exported symbol, so we have to add it explicitly.
58 */
59 namespace {
60 class StatSymbols {
61 public:
62 StatSymbols() {
63 sys::DynamicLibrary::AddSymbol("stat", (void*)(intptr_t)stat);
64 sys::DynamicLibrary::AddSymbol("fstat", (void*)(intptr_t)fstat);
65 sys::DynamicLibrary::AddSymbol("lstat", (void*)(intptr_t)lstat);
66 sys::DynamicLibrary::AddSymbol("stat64", (void*)(intptr_t)stat64);
67 sys::DynamicLibrary::AddSymbol("\x1stat64", (void*)(intptr_t)stat64);
68 sys::DynamicLibrary::AddSymbol("\x1open64", (void*)(intptr_t)open64);
69 sys::DynamicLibrary::AddSymbol("\x1lseek64", (void*)(intptr_t)lseek64);
70 sys::DynamicLibrary::AddSymbol("fstat64", (void*)(intptr_t)fstat64);
71 sys::DynamicLibrary::AddSymbol("lstat64", (void*)(intptr_t)lstat64);
72 sys::DynamicLibrary::AddSymbol("atexit", (void*)(intptr_t)atexit);
73 sys::DynamicLibrary::AddSymbol("mknod", (void*)(intptr_t)mknod);
74 }
75 };
76 }
77 static StatSymbols initStatSymbols;
78 #endif // __linux__
79
80 // jit_exit - Used to intercept the "exit" library call.
81 static void jit_exit(int Status) {
82 runAtExitHandlers(); // Run atexit handlers...
83 exit(Status);
84 }
85
86 // jit_atexit - Used to intercept the "atexit" library call.
87 static int jit_atexit(void (*Fn)()) {
88 AtExitHandlers.push_back(Fn); // Take note of atexit handler...
89 return 0; // Always successful
90 }
91
92 static int jit_noop() {
93 return 0;
94 }
95
96 //===----------------------------------------------------------------------===//
97 //
98 /// getPointerToNamedFunction - This method returns the address of the specified
99 /// function by using the dynamic loader interface. As such it is only useful
100 /// for resolving library symbols, not code generated symbols.
101 ///
102 void *JIT::getPointerToNamedFunction(const std::string &Name,
103 bool AbortOnFailure) {
104 if (!isSymbolSearchingDisabled()) {
105 // Check to see if this is one of the functions we want to intercept. Note,
106 // we cast to intptr_t here to silence a -pedantic warning that complains
107 // about casting a function pointer to a normal pointer.
108 if (Name == "exit") return (void*)(intptr_t)&jit_exit;
109 if (Name == "atexit") return (void*)(intptr_t)&jit_atexit;
110
111 // We should not invoke parent's ctors/dtors from generated main()!
112 // On Mingw and Cygwin, the symbol __main is resolved to
113 // callee's(eg. tools/lli) one, to invoke wrong duplicated ctors
114 // (and register wrong callee's dtors with atexit(3)).
115 // We expect ExecutionEngine::runStaticConstructorsDestructors()
116 // is called before ExecutionEngine::runFunctionAsMain() is called.
117 if (Name == "__main") return (void*)(intptr_t)&jit_noop;
118
119 const char *NameStr = Name.c_str();
120 // If this is an asm specifier, skip the sentinal.
121 if (NameStr[0] == 1) ++NameStr;
122
123 // If it's an external function, look it up in the process image...
124 void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr);
125 if (Ptr) return Ptr;
126
127 // If it wasn't found and if it starts with an underscore ('_') character,
128 // and has an asm specifier, try again without the underscore.
129 if (Name[0] == 1 && NameStr[0] == '_') {
130 Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr+1);
131 if (Ptr) return Ptr;
132 }
133
134 // Darwin/PPC adds $LDBLStub suffixes to various symbols like printf. These
135 // are references to hidden visibility symbols that dlsym cannot resolve.
136 // If we have one of these, strip off $LDBLStub and try again.
137 #if defined(__APPLE__) && defined(__ppc__)
138 if (Name.size() > 9 && Name[Name.size()-9] == '$' &&
139 memcmp(&Name[Name.size()-8], "LDBLStub", 8) == 0) {
140 // First try turning $LDBLStub into $LDBL128. If that fails, strip it off.
141 // This mirrors logic in libSystemStubs.a.
142 std::string Prefix = std::string(Name.begin(), Name.end()-9);
143 if (void *Ptr = getPointerToNamedFunction(Prefix+"$LDBL128", false))
144 return Ptr;
145 if (void *Ptr = getPointerToNamedFunction(Prefix, false))
146 return Ptr;
147 }
148 #endif
149 }
150
151 /// If a LazyFunctionCreator is installed, use it to get/create the function.
152 if (LazyFunctionCreator)
153 if (void *RP = LazyFunctionCreator(Name))
154 return RP;
155
156 if (AbortOnFailure) {
157 report_fatal_error("Program used external function '"+Name+
158 "' which could not be resolved!");
159 }
160 return 0;
161 }
2222 #include "llvm/CodeGen/MachineCodeInfo.h"
2323 #include "llvm/ExecutionEngine/GenericValue.h"
2424 #include "llvm/ExecutionEngine/JITEventListener.h"
25 #include "llvm/ExecutionEngine/JITMemoryManager.h"
2526 #include "llvm/Target/TargetData.h"
2627 #include "llvm/Target/TargetMachine.h"
2728 #include "llvm/Target/TargetJITInfo.h"
266267 }
267268
268269 JIT::JIT(Module *M, TargetMachine &tm, TargetJITInfo &tji,
269 JITMemoryManager *JMM, bool GVsWithCode)
270 : ExecutionEngine(M), TM(tm), TJI(tji), AllocateGVsWithCode(GVsWithCode),
271 isAlreadyCodeGenerating(false) {
270 JITMemoryManager *jmm, bool GVsWithCode)
271 : ExecutionEngine(M), TM(tm), TJI(tji), JMM(jmm),
272 AllocateGVsWithCode(GVsWithCode), isAlreadyCodeGenerating(false) {
272273 setTargetData(TM.getTargetData());
273274
274275 jitstate = new JITState(M);
710711 }
711712 }
712713
714 void *JIT::getPointerToNamedFunction(const std::string &Name,
715 bool AbortOnFailure){
716 if (!isSymbolSearchingDisabled()) {
717 void *ptr = JMM->getPointerToNamedFunction(Name, false);
718 if (ptr)
719 return ptr;
720 }
721
722 /// If a LazyFunctionCreator is installed, use it to get/create the function.
723 if (LazyFunctionCreator)
724 if (void *RP = LazyFunctionCreator(Name))
725 return RP;
726
727 if (AbortOnFailure) {
728 report_fatal_error("Program used external function '"+Name+
729 "' which could not be resolved!");
730 }
731 return 0;
732 }
733
734
713735 /// getOrEmitGlobalVariable - Return the address of the specified global
714736 /// variable, possibly emitting it to memory if needed. This is used by the
715737 /// Emitter.
5757 TargetMachine &TM; // The current target we are compiling to
5858 TargetJITInfo &TJI; // The JITInfo for the target we are compiling to
5959 JITCodeEmitter *JCE; // JCE object
60 JITMemoryManager *JMM;
6061 std::vector EventListeners;
6162
6263 /// AllocateGVsWithCode - Some applications require that global variables and
313313 /// should allocate a separate slab.
314314 static const size_t DefaultSizeThreshold;
315315
316 /// getPointerToNamedFunction - This method returns the address of the
317 /// specified function by using the dlsym function call. As such it is only
318 /// useful for resolving library symbols, not code generated symbols.
319 ///
320 /// If AbortOnFailure is false and no function with the given name is
321 /// found, this function silently returns a null pointer. Otherwise,
322 /// it prints a message to stderr and aborts.
323 ///
324 virtual void *getPointerToNamedFunction(const std::string &Name,
325 bool AbortOnFailure = true);
326
316327 void AllocateGOT();
317328
318329 // Testing methods.
756767 return true;
757768 }
758769
770 //===----------------------------------------------------------------------===//
771 // getPointerToNamedFunction() implementation.
772 //===----------------------------------------------------------------------===//
773 #include "llvm/Support/ErrorHandling.h"
774 #include "llvm/Support/DynamicLibrary.h"
775 #include "llvm/Config/config.h"
776
777 // AtExitHandlers - List of functions to call when the program exits,
778 // registered with the atexit() library function.
779 static std::vector AtExitHandlers;
780
781 /// runAtExitHandlers - Run any functions registered by the program's
782 /// calls to atexit(3), which we intercept and store in
783 /// AtExitHandlers.
784 ///
785 static void runAtExitHandlers() {
786 while (!AtExitHandlers.empty()) {
787 void (*Fn)() = AtExitHandlers.back();
788 AtExitHandlers.pop_back();
789 Fn();
790 }
791 }
792
793 //===----------------------------------------------------------------------===//
794 // Function stubs that are invoked instead of certain library calls
795 //===----------------------------------------------------------------------===//
796
797 // Force the following functions to be linked in to anything that uses the
798 // JIT. This is a hack designed to work around the all-too-clever Glibc
799 // strategy of making these functions work differently when inlined vs. when
800 // not inlined, and hiding their real definitions in a separate archive file
801 // that the dynamic linker can't see. For more info, search for
802 // 'libc_nonshared.a' on Google, or read http://llvm.org/PR274.
803 #if defined(__linux__)
804 #if defined(HAVE_SYS_STAT_H)
805 #include
806 #endif
807 #include
808 #include
809 /* stat functions are redirecting to __xstat with a version number. On x86-64
810 * linking with libc_nonshared.a and -Wl,--export-dynamic doesn't make 'stat'
811 * available as an exported symbol, so we have to add it explicitly.
812 */
813 namespace {
814 class StatSymbols {
815 public:
816 StatSymbols() {
817 sys::DynamicLibrary::AddSymbol("stat", (void*)(intptr_t)stat);
818 sys::DynamicLibrary::AddSymbol("fstat", (void*)(intptr_t)fstat);
819 sys::DynamicLibrary::AddSymbol("lstat", (void*)(intptr_t)lstat);
820 sys::DynamicLibrary::AddSymbol("stat64", (void*)(intptr_t)stat64);
821 sys::DynamicLibrary::AddSymbol("\x1stat64", (void*)(intptr_t)stat64);
822 sys::DynamicLibrary::AddSymbol("\x1open64", (void*)(intptr_t)open64);
823 sys::DynamicLibrary::AddSymbol("\x1lseek64", (void*)(intptr_t)lseek64);
824 sys::DynamicLibrary::AddSymbol("fstat64", (void*)(intptr_t)fstat64);
825 sys::DynamicLibrary::AddSymbol("lstat64", (void*)(intptr_t)lstat64);
826 sys::DynamicLibrary::AddSymbol("atexit", (void*)(intptr_t)atexit);
827 sys::DynamicLibrary::AddSymbol("mknod", (void*)(intptr_t)mknod);
828 }
829 };
830 }
831 static StatSymbols initStatSymbols;
832 #endif // __linux__
833
834 // jit_exit - Used to intercept the "exit" library call.
835 static void jit_exit(int Status) {
836 runAtExitHandlers(); // Run atexit handlers...
837 exit(Status);
838 }
839
840 // jit_atexit - Used to intercept the "atexit" library call.
841 static int jit_atexit(void (*Fn)()) {
842 AtExitHandlers.push_back(Fn); // Take note of atexit handler...
843 return 0; // Always successful
844 }
845
846 static int jit_noop() {
847 return 0;
848 }
849
850 //===----------------------------------------------------------------------===//
851 //
852 /// getPointerToNamedFunction - This method returns the address of the specified
853 /// function by using the dynamic loader interface. As such it is only useful
854 /// for resolving library symbols, not code generated symbols.
855 ///
856 void *DefaultJITMemoryManager::getPointerToNamedFunction(const std::string &Name,
857 bool AbortOnFailure) {
858 // Check to see if this is one of the functions we want to intercept. Note,
859 // we cast to intptr_t here to silence a -pedantic warning that complains
860 // about casting a function pointer to a normal pointer.
861 if (Name == "exit") return (void*)(intptr_t)&jit_exit;
862 if (Name == "atexit") return (void*)(intptr_t)&jit_atexit;
863
864 // We should not invoke parent's ctors/dtors from generated main()!
865 // On Mingw and Cygwin, the symbol __main is resolved to
866 // callee's(eg. tools/lli) one, to invoke wrong duplicated ctors
867 // (and register wrong callee's dtors with atexit(3)).
868 // We expect ExecutionEngine::runStaticConstructorsDestructors()
869 // is called before ExecutionEngine::runFunctionAsMain() is called.
870 if (Name == "__main") return (void*)(intptr_t)&jit_noop;
871
872 const char *NameStr = Name.c_str();
873 // If this is an asm specifier, skip the sentinal.
874 if (NameStr[0] == 1) ++NameStr;
875
876 // If it's an external function, look it up in the process image...
877 void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr);
878 if (Ptr) return Ptr;
879
880 // If it wasn't found and if it starts with an underscore ('_') character,
881 // try again without the underscore.
882 if (NameStr[0] == '_') {
883 Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr+1);
884 if (Ptr) return Ptr;
885 }
886
887 // Darwin/PPC adds $LDBLStub suffixes to various symbols like printf. These
888 // are references to hidden visibility symbols that dlsym cannot resolve.
889 // If we have one of these, strip off $LDBLStub and try again.
890 #if defined(__APPLE__) && defined(__ppc__)
891 if (Name.size() > 9 && Name[Name.size()-9] == '$' &&
892 memcmp(&Name[Name.size()-8], "LDBLStub", 8) == 0) {
893 // First try turning $LDBLStub into $LDBL128. If that fails, strip it off.
894 // This mirrors logic in libSystemStubs.a.
895 std::string Prefix = std::string(Name.begin(), Name.end()-9);
896 if (void *Ptr = getPointerToNamedFunction(Prefix+"$LDBL128", false))
897 return Ptr;
898 if (void *Ptr = getPointerToNamedFunction(Prefix, false))
899 return Ptr;
900 }
901 #endif
902
903 if (AbortOnFailure) {
904 report_fatal_error("Program used external function '"+Name+
905 "' which could not be resolved!");
906 }
907 return 0;
908 }
909
910
911
759912 JITMemoryManager *JITMemoryManager::CreateDefaultMemManager() {
760913 return new DefaultJITMemoryManager();
761914 }
0 add_llvm_library(LLVMMCJIT
11 MCJIT.cpp
22 MCJITMemoryManager.cpp
3 Intercept.cpp
43 )
+0
-162
lib/ExecutionEngine/MCJIT/Intercept.cpp less more
None //===-- Intercept.cpp - System function interception routines -------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // If a function call occurs to an external function, the JIT is designed to use
10 // the dynamic loader interface to find a function to call. This is useful for
11 // calling system calls and library functions that are not available in LLVM.
12 // Some system calls, however, need to be handled specially. For this reason,
13 // we intercept some of them here and use our own stubs to handle them.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #include "MCJIT.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/DynamicLibrary.h"
20 #include "llvm/Config/config.h"
21 using namespace llvm;
22
23 // AtExitHandlers - List of functions to call when the program exits,
24 // registered with the atexit() library function.
25 static std::vector AtExitHandlers;
26
27 /// runAtExitHandlers - Run any functions registered by the program's
28 /// calls to atexit(3), which we intercept and store in
29 /// AtExitHandlers.
30 ///
31 static void runAtExitHandlers() {
32 while (!AtExitHandlers.empty()) {
33 void (*Fn)() = AtExitHandlers.back();
34 AtExitHandlers.pop_back();
35 Fn();
36 }
37 }
38
39 //===----------------------------------------------------------------------===//
40 // Function stubs that are invoked instead of certain library calls
41 //===----------------------------------------------------------------------===//
42
43 // Force the following functions to be linked in to anything that uses the
44 // JIT. This is a hack designed to work around the all-too-clever Glibc
45 // strategy of making these functions work differently when inlined vs. when
46 // not inlined, and hiding their real definitions in a separate archive file
47 // that the dynamic linker can't see. For more info, search for
48 // 'libc_nonshared.a' on Google, or read http://llvm.org/PR274.
49 #if defined(__linux__)
50 #if defined(HAVE_SYS_STAT_H)
51 #include
52 #endif
53 #include
54 #include
55 /* stat functions are redirecting to __xstat with a version number. On x86-64
56 * linking with libc_nonshared.a and -Wl,--export-dynamic doesn't make 'stat'
57 * available as an exported symbol, so we have to add it explicitly.
58 */
59 namespace {
60 class StatSymbols {
61 public:
62 StatSymbols() {
63 sys::DynamicLibrary::AddSymbol("stat", (void*)(intptr_t)stat);
64 sys::DynamicLibrary::AddSymbol("fstat", (void*)(intptr_t)fstat);
65 sys::DynamicLibrary::AddSymbol("lstat", (void*)(intptr_t)lstat);
66 sys::DynamicLibrary::AddSymbol("stat64", (void*)(intptr_t)stat64);
67 sys::DynamicLibrary::AddSymbol("\x1stat64", (void*)(intptr_t)stat64);
68 sys::DynamicLibrary::AddSymbol("\x1open64", (void*)(intptr_t)open64);
69 sys::DynamicLibrary::AddSymbol("\x1lseek64", (void*)(intptr_t)lseek64);
70 sys::DynamicLibrary::AddSymbol("fstat64", (void*)(intptr_t)fstat64);
71 sys::DynamicLibrary::AddSymbol("lstat64", (void*)(intptr_t)lstat64);
72 sys::DynamicLibrary::AddSymbol("atexit", (void*)(intptr_t)atexit);
73 sys::DynamicLibrary::AddSymbol("mknod", (void*)(intptr_t)mknod);
74 }
75 };
76 }
77 static StatSymbols initStatSymbols;
78 #endif // __linux__
79
80 // jit_exit - Used to intercept the "exit" library call.
81 static void jit_exit(int Status) {
82 runAtExitHandlers(); // Run atexit handlers...
83 exit(Status);
84 }
85
86 // jit_atexit - Used to intercept the "atexit" library call.
87 static int jit_atexit(void (*Fn)()) {
88 AtExitHandlers.push_back(Fn); // Take note of atexit handler...
89 return 0; // Always successful
90 }
91
92 static int jit_noop() {
93 return 0;
94 }
95
96 //===----------------------------------------------------------------------===//
97 //
98 /// getPointerToNamedFunction - This method returns the address of the specified
99 /// function by using the dynamic loader interface. As such it is only useful
100 /// for resolving library symbols, not code generated symbols.
101 ///
102 void *MCJIT::getPointerToNamedFunction(const std::string &Name,
103 bool AbortOnFailure) {
104 if (!isSymbolSearchingDisabled()) {
105 // Check to see if this is one of the functions we want to intercept. Note,
106 // we cast to intptr_t here to silence a -pedantic warning that complains
107 // about casting a function pointer to a normal pointer.
108 if (Name == "exit") return (void*)(intptr_t)&jit_exit;
109 if (Name == "atexit") return (void*)(intptr_t)&jit_atexit;
110
111 // We should not invoke parent's ctors/dtors from generated main()!
112 // On Mingw and Cygwin, the symbol __main is resolved to
113 // callee's(eg. tools/lli) one, to invoke wrong duplicated ctors
114 // (and register wrong callee's dtors with atexit(3)).
115 // We expect ExecutionEngine::runStaticConstructorsDestructors()
116 // is called before ExecutionEngine::runFunctionAsMain() is called.
117 if (Name == "__main") return (void*)(intptr_t)&jit_noop;
118
119 const char *NameStr = Name.c_str();
120 // If this is an asm specifier, skip the sentinal.
121 if (NameStr[0] == 1) ++NameStr;
122
123 // If it's an external function, look it up in the process image...
124 void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr);
125 if (Ptr) return Ptr;
126
127 // If it wasn't found and if it starts with an underscore ('_') character,
128 // and has an asm specifier, try again without the underscore.
129 if (Name[0] == 1 && NameStr[0] == '_') {
130 Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr+1);
131 if (Ptr) return Ptr;
132 }
133
134 // Darwin/PPC adds $LDBLStub suffixes to various symbols like printf. These
135 // are references to hidden visibility symbols that dlsym cannot resolve.
136 // If we have one of these, strip off $LDBLStub and try again.
137 #if defined(__APPLE__) && defined(__ppc__)
138 if (Name.size() > 9 && Name[Name.size()-9] == '$' &&
139 memcmp(&Name[Name.size()-8], "LDBLStub", 8) == 0) {
140 // First try turning $LDBLStub into $LDBL128. If that fails, strip it off.
141 // This mirrors logic in libSystemStubs.a.
142 std::string Prefix = std::string(Name.begin(), Name.end()-9);
143 if (void *Ptr = getPointerToNamedFunction(Prefix+"$LDBL128", false))
144 return Ptr;
145 if (void *Ptr = getPointerToNamedFunction(Prefix, false))
146 return Ptr;
147 }
148 #endif
149 }
150
151 /// If a LazyFunctionCreator is installed, use it to get/create the function.
152 if (LazyFunctionCreator)
153 if (void *RP = LazyFunctionCreator(Name))
154 return RP;
155
156 if (AbortOnFailure) {
157 report_fatal_error("Program used external function '"+Name+
158 "' which could not be resolved!");
159 }
160 return 0;
161 }
214214
215215 llvm_unreachable("Full-featured argument passing not supported yet!");
216216 }
217
218 void *MCJIT::getPointerToNamedFunction(const std::string &Name,
219 bool AbortOnFailure){
220 if (!isSymbolSearchingDisabled()) {
221 void *ptr = MemMgr->getPointerToNamedFunction(Name, false);
222 if (ptr)
223 return ptr;
224 }
225
226 /// If a LazyFunctionCreator is installed, use it to get/create the function.
227 if (LazyFunctionCreator)
228 if (void *RP = LazyFunctionCreator(Name))
229 return RP;
230
231 if (AbortOnFailure) {
232 report_fatal_error("Program used external function '"+Name+
233 "' which could not be resolved!");
234 }
235 return 0;
236 }
6666 ///
6767 virtual void *getPointerToNamedFunction(const std::string &Name,
6868 bool AbortOnFailure = true);
69
6970 /// mapSectionAddress - map a section to its target address space value.
7071 /// Map the address of a JIT section as returned from the memory manager
7172 /// to the address in the target process as the running code will see it.
6262 RecordingJITMemoryManager()
6363 : Base(JITMemoryManager::CreateDefaultMemManager()) {
6464 stubsAllocated = 0;
65 }
66 virtual void *getPointerToNamedFunction(const std::string &Name,
67 bool AbortOnFailure = true) {
68 return Base->getPointerToNamedFunction(Name, AbortOnFailure);
6569 }
6670
6771 virtual void setMemoryWritable() { Base->setMemoryWritable(); }