[PATCH] D47404: llvm-objcopy: Set sh_link to 0 on unrecognized symtab-linked sections.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 30 12:36:39 PDT 2018
This revision was automatically updated to reflect the committed changes.
pcc marked 2 inline comments as done.
Closed by commit rL333581: llvm-objcopy: Set sh_link to 0 on unrecognized symtab-linked sections. (authored by pcc, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D47404?vs=148698&id=149182#toc
Repository:
rL LLVM
https://reviews.llvm.org/D47404
Files:
llvm/trunk/test/tools/llvm-objcopy/symtab-link.test
llvm/trunk/tools/llvm-objcopy/Object.cpp
Index: llvm/trunk/test/tools/llvm-objcopy/symtab-link.test
===================================================================
--- llvm/trunk/test/tools/llvm-objcopy/symtab-link.test
+++ llvm/trunk/test/tools/llvm-objcopy/symtab-link.test
@@ -0,0 +1,27 @@
+# RUN: yaml2obj %s > %t
+# RUN: llvm-objcopy %t %t2
+# RUN: llvm-readobj -sections %t2 | FileCheck %s
+# RUN: cp %t %t3
+# RUN: llvm-strip --strip-debug %t3
+# RUN: llvm-readobj -sections %t3 | FileCheck %s
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .foo
+ Link: .symtab
+ Type: SHT_PROGBITS
+ Flags: [ ]
+
+# CHECK: Name: .foo
+# CHECK-NEXT: Type:
+# CHECK-NEXT: Flags [ (0x0)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address:
+# CHECK-NEXT: Offset:
+# CHECK-NEXT: Size:
+# CHECK-NEXT: Link: 0
Index: llvm/trunk/tools/llvm-objcopy/Object.cpp
===================================================================
--- llvm/trunk/tools/llvm-objcopy/Object.cpp
+++ llvm/trunk/tools/llvm-objcopy/Object.cpp
@@ -401,15 +401,17 @@
}
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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47404.149182.patch
Type: text/x-patch
Size: 1738 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180530/5bf4b2ff/attachment.bin>
More information about the llvm-commits
mailing list