[lld] r349979 - gdb-index: Handle errors when parsing ranges

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 26 11:05:51 PST 2018


On Fri, Dec 21, 2018 at 4:34 PM David Blaikie via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: dblaikie
> Date: Fri Dec 21 16:31:05 2018
> New Revision: 349979
>
> URL: http://llvm.org/viewvc/llvm-project?rev=349979&view=rev
> Log:
> 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.
>
> Added:
>     lld/trunk/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s
>     lld/trunk/test/ELF/gdb-index-invalid-ranges.s
> Modified:
>     lld/trunk/ELF/SyntheticSections.cpp
>
> Modified: lld/trunk/ELF/SyntheticSections.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=349979&r1=349978&r2=349979&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/SyntheticSections.cpp (original)
> +++ lld/trunk/ELF/SyntheticSections.cpp Fri Dec 21 16:31:05 2018
> @@ -2408,17 +2408,18 @@ static std::vector<GdbIndexSection::CuEn
>    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, In
>      }
>      ++CuIdx;
>    }
> -  return Ret;
> +
> +  return std::move(Ret);
>  }
>
>  template <class ELFT>
> @@ -2563,7 +2565,17 @@ template <class ELFT> GdbIndexSection *G
>
>      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);
> +    }
>

fatal() immediately terminates the process, and it is preferred to use
error() which does return whenever possible. Also I think you can use
toString(Sec) to stringize sections (including concatenating an archive
file name) easily. I'll address them in a follow-up patch.

+    Chunks[I].AddressAreas = *AddressAreas;
>      NameAttrs[I] = readPubNamesAndTypes<ELFT>(
>          static_cast<const LLDDwarfObj<ELFT> &>(Dwarf.getDWARFObj()),
>          Chunks[I].CompilationUnits);
>
> Added: lld/trunk/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s?rev=349979&view=auto
>
> ==============================================================================
> --- lld/trunk/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s (added)
> +++ lld/trunk/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s Fri Dec 21
> 16:31:05 2018
> @@ -0,0 +1,2 @@
> +main:
> +  callq f1
>
> Added: lld/trunk/test/ELF/gdb-index-invalid-ranges.s
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gdb-index-invalid-ranges.s?rev=349979&view=auto
>
> ==============================================================================
> --- lld/trunk/test/ELF/gdb-index-invalid-ranges.s (added)
> +++ lld/trunk/test/ELF/gdb-index-invalid-ranges.s Fri Dec 21 16:31:05 2018
> @@ -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", at progbits
> +.globl f1
> +.Lfunc_begin0:
> +f1:
> + nop
> +.Lfunc_end0:
> +
> +.section .debug_abbrev,"", at 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,"", at 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,"", at progbits
> +.Ldebug_ranges0:
> +.quad .Lfunc_begin0
> +.quad .Lfunc_end0
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181226/a41875a1/attachment.html>


More information about the llvm-commits mailing list