Index: ELF/GdbIndex.h =================================================================== --- ELF/GdbIndex.h +++ ELF/GdbIndex.h @@ -30,6 +30,7 @@ StringRef AbbrevSection; StringRef GnuPubNamesSection; StringRef GnuPubTypesSection; + StringRef StrSection; template llvm::Optional 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); } } 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" + +@foo = global i32 0, align 4, !dbg !0 +@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)"}