From 1651ac13be81bae08365dda486263a1fec04f2d2 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 30 May 2018 19:30:39 +0000 Subject: llvm-objcopy: Set sh_link to 0 on unrecognized symtab-linked sections. 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. Differential Revision: https://reviews.llvm.org/D47404 llvm-svn: 333581 --- llvm/tools/llvm-objcopy/Object.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'llvm/tools/llvm-objcopy/Object.cpp') diff --git a/llvm/tools/llvm-objcopy/Object.cpp b/llvm/tools/llvm-objcopy/Object.cpp index c00477a1980..6b656c6b2f7 100644 --- a/llvm/tools/llvm-objcopy/Object.cpp +++ b/llvm/tools/llvm-objcopy/Object.cpp @@ -401,15 +401,17 @@ void GroupSection::markSymbols() { } void Section::initialize(SectionTableRef SecTable) { - if (Link != ELF::SHN_UNDEF) + if (Link != ELF::SHN_UNDEF) { LinkSection = SecTable.getSection(Link, "Link field value " + Twine(Link) + " in section " + Name + " is invalid"); + if (LinkSection->Type == ELF::SHT_SYMTAB) + LinkSection = nullptr; + } } void Section::finalize() { - if (LinkSection) - this->Link = LinkSection->Index; + this->Link = LinkSection ? LinkSection->Index : 0; } void GnuDebugLinkSection::init(StringRef File, StringRef Data) { -- cgit v1.2.3