[llvm-commits] [llvm] r61674 - in /llvm/trunk/lib/ExecutionEngine/JIT: Intercept.cpp JIT.cpp JIT.h JITEmitter.cpp
Dan Gohman
gohman at apple.com
Sun Jan 4 21:32:43 PST 2009
Author: djg
Date: Sun Jan 4 23:32:42 2009
New Revision: 61674
URL: http://llvm.org/viewvc/llvm-project?rev=61674&view=rev
Log:
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.
Modified:
llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp
llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp
llvm/trunk/lib/ExecutionEngine/JIT/JIT.h
llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
Modified: llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp?rev=61674&r1=61673&r2=61674&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp Sun Jan 4 23:32:42 2009
@@ -90,7 +90,8 @@
/// 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 @@
// 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 @@
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;
}
Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp?rev=61674&r1=61673&r2=61674&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Sun Jan 4 23:32:42 2009
@@ -509,16 +509,17 @@
<< "' 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;
}
Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.h?rev=61674&r1=61673&r2=61674&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JIT.h (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.h Sun Jan 4 23:32:42 2009
@@ -89,7 +89,12 @@
/// 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.
Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=61674&r1=61673&r2=61674&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp Sun Jan 4 23:32:42 2009
@@ -177,9 +177,14 @@
// 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 @@
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";
More information about the llvm-commits
mailing list