[PATCH] D39542: [ELF] - Teach LLD to use information from .debug_str for error reporting.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 16 02:05:37 PST 2017


grimar updated this revision to Diff 123137.
grimar added subscribers: dblaikie, aprantl.
grimar added a comment.
This revision is now accepted and ready to land.
Herald added subscribers: JDevlieghere, arichardson.

Reason of crash was that DWARF parsers performs an attempt to parse address ranges
from .dwo files. Previously when no .debug_str was provided by LLD, it failed to do that
and things just worked. After this patch started to provide ".debug_str", code of DWARF
parsers attempts to call DWARFObject::getFileName() to open .dwo and methid was not
implemented in LLD.

I don't know why DWARF parser might want to collect address ranges from .dwo files and
wrote a mail "Collecting address ranges in DWARFUnit::collectAddressRanges." with question
about that. It seems excessive logic, at least it is not covered by any testcases I found.

In this patch I suggest to implement stub returning empty string for now. That way nothing
changes for LLD, we will return empty file name and DWARF parser will fail to parse .dwo file
for collecting address ranges. But at the same time we will not crash and so can land this patch.

Added testcase which crashed with llvm_unreachable at
https://github.com/llvm-mirror/llvm/blob/master/lib/DebugInfo/DWARF/DWARFUnit.cpp#L335
in previous iteration.


https://reviews.llvm.org/D39542

Files:
  ELF/GdbIndex.cpp
  ELF/GdbIndex.h
  test/ELF/conflict-debug-variable2.s
  test/ELF/gdb-index-noranges.s


Index: test/ELF/gdb-index-noranges.s
===================================================================
--- test/ELF/gdb-index-noranges.s
+++ test/ELF/gdb-index-noranges.s
@@ -0,0 +1,49 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
+
+## Input is reduced from following code and invocation:
+## clang++ -gsplit-dwarf -c test.ii -o test.s -S
+## clang version: 6.0.0 (trunk 318293)
+##
+## test.ii:
+## int a;
+##
+## Debug information does not contain any address ranges.
+## We crashed in that case. Check we don't.
+# RUN: ld.lld --gdb-index %t1.o -o %t
+
+.section  .debug_str,"MS", at progbits,1
+.Lskel_string0:
+  .asciz  "t.dwo"
+.Lskel_string1:
+  .asciz  "path"
+
+.section  .debug_abbrev,"", at progbits
+  .byte  1                       # Abbreviation Code
+  .byte  17                      # DW_TAG_compile_unit
+  .byte  0                       # DW_CHILDREN_no
+  .byte  16                      # DW_AT_stmt_list
+  .byte  23                      # DW_FORM_sec_offset
+  .ascii  "\260B"                # DW_AT_GNU_dwo_name
+  .byte  14                      # DW_FORM_strp
+  .byte  27                      # DW_AT_comp_dir
+  .byte  14                      # DW_FORM_strp
+  .ascii  "\261B"                # DW_AT_GNU_dwo_id
+  .byte  7                       # DW_FORM_data8
+  .ascii  "\263B"                # DW_AT_GNU_addr_base
+  .byte  23                      # DW_FORM_sec_offset
+  .byte  0                       # EOM(1)
+  .byte  0                       # EOM(2)
+  .byte  0                       # EOM(3)
+
+.section .debug_info,"", at progbits
+  .long  32                      # Length of Unit
+  .short  4                      # DWARF version number
+  .long  .debug_abbrev           # Offset Into Abbrev. Section
+  .byte  8                       # Address Size (in bytes)
+  .byte  1                       # Abbrev [1] 0xb:0x19 DW_TAG_compile_unit
+  .long  0                       # DW_AT_stmt_list
+  .long  .Lskel_string0          # DW_AT_GNU_dwo_name
+  .long  .Lskel_string1          # DW_AT_comp_dir
+  .quad  -3824446529333676116    # DW_AT_GNU_dwo_id
+  .long  0                       # DW_AT_GNU_addr_base
Index: ELF/GdbIndex.h
===================================================================
--- ELF/GdbIndex.h
+++ ELF/GdbIndex.h
@@ -30,6 +30,7 @@
   StringRef AbbrevSection;
   StringRef GnuPubNamesSection;
   StringRef GnuPubTypesSection;
+  StringRef StrSection;
 
   template <class RelTy>
   llvm::Optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &Sec,
@@ -47,9 +48,10 @@
   const llvm::DWARFSection &getLineSection() const override {
     return LineSection;
   }
+  StringRef getFileName() const override { return ""; }
   StringRef getCUIndexSection() const override { return ""; }
   StringRef getAbbrevSection() const override { return AbbrevSection; }
-  StringRef getStringSection() const override { return ""; }
+  StringRef getStringSection() const override { return StrSection; }
   StringRef getGnuPubNamesSection() const override {
     return GnuPubNamesSection;
   }
Index: ELF/GdbIndex.cpp
===================================================================
--- ELF/GdbIndex.cpp
+++ ELF/GdbIndex.cpp
@@ -44,6 +44,8 @@
       GnuPubNamesSection = toStringRef(Sec->Data);
     else if (Sec->Name == ".debug_gnu_pubtypes")
       GnuPubTypesSection = toStringRef(Sec->Data);
+    else if (Sec->Name == ".debug_str")
+      StrSection = toStringRef(Sec->Data);
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39542.123137.patch
Type: text/x-patch
Size: 3475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171116/a0808675/attachment.bin>


More information about the llvm-commits mailing list