Bug 12163 - --start/end-group causes bogus 'multiple definition of ...' error.
Summary: --start/end-group causes bogus 'multiple definition of ...' error.
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-27 09:47 UTC by Pawel Sikora
Modified: 2011-06-02 20:19 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
testcase. (374 bytes, application/x-gzip)
2011-01-16 13:30 UTC, Pawel Sikora
Details
Patch to prevent loading the same archive twice as a whole archive (736 bytes, patch)
2011-06-02 19:04 UTC, Cary Coutant
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel Sikora 2010-10-27 09:47:11 UTC
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.
Comment 1 Pawel Sikora 2011-01-16 13:30:50 UTC
Created attachment 5198 [details]
testcase.
Comment 2 Pawel Sikora 2011-01-16 13:33:00 UTC
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
Comment 3 Cary Coutant 2011-06-02 19:04:00 UTC
Created attachment 5763 [details]
Patch to prevent loading the same archive twice as a whole archive

This patch should fix the problem.
Comment 4 cvs-commit@gcc.gnu.org 2011-06-02 20:13:28 UTC
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
Comment 5 Cary Coutant 2011-06-02 20:19:34 UTC
Fixed with above commit.