[clang] 4054c68 - [XCOFF][DWARF] XCOFF64 should be able to select the dwarf format in intergrated-as mode.
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 16 00:02:51 PDT 2023
Author: esmeyi
Date: 2023-05-16T03:02:00-04:00
New Revision: 4054c68644dfebbb584bca698a25d18d1d312bae
URL: https://github.com/llvm/llvm-project/commit/4054c68644dfebbb584bca698a25d18d1d312bae
DIFF: https://github.com/llvm/llvm-project/commit/4054c68644dfebbb584bca698a25d18d1d312bae.diff
LOG: [XCOFF][DWARF] XCOFF64 should be able to select the dwarf format in intergrated-as mode.
Summary: DWARF32 is not supported for XCOFF64 under non-integrated-as mode on AIX, because system assembler will fill the debug section lengths according to DWARF64 format. While in intergrated-as mode, XCOFF64 should be able to select the DWARF format.
Reviewed By: shchenz
Differential Revision: https://reviews.llvm.org/D150181
Added:
llvm/test/DebugInfo/XCOFF/dwarf-format.ll
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/debug-options-as.c
clang/test/Driver/debug-options.c
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/test/CodeGen/PowerPC/aix-dwarf.ll
llvm/test/CodeGen/PowerPC/aix-xcoff-exception-section-debug.ll
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index e1fc3cf89ba0c..a230bc45a08fc 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4144,9 +4144,9 @@ static void renderDwarfFormat(const Driver &D, const llvm::Triple &T,
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/clang/test/Driver/debug-options-as.c b/clang/test/Driver/debug-options-as.c
index 87268e8c5deaf..baa6bf1e70f1a 100644
--- a/clang/test/Driver/debug-options-as.c
+++ b/clang/test/Driver/debug-options-as.c
@@ -59,7 +59,7 @@
//
// GDWARF64_VER: error: invalid argument '-gdwarf64' only allowed with 'DWARFv3 or greater'
// GDWARF64_32ARCH: error: invalid argument '-gdwarf64' only allowed with '64 bit architecture'
-// GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF platforms'
+// GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF/XCOFF platforms'
// Check that -gdwarf-N can be placed before other options of the "-g" group.
// RUN: %clang -### -c -g -gdwarf-3 -target %itanium_abi_triple -fintegrated-as -x assembler %s 2>&1 \
diff --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c
index 8617949cea1c8..1799f2cc1492b 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -462,7 +462,7 @@
// GDWARF64_ON: "-gdwarf64"
// GDWARF64_VER: error: invalid argument '-gdwarf64' only allowed with 'DWARFv3 or greater'
// GDWARF64_32ARCH: error: invalid argument '-gdwarf64' only allowed with '64 bit architecture'
-// GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF platforms'
+// GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF/XCOFF platforms'
/// Default to -fno-dwarf-directory-asm for -fno-integrated-as before DWARF v5.
// RUN: %clang -### -target x86_64 -c -gdwarf-2 %s 2>&1 | FileCheck --check-prefix=DIRECTORY %s
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index b260e4069feed..ba08680e9d715 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -397,14 +397,17 @@ DwarfDebug::DwarfDebug(AsmPrinter *A)
// 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.
+ bool IsXcoff = TT.isOSBinFormatXCOFF();
+ bool UseIntegratedAs = Asm->OutStreamer->isIntegratedAssemblerRequired();
Dwarf64 &=
- ((Asm->TM.Options.MCOptions.Dwarf64 || MMI->getModule()->isDwarf64()) &&
- TT.isOSBinFormatELF()) ||
- TT.isOSBinFormatXCOFF();
+ ((TT.isOSBinFormatELF() || (IsXcoff && UseIntegratedAs)) &&
+ (Asm->TM.Options.MCOptions.Dwarf64 || MMI->getModule()->isDwarf64())) ||
+ (IsXcoff && !UseIntegratedAs);
- if (!Dwarf64 && TT.isArch64Bit() && TT.isOSBinFormatXCOFF())
- report_fatal_error("XCOFF requires DWARF64 for 64-bit mode!");
+ if (!Dwarf64 && TT.isArch64Bit() && IsXcoff && !UseIntegratedAs)
+ report_fatal_error(
+ "XCOFF requires DWARF64 for 64-bit mode on non-integrated-as mode!");
UseRangesSection = !NoDwarfRangesSection && !TT.isNVPTX();
diff --git a/llvm/test/CodeGen/PowerPC/aix-dwarf.ll b/llvm/test/CodeGen/PowerPC/aix-dwarf.ll
index 0a4032f2acecd..4535d01210b16 100644
--- a/llvm/test/CodeGen/PowerPC/aix-dwarf.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-dwarf.ll
@@ -65,7 +65,7 @@ entry:
; SEC32-NEXT: RelocationPointer: 0x1F4
; SEC64-NEXT: Size: 0x18
; SEC64-NEXT: RawDataOffset: 0x1A8
-; SEC64-NEXT: RelocationPointer: 0x2C8
+; SEC64-NEXT: RelocationPointer: 0x29C
; SEC-NEXT: LineNumberPointer: 0x0
; SEC-NEXT: NumberOfRelocations: 2
; SEC-NEXT: NumberOfLineNumbers: 0
@@ -93,9 +93,9 @@ entry:
; SEC32-NEXT: Size: 0x57
; SEC32-NEXT: RawDataOffset: 0x15C
; SEC32-NEXT: RelocationPointer: 0x208
-; SEC64-NEXT: Size: 0x6F
+; SEC64-NEXT: Size: 0x5F
; SEC64-NEXT: RawDataOffset: 0x200
-; SEC64-NEXT: RelocationPointer: 0x2E4
+; SEC64-NEXT: RelocationPointer: 0x2B8
; SEC-NEXT: LineNumberPointer: 0x0
; SEC-NEXT: NumberOfRelocations: 4
; SEC-NEXT: NumberOfLineNumbers: 0
@@ -109,9 +109,9 @@ entry:
; SEC32-NEXT: Size: 0x36
; SEC32-NEXT: RawDataOffset: 0x1BC
; SEC32-NEXT: RelocationPointer: 0x230
-; SEC64-NEXT: Size: 0x46
-; SEC64-NEXT: RawDataOffset: 0x280
-; SEC64-NEXT: RelocationPointer: 0x31C
+; SEC64-NEXT: Size: 0x3A
+; SEC64-NEXT: RawDataOffset: 0x260
+; SEC64-NEXT: RelocationPointer: 0x2F0
; SEC-NEXT: LineNumberPointer: 0x0
; SEC-NEXT: NumberOfRelocations: 1
; SEC-NEXT: NumberOfLineNumbers: 0
@@ -131,10 +131,10 @@ entry:
; RELO64: RELOCATION RECORDS FOR [.dwinfo]:
; RELO64-NEXT: OFFSET TYPE VALUE
-; RELO64-NEXT: 000000000000000e R_POS .dwabrev
-; RELO64-NEXT: 000000000000000b R_POS .dwline
-; RELO64-NEXT: 0000000000000041 R_POS .text
-; RELO64-NEXT: 000000000000004e R_POS .text
+; RELO64-NEXT: 0000000000000006 R_POS .dwabrev
+; RELO64-NEXT: 0000000000000027 R_POS .dwline
+; RELO64-NEXT: 0000000000000009 R_POS .text
+; RELO64-NEXT: 0000000000000016 R_POS .text
; RELO64: RELOCATION RECORDS FOR [.dwline]:
; RELO64-NEXT: OFFSET TYPE VALUE
-; RELO64-NEXT: 000000000000000c R_POS .text
+; RELO64-NEXT: 0000000000000000 R_POS .text
diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-exception-section-debug.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-exception-section-debug.ll
index 01d0aa9e173f9..9a816ad4b31c9 100644
--- a/llvm/test/CodeGen/PowerPC/aix-xcoff-exception-section-debug.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-exception-section-debug.ll
@@ -3,8 +3,8 @@
; Exception auxilliary entries are present in the 64-bit tests because 64-bit && debug enabled are the requirements.
; RUN: llc -mtriple=powerpc-ibm-aix-xcoff -filetype=obj -o %t_32.o < %s
; RUN: llvm-readobj --syms %t_32.o | FileCheck %s --check-prefix=SYMS32
-; RUN: llc -mtriple=powerpc64-unknown-aix -filetype=obj -o %t_32.o < %s
-; RUN: llvm-readobj --syms %t_32.o | FileCheck %s --check-prefix=SYMS64
+; RUN: llc -mtriple=powerpc64-unknown-aix -filetype=obj -o %t_64.o < %s
+; RUN: llvm-readobj --syms %t_64.o | FileCheck %s --check-prefix=SYMS64
; If any debug information is included in a module and is XCOFF64, exception auxilliary entries are emitted
@@ -93,7 +93,7 @@ define dso_local void @test__trap_annotation_debug(i32 %a) !dbg !4 {
; SYMS64-NEXT: NumberOfAuxEntries: 3
; SYMS64-NEXT: Exception Auxiliary Entry {
; SYMS64-NEXT: Index: [[#IND+1]]
-; SYMS64-NEXT: OffsetToExceptionTable: 0x398
+; SYMS64-NEXT: OffsetToExceptionTable: 0x38C
; SYMS64-NEXT: SizeOfFunction: 0x18
; SYMS64-NEXT: SymbolIndexOfNextBeyond: [[#IND+4]]
; SYMS64-NEXT: Auxiliary Type: AUX_EXCEPT (0xFF)
@@ -126,7 +126,7 @@ define dso_local void @test__trap_annotation_debug(i32 %a) !dbg !4 {
; SYMS64-NEXT: NumberOfAuxEntries: 3
; SYMS64-NEXT: Exception Auxiliary Entry {
; SYMS64-NEXT: Index: [[#IND+5]]
-; SYMS64-NEXT: OffsetToExceptionTable: 0x3AC
+; SYMS64-NEXT: OffsetToExceptionTable: 0x3A0
; SYMS64-NEXT: SizeOfFunction: 0x68
; SYMS64-NEXT: SymbolIndexOfNextBeyond: [[#IND+8]]
; SYMS64-NEXT: Auxiliary Type: AUX_EXCEPT (0xFF)
diff --git a/llvm/test/DebugInfo/XCOFF/dwarf-format.ll b/llvm/test/DebugInfo/XCOFF/dwarf-format.ll
new file mode 100644
index 0000000000000..337dfbf2884de
--- /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"
+
+ at 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"}
More information about the cfe-commits
mailing list