diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4131,9 +4131,9 @@ else if (!T.isArch64Bit()) D.Diag(diag::err_drv_argument_only_allowed_with) << DwarfFormatArg->getAsString(Args) << "64 bit architecture"; - else if (!T.isOSBinFormatELF()) + else if (!(T.isOSBinFormatELF() || T.isOSBinFormatXCOFF())) D.Diag(diag::err_drv_argument_only_allowed_with) - << DwarfFormatArg->getAsString(Args) << "ELF platforms"; + << DwarfFormatArg->getAsString(Args) << "ELF/XCOFF platforms"; } DwarfFormatArg->render(Args, CmdArgs); 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 @@ -389,6 +389,7 @@ DwarfVersion = TT.isNVPTX() ? 2 : (DwarfVersion ? DwarfVersion : dwarf::DWARF_VERSION); + bool UseIntegratedAs = Asm->OutStreamer->isIntegratedAssemblerRequired(); bool Dwarf64 = DwarfVersion >= 3 && // DWARF64 was introduced in DWARFv3. TT.isArch64Bit(); // DWARF64 requires 64-bit relocations. @@ -396,15 +397,18 @@ // 1: For ELF when requested. // 2: For XCOFF64: the AIX assembler will fill in debug section lengths // according to the DWARF64 format for 64-bit assembly, so we must use - // DWARF64 in the compiler too for 64-bit mode. + // DWARF64 in the compiler for 64-bit mode on non-integrated-as mode. Dwarf64 &= - ((Asm->TM.Options.MCOptions.Dwarf64 || MMI->getModule()->isDwarf64()) && - TT.isOSBinFormatELF()) || - TT.isOSBinFormatXCOFF(); - - if (!Dwarf64 && TT.isArch64Bit() && TT.isOSBinFormatXCOFF()) - report_fatal_error("XCOFF requires DWARF64 for 64-bit mode!"); - + ((TT.isOSBinFormatELF() || + (TT.isOSBinFormatXCOFF() && UseIntegratedAs)) && + (Asm->TM.Options.MCOptions.Dwarf64 || MMI->getModule()->isDwarf64())) || + (TT.isOSBinFormatXCOFF() && !UseIntegratedAs); + + if (!Dwarf64 && TT.isArch64Bit() && TT.isOSBinFormatXCOFF() && + !UseIntegratedAs) + report_fatal_error( + "XCOFF requires DWARF64 for 64-bit mode on non-integrated-as mode!"); + UseRangesSection = !NoDwarfRangesSection && !TT.isNVPTX(); // Use sections as references. Force for NVPTX. diff --git a/llvm/test/DebugInfo/XCOFF/dwarf-format.ll b/llvm/test/DebugInfo/XCOFF/dwarf-format.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/XCOFF/dwarf-format.ll @@ -0,0 +1,33 @@ +; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -filetype=obj %s -o - \ +; RUN: | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK + +; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -filetype=obj -dwarf64 %s -o - \ +; RUN: | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK64 + +; CHECK: file format aix5coff64-rs6000 +; CHECK: format: DWARF32 + +; CHECK64: file format aix5coff64-rs6000 +; CHECK64: format: DWARF64 + +source_filename = "1.c" +target datalayout = "E-m:a-p:32:32-Fi32-i64:64-n32" + +@foo = global i32 0, align 4, !dbg !0 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!6, !7, !8, !9, !10} +!llvm.ident = !{!11} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 17.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None) +!3 = !DIFile(filename: "1.c", directory: "llvm-project") +!4 = !{!0} +!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!6 = !{i32 7, !"Dwarf Version", i32 3} +!7 = !{i32 2, !"Debug Info Version", i32 3} +!8 = !{i32 1, !"wchar_size", i32 2} +!9 = !{i32 8, !"PIC Level", i32 2} +!10 = !{i32 7, !"frame-pointer", i32 2} +!11 = !{!"clang version 17.0.0"}