GCC 4.5.0 20100114.
Created attachment 19614 [details] Testcase It produces error: undefined reference to 'i'
Works when linking in comm.o main.o order. I guess the linker resolution handling is bogus.
I see 2 main.o 2 78 PREVAILING_DEF main 81 RESOLVED_IR i comm.o 1 78 RESOLVED_IR i which is obviously bogus for comm.o.
*** Bug 43355 has been marked as a duplicate of this bug. ***
Ian? What's gold up to here?
It works with the llvm plugin for gold. I also find the gold output funny. What the llvm plugin does is if (I->syms[i].resolution == LDPR_PREVAILING_DEF || (I->syms[i].def == LDPK_COMMON && I->syms[i].resolution == LDPR_RESOLVED_IR)) { .... So it has a special case for common + resolved_ir. Let me try to find when this was added.
The llvm change is http://llvm.org/viewvc/llvm-project?view=rev&revision=64616 so I still don't know why gold is not returning LDPR_PREVAILING_DEF for the common symbol definition.
Cary, can you give advice and/or fix gold and/or the linker plugin?
(In reply to comment #2) > Works when linking in comm.o main.o order. FWIW one can construct test cases where neither order works, e.g., cat >main.c <<\EOF extern int i; int j; int main(void) { i = 0; return i; } EOF cat >comm.c <<\EOF extern int j; int i; int f() { return j; } EOF (libtool likes to produce such code with preload symfiles)
Created attachment 20267 [details] Gold patch to fix common symbol handling This gold patch ought to fix the problem. Please verify and I'll send it upstream to binutils. * plugin.cc (Pluginobj::get_symbol_resolution_info): Check for prevailing definitions of common symbols. * testsuite/plugin_test_6.sh: New testcase. * testsuite/plugin_common_test_1.c: New testcase. * testsuite/plugin_common_test_2.c: New testcase.
Created attachment 20269 [details] Updated gold patch to fix common symbol handling Sorry, I forgot to include the updated testsuite/Makefile.* in the patch... * plugin.cc (Pluginobj::get_symbol_resolution_info): Check for prevailing definitions of common symbols. * testsuite/plugin_test_6.sh: New test case. * testsuite/plugin_common_test_1.c: New test case. * testsuite/plugin_common_test_2.c: New test case. * testsuite/Makefile.am (plugin_test_6): New test case. * testsuite/Makefile.in: Regenerate.
(In reply to comment #11) This patch works for me. Thanks for looking into this!
gold patch committed