[PATCH] D130073: [BOLT] Handle broken .dynsym in stripped binaries
Amir Ayupov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 22 11:24:16 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8eb68d92d4d0: [BOLT] Handle broken .dynsym in stripped binaries (authored by nhuhuan, committed by Amir).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130073/new/
https://reviews.llvm.org/D130073
Files:
bolt/lib/Rewrite/RewriteInstance.cpp
bolt/test/X86/Inputs/broken_dynsym.yaml
bolt/test/X86/broken_dynsym.test
Index: bolt/test/X86/broken_dynsym.test
===================================================================
--- /dev/null
+++ bolt/test/X86/broken_dynsym.test
@@ -0,0 +1,8 @@
+# This test checks if BOLT can process stripped binaries, where symbol's section
+# header index is corrupted due to strip tool.
+
+# RUN: yaml2obj %p/Inputs/broken_dynsym.yaml -o %t
+# RUN: llvm-strip -s %t
+# RUN: llvm-bolt %t -o %t.bolt | FileCheck %s
+
+# CHECK-NOT: section index out of bounds
Index: bolt/test/X86/Inputs/broken_dynsym.yaml
===================================================================
--- /dev/null
+++ bolt/test/X86/Inputs/broken_dynsym.yaml
@@ -0,0 +1,33 @@
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+ProgramHeaders:
+ - Type: PT_LOAD
+ FirstSec: .a
+ LastSec: .a
+ Align: 0x1000
+Sections:
+ - Name: .a
+ Type: SHT_PROGBITS
+ Content: 00
+ AddressAlign: 0x1
+ - Name: .b
+ Type: 0
+ AddressAlign: 0x1
+ - Name: .bss
+ Type: 0
+ AddressAlign: 0x1
+ - Type: SectionHeaderTable
+ Sections:
+ - Name: .dynsym
+ - Name: .dynstr
+ - Name: .a
+ - Name: .b
+ - Name: .bss
+ - Name: .strtab
+ - Name: .shstrtab
+DynamicSymbols:
+ - Section: .bss
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -4465,6 +4465,14 @@
std::vector<ELFSymTy> Symbols;
auto getNewSectionIndex = [&](uint32_t OldIndex) {
+ // For dynamic symbol table, the section index could be wrong on the input,
+ // and its value is ignored by the runtime if it's different from
+ // SHN_UNDEF and SHN_ABS.
+ // However, we still need to update dynamic symbol table, so return a
+ // section index, even though the index is broken.
+ if (IsDynSym && OldIndex >= NewSectionIndex.size())
+ return OldIndex;
+
assert(OldIndex < NewSectionIndex.size() && "section index out of bounds");
const uint32_t NewIndex = NewSectionIndex[OldIndex];
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130073.446913.patch
Type: text/x-patch
Size: 2142 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220722/e93523a6/attachment.bin>
More information about the llvm-commits
mailing list