diff options
author | David Blaikie <dblaikie@gmail.com> | 2018-12-22 00:31:05 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2018-12-22 00:31:05 +0000 |
commit | ec5e93359fff4126f55e70cfbd3dba16f4f7dc4d (patch) | |
tree | bf78de40a2ad7a61643083a7420041000c39d445 /lld | |
parent | f9d1f06930b32d52a741f84189cfcb8220e2966f (diff) |
gdb-index: Handle errors when parsing ranges
When parsing CU ranges for gdb-index, handle the error (now propagated
up though the API lld is calling here - previously the error was
printed within the libDebugInfo API, not allowing lld to format or
handle the message at all) - including information about the object and
archive name, as well as failing the link.
Diffstat (limited to 'lld')
-rw-r--r-- | lld/ELF/SyntheticSections.cpp | 24 | ||||
-rw-r--r-- | lld/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s | 2 | ||||
-rw-r--r-- | lld/test/ELF/gdb-index-invalid-ranges.s | 42 |
3 files changed, 62 insertions, 6 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index dafd2d02def..d84d9472e40 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -2408,17 +2408,18 @@ static std::vector<GdbIndexSection::CuEntry> readCuList(DWARFContext &Dwarf) { return Ret; } -static std::vector<GdbIndexSection::AddressEntry> +static Expected<std::vector<GdbIndexSection::AddressEntry>> readAddressAreas(DWARFContext &Dwarf, InputSection *Sec) { std::vector<GdbIndexSection::AddressEntry> Ret; uint32_t CuIdx = 0; for (std::unique_ptr<DWARFUnit> &Cu : Dwarf.compile_units()) { - DWARFAddressRangesVector Ranges; - Cu->collectAddressRanges(Ranges); + Expected<DWARFAddressRangesVector> Ranges = Cu->collectAddressRanges(); + if (!Ranges) + return Ranges.takeError(); ArrayRef<InputSectionBase *> Sections = Sec->File->getSections(); - for (DWARFAddressRange &R : Ranges) { + for (DWARFAddressRange &R : *Ranges) { InputSectionBase *S = Sections[R.SectionIndex]; if (!S || S == &InputSection::Discarded || !S->Live) continue; @@ -2431,7 +2432,8 @@ readAddressAreas(DWARFContext &Dwarf, InputSection *Sec) { } ++CuIdx; } - return Ret; + + return std::move(Ret); } template <class ELFT> @@ -2563,7 +2565,17 @@ template <class ELFT> GdbIndexSection *GdbIndexSection::create() { Chunks[I].Sec = Sections[I]; Chunks[I].CompilationUnits = readCuList(Dwarf); - Chunks[I].AddressAreas = readAddressAreas(Dwarf, Sections[I]); + Expected<std::vector<GdbIndexSection::AddressEntry>> AddressAreas = + readAddressAreas(Dwarf, Sections[I]); + if (!AddressAreas) { + std::string Msg = File->getName(); + Msg += ": "; + if (!File->ArchiveName.empty()) + Msg += "in archive " + File->ArchiveName + ": "; + Msg += toString(AddressAreas.takeError()); + fatal(Msg); + } + Chunks[I].AddressAreas = *AddressAreas; NameAttrs[I] = readPubNamesAndTypes<ELFT>( static_cast<const LLDDwarfObj<ELFT> &>(Dwarf.getDWARFObj()), Chunks[I].CompilationUnits); diff --git a/lld/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s b/lld/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s new file mode 100644 index 00000000000..d7e0bd29d2f --- /dev/null +++ b/lld/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s @@ -0,0 +1,2 @@ +main: + callq f1 diff --git a/lld/test/ELF/gdb-index-invalid-ranges.s b/lld/test/ELF/gdb-index-invalid-ranges.s new file mode 100644 index 00000000000..05165a24bc5 --- /dev/null +++ b/lld/test/ELF/gdb-index-invalid-ranges.s @@ -0,0 +1,42 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: not ld.lld --gdb-index -e main %t.o -o %t 2>&1 | FileCheck %s +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/gdb-index-invalid-ranges.obj.s -o %t2.o +# RUN: llvm-ar rc %t.a %t.o +# RUN: not ld.lld --gdb-index -e main %t2.o %t.a -o %t 2>&1 | FileCheck --check-prefix=ARCHIVE %s + +# CHECK: ld.lld: error: {{.*}}gdb-index-invalid-ranges.s.tmp.o: decoding address ranges: invalid range list entry at offset 0x10 +# ARCHIVE: ld.lld: error: gdb-index-invalid-ranges.s.tmp.o: in archive {{.*}}gdb-index-invalid-ranges.s.tmp.a: decoding address ranges: invalid range list entry at offset 0x10 + +.section .text.foo1,"ax",@progbits +.globl f1 +.Lfunc_begin0: +f1: + nop +.Lfunc_end0: + +.section .debug_abbrev,"",@progbits +.byte 1 # Abbreviation Code +.byte 17 # DW_TAG_compile_unit +.byte 0 # DW_CHILDREN_no +.byte 85 # DW_AT_ranges +.byte 23 # DW_FORM_sec_offset +.byte 0 # EOM(1) +.byte 0 # EOM(2) +.byte 0 # EOM(3) + +.section .debug_info,"",@progbits +.Lcu_begin0: +.long .Lunit_end0-.Lunit_begin0 # Length of Unit +.Lunit_begin0: +.short 4 # DWARF version number +.long .debug_abbrev # Offset Into Abbrev. Section +.byte 8 # Address Size (in bytes) +.byte 1 # Abbrev [1] 0xb:0x1f DW_TAG_compile_unit +.long .Ldebug_ranges0 # DW_AT_ranges +.Lunit_end0: + +.section .debug_ranges,"",@progbits +.Ldebug_ranges0: +.quad .Lfunc_begin0 +.quad .Lfunc_end0 |