<div dir="ltr"><div dir="ltr">Sure. Here is my follow-up: <a href="https://reviews.llvm.org/rL350070">https://reviews.llvm.org/rL350070</a></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Dec 28, 2018 at 10:16 PM David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 26, 2018 at 11:11 AM Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Fri, Dec 21, 2018 at 4:34 PM David Blaikie via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div></div><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: dblaikie<br>
Date: Fri Dec 21 16:31:05 2018<br>
New Revision: 349979<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=349979&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=349979&view=rev</a><br>
Log:<br>
gdb-index: Handle errors when parsing ranges<br>
<br>
When parsing CU ranges for gdb-index, handle the error (now propagated<br>
up though the API lld is calling here - previously the error was<br>
printed within the libDebugInfo API, not allowing lld to format or<br>
handle the message at all) - including information about the object and<br>
archive name, as well as failing the link.<br>
<br>
Added:<br>
    lld/trunk/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s<br>
    lld/trunk/test/ELF/gdb-index-invalid-ranges.s<br>
Modified:<br>
    lld/trunk/ELF/SyntheticSections.cpp<br>
<br>
Modified: lld/trunk/ELF/SyntheticSections.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=349979&r1=349978&r2=349979&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=349979&r1=349978&r2=349979&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/SyntheticSections.cpp (original)<br>
+++ lld/trunk/ELF/SyntheticSections.cpp Fri Dec 21 16:31:05 2018<br>
@@ -2408,17 +2408,18 @@ static std::vector<GdbIndexSection::CuEn<br>
   return Ret;<br>
 }<br>
