This works: $ ./gold/ld-new -plugin ./gold/testsuite/plugin_test.so --no-demangle -shared -o test.so bar.o foo.o API version: 1 gold version: 111 bar.o: claim file hook called (offset = 0, size = 936) foo.o: claim file hook called (offset = 0, size = 1176) all symbols read hook called cleanup hook called But this fails: $ ./gold/ld-new -plugin ./gold/testsuite/plugin_test.so --no-demangle -shared -o test.so bar.syms foo.o API version: 1 gold version: 111 bar.syms: claim file hook called (offset = 0, size = 596) bar.syms: claiming file, adding 1 symbols foo.o: claim file hook called (offset = 0, size = 1176) all symbols read hook called bar.syms: xyz: PREVAILING_DEF_REG bar.o: adding new input file ./gold/ld-new: error: foo.o: requires dynamic reloc which may overflow at runtime; recompile with -fPIC ./gold/ld-new: foo.o: in function bar:foo.ll(.text+0x4): warning: relocation refers to discarded section ./gold/ld-new: error: hidden symbol 'xyz' is not defined locally cleanup hook called
Created attachment 5237 [details] foo.o
Created attachment 5238 [details] bar.o
Created attachment 5239 [details] bar.syms
I noticed that the real problem is that plugins don't support linkonce. We select the symbol from the IL file but the section from the elf file :-) Shouldn't be too hard to add support, but I will try to get LLVM to use comdat instead. Should I close as wontfix?
Is this related to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47247
with GNU gold (GNU Binutils 2.21.1) 1.11 and gcc-4_7-branch revision 187326 with linker-plugin enabled I get this type of errors ld: error: hidden symbol '_ZThn16_N5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEED0Ev' is not defined locally ld: /tmp/innocent/ccggD26x.ltrans8.ltrans.o: in function _ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE.local.4390:ccggD26x.ltrans8.o(.data.rel.ro+0x1558): warning: relocation refers to discarded section does not occur w/o linker-plugin is the problem on gcc or gold side? (posted also on http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47247)
This bug report is specifically about plugins and linkonce. Please don't add separate bug reports to this one. Instead, open a new bug report. Thanks. Without a test case it's impossible to be sure, but I think "hidden symbol is not defined locally" is more likely to be a GCC problem.
> I noticed that the real problem is that plugins don't support linkonce. We > select the symbol from the IL file but the section from the elf file :-) > > Shouldn't be too hard to add support, but I will try to get LLVM to use > comdat instead. > > Should I close as wontfix? Yeah, I think comdat is the right way to go. BTW, with plugin_test.so, it doesn't recognize comdat symbols from the .syms file, but if you add the comdat key as a --plugin-opt, it will special-case a symbol of the same name. Limited use, but sufficient for the test cases.