Bug 14189 - --gc-sections doesn't work
Summary: --gc-sections doesn't work
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-31 18:58 UTC by Ronald Wahl
Modified: 2014-06-13 02:50 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments
test case (565 bytes, application/x-gzip)
2012-05-31 18:58 UTC, Ronald Wahl
Details
test case with assembly only (971 bytes, application/x-gzip)
2012-05-31 20:45 UTC, Ronald Wahl
Details
Do not increment refcount for locally bound symbols. (333 bytes, patch)
2012-06-29 13:23 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ronald Wahl 2012-05-31 18:58:29 UTC
Created attachment 6428 [details]
test case

I have an issue were I get an "assertion fail ../../bfd/elf32-arm.c:12264" when I link a shared library which links itself two static libraries and hides the symbols using the "--exclude-libs ALL" switch. The sources are build with -ffunction-sections and -fdata-sections and at link time --gc-section is used. When removing --gc-sections or --exclude-libs the problem disappears.

See the attached testcase (tar containing 3 short C files and a Makefile which you need to adapt for the right compiler name since it is an arm cross compiler)

Actually the output is currently:

$ make
../bin/arm-PP-linux-uclibcgnueabi-gcc -fPIC -ffunction-sections -fdata-sections -c -o test.o test.c
../bin/arm-PP-linux-uclibcgnueabi-gcc -fPIC -ffunction-sections -fdata-sections -c -o test1.o test1.c
rm -f libtest1.a
../bin/arm-PP-linux-uclibcgnueabi-ar cru libtest1.a test1.o
../bin/arm-PP-linux-uclibcgnueabi-gcc -fPIC -ffunction-sections -fdata-sections -c -o test2.o test2.c
rm -f libtest2.a
../bin/arm-PP-linux-uclibcgnueabi-ar cru libtest2.a test2.o
../bin/arm-PP-linux-uclibcgnueabi-gcc -shared -o libtest.so test.o -Wl,--gc-sections,--exclude-libs,ALL -L. -ltest2 -ltest1
/opt/pp_toolchain/cross/008/bin/../lib/gcc/arm-pp-linux-uclibcgnueabi/4.6.3/../../../../arm-pp-linux-uclibcgnueabi/bin/ld: BFD (Linux/GNU Binutils) 2.22.52.0.2.20120424 assertion fail ../../bfd/elf32-arm.c:12264

Looking at the code I saw that there was some recent activity where the assert is generated (PLT ref count book-keeping check). Probably some case was overlooked?!
Comment 1 H.J. Lu 2012-05-31 19:09:50 UTC
Please provide a self-contained testcase with only assembly codes
for cross binutils.  Not all binutils developers have ARM cross
compilers.
Comment 2 Ronald Wahl 2012-05-31 20:45:08 UTC
Created attachment 6430 [details]
test case with assembly only

Added test case which uses only assembly so no cross compiler is required.
Comment 3 H.J. Lu 2012-05-31 21:08:22 UTC
It was caused by

http://sourceware.org/ml/binutils-cvs/2011-03/msg00080.html
Comment 4 Michael Tremer 2012-06-24 19:30:33 UTC
Is there a fix available for this bug?

Apparently, the build of systemd for ARM is broken when passing --gc-sections to ld. This is reproducible on IPFire as well as Fedora.

https://bugs.freedesktop.org/show_bug.cgi?id=51365
Comment 5 Nick Clifton 2012-06-29 13:23:13 UTC
Created attachment 6496 [details]
Do not increment refcount for locally bound symbols.
Comment 6 Nick Clifton 2012-06-29 13:26:16 UTC
Hi Michael, Hi Ronald,

  Please could you try out the uploaded patch and let me know if it works for you ?

Cheers
  Nick
Comment 7 Michael Tremer 2012-06-29 14:59:46 UTC
Hi Nick,

I can confirm that the patch fixes the problem over here. The build of systemd runs through without any assertion errors.

Thank you very much.
Comment 8 Sourceware Commits 2012-06-29 15:20:44 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	nickc@sourceware.org	2012-06-29 15:20:31

Modified files:
	bfd            : ChangeLog elf32-arm.c 

Log message:
	PR ld/14189
	* elf32-arm.c (elf32_arm_check_relocs): Do not increment refcount
	for locally bound symbols.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5737&r2=1.5738
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf32-arm.c.diff?cvsroot=src&r1=1.295&r2=1.296
Comment 9 Nick Clifton 2012-06-29 15:21:53 UTC
Patch applied.
Comment 10 Ronald Wahl 2012-06-29 15:31:57 UTC
The patch works here as well. Thanks!