<br>
-static std::vector<GdbIndexSection::AddressEntry><br>
+static Expected<std::vector<GdbIndexSection::AddressEntry>><br>
 readAddressAreas(DWARFContext &Dwarf, InputSection *Sec) {<br>
   std::vector<GdbIndexSection::AddressEntry> Ret;<br>
<br>
   uint32_t CuIdx = 0;<br>
   for (std::unique_ptr<DWARFUnit> &Cu : Dwarf.compile_units()) {<br>
-    DWARFAddressRangesVector Ranges;<br>
-    Cu->collectAddressRanges(Ranges);<br>
+    Expected<DWARFAddressRangesVector> Ranges = Cu->collectAddressRanges();<br>
+    if (!Ranges)<br>
+      return Ranges.takeError();<br>
<br>
     ArrayRef<InputSectionBase *> Sections = Sec->File->getSections();<br>
-    for (DWARFAddressRange &R : Ranges) {<br>
+    for (DWARFAddressRange &R : *Ranges) {<br>
       InputSectionBase *S = Sections[R.SectionIndex];<br>
       if (!S || S == &InputSection::Discarded || !S->Live)<br>
         continue;<br>
@@ -2431,7 +2432,8 @@ readAddressAreas(DWARFContext &Dwarf, In<br>
     }<br>
     ++CuIdx;<br>
   }<br>
-  return Ret;<br>
+<br>
+  return std::move(Ret);<br>
 }<br>
<br>
 template <class ELFT><br>
@@ -2563,7 +2565,17 @@ template <class ELFT> GdbIndexSection *G<br>
<br>
     Chunks[I].Sec = Sections[I];<br>
     Chunks[I].CompilationUnits = readCuList(Dwarf);<br>
-    Chunks[I].AddressAreas = readAddressAreas(Dwarf, Sections[I]);<br>
+    Expected<std::vector<GdbIndexSection::AddressEntry>> AddressAreas =<br>
+        readAddressAreas(Dwarf, Sections[I]);<br>
+    if (!AddressAreas) {<br>
+      std::string Msg = File->getName();<br>
+      Msg += ": ";<br>
+      if (!File->ArchiveName.empty())<br>
+        Msg += "in archive " + File->ArchiveName + ": ";<br>
+      Msg += toString(AddressAreas.takeError());<br>
+      fatal(Msg);<br>
+    }<br></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>fatal() immediately terminates the process, and it is preferred to use error() which does return whenever possible.</div></div></div></blockquote><div><br>Fair enough - this was a "first pass" sort of approach.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div> 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.</div></div></div></blockquote><div><br>Oh, nice - thanks! I went looking for it through test cases, etc, and the example for duplicate symbols was the codepath I found, which used some more manual logic like this.<br><br>Could you reply here with the revisions of the followups, so I can take a look/understand?<br><br>Thanks again,<br>- Dave<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+    Chunks[I].AddressAreas = *AddressAreas;<br>
     NameAttrs[I] = readPubNamesAndTypes<ELFT>(<br>
         static_cast<const LLDDwarfObj<ELFT> &>(Dwarf.getDWARFObj()),<br>
         Chunks[I].CompilationUnits);<br>
<br>
Added: lld/trunk/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s?rev=349979&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s?rev=349979&view=auto</a><br>
==============================================================================<br>
--- lld/trunk/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s (added)<br>
+++ lld/trunk/test/ELF/Inputs/gdb-index-invalid-ranges.obj.s Fri Dec 21 16:31:05 2018<br>
@@ -0,0 +1,2 @@<br>
+main:<br>
+  callq f1<br>
<br>
Added: lld/trunk/test/ELF/gdb-index-invalid-ranges.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gdb-index-invalid-ranges.s?rev=349979&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gdb-index-invalid-ranges.s?rev=349979&view=auto</a><br>
==============================================================================<br>
--- lld/trunk/test/ELF/gdb-index-invalid-ranges.s (added)<br>
+++ lld/trunk/test/ELF/gdb-index-invalid-ranges.s Fri Dec 21 16:31:05 2018<br>
@@ -0,0 +1,42 @@<br>
+# REQUIRES: x86<br>
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o<br>
+# RUN: not ld.lld --gdb-index -e main %t.o -o %t 2>&1 | FileCheck %s<br>
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/gdb-index-invalid-ranges.obj.s -o %t2.o<br>
+# RUN: llvm-ar rc %t.a %t.o<br>
+# RUN: not ld.lld --gdb-index -e main %t2.o %t.a -o %t 2>&1 | FileCheck --check-prefix=ARCHIVE %s<br>
+<br>
+# CHECK: ld.lld: error: {{.*}}gdb-index-invalid-ranges.s.tmp.o: decoding address ranges: invalid range list entry at offset 0x10<br>
+# 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<br>
+<br>
+.section .text.foo1,"ax",@progbits<br>
+.globl f1<br>
+.Lfunc_begin0:<br>
+f1:<br>
+ nop<br>
+.Lfunc_end0:<br>
+<br>
+.section .debug_abbrev,"",@progbits<br>
+.byte 1                       # Abbreviation Code<br>
+.byte 17                      # DW_TAG_compile_unit<br>
+.byte 0                       # DW_CHILDREN_no<br>
+.byte 85                      # DW_AT_ranges<br>
+.byte 23                      # DW_FORM_sec_offset<br>
+.byte 0                       # EOM(1)<br>
+.byte 0                       # EOM(2)<br>
+.byte 0                       # EOM(3)<br>
+<br>
+.section .debug_info,"",@progbits<br>
+.Lcu_begin0:<br>
+.long .Lunit_end0-.Lunit_begin0 # Length of Unit<br>
+.Lunit_begin0:<br>
+.short 4                      # DWARF version number<br>
+.long .debug_abbrev           # Offset Into Abbrev. Section<br>
+.byte 8                       # Address Size (in bytes)<br>
+.byte 1                       # Abbrev [1] 0xb:0x1f DW_TAG_compile_unit<br>
+.long .Ldebug_ranges0         # DW_AT_ranges<br>
+.Lunit_end0:<br>
+<br>
+.section .debug_ranges,"",@progbits<br>
+.Ldebug_ranges0:<br>
+.quad .Lfunc_begin0<br>
+.quad .Lfunc_end0<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></blockquote></div></div>
</blockquote></div>