[ELF] - Fixed assertion fail when symbol table has invalid sh_info value.
authorGeorge Rimar <grimar@accesssoftek.com>
Tue, 11 Oct 2016 09:07:14 +0000 (09:07 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Tue, 11 Oct 2016 09:07:14 +0000 (09:07 +0000)
This part was splitted from D25016.

When sh_info value was set in the way that non-local symbol was treated as local, lld
was asserting, patch fixes that.

Differential revision: https://reviews.llvm.org/D25371

llvm-svn: 283859

lld/ELF/Writer.cpp
lld/test/ELF/invalid/Inputs/symtab-sh_info3.elf [new file with mode: 0644]
lld/test/ELF/invalid/symtab-sh-info.s

index 1cb47b8..a7ba822 100644 (file)
@@ -366,6 +366,9 @@ template <class ELFT> void Writer<ELFT>::copyLocalSymbols() {
   for (elf::ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles()) {
     StringRef StrTab = F->getStringTable();
     for (SymbolBody *B : F->getLocalSymbols()) {
+      if (!B->IsLocal)
+        fatal(getFilename(F) +
+              ": broken object: getLocalSymbols returns a non-local symbol");
       auto *DR = dyn_cast<DefinedRegular<ELFT>>(B);
       // No reason to keep local undefined symbol in symtab.
       if (!DR)
diff --git a/lld/test/ELF/invalid/Inputs/symtab-sh_info3.elf b/lld/test/ELF/invalid/Inputs/symtab-sh_info3.elf
new file mode 100644 (file)
index 0000000..ca889fb
Binary files /dev/null and b/lld/test/ELF/invalid/Inputs/symtab-sh_info3.elf differ
index 727639f..3522ae5 100644 (file)
@@ -2,3 +2,8 @@
 ## so sh_info should be at least 1 in a valid ELF.
 # RUN: not ld.lld %p/Inputs/symtab-sh_info2.elf -o %t2 2>&1 | FileCheck %s
 # CHECK: invalid sh_info in symbol table
+
+## sh_info contains invalid value saying non-local symbol is local.
+# RUN: not ld.lld %p/Inputs/symtab-sh_info3.elf -o %t2 2>&1 | \
+# RUN:   FileCheck --check-prefix=INVALID-SYMTAB-SHINFO %s
+# INVALID-SYMTAB-SHINFO: broken object: getLocalSymbols returns a non-local symbol