Bug 9933 - `strip --strip-unneeded` strips common symbols from relocatable objects
Summary: `strip --strip-unneeded` strips common symbols from relocatable objects
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.20
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-08 23:36 UTC by Mike Frysinger
Modified: 2009-10-17 07:15 UTC (History)
4 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Frysinger 2009-03-08 23:36:16 UTC
strip seems to have always behaved this way.  versions 2.16 and older stripped
both types of objects, but with 2.17 and newer, "j" is correctly left.  tested
2.1{5,6,7,8,9} and 2.19.51.0.2.

$ cat test.c
int i;
int j = 1;
$ gcc -c test.c
$ readelf -s test.o | grep OBJ
     7: 0000000000000000     4 OBJECT  GLOBAL DEFAULT    2 j
     8: 0000000000000004     4 OBJECT  GLOBAL DEFAULT  COM i
$ strip --strip-unneeded test.o
$ readelf -s test.o | grep OBJ
     7: 0000000000000000     4 OBJECT  GLOBAL DEFAULT    2 j

"i" has wrongly been stripped
Comment 1 H.J. Lu 2009-03-09 16:54:22 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2009-03/msg00148.html
Comment 2 Sourceware Commits 2009-03-10 00:48:24 UTC
Subject: Bug 9933

CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2009-03-10 00:48:10

Modified files:
	binutils       : ChangeLog objcopy.c 
	binutils/testsuite: ChangeLog 
	binutils/testsuite/binutils-all: objcopy.exp 
Added files:
	binutils/testsuite/binutils-all: copy-4.d 

Log message:
	binutils/
	
	2009-03-09  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR binutils/9933
	* objcopy.c (filter_symbols): Properly handle common symbols
	in relocatable file.
	
	binutils/testsuite/
	
	2009-03-09  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR binutils/9933
	* binutils-all/copy-4.d: New.
	
	* binutils-all/objcopy.exp: Run copy-4.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/binutils/ChangeLog.diff?cvsroot=src&r1=1.1437&r2=1.1438
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/binutils/objcopy.c.diff?cvsroot=src&r1=1.125&r2=1.126
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/binutils/testsuite/ChangeLog.diff?cvsroot=src&r1=1.166&r2=1.167
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/binutils/testsuite/binutils-all/copy-4.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/binutils/testsuite/binutils-all/objcopy.exp.diff?cvsroot=src&r1=1.53&r2=1.54

Comment 3 H.J. Lu 2009-03-10 00:51:28 UTC
Fixed.
Comment 4 Vincent Rivière 2009-10-16 20:58:00 UTC
The new testcase copy-4 fails on target m68k-netbsd (using a.out).
The test seems to be valid, maybe the fix didn't work for a.out objects.
Comment 5 Alan Modra 2009-10-17 07:15:35 UTC
The fix doesn't work on aout because EXEC_P is set for the bfd flags on your
object file, thus "relocatable" in objcopy.c:filter_symbols is not set.  EXEC_P
is set incorrectly at bfd/aoutx.h:633, and it's been that way since rev 1.1 of
the file.