[llvm] r266692 - [DWARF] Force a linkage_name on an inlined subprogram's abstract origin.

Paul Robinson via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 18 15:41:41 PDT 2016


Author: probinson
Date: Mon Apr 18 17:41:41 2016
New Revision: 266692

URL: http://llvm.org/viewvc/llvm-project?rev=266692&view=rev
Log:
[DWARF] Force a linkage_name on an inlined subprogram's abstract origin.

When we suppress linkage names, for a non-inlined subprogram the name
can still be found in the object-file symbol table, because we have
the code address of the subprogram.  This is not necessarily the case
for an inlined subprogram, so we still want to emit the linkage name
in the DWARF.  Put this on the abstract-origin DIE because it's common
to all inlined instances.

Differential Revision: http://reviews.llvm.org/D18706

Added:
    llvm/trunk/test/DebugInfo/Generic/linkage-name-abstract.ll
Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    llvm/trunk/test/DebugInfo/Generic/PR20038.ll
    llvm/trunk/test/DebugInfo/Generic/cross-cu-inlining.ll
    llvm/trunk/test/DebugInfo/Generic/enum-types.ll
    llvm/trunk/test/DebugInfo/Generic/namespace.ll
    llvm/trunk/test/DebugInfo/Generic/namespace_function_definition.ll
    llvm/trunk/test/DebugInfo/Generic/namespace_inline_function_definition.ll
    llvm/trunk/test/Linker/type-unique-odr-a.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=266692&r1=266691&r2=266692&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Mon Apr 18 17:41:41 2016
@@ -185,7 +185,8 @@ DIE *DwarfCompileUnit::getOrCreateGlobal
     }
 
     addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);
-    addLinkageName(*VariableDIE, GV->getLinkageName());
+    if (DD->useAllLinkageNames())
+      addLinkageName(*VariableDIE, GV->getLinkageName());
   } else if (const ConstantInt *CI =
                  dyn_cast_or_null<ConstantInt>(GV->getVariable())) {
     addConstantValue(*VariableDIE, CI, GTy);

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=266692&r1=266691&r2=266692&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Mon Apr 18 17:41:41 2016
@@ -105,13 +105,21 @@ DwarfPubSections("generate-dwarf-pub-sec
                             clEnumVal(Disable, "Disabled"), clEnumValEnd),
                  cl::init(Default));
 
-static cl::opt<DefaultOnOff>
-DwarfLinkageNames("dwarf-linkage-names", cl::Hidden,
-                  cl::desc("Emit DWARF linkage-name attributes."),
-                  cl::values(clEnumVal(Default, "Default for platform"),
-                             clEnumVal(Enable, "Enabled"),
-                             clEnumVal(Disable, "Disabled"), clEnumValEnd),
-                  cl::init(Default));
+enum LinkageNameOption {
+  DefaultLinkageNames,
+  AllLinkageNames,
+  AbstractLinkageNames
+};
+static cl::opt<LinkageNameOption>
+    DwarfLinkageNames("dwarf-linkage-names", cl::Hidden,
+                      cl::desc("Which DWARF linkage-name attributes to emit."),
+                      cl::values(clEnumValN(DefaultLinkageNames, "Default",
+                                            "Default for platform"),
+                                 clEnumValN(AllLinkageNames, "All", "All"),
+                                 clEnumValN(AbstractLinkageNames, "Abstract",
+                                            "Abstract subprograms"),
+                                 clEnumValEnd),
+                      cl::init(DefaultLinkageNames));
 
 static const char *const DWARFGroupName = "DWARF Emission";
 static const char *const DbgTimerName = "DWARF Debug Writer";
@@ -245,11 +253,11 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Mo
   else
     HasDwarfPubSections = DwarfPubSections == Enable;
 
-  // SCE does not use linkage names.
-  if (DwarfLinkageNames == Default)
-    UseLinkageNames = !tuneForSCE();
+  // SCE defaults to linkage names only for abstract subprograms.
+  if (DwarfLinkageNames == DefaultLinkageNames)
+    UseAllLinkageNames = !tuneForSCE();
   else
-    UseLinkageNames = DwarfLinkageNames == Enable;
+    UseAllLinkageNames = DwarfLinkageNames == AllLinkageNames;
 
   unsigned DwarfVersionNumber = Asm->TM.Options.MCOptions.DwarfVersion;
   DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=266692&r1=266691&r2=266692&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Mon Apr 18 17:41:41 2016
@@ -249,8 +249,8 @@ class DwarfDebug : public DebugHandlerBa
   /// Whether to use the GNU TLS opcode (instead of the standard opcode).
   bool UseGNUTLSOpcode;
 
-  /// Whether to emit DW_AT_[MIPS_]linkage_name.
-  bool UseLinkageNames;
+  /// Whether to emit all linkage names, or just abstract subprograms.
+  bool UseAllLinkageNames;
 
   /// Version of dwarf we're emitting.
   unsigned DwarfVersion;
@@ -478,8 +478,9 @@ public:
     SymSize[Sym] = Size;
   }
 
