diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp index 63bec960936..878c3c33bb5 100644 --- a/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -213,9 +213,14 @@ void Emitter::emitWordAt(unsigned W, unsigned *Ptr) { uint64_t Emitter::getGlobalValueAddress(GlobalValue *V) { // Try looking up the function to see if it is already compiled, if not return // 0. - if (isa(V)) - return (intptr_t)TheJIT->getPointerToGlobalIfAvailable(V); - else { + if (Function *F = dyn_cast(V)) { + void *Addr = TheJIT->getPointerToGlobalIfAvailable(F); + if (Addr == 0 && F->hasExternalLinkage()) { + // Do not output stubs for external functions. + Addr = TheJIT->getPointerToFunction(F); + } + return (intptr_t)Addr; + } else { return (intptr_t)TheJIT->getOrEmitGlobalVariable(cast(V)); } }