问题
I'm having trouble linking a shared library using gcc 3.2.3 with binutils 2.18. When I try to link the library I get the following error:
.gnu.linkonce.t_... referenced in section .rodata: defined in discarded section .gnu.linkonce.t...
I've done a fair amount of googling on this and most places seem to indicate it is a regression introduce in binutils 2.17 and later fixed in 2.18.50, but I was curious if anybody knew if there were any particular workarounds for the issue without having to touch binutils and gcc.
Thanks.
回答1:
This turned out to be a strange result where the system was mismatching gcc with a different binutils. /usr/bin/gcc was being used (3.2.3) and /usr/local/bin/ld was being used with it due to /usr/local/bin being in front of /usr/bin in the path. When we switched so that /usr/bin was at the front of the path, the appropriate /usr/bin/ld was called (binutils 2.14) and this seems to have resolved the problem.
回答2:
This bug was found and was reported here GCC bugzilla, a small testcase that focuses on the bug was provided in the comments which I found it to be really helpful not to waste time. This bug was fixed starting GCC 3.4.6
.
I have had this issue while using GCC 3.3.1
with binutils 2.15.92
and binutils 2.17.50
and both didn't work. So, for me it clearly wasn't the mix of GCC
and binutils
versions that made the problem.
If you must use an older GCC
version you may use this patch provided by H.J.
and do it manually then rebuild your old GCC
again.
Fix without COMDAT group
Fix with COMDAT group
Check the attachements in the provided links that shows the exact diff for the fix.
I have did it myself and tested it and it worked successfully, patching GCC 3.3.1
with the first fix "without COMDAT group", rebuilt it and used it with binutils 2.15.92
and binutils 2.17.50
.
来源:https://stackoverflow.com/questions/1239730/help-with-linker-failer-gnu-linkonce-t