testcase: $ cat t.cpp #include <cstdio> void foo() { std::puts( "foo()" ); } $ /local/devel/toolchain45/x86_64-gnu-linux.mt_alloc/bin/x86_64-gnu-linux-g++ t.cpp -c -fpic $ /local/devel/toolchain45/x86_64-gnu-linux.mt_alloc/bin/x86_64-gnu-linux-ar rc t.a t.o $ /local/devel/toolchain45/x86_64-gnu-linux.mt_alloc/bin/x86_64-gnu-linux-ld.gold -L /local/devel/toolchain45/x86_64-gnu-linux.mt_alloc/lib64 -L /local/devel/toolchain45/x86_64-gnu-linux.mt_alloc/usr/lib64 -z defs -shared -o t.so --start-group --whole-archive t.a --no-whole-archive --end-group -lc /local/devel/toolchain45/x86_64-gnu-linux.mt_alloc/bin/x86_64-gnu-linux-ld.gold: error: t.a(t.o): multiple definition of 'foo()' /local/devel/toolchain45/x86_64-gnu-linux.mt_alloc/bin/x86_64-gnu-linux-ld.gold: t.a(t.o): previous definition here with classic BFD linked it works fine.
Created attachment 5198 [details] testcase.
with the latest binutils-2.21.51.0.5 bug still occurs: $ LANG=C make g++ t.cpp -fpic -c ar rc t.a t.o ld.bfd -z defs -shared -o t-bfd.so --start-group --whole-archive t.a --no-whole-archive --end-group -lc ld.gold -z defs -shared -o t-gold.so --start-group --whole-archive t.a --no-whole-archive --end-group -lc ld.gold: error: t.a(t.o): multiple definition of 'foo()' ld.gold: t.a(t.o): previous definition here ld.gold: warning: skipping incompatible /usr/lib/libc.so while searching for c ld.gold: error: cannot find -lc ld.gold: t.a(t.o): in function foo():t.cpp(.text+0xc): error: undefined reference to 'puts' ld.gold: t.a(t.o): in function foo():t.cpp(.text+0xc): error: undefined reference to 'puts' make: *** [all] Error 1
Created attachment 5763 [details] Patch to prevent loading the same archive twice as a whole archive This patch should fix the problem.
CVSROOT: /cvs/src Module name: src Changes by: ccoutant@sourceware.org 2011-06-02 20:13:23 Modified files: gold : ChangeLog archive.cc archive.h Log message: PR gold/12163 * gold/archive.cc (Archive::Archive): Initialize new data member. (Archive::include_all_members): Return if archive has already been included. * gold/archive.h (Archive::include_all_members_): New data member. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/ChangeLog.diff?cvsroot=src&r1=1.744&r2=1.745 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/archive.cc.diff?cvsroot=src&r1=1.68&r2=1.69 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/archive.h.diff?cvsroot=src&r1=1.36&r2=1.37
Fixed with above commit.