[PATCH] D51493: [llvm-strip] Allow copying relocation sections without symbol tables.
Jordan Rupprecht via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 30 09:58:27 PDT 2018
rupprecht created this revision.
rupprecht added a reviewer: jakehehrlich.
Herald added a reviewer: alexshap.
Herald added a subscriber: llvm-commits.
Fixes the error "Link field value 0 in section .rela.plt is invalid" when copying/stripping certain binaries. Minimal repro:
$ cat /tmp/a.c
int main() { return 0; }
$ clang -static /tmp/a.c -o /tmp/a
$ llvm-strip /tmp/a -o /tmp/b
llvm-strip: error: Link field value 0 in section .rela.plt is invalid.
Repository:
rL LLVM
https://reviews.llvm.org/D51493
Files:
test/tools/llvm-objcopy/reloc-no-symtab.test
tools/llvm-objcopy/Object.cpp
Index: tools/llvm-objcopy/Object.cpp
===================================================================
--- tools/llvm-objcopy/Object.cpp
+++ tools/llvm-objcopy/Object.cpp
@@ -375,11 +375,13 @@
template <class SymTabType>
void RelocSectionWithSymtabBase<SymTabType>::initialize(
SectionTableRef SecTable) {
- setSymTab(SecTable.getSectionOfType<SymTabType>(
- Link,
- "Link field value " + Twine(Link) + " in section " + Name + " is invalid",
- "Link field value " + Twine(Link) + " in section " + Name +
- " is not a symbol table"));
+ if (Link != SHN_UNDEF)
+ setSymTab(SecTable.getSectionOfType<SymTabType>(
+ Link,
+ "Link field value " + Twine(Link) + " in section " + Name +
+ " is invalid",
+ "Link field value " + Twine(Link) + " in section " + Name +
+ " is not a symbol table"));
if (Info != SHN_UNDEF)
setSection(SecTable.getSection(Info, "Info field value " + Twine(Info) +
@@ -391,7 +393,8 @@
template <class SymTabType>
void RelocSectionWithSymtabBase<SymTabType>::finalize() {
- this->Link = Symbols->Index;
+ if (Symbols != nullptr)
+ this->Link = Symbols->Index;
if (SecToApplyRel != nullptr)
this->Info = SecToApplyRel->Index;
}
Index: test/tools/llvm-objcopy/reloc-no-symtab.test
===================================================================
--- /dev/null
+++ test/tools/llvm-objcopy/reloc-no-symtab.test
@@ -0,0 +1,44 @@
+# Regression test for the following case:
+# $ cat /tmp/a.c
+# int main() { return 0; }
+# $ clang -static /tmp/a.c -o /tmp/a
+# $ llvm-strip /tmp/a -o /tmp/b
+# llvm-strip: error: Link field value 0 in section .rela.plt is invalid.
+
+# RUN: yaml2obj %s > %t.original
+# RUN: llvm-strip %t.original -o %t.stripped
+# RUN: llvm-readobj -sections %t.stripped | FileCheck %s
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ - Name: .rela.plt
+ Type: SHT_RELA
+ Flags: [ SHF_ALLOC, SHF_INFO_LINK ]
+ Info: .got.plt
+ Link: 0
+ - Name: .plt
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ - Name: .got.plt
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+
+# CHECK: Name: .rela.plt
+# CHECK-NEXT: Type: SHT_RELA
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: SHF_ALLOC
+# CHECK-NEXT: SHF_INFO_LINK
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address:
+# CHECK-NEXT: Offset:
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Link: 0
+# CHECK-NEXT: Info: 4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51493.163359.patch
Type: text/x-patch
Size: 2739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180830/c91f7208/attachment.bin>
More information about the llvm-commits
mailing list