-  /// Returns whether to emit DW_AT_[MIPS_]linkage_name.
-  bool useLinkageNames() const { return UseLinkageNames; }
+  /// Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
+  /// If not, we still might emit certain cases.
+  bool useAllLinkageNames() const { return UseAllLinkageNames; }
 
   /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
   /// standard DW_OP_form_tls_address opcode

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=266692&r1=266691&r2=266692&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Mon Apr 18 17:41:41 2016
@@ -665,7 +665,7 @@ void DwarfUnit::addConstantValue(DIE &Di
 }
 
 void DwarfUnit::addLinkageName(DIE &Die, StringRef LinkageName) {
-  if (!LinkageName.empty() && DD->useLinkageNames())
+  if (!LinkageName.empty())
     addString(Die,
               DD->getDwarfVersion() >= 4 ? dwarf::DW_AT_linkage_name
                                          : dwarf::DW_AT_MIPS_linkage_name,
@@ -1169,7 +1169,9 @@ bool DwarfUnit::applySubprogramDefinitio
   assert(((LinkageName.empty() || DeclLinkageName.empty()) ||
           LinkageName == DeclLinkageName) &&
          "decl has a linkage name and it is different");
-  if (DeclLinkageName.empty())
+  if (DeclLinkageName.empty() &&
+      // Always emit it for abstract subprograms.
+      (DD->useAllLinkageNames() || DU->getAbstractSPDies().lookup(SP)))
     addLinkageName(SPDie, LinkageName);
 
   if (!DeclDie)

Modified: llvm/trunk/test/DebugInfo/Generic/PR20038.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/PR20038.ll?rev=266692&r1=266691&r2=266692&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/PR20038.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/PR20038.ll Mon Apr 18 17:41:41 2016
@@ -3,7 +3,7 @@
 ; For some reason, the output when targetting sparc is not quite as expected.
 ; XFAIL: sparc
 
-; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Enable < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
+; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
 
 ; IR generated from clang -O0 with:
 ; struct C {

Modified: llvm/trunk/test/DebugInfo/Generic/cross-cu-inlining.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/cross-cu-inlining.ll?rev=266692&r1=266691&r2=266692&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/cross-cu-inlining.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/cross-cu-inlining.ll Mon Apr 18 17:41:41 2016
@@ -1,7 +1,7 @@
 ; REQUIRES: object-emission
 
-; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Enable < %s | llvm-dwarfdump -debug-dump=info - | FileCheck -implicit-check-not=DW_TAG %s
-; RUN: %llc_dwarf -dwarf-accel-tables=Enable -dwarf-linkage-names=Enable -O0 -filetype=obj < %s | llvm-dwarfdump - | FileCheck --check-prefix=CHECK-ACCEL --check-prefix=CHECK %s
+; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -debug-dump=info - | FileCheck -implicit-check-not=DW_TAG %s
+; RUN: %llc_dwarf -dwarf-accel-tables=Enable -dwarf-linkage-names=All -O0 -filetype=obj < %s | llvm-dwarfdump - | FileCheck --check-prefix=CHECK-ACCEL --check-prefix=CHECK %s
 
 ; Build from source:
 ; $ clang++ a.cpp b.cpp -g -c -emit-llvm

Modified: llvm/trunk/test/DebugInfo/Generic/enum-types.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/enum-types.ll?rev=266692&r1=266691&r2=266692&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/enum-types.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/enum-types.ll Mon Apr 18 17:41:41 2016
@@ -1,6 +1,6 @@
 ; REQUIRES: object-emission
 ;
-; RUN: %llc_dwarf -filetype=obj -O0 -dwarf-linkage-names=Enable < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
+; RUN: %llc_dwarf -filetype=obj -O0 -dwarf-linkage-names=All < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
 
 ; Make sure we can handle enums with the same identifier but in enum types of
 ; different compile units.

Added: llvm/trunk/test/DebugInfo/Generic/linkage-name-abstract.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/linkage-name-abstract.ll?rev=266692&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/linkage-name-abstract.ll (added)
+++ llvm/trunk/test/DebugInfo/Generic/linkage-name-abstract.ll Mon Apr 18 17:41:41 2016
@@ -0,0 +1,73 @@
+; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Abstract < %s | llvm-dwarfdump -debug-dump=info - > %t
+; RUN: FileCheck %s -check-prefix=ONENAME < %t
+; RUN: FileCheck %s -check-prefix=REF < %t 
+; Verify tuning for SCE gets us Abstract only.
+; RUN: %llc_dwarf -O0 -filetype=obj -debugger-tune=sce < %s | llvm-dwarfdump -debug-dump=info - > %t
+; RUN: FileCheck %s -check-prefix=ONENAME < %t
+; RUN: FileCheck %s -check-prefix=REF < %t 
+; REQUIRES: object-emission
+
+; Verify that the only linkage-name present is the abstract origin of the
+; inlined subprogram.
+
+; IR generated from clang -O0 with:
+; void f1();
+; __attribute__((always_inline)) void f2() { 
+;   f1();
+; }
+; void f3() {
+;   f2();
+; }
+
+; Show that there's only one linkage_name.
+; ONENAME:     {{DW_AT(_MIPS)?_linkage_name}}
+; ONENAME-NOT: {{DW_AT(_MIPS)?_linkage_name}}
+
+; Locate the subprogram DIE with the linkage name.
+; Show that the inlined_subroutine refers to it.
+; REF:     DW_TAG_subprogram
+; REF:     [[FOO:0x.*]]: DW_TAG_subprogram
+; REF-NOT: {{DW_TAG|NULL}}
+; REF:     {{DW_AT(_MIPS)?_linkage_name}}
+; REF:     DW_TAG_inlined_subroutine
+; REF-NOT: {{DW_TAG|NULL}}
+; REF:     DW_AT_abstract_origin {{.*}} {[[FOO]]}
+
+; Function Attrs: alwaysinline uwtable
+define void @_Z2f2v() #0 !dbg !4 {
+entry:
+  call void @_Z2f1v(), !dbg !11
+  ret void, !dbg !12
+}
+
+declare void @_Z2f1v()
+
+; Function Attrs: uwtable
+define void @_Z2f3v() #2 !dbg !7 {
+entry:
+  call void @_Z2f1v(), !dbg !13
+  ret void, !dbg !15
+}
+
+attributes #0 = { alwaysinline uwtable }
+attributes #2 = { uwtable }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!8, !9}
+!llvm.ident = !{!10}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 265282)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "linkage-name-abstract.cpp", directory: "/home/probinson/projects/scratch")
+!2 = !{}
+!4 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
+!5 = !DISubroutineType(types: !6)
+!6 = !{null}
+!7 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !1, file: !1, line: 5, type: !5, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
+!8 = !{i32 2, !"Dwarf Version", i32 4}
+!9 = !{i32 2, !"Debug Info Version", i32 3}
+!10 = !{!"clang version 3.9.0 (trunk 265282)"}
+!11 = !DILocation(line: 3, column: 3, scope: !4)
+!12 = !DILocation(line: 4, column: 1, scope: !4)
+!13 = !DILocation(line: 3, column: 3, scope: !4, inlinedAt: !14)
+!14 = distinct !DILocation(line: 6, column: 3, scope: !7)
+!15 = !DILocation(line: 7, column: 1, scope: !7)

