Don't crash on broken debug info.

llvm-svn: 319367
This commit is contained in:
Rafael Espindola
2017-11-29 22:09:16 +00:00
parent 0e508d69fd
commit f893396d1b
2 changed files with 52 additions and 5 deletions

View File

@@ -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};
}

View File

@@ -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