When stripping sections from an ELF object (eg. with objcopy -g) the resulting
object has invalid sh_link fields for LINK ORDER sections.
Created attachment 782 [details]
Created attachment 783 [details]
Output of objcopy -g
The problem is that elf_discarded_section points to the input section, but
this is not the linker.
A patch is posted at
is similar. But it doesn't handle a section is removed by "-R".
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.
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.