summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/GdbIndex.cpp13
-rw-r--r--lld/test/ELF/undef-broken-debug.test44
2 files changed, 52 insertions, 5 deletions
diff --git a/lld/ELF/GdbIndex.cpp b/lld/ELF/GdbIndex.cpp
index 3b82beed5f6..9e0d0bcc01b 100644
--- a/lld/ELF/GdbIndex.cpp
+++ b/lld/ELF/GdbIndex.cpp
@@ -68,14 +68,17 @@ LLDDwarfObj<ELFT>::findAux(const InputSectionBase &Sec, uint64_t Pos,
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};
}
diff --git a/lld/test/ELF/undef-broken-debug.test b/lld/test/ELF/undef-broken-debug.test
new file mode 100644
index 00000000000..c9b0dffff47
--- /dev/null
+++ b/lld/test/ELF/undef-broken-debug.test
@@ -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
OpenPOWER on IntegriCloud