[PATCH] D39491: [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
Wed Nov 1 06:24:47 PDT 2017


grimar created this revision.
Herald added subscribers: aprantl, emaste.

https://reviews.llvm.org/D38721 teached LLD to report line numbers for duplicate valiables definitions,
though currently LLD is unable to do that for case when strings are not built in
.debug_info, but stored in `.debug_str` instead.

That is because out LLDDwarfObj does not handle `.debug_str` yet. 
Patch fixes that.


https://reviews.llvm.org/D39491

Files:
  ELF/GdbIndex.cpp
  ELF/GdbIndex.h
  test/ELF/conflict-debug-variable2.ll


Index: test/ELF/conflict-debug-variable2.ll
===================================================================
--- test/ELF/conflict-debug-variable2.ll
+++ test/ELF/conflict-debug-variable2.ll
@@ -0,0 +1,58 @@
+; REQUIRES: x86
+; RUN: llc %s -o %t.o -filetype=obj
+
+;; Check input file contains DW_FORM_strp references to .debug_str.
+; RUN: llvm-dwarfdump %t.o -v | FileCheck -check-prefix=INPUT %s
+; INPUT:     .debug_info contents:
+; INPUT:      DW_TAG_variable [2]
+; INPUT-NEXT:  DW_AT_name [DW_FORM_strp]             ( .debug_str[0x00000035] = "foo")
+; INPUT-NEXT:  DW_AT_type [DW_FORM_ref4]             (cu + 0x0033 => {0x00000033} "int")
+; INPUT-NEXT:  DW_AT_external [DW_FORM_flag_present] (true)
+; INPUT-NEXT:  DW_AT_decl_file [DW_FORM_data1]       ("/home/path{{[\\/]}}test.c")
+; INPUT-NEXT:  DW_AT_decl_line [DW_FORM_data1]       (1)
+; INPUT-NEXT:  DW_AT_location [DW_FORM_exprloc]      (DW_OP_addr 0x0)
+; INPUT:      DW_TAG_variable [2]
+; INPUT-NEXT:  DW_AT_name [DW_FORM_strp]             ( .debug_str[0x0000003d] = "bar")
+; INPUT-NEXT:  DW_AT_type [DW_FORM_ref4]             (cu + 0x0033 => {0x00000033} "int")
+; INPUT-NEXT:  DW_AT_external [DW_FORM_flag_present] (true)
+; INPUT-NEXT:  DW_AT_decl_file [DW_FORM_data1]       ("/home/path{{[\\/]}}test.c")
+; INPUT-NEXT:  DW_AT_decl_line [DW_FORM_data1]       (2)
+; INPUT-NEXT:  DW_AT_location [DW_FORM_exprloc]      (DW_OP_addr 0x0)
+
+;; Check are able to we use information from .debug_info in messages.
+; RUN: not ld.lld %t.o %t.o -o %t 2>&1 | FileCheck %s
+; CHECK:      duplicate symbol: bar
+; CHECK-NEXT: >>> defined at test.c:2
+; CHECK-NEXT: >>>            {{.*}}:(bar)
+; CHECK-NEXT: >>> defined at test.c:2
+; CHECK-NEXT: >>>            {{.*}}:(.data+0x0)
+; CHECK:      duplicate symbol: foo
+; CHECK-NEXT: >>> defined at test.c:1
+; CHECK-NEXT: >>>            {{.*}}:(foo)
+; CHECK-NEXT: >>> defined at test.c:1
+; CHECK-NEXT: >>>            {{.*}}:(.bss+0x0)
+
+source_filename = "test.c"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at foo = global i32 0, align 4, !dbg !0
+ at bar = global i32 1, align 4, !dbg !6
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!9, !10, !11}
+!llvm.ident = !{!12}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 6.0.0 (trunk 316661)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
+!3 = !DIFile(filename: "test.c", directory: "/home/path")
+!4 = !{}
+!5 = !{!0, !6}
+!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
+!7 = distinct !DIGlobalVariable(name: "bar", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{i32 2, !"Dwarf Version", i32 4}
+!10 = !{i32 2, !"Debug Info Version", i32 3}
+!11 = !{i32 1, !"wchar_size", i32 4}
+!12 = !{!"clang version 6.0.0 (trunk 316661)"}
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,
@@ -49,7 +50,7 @@
   }
   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: D39491.121122.patch
Type: text/x-patch
Size: 4306 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171101/4f3c79ba/attachment.bin>


More information about the llvm-commits mailing list