diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 1cb47b81adf8..a7ba822fd23f 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -366,6 +366,9 @@ template void Writer::copyLocalSymbols() { for (elf::ObjectFile *F : Symtab::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>(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 index 000000000000..ca889fbca1aa Binary files /dev/null and b/lld/test/ELF/invalid/Inputs/symtab-sh_info3.elf differ diff --git a/lld/test/ELF/invalid/symtab-sh-info.s b/lld/test/ELF/invalid/symtab-sh-info.s index 727639f4910d..3522ae550c08 100644 --- a/lld/test/ELF/invalid/symtab-sh-info.s +++ b/lld/test/ELF/invalid/symtab-sh-info.s @@ -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