Index: lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -41,6 +41,11 @@ cl::desc("Generate DWARF4 type units."), cl::init(false)); +static cl::opt +SuppressLinkageNames("suppress-dwarf-linkage-names", cl::Hidden, + cl::desc("Suppress the DWARF DW_AT_(MIPS_)?linkage_name entries"), + cl::init(false)); + /// Unit - Unit constructor. DwarfUnit::DwarfUnit(unsigned UID, dwarf::Tag UnitTag, DICompileUnit Node, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU) @@ -1462,14 +1467,16 @@ // Add function template parameters. addTemplateParams(SPDie, SP.getTemplateParams()); - // Add the linkage name if we have one and it isn't in the Decl. - StringRef LinkageName = SP.getLinkageName(); - assert(((LinkageName.empty() || DeclLinkageName.empty()) || - LinkageName == DeclLinkageName) && - "decl has a linkage name and it is different"); - if (!LinkageName.empty() && DeclLinkageName.empty()) - addString(SPDie, dwarf::DW_AT_MIPS_linkage_name, - GlobalValue::getRealLinkageName(LinkageName)); + if (!SuppressLinkageNames) { + // Add the linkage name if we have one and it isn't in the Decl. + StringRef LinkageName = SP.getLinkageName(); + assert(((LinkageName.empty() || DeclLinkageName.empty()) || + LinkageName == DeclLinkageName) && + "decl has a linkage name and it is different"); + if (!LinkageName.empty() && DeclLinkageName.empty()) + addString(SPDie, dwarf::DW_AT_MIPS_linkage_name, + GlobalValue::getRealLinkageName(LinkageName)); + } if (DeclDie) { // Refer to the function declaration where all the other attributes will be @@ -1691,17 +1698,19 @@ } else { addBlock(*VariableDIE, dwarf::DW_AT_location, Loc); } - // Add the linkage name. - StringRef LinkageName = GV.getLinkageName(); - if (!LinkageName.empty()) - // From DWARF4: DIEs to which DW_AT_linkage_name may apply include: - // TAG_common_block, TAG_constant, TAG_entry_point, TAG_subprogram and - // TAG_variable. - addString(IsStaticMember && VariableSpecDIE ? *VariableSpecDIE - : *VariableDIE, - DD->getDwarfVersion() >= 4 ? dwarf::DW_AT_linkage_name - : dwarf::DW_AT_MIPS_linkage_name, - GlobalValue::getRealLinkageName(LinkageName)); + if (!SuppressLinkageNames) { + // Add the linkage name. + StringRef LinkageName = GV.getLinkageName(); + if (!LinkageName.empty()) + // From DWARF4: DIEs to which DW_AT_linkage_name may apply include: + // TAG_common_block, TAG_constant, TAG_entry_point, TAG_subprogram and + // TAG_variable. + addString(IsStaticMember && VariableSpecDIE ? *VariableSpecDIE + : *VariableDIE, + DD->getDwarfVersion() >= 4 ? dwarf::DW_AT_linkage_name + : dwarf::DW_AT_MIPS_linkage_name, + GlobalValue::getRealLinkageName(LinkageName)); + } } else if (const ConstantInt *CI = dyn_cast_or_null(GV.getConstant())) { // AT_const_value was added when the static member was created. To avoid Index: test/DebugInfo/suppress-linkage-entry-3.ll =================================================================== --- test/DebugInfo/suppress-linkage-entry-3.ll +++ test/DebugInfo/suppress-linkage-entry-3.ll @@ -0,0 +1,51 @@ +; REQUIRES: object-emission + +; RUN: %llc_dwarf -suppress-dwarf-linkage-names -dwarf-version=3 -O0 -filetype=obj < %s > %t +; RUN: llvm-dwarfdump %t | FileCheck %s + +; The test checks whether the DWARF linkage name attributes are suppressed (DWARF 3). +; The IR was generated with 'clang -gdwarf-3' from the following source: + +; namespace bar { +; int i; +; } +; +; void foo() +; { +; } + +; CHECK-NOT: DW_AT_MIPS_linkage_name +; CHECK-NOT: DW_AT_linkage_name + +; ModuleID = 'test.cpp' + +@_ZN3bar1iE = global i32 0, align 4 + +; Function Attrs: nounwind uwtable +define void @_Z3foov() #0 { +entry: + ret void, !dbg !15 +} + +attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!12, !13} +!llvm.ident = !{!14} + +!0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.6.0 (218392)", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !8, metadata !2, metadata !"", i32 1} ; [ DW_TAG_compile_unit ] [/home/user/test/test.cpp] [DW_LANG_C_plus_plus] +!1 = metadata !{metadata !"test.cpp", metadata !"/home/user/test"} +!2 = metadata !{} +!3 = metadata !{metadata !4} +!4 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"foo", metadata !"foo", metadata !"_Z3foov", i32 5, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void ()* @_Z3foov, null, null, metadata !2, i32 6} ; [ DW_TAG_subprogram ] [line 5] [def] [scope 6] [foo] +!5 = metadata !{i32 786473, metadata !1} ; [ DW_TAG_file_type ] [/home/user/test/test.cpp] +!6 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !7, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] +!7 = metadata !{null} +!8 = metadata !{metadata !9} +!9 = metadata !{i32 786484, i32 0, metadata !10, metadata !"i", metadata !"i", metadata !"_ZN3bar1iE", metadata !5, i32 2, metadata !11, i32 0, i32 1, i32* @_ZN3bar1iE, null} ; [ DW_TAG_variable ] [i] [line 2] [def] +!10 = metadata !{i32 786489, metadata !1, null, metadata !"bar", i32 1} ; [ DW_TAG_namespace ] [bar] [line 1] +!11 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed] +!12 = metadata !{i32 2, metadata !"Dwarf Version", i32 3} +!13 = metadata !{i32 2, metadata !"Debug Info Version", i32 1} +!14 = metadata !{metadata !"clang version 3.6.0 (218392)"} +!15 = metadata !{i32 7, i32 1, metadata !4, null} Index: test/DebugInfo/suppress-linkage-entry-4.ll =================================================================== --- test/DebugInfo/suppress-linkage-entry-4.ll +++ test/DebugInfo/suppress-linkage-entry-4.ll @@ -0,0 +1,52 @@ +; REQUIRES: object-emission + +; RUN: %llc_dwarf -suppress-dwarf-linkage-names -dwarf-version=4 -O0 -filetype=obj < %s > %t +; RUN: llvm-dwarfdump %t | FileCheck %s + + +; The test checks whether the DWARF linkage name attributes are suppressed (DWARF 4). +; The IR was generated with 'clang -gdwarf-4' from the following source: + +; namespace bar { +; int i; +; } +; +; void foo() +; { +; } + +; CHECK-NOT: DW_AT_MIPS_linkage_name +; CHECK-NOT: DW_AT_linkage_name + +; ModuleID = 'test.cpp' + +@_ZN3bar1iE = global i32 0, align 4 + +; Function Attrs: nounwind uwtable +define void @_Z3foov() #0 { +entry: + ret void, !dbg !15 +} + +attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!12, !13} +!llvm.ident = !{!14} + +!0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.6.0 (218392)", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !8, metadata !2, metadata !"", i32 1} ; [ DW_TAG_compile_unit ] [/home/user/test/test.cpp] [DW_LANG_C_plus_plus] +!1 = metadata !{metadata !"test.cpp", metadata !"/home/user/test"} +!2 = metadata !{} +!3 = metadata !{metadata !4} +!4 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"foo", metadata !"foo", metadata !"_Z3foov", i32 5, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void ()* @_Z3foov, null, null, metadata !2, i32 6} ; [ DW_TAG_subprogram ] [line 5] [def] [scope 6] [foo] +!5 = metadata !{i32 786473, metadata !1} ; [ DW_TAG_file_type ] [/home/user/test/test.cpp] +!6 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !7, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] +!7 = metadata !{null} +!8 = metadata !{metadata !9} +!9 = metadata !{i32 786484, i32 0, metadata !10, metadata !"i", metadata !"i", metadata !"_ZN3bar1iE", metadata !5, i32 2, metadata !11, i32 0, i32 1, i32* @_ZN3bar1iE, null} ; [ DW_TAG_variable ] [i] [line 2] [def] +!10 = metadata !{i32 786489, metadata !1, null, metadata !"bar", i32 1} ; [ DW_TAG_namespace ] [bar] [line 1] +!11 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed] +!12 = metadata !{i32 2, metadata !"Dwarf Version", i32 4} +!13 = metadata !{i32 2, metadata !"Debug Info Version", i32 1} +!14 = metadata !{metadata !"clang version 3.6.0 (218392)"} +!15 = metadata !{i32 7, i32 1, metadata !4, null}