diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1247,10 +1247,12 @@ ? dwarf::DW_AT_dwo_name : dwarf::DW_AT_GNU_dwo_name; finishUnitAttributes(TheCU.getCUNode(), TheCU); - TheCU.addString(TheCU.getUnitDie(), attrDWOName, - Asm->TM.Options.MCOptions.SplitDwarfFile); - SkCU->addString(SkCU->getUnitDie(), attrDWOName, - Asm->TM.Options.MCOptions.SplitDwarfFile); + StringRef embeddedDWOName = TheCU.getCUNode()->getSplitDebugFilename(); + if (embeddedDWOName.empty()) { + embeddedDWOName = Asm->TM.Options.MCOptions.SplitDwarfFile; + } + TheCU.addString(TheCU.getUnitDie(), attrDWOName, embeddedDWOName); + SkCU->addString(SkCU->getUnitDie(), attrDWOName, embeddedDWOName); // Emit a unique identifier for this CU. uint64_t ID = DIEHash(Asm, &TheCU).computeCUSignature(DWOName, TheCU.getUnitDie()); diff --git a/llvm/test/DebugInfo/X86/debug-macinfo-split-dwarf.ll b/llvm/test/DebugInfo/X86/debug-macinfo-split-dwarf.ll --- a/llvm/test/DebugInfo/X86/debug-macinfo-split-dwarf.ll +++ b/llvm/test/DebugInfo/X86/debug-macinfo-split-dwarf.ll @@ -44,7 +44,7 @@ !llvm.module.flags = !{!21, !22, !23} !llvm.ident = !{!24} -!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "debug-macro-split-dwarf.dwo", emissionKind: FullDebug, enums: !2, macros: !3, nameTableKind: GNU) +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, macros: !3, nameTableKind: GNU) !1 = !DIFile(filename: "debug-macro-split-dwarf.c", directory: "/", checksumkind: CSK_MD5, checksum: "e74d0fa8f714535c1bac6da2ffbbd898") !2 = !{} !3 = !{!4, !14, !15, !16, !17, !18, !19, !20} diff --git a/llvm/test/DebugInfo/dwo-different-name.ll b/llvm/test/DebugInfo/dwo-different-name.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/dwo-different-name.ll @@ -0,0 +1,16 @@ +; RUN: %llc_dwarf %s -filetype=obj -o %t --split-dwarf-file from-mc-options.dwo +; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s +; REQUIRES: default_triple, object-emission +; +; CHECK: DW_AT_GNU_dwo_name ("from-debuginfo.dwo") +; CHECK-NOT: DW_AT_GNU_dwo_name ("from-mc-options.dwo") + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Clang", isOptimized: false, runtimeVersion: 2, splitDebugFilename: "from-debuginfo.dwo", emissionKind: FullDebug, enums: !2, globals: !2, retainedTypes: !5) +!1 = !DIFile(filename: "", directory: "/") +!2 = !{} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{!6} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) diff --git a/llvm/test/tools/llvm-dwp/X86/absolute_paths.test b/llvm/test/tools/llvm-dwp/X86/absolute_paths.test --- a/llvm/test/tools/llvm-dwp/X86/absolute_paths.test +++ b/llvm/test/tools/llvm-dwp/X86/absolute_paths.test @@ -22,7 +22,7 @@ !llvm.module.flags = !{!3, !4, !5, !6} !llvm.ident = !{!7} -!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.1", isOptimized: true, runtimeVersion: 0, splitDebugFilename: "test.dwo", emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: GNU) +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.1", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: GNU) !1 = !DIFile(filename: "/tmp/test.c", directory: "/tmp") !2 = !{} !3 = !{i32 7, !"Dwarf Version", i32 4}