This is an archive of the discontinued LLVM Phabricator instance.

llvm-objcopy: Set sh_link to 0 on unrecognized symtab-linked sections.
ClosedPublic

Authored by pcc on May 25 2018, 6:33 PM.

Details

Summary

Per discussion on the generic-abi mailing list:
https://groups.google.com/forum/#!topic/generic-abi/MPr8TVtnVn4

An object file manipulation tool must either write out a symbol
table with the same number of entries as the original symbol table
and in the same order, or if this is impossible, refuse to operate
on the object file if it has unrecognized sections that are linked
to the symtab section. However, existing tools (namely GNU strip,
GNU objcopy and ld.{bfd,gold,lld} -r) do not comply with this at
present: they change symbol table indexes and set sh_link to 0 on
the unrecognized symtab-linked sections.

We intend to use the latter as a (temporary) signal that a tool has
operated on a proposed new symtab-linked section and invalidated the
symbol table indexes. However, llvm-objcopy currently keeps sh_link
pointing to the new symtab section. This patch changes llvm-objcopy
to set sh_link to 0 to match the behaviour of the other tools.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc created this revision.May 25 2018, 6:33 PM

to me LG, but i would wait for @jhenderson .

alexander-shaposhnikov added inline comments.
llvm/tools/llvm-objcopy/Object.cpp
399 ↗(On Diff #148698)

nit:

this->Link = LinkSection ? LinkSection->Index : 0;
This revision is now accepted and ready to land.May 25 2018, 11:59 PM
jhenderson accepted this revision.May 29 2018, 2:02 AM

LGTM with the suggested test change.

I'm not a massive fan of this behaviour, but it makes sense to follow GNU's lead on this until such point as there's a standards-defined way of doing it. I'm assuming that all tools out there already know how to consume such special sections.

llvm/test/tools/llvm-objcopy/symtab-link.test
2 ↗(On Diff #148698)

Based on a comment I think I saw in the gABI thread, that suggests that it's important for llvm-strip to follow the same behaviour, would it be worth adding an equivalent case using llvm-strip? There are some other tests that show how we typically do this.

This revision was automatically updated to reflect the committed changes.
pcc marked 2 inline comments as done.