Bug 9945 - strip --strip-unneeded removes symbol table
Summary: strip --strip-unneeded removes symbol table
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-12 18:46 UTC by H.J. Lu
Modified: 2009-03-13 14:46 UTC (History)
2 users (show)

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


Attachments
A patch (966 bytes, patch)
2009-03-12 21:24 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2009-03-12 18:46:04 UTC
[hjl@gnu-6 testsuite]$ cat x.s
	.arch armv4
	.text
	bx	lr
[hjl@gnu-6 testsuite]$ ../as-new  -meabi=4 --fix-v4bx -o x.o x.s   
[hjl@gnu-6 testsuite]$ readelf -S x.o
There are 9 section headers, starting at offset 0x94:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 000034 000004 00  AX  0   0  1
  [ 2] .rel.text         REL             00000000 000260 000008 08      7   1  4
  [ 3] .data             PROGBITS        00000000 000038 000000 00  WA  0   0  1
  [ 4] .bss              NOBITS          00000000 000038 000000 00  WA  0   0  1
  [ 5] .ARM.attributes   ARM_ATTRIBUTES  00000000 000038 000019 00      0   0  1
  [ 6] .shstrtab         STRTAB          00000000 000051 000040 00      0   0  1
  [ 7] .symtab           SYMTAB          00000000 0001fc 000060 10      8   6  4
  [ 8] .strtab           STRTAB          00000000 00025c 000004 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)
[hjl@gnu-6 testsuite]$  ../../binutils/strip-new --strip-unneeded x.o -o b.o
[hjl@gnu-6 testsuite]$ readelf -S b.o
There are 7 section headers, starting at offset 0x84:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 000034 000004 00  AX  0   0  1
  [ 2] .rel.text         REL             00000000 00019c 000008 08      0   1  4
  [ 3] .data             PROGBITS        00000000 000038 000000 00  WA  0   0  1
  [ 4] .bss              NOBITS          00000000 000038 000000 00  WA  0   0  1
  [ 5] .ARM.attributes   ARM_ATTRIBUTES  00000000 000038 000019 00      0   0  1
  [ 6] .shstrtab         STRTAB          00000000 000051 000030 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)
[hjl@gnu-6 testsuite]$ readelf -r b.o

Relocation section '.rel.text' at offset 0x19c contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  00000028 R_ARM_V4BX       
[hjl@gnu-6 testsuite]$ 

Symbol table is needed for R_ARM_V4BX, which references the first
entry of symbol table.
Comment 1 H.J. Lu 2009-03-12 21:22:21 UTC
*** Bug 9934 has been marked as a duplicate of this bug. ***
Comment 2 H.J. Lu 2009-03-12 21:24:28 UTC
Created attachment 3818 [details]
A patch

Relocation will need symbol table. This patch will keep symbol
table if there are any relocations in output.
Comment 3 Nick Clifton 2009-03-13 11:29:23 UTC
Hi H.J.

  Patch approved - please apply.

Cheers
  Nick
Comment 4 Sourceware Commits 2009-03-13 13:40:10 UTC
Subject: Bug 9945

CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2009-03-13 13:39:57

Modified files:
	bfd            : ChangeLog elf.c 
	binutils       : ChangeLog objcopy.c 

Log message:
	bfd/
	
	2009-03-13  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR binutils/9945
	* elf.c (assign_section_numbers): Generate symbol table if there
	is any relocation in output.
	(_bfd_elf_compute_section_file_positions): Likewise.
	
	binutils/
	
	2009-03-13  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR binutils/9945
	* objcopy.c (copy_object): Clear HAS_RELOC when stripping all.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.4497&r2=1.4498
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/elf.c.diff?cvsroot=src&r1=1.477&r2=1.478
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/binutils/ChangeLog.diff?cvsroot=src&r1=1.1439&r2=1.1440
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/binutils/objcopy.c.diff?cvsroot=src&r1=1.126&r2=1.127

Comment 5 H.J. Lu 2009-03-13 14:46:00 UTC
Fixed.