[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 05:37:47 PDT 2016
grimar created this revision.
grimar added reviewers: ruiu, rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.
When sh_info value was set in the way that non-local symbol was treated as local, lld
was asserting.
Testcase was created using hex editor, basing on problem revealed by
id_000001,sig_11,src_000000,op_flip1,pos_100 from PR30540.
I think it is not possible to craft testcase file without hex editor.
For example yaml2obj does not provide
ability to set sh_info field to any value, it has next code for that:
```
// One greater than symbol table index of the last local symbol.
SHeader.sh_info = Doc.Symbols.Local.size() + 1;
```
Patch separates testing of sh_info field to separate file.
If we land D25010, then I think there is no reason to keep all testcases for invalid inputs in a single file,
and probably better to split and group them.
https://reviews.llvm.org/D25016
Files:
ELF/Writer.cpp
test/ELF/Inputs/invalid-symtab-sh_info2.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,8 @@
+# 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
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: test/ELF/Inputs/invalid-symtab-sh_info2.elf
===================================================================
--- test/ELF/Inputs/invalid-symtab-sh_info2.elf
+++ test/ELF/Inputs/invalid-symtab-sh_info2.elf
@@ -0,0 +1 @@
+ELF > @ @ @ 0 ° µ ! foo .text .shstrtab .strtab .symtab
\ No newline at end of file
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -387,7 +387,8 @@
continue;
if (!includeInSymtab<ELFT>(*B))
continue;
- StringRef SymName(StrTab + B->getNameOffset());
+ if (!B->IsLocal)
+ fatal(getFilename(F) + ": invalid sh_info in symbol table");
InputSectionBase<ELFT> *Sec = DR->Section;
if (!shouldKeepInSymtab<ELFT>(Sec, SymName, *B))
continue;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25016.72808.patch
Type: text/x-patch
Size: 2527 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160928/9ae3cd28/attachment.bin>
More information about the llvm-commits
mailing list