Bugzilla – Bug 58
[linker] linkonce globals should link successfully to external globals
Last modified: 2004-09-07 18:40:27
You need to log in before you can comment on or make changes to this bug.
The linker is refusing to link linkonce globals to externally visible globals. This is wrong, it should just drop the linkonce global like it does for weak symbols. This is tested by Linker/2003-10-27-LinkOncePromote.ll This does not really effect 1.0, because the C/C++ front-end never produced linkonce globals.
This is now fixed: http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20031027/008864.html
Stacker produces linkonce globals and this bug is not resolved in 1.3. The attached test case is reduced from a two bytecode files: the prime.st file compiled to bytecode and the stacker runtime compiled to bytecode. One declares that _stack_ variable extern, the other declares it linkonce. Attempting to run this with lli produces: Could not resolve external global address: _stack_ lli((anonymous namespace)::PrintStackTrace()+0x1a)[0x85633e6] lli((anonymous namespace)::SignalHandler(int)+0xc7)[0x8563653] /lib/tls/libc.so.6[0x420277b8] /lib/tls/libc.so.6(abort+0x1d5)[0x42028c55] lli(llvm::JIT::getOrEmitGlobalVariable(llvm::GlobalVariable const*)+0xad)[0x83262fb] lli((anonymous namespace)::Emitter::getGlobalValueAddress(llvm::GlobalValue*)+0x59)[0x83243f3] lli((anonymous namespace)::Emitter::emitGlobalAddressForPtr(llvm::GlobalValue*)+0x25)[0x838a13f] lli((anonymous namespace)::Emitter::emitInstruction(llvm::MachineInstr const&)+0x5a7)[0x838afc7] lli((anonymous namespace)::Emitter::emitBasicBlock(llvm::MachineBasicBlock const&)+0xaa)[0x8389f70] lli((anonymous namespace)::Emitter::runOnMachineFunction(llvm::MachineFunction&)+0xc6)[0x8389dd4] lli(llvm::MachineFunctionPass::runOnFunction(llvm::Function&)+0x29)[0x8347df1] lli(llvm::PassManagerTraits<llvm::Function>::runPass(llvm::FunctionPass*, llvm::Function*)+0x1f)[0x84db56f] lli(llvm::PassManagerT<llvm::Function>::runOnUnit(llvm::Function*)+0x5c0)[0x84dae2c] lli(llvm::PassManagerTraits<llvm::Function>::runOnFunction(llvm::Function&)+0x1f)[0x84dbaa1] lli(llvm::FunctionPass::run(llvm::Function&)+0x6a)[0x848314a] lli(llvm::FunctionPassManager::run(llvm::Function&)+0xe7)[0x84826e9] lli(llvm::JIT::runJITOnFunction(llvm::Function*)+0x4f)[0x8325fcb] lli(llvm::JIT::getPointerToFunction(llvm::Function*)+0x15f)[0x832617b] lli(llvm::JIT::runFunction(llvm::Function*, std::vector<llvm::GenericValue, std::allocator<llvm::GenericValue> > const&)+0x4e)[0x8325254] lli(llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, char const* const*)+0x2ee)[0x8377ef6] lli(main+0x2dd)[0x830abb1] /lib/tls/libc.so.6(__libc_start_main+0xe4)[0x42015704] lli(dlopen+0x41)[0x830a731] Aborted (core dumped) Compiling the file with llc produces the following x86 assembly: .intel_syntax .text .align 16 .globl main .type main, @function main: .LBBmain_0: # mov %EAX, OFFSET _stack_ mov %EAX, DWORD PTR [%EAX] #IMPLICIT_USE ret .data .comm l1__stack_,8192,4 # [2048 x int]* %_stack_ Which, if you try to link it, produces: bash-2.05b$ gcc prime.s -o prime /tmp/cc1blvtd.o(.text+0x1): In function `main': : undefined reference to `_stack_' collect2: ld returned 1 exit status
Created an attachment (id=171) [details] Test Case Showing Bug Not Resolved A reduced test case from a Stacker compile.
This bug shouldn't be reopened, as this is a different issue than the original PR. If you think there's a bug, please refile as a new one. You might try to run the -funcresolve pass on this testcase, it will probably do what you want. Note that the real solution to this problem is to fix bug 411. -Chris