From 1b51b7fc7f99f1d291284d83aaa8bcc4ce5fd62c Mon Sep 17 00:00:00 2001 From: George Rimar Date: Fri, 7 Jul 2017 09:18:05 +0000 Subject: [PATCH] [ELF] - Fail the link if something happens on DWARF parsing stage of -gdb-index building This is relative to PR33173, Previously if something wrong happened on DWARF parsers side during parsing object for building gdb index (like was in PR: unsupported relocation) then LLD continued and finished the link. DWARF parsers sure showed error message on their side, but that is all. Patch changes behavior to fail the link in this case and show more detailed message. Differential revision: https://reviews.llvm.org/D34814 llvm-svn: 307370 --- lld/ELF/SyntheticSections.cpp | 6 ++- .../invalid/invalid-debug-relocations.test | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 lld/test/ELF/invalid/invalid-debug-relocations.test diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index bbc5508e79dd..7c09e8e84d06 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1811,7 +1811,11 @@ GdbIndexChunk GdbIndexSection::readDwarf(InputSection *Sec) { return {}; } - DWARFContextInMemory Dwarf(*Obj.get()); + DWARFContextInMemory Dwarf(*Obj.get(), nullptr, [&](Error E) { + error(toString(Sec->File) + ": error parsing DWARF data:\n>>> " + + toString(std::move(E))); + return ErrorPolicy::Continue; + }); GdbIndexChunk Ret; Ret.CompilationUnits = readCuList(Dwarf, Sec); diff --git a/lld/test/ELF/invalid/invalid-debug-relocations.test b/lld/test/ELF/invalid/invalid-debug-relocations.test new file mode 100644 index 000000000000..75e41d18514f --- /dev/null +++ b/lld/test/ELF/invalid/invalid-debug-relocations.test @@ -0,0 +1,41 @@ +# REQUIRES: x86 +# RUN: yaml2obj %s -o %t.o +# RUN: not ld.lld -gdb-index %t.o -o %t.exe 2>&1 | FileCheck %s + +# CHECK: error: {{.*}}.o: error parsing DWARF data: +# CHECK-NEXT: >>> failed to compute relocation: Unknown, Invalid data was encountered while parsing the file + +!ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_386 +Sections: + - Type: SHT_PROGBITS + Name: .text + Flags: [ ] + AddressAlign: 0x04 + Content: "0000" + - Type: SHT_PROGBITS + Name: .debug_info + Flags: [ ] + AddressAlign: 0x04 + Content: "0000" + - Type: SHT_REL + Name: .rel.debug_info + Link: .symtab + Info: .debug_info + Relocations: + - Offset: 0 + Symbol: _start + Type: 0xFF + - Offset: 4 + Symbol: _start + Type: 0xFF +Symbols: + Global: + - Name: _start + Type: STT_FUNC + Section: .text + Value: 0x0