Modified: llvm/trunk/test/DebugInfo/Generic/namespace.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/namespace.ll?rev=266692&r1=266691&r2=266692&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/namespace.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/namespace.ll Mon Apr 18 17:41:41 2016
@@ -1,6 +1,6 @@
 ; REQUIRES: object-emission
 
-; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Enable < %s | llvm-dwarfdump - | FileCheck %s
+; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump - | FileCheck %s
 ; CHECK: debug_info contents
 ; CHECK: [[NS1:0x[0-9a-f]*]]:{{ *}}DW_TAG_namespace
 ; CHECK-NEXT: DW_AT_name{{.*}} = "A"

Modified: llvm/trunk/test/DebugInfo/Generic/namespace_function_definition.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/namespace_function_definition.ll?rev=266692&r1=266691&r2=266692&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/namespace_function_definition.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/namespace_function_definition.ll Mon Apr 18 17:41:41 2016
@@ -1,6 +1,6 @@
 ; REQUIRES: object-emission
 
-; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Enable < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
+; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
 
 ; Generated from clang with the following source:
 ; namespace ns {

Modified: llvm/trunk/test/DebugInfo/Generic/namespace_inline_function_definition.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/namespace_inline_function_definition.ll?rev=266692&r1=266691&r2=266692&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/namespace_inline_function_definition.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/namespace_inline_function_definition.ll Mon Apr 18 17:41:41 2016
@@ -1,6 +1,6 @@
 ; REQUIRES: object-emission
 
-; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Enable < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
+; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
 
 ; Generate from clang with the following source. Note that the definition of
 ; the inline function follows its use to workaround another bug that should be

Modified: llvm/trunk/test/Linker/type-unique-odr-a.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/type-unique-odr-a.ll?rev=266692&r1=266691&r2=266692&view=diff
==============================================================================
--- llvm/trunk/test/Linker/type-unique-odr-a.ll (original)
+++ llvm/trunk/test/Linker/type-unique-odr-a.ll Mon Apr 18 17:41:41 2016
@@ -1,11 +1,11 @@
 ; REQUIRES: default_triple, object-emission
 ;
 ; RUN: llvm-link %s %p/type-unique-odr-b.ll -S -o - \
-; RUN:   | %llc_dwarf -dwarf-linkage-names=Enable -filetype=obj -O0 \
+; RUN:   | %llc_dwarf -dwarf-linkage-names=All -filetype=obj -O0 \
 ; RUN:   | llvm-dwarfdump -debug-dump=info - \
 ; RUN:   | FileCheck %s
 ; RUN: llvm-link %p/type-unique-odr-b.ll %s -S -o - \
-; RUN:   | %llc_dwarf -dwarf-linkage-names=Enable -filetype=obj -O0 \
+; RUN:   | %llc_dwarf -dwarf-linkage-names=All -filetype=obj -O0 \
 ; RUN:   | llvm-dwarfdump -debug-dump=info - \
 ; RUN:   | FileCheck %s
 ;




More information about the llvm-commits mailing list