diff options
| author | Dan Gohman <gohman@apple.com> | 2009-01-05 05:32:42 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2009-01-05 05:32:42 +0000 |
| commit | d32ec016ccf04867f1d20d8f7dd0764a77a7fbd9 (patch) | |
| tree | 34f823eadb3d961cf136c3c1d2d3b1106aabe3cf /llvm/lib/ExecutionEngine/JIT | |
| parent | 74f249517eac5a5fc5633364306c7f120ea5d47f (diff) | |
| download | bcm5719-llvm-d32ec016ccf04867f1d20d8f7dd0764a77a7fbd9.tar.gz bcm5719-llvm-d32ec016ccf04867f1d20d8f7dd0764a77a7fbd9.zip | |
Handle weak_extern in the JIT. This fixes
SingleSource/UnitTests/2007-04-25-weak.c in JIT mode. The test
now passes on systems which are able to produce a correct
reference output to compare with.
llvm-svn: 61674
Diffstat (limited to 'llvm/lib/ExecutionEngine/JIT')
| -rw-r--r-- | llvm/lib/ExecutionEngine/JIT/Intercept.cpp | 15 | ||||
| -rw-r--r-- | llvm/lib/ExecutionEngine/JIT/JIT.cpp | 9 | ||||
| -rw-r--r-- | llvm/lib/ExecutionEngine/JIT/JIT.h | 7 | ||||
| -rw-r--r-- | llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp | 10 |
4 files changed, 28 insertions, 13 deletions
diff --git a/llvm/lib/ExecutionEngine/JIT/Intercept.cpp b/llvm/lib/ExecutionEngine/JIT/Intercept.cpp index af8b58ed4dc..1590925b044 100644 --- a/llvm/lib/ExecutionEngine/JIT/Intercept.cpp +++ b/llvm/lib/ExecutionEngine/JIT/Intercept.cpp @@ -90,7 +90,8 @@ static int jit_atexit(void (*Fn)(void)) { /// function by using the dynamic loader interface. As such it is only useful /// for resolving library symbols, not code generated symbols. /// -void *JIT::getPointerToNamedFunction(const std::string &Name) { +void *JIT::getPointerToNamedFunction(const std::string &Name, + bool AbortOnFailure) { if (!isSymbolSearchingDisabled()) { // Check to see if this is one of the functions we want to intercept. Note, // we cast to intptr_t here to silence a -pedantic warning that complains @@ -122,9 +123,9 @@ void *JIT::getPointerToNamedFunction(const std::string &Name) { // First try turning $LDBLStub into $LDBL128. If that fails, strip it off. // This mirrors logic in libSystemStubs.a. std::string Prefix = std::string(Name.begin(), Name.end()-9); - if (void *Ptr = getPointerToNamedFunction(Prefix+"$LDBL128")) + if (void *Ptr = getPointerToNamedFunction(Prefix+"$LDBL128"), false) return Ptr; - if (void *Ptr = getPointerToNamedFunction(Prefix)) + if (void *Ptr = getPointerToNamedFunction(Prefix), false) return Ptr; } #endif @@ -135,8 +136,10 @@ void *JIT::getPointerToNamedFunction(const std::string &Name) { if (void *RP = LazyFunctionCreator(Name)) return RP; - cerr << "ERROR: Program used external function '" << Name - << "' which could not be resolved!\n"; - abort(); + if (AbortOnFailure) { + cerr << "ERROR: Program used external function '" << Name + << "' which could not be resolved!\n"; + abort(); + } return 0; } diff --git a/llvm/lib/ExecutionEngine/JIT/JIT.cpp b/llvm/lib/ExecutionEngine/JIT/JIT.cpp index 5d5ecc4fe77..6cd1c509785 100644 --- a/llvm/lib/ExecutionEngine/JIT/JIT.cpp +++ b/llvm/lib/ExecutionEngine/JIT/JIT.cpp @@ -509,16 +509,17 @@ void *JIT::getPointerToFunction(Function *F) { << "' from bitcode file: " << ErrorMsg << "\n"; abort(); } - } - if (void *Addr = getPointerToGlobalIfAvailable(F)) { - return Addr; + // Now retry to get the address. + if (void *Addr = getPointerToGlobalIfAvailable(F)) + return Addr; } MutexGuard locked(lock); if (F->isDeclaration()) { - void *Addr = getPointerToNamedFunction(F->getName()); + bool AbortOnFailure = F->getLinkage() != GlobalValue::ExternalWeakLinkage; + void *Addr = getPointerToNamedFunction(F->getName(), AbortOnFailure); addGlobalMapping(F, Addr); return Addr; } diff --git a/llvm/lib/ExecutionEngine/JIT/JIT.h b/llvm/lib/ExecutionEngine/JIT/JIT.h index 2eee2e980ce..b9299996033 100644 --- a/llvm/lib/ExecutionEngine/JIT/JIT.h +++ b/llvm/lib/ExecutionEngine/JIT/JIT.h @@ -89,7 +89,12 @@ public: /// specified function by using the dlsym function call. As such it is only /// useful for resolving library symbols, not code generated symbols. /// - void *getPointerToNamedFunction(const std::string &Name); + /// If AbortOnFailure is false and no function with the given name is + /// found, this function silently returns a null pointer. Otherwise, + /// it prints a message to stderr and aborts. + /// + void *getPointerToNamedFunction(const std::string &Name, + bool AbortOnFailure = true); // CompilationCallback - Invoked the first time that a call site is found, // which causes lazy compilation of the target function. diff --git a/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp b/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp index e041767f8f3..3f3f681f610 100644 --- a/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -177,9 +177,14 @@ void *JITResolver::getFunctionStub(Function *F) { // Call the lazy resolver function unless we already KNOW it is an external // function, in which case we just skip the lazy resolution step. void *Actual = (void*)(intptr_t)LazyResolverFn; - if (F->isDeclaration() && !F->hasNotBeenReadFromBitcode()) + if (F->isDeclaration() && !F->hasNotBeenReadFromBitcode()) { Actual = TheJIT->getPointerToFunction(F); + // If we resolved the symbol to a null address (eg. a weak external) + // don't emit a stub. Return a null pointer to the application. + if (!Actual) return 0; + } + // Otherwise, codegen a new stub. For now, the stub will call the lazy // resolver function. Stub = TheJIT->getJITInfo().emitFunctionStub(F, Actual, @@ -905,7 +910,8 @@ bool JITEmitter::finishFunction(MachineFunction &F) { void *ResultPtr = 0; if (!MR.letTargetResolve()) { if (MR.isExternalSymbol()) { - ResultPtr = TheJIT->getPointerToNamedFunction(MR.getExternalSymbol()); + ResultPtr = TheJIT->getPointerToNamedFunction(MR.getExternalSymbol(), + false); DOUT << "JIT: Map \'" << MR.getExternalSymbol() << "\' to [" << ResultPtr << "]\n"; |

