[lld] r319367 - Don't crash on broken debug info.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 29 14:09:16 PST 2017
Author: rafael
Date: Wed Nov 29 14:09:16 2017
New Revision: 319367
URL: http://llvm.org/viewvc/llvm-project?rev=319367&view=rev
Log:
Don't crash on broken debug info.
Added:
lld/trunk/test/ELF/undef-broken-debug.test
Modified:
lld/trunk/ELF/GdbIndex.cpp
Modified: lld/trunk/ELF/GdbIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/GdbIndex.cpp?rev=319367&r1=319366&r2=319367&view=diff
==============================================================================
--- lld/trunk/ELF/GdbIndex.cpp (original)
+++ lld/trunk/ELF/GdbIndex.cpp Wed Nov 29 14:09:16 2017
@@ -68,14 +68,17 @@ LLDDwarfObj<ELFT>::findAux(const InputSe
uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);
const typename ELFT::Sym &Sym = File->getELFSyms()[SymIndex];
uint32_t SecIndex = File->getSectionIndex(Sym);
- Symbol &B = File->getRelocTargetSym(Rel);
- auto &DR = cast<Defined>(B);
- uint64_t Val = DR.Value + getAddend<ELFT>(Rel);
+
+ // Broken debug info can point to a non-Defined symbol, just ignore it.
+ auto *DR = dyn_cast<Defined>(&File->getRelocTargetSym(Rel));
+ if (!DR)
+ return None;
+ uint64_t Val = DR->Value + getAddend<ELFT>(Rel);
// FIXME: We should be consistent about always adding the file
// offset or not.
- if (DR.Section->Flags & ELF::SHF_ALLOC)
- Val += cast<InputSection>(DR.Section)->getOffsetInFile();
+ if (DR->Section->Flags & ELF::SHF_ALLOC)
+ Val += cast<InputSection>(DR->Section)->getOffsetInFile();
return RelocAddrEntry{SecIndex, Val};
}
Added: lld/trunk/test/ELF/undef-broken-debug.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/undef-broken-debug.test?rev=319367&view=auto
==============================================================================
--- lld/trunk/test/ELF/undef-broken-debug.test (added)
+++ lld/trunk/test/ELF/undef-broken-debug.test Wed Nov 29 14:09:16 2017
@@ -0,0 +1,44 @@
+# REQUIRES: x86
+# RUN: yaml2obj %s -o %t.o
+# RUN: not ld.lld %t.o -o %t.exe 2>&1 | FileCheck %s
+
+# The debug info has a broken relocation. Check that we don't crash
+# and still report the undefined symbol.
+
+# CHECK: error: undefined symbol: bar
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Content: '0000000000000000'
+ - Name: .rela.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ Relocations:
+ - Offset: 0x0000000000000000
+ Symbol: bar
+ Type: R_X86_64_64
+ - Name: .debug_line
+ Type: SHT_PROGBITS
+ Content: 3300000002001C0000000101FB0E0D000101010100000001000001006162632E7300000000000009020000000000000000140208000101
+ - Name: .rela.debug_line
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .debug_line
+ Relocations:
+ - Offset: 0x0000000000000029
+ Symbol: bar
+ Type: R_X86_64_64
+Symbols:
+ Global:
+ - Name: _start
+ Section: .text
+ - Name: bar
More information about the llvm-commits
mailing list