[PATCH] D25016: [ELF] - Fixed assert fail when symbol table has invalid sh_info value.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 28 06:30:02 PDT 2016
grimar updated this revision to Diff 72816.
grimar added a comment.
- Added testcase for sh_info == 0.
- Do verification check earlier.
https://reviews.llvm.org/D25016
Files:
ELF/InputFiles.cpp
ELF/Writer.cpp
test/ELF/Inputs/invalid-symtab-sh_info2.elf
test/ELF/Inputs/invalid-symtab-sh_info3.elf
test/ELF/invalid-elf.test
test/ELF/invalid-symtab-sh-info.s
Index: test/ELF/invalid-symtab-sh-info.s
===================================================================
--- test/ELF/invalid-symtab-sh-info.s
+++ test/ELF/invalid-symtab-sh-info.s
@@ -0,0 +1,13 @@
+## sh_info contains value greater than total amount of symbols.
+# RUN: not ld.lld %p/Inputs/invalid-symtab-sh_info.elf -o %t2 2>&1 | \
+# RUN: FileCheck --check-prefix=INVALID-SYMTAB-SHINFO %s
+# INVALID-SYMTAB-SHINFO: invalid sh_info in symbol table
+
+## sh_info contains invalid value saying non-local symbol is local.
+# RUN: not ld.lld %p/Inputs/invalid-symtab-sh_info2.elf -o %t2 2>&1 | \
+# RUN: FileCheck --check-prefix=INVALID-SYMTAB-SHINFO %s
+
+## sh_info contains zero value. First entry in a symbol table is always completely zeroed,
+## so sh_info should be at least 1 in a valid ELF.
+# RUN: not ld.lld %p/Inputs/invalid-symtab-sh_info3.elf -o %t2 2>&1 | \
+# RUN: FileCheck --check-prefix=INVALID-SYMTAB-SHINFO %s
Index: test/ELF/invalid-elf.test
===================================================================
--- test/ELF/invalid-elf.test
+++ test/ELF/invalid-elf.test
@@ -8,10 +8,6 @@
# RUN: FileCheck --check-prefix=INVALID-FILE-CLASS %s
# INVALID-FILE-CLASS: invalid file class: test.o
-# RUN: not ld.lld %p/Inputs/invalid-symtab-sh_info.elf -o %t2 2>&1 | \
-# RUN: FileCheck --check-prefix=INVALID-SYMTAB-SHINFO %s
-# INVALID-SYMTAB-SHINFO: invalid sh_info in symbol table
-
# RUN: not ld.lld %p/Inputs/invalid-binding.elf -o %t2 2>&1 | \
# RUN: FileCheck --check-prefix=INVALID-BINDING %s
# INVALID-BINDING: unexpected binding
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -381,6 +381,9 @@
for (elf::ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles()) {
const char *StrTab = F->getStringTable().data();
for (SymbolBody *B : F->getLocalSymbols()) {
+ if (!B->IsLocal)
+ fatal(getFilename(F) + ": invalid sh_info in symbol table");
+
auto *DR = dyn_cast<DefinedRegular<ELFT>>(B);
// No reason to keep local undefined symbol in symtab.
if (!DR)
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -81,7 +81,7 @@
Elf_Sym_Range Syms = ELFObj.symbols(Symtab);
uint32_t NumSymbols = std::distance(Syms.begin(), Syms.end());
uint32_t FirstNonLocal = Symtab->sh_info;
- if (FirstNonLocal > NumSymbols)
+ if (!FirstNonLocal || (FirstNonLocal > NumSymbols))
fatal(getFilename(this) + ": invalid sh_info in symbol table");
if (OnlyGlobals)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25016.72816.patch
Type: text/x-patch
Size: 2666 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160928/d6ad34c8/attachment.bin>
More information about the llvm-commits
mailing list