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];
--- /dev/null
+# 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