Bug 1991

Summary: objcopy does not update sh_link correctly
Product: binutils Reporter: Andreas Schwab <schwab>
Component: binutilsAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: bug-binutils, hjl.tools
Priority: P2    
Version: 2.17   
Target Milestone: ---   
Host: Target: ia64-*-*
Build: Last reconfirmed:
Attachments: Test object
Output of objcopy -g

Description Andreas Schwab 2005-12-07 16:55:55 UTC
When stripping sections from an ELF object (eg. with objcopy -g) the resulting 
object has invalid sh_link fields for LINK ORDER sections.
Comment 1 Andreas Schwab 2005-12-07 16:57:22 UTC
Created attachment 782 [details]
Test object
Comment 2 Andreas Schwab 2005-12-07 16:57:59 UTC
Created attachment 783 [details]
Output of objcopy -g
Comment 3 Andreas Schwab 2005-12-07 17:07:51 UTC
The problem is that elf_discarded_section points to the input section, but 
this is not the linker. 
Comment 4 H.J. Lu 2005-12-07 18:53:34 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2005-12/msg00058.html

http://sourceware.org/ml/binutils/2005-12/msg00056.html

is similar. But it doesn't handle a section is removed by "-R".
Comment 5 Alan Modra 2005-12-08 06:23:01 UTC
A similar problem can be seen on older dynamic objects.  When stripping debug
sections, section syms for the removed sections are not removed from .dynsym,
because strip doesn't touch .dynsym.  This leaves symbols with invalid st_shndx
fields.  Dynamic objects created with newer binutils avoid the problem to some
extent by not emitting dynamic section syms for debug sections.
Comment 6 H.J. Lu 2005-12-31 22:04:24 UTC
I am closing this bug. If we really want to handle .dynsym in DSOs created
by old linker, we can open a new bug report.