Skip to content

Commit 4054c68

Browse files
author
esmeyi
committed
[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
1 parent b9c0e59 commit 4054c68

File tree

7 files changed

+61
-25
lines changed

7 files changed

+61
-25
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4144,9 +4144,9 @@ static void renderDwarfFormat(const Driver &D, const llvm::Triple &T,
41444144
else if (!T.isArch64Bit())
41454145
D.Diag(diag::err_drv_argument_only_allowed_with)
41464146
<< DwarfFormatArg->getAsString(Args) << "64 bit architecture";
4147-
else if (!T.isOSBinFormatELF())
4147+
else if (!(T.isOSBinFormatELF() || T.isOSBinFormatXCOFF()))
41484148
D.Diag(diag::err_drv_argument_only_allowed_with)
4149-
<< DwarfFormatArg->getAsString(Args) << "ELF platforms";
4149+
<< DwarfFormatArg->getAsString(Args) << "ELF/XCOFF platforms";
41504150
}
41514151

41524152
DwarfFormatArg->render(Args, CmdArgs);

clang/test/Driver/debug-options-as.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
//
6060
// GDWARF64_VER: error: invalid argument '-gdwarf64' only allowed with 'DWARFv3 or greater'
6161
// GDWARF64_32ARCH: error: invalid argument '-gdwarf64' only allowed with '64 bit architecture'
62-
// GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF platforms'
62+
// GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF/XCOFF platforms'
6363

6464
// Check that -gdwarf-N can be placed before other options of the "-g" group.
6565
// RUN: %clang -### -c -g -gdwarf-3 -target %itanium_abi_triple -fintegrated-as -x assembler %s 2>&1 \

clang/test/Driver/debug-options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@
462462
// GDWARF64_ON: "-gdwarf64"
463463
// GDWARF64_VER: error: invalid argument '-gdwarf64' only allowed with 'DWARFv3 or greater'
464464
// GDWARF64_32ARCH: error: invalid argument '-gdwarf64' only allowed with '64 bit architecture'
465-
// GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF platforms'
465+
// GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF/XCOFF platforms'
466466

467467
/// Default to -fno-dwarf-directory-asm for -fno-integrated-as before DWARF v5.
468468
// RUN: %clang -### -target x86_64 -c -gdwarf-2 %s 2>&1 | FileCheck --check-prefix=DIRECTORY %s

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,17 @@ DwarfDebug::DwarfDebug(AsmPrinter *A)
397397
// 1: For ELF when requested.
398398
// 2: For XCOFF64: the AIX assembler will fill in debug section lengths
399399
// according to the DWARF64 format for 64-bit assembly, so we must use
400-
// DWARF64 in the compiler too for 64-bit mode.
400+
// DWARF64 in the compiler for 64-bit mode on non-integrated-as mode.
401+
bool IsXcoff = TT.isOSBinFormatXCOFF();
402+
bool UseIntegratedAs = Asm->OutStreamer->isIntegratedAssemblerRequired();
401403
Dwarf64 &=
402-
((Asm->TM.Options.MCOptions.Dwarf64 || MMI->getModule()->isDwarf64()) &&
403-
TT.isOSBinFormatELF()) ||
404-
TT.isOSBinFormatXCOFF();
404+
((TT.isOSBinFormatELF() || (IsXcoff && UseIntegratedAs)) &&
405+
(Asm->TM.Options.MCOptions.Dwarf64 || MMI->getModule()->isDwarf64())) ||
406+
(IsXcoff && !UseIntegratedAs);
405407

406-
if (!Dwarf64 && TT.isArch64Bit() && TT.isOSBinFormatXCOFF())
407-
report_fatal_error("XCOFF requires DWARF64 for 64-bit mode!");
408+
if (!Dwarf64 && TT.isArch64Bit() && IsXcoff && !UseIntegratedAs)
409+
report_fatal_error(
410+
"XCOFF requires DWARF64 for 64-bit mode on non-integrated-as mode!");
408411

409412
UseRangesSection = !NoDwarfRangesSection && !TT.isNVPTX();
410413

llvm/test/CodeGen/PowerPC/aix-dwarf.ll

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ entry:
6565
; SEC32-NEXT: RelocationPointer: 0x1F4
6666
; SEC64-NEXT: Size: 0x18
6767
; SEC64-NEXT: RawDataOffset: 0x1A8
68-
; SEC64-NEXT: RelocationPointer: 0x2C8
68+
; SEC64-NEXT: RelocationPointer: 0x29C
6969
; SEC-NEXT: LineNumberPointer: 0x0
7070
; SEC-NEXT: NumberOfRelocations: 2
7171
; SEC-NEXT: NumberOfLineNumbers: 0
@@ -93,9 +93,9 @@ entry:
9393
; SEC32-NEXT: Size: 0x57
9494
; SEC32-NEXT: RawDataOffset: 0x15C
9595
; SEC32-NEXT: RelocationPointer: 0x208
96-
; SEC64-NEXT: Size: 0x6F
96+
; SEC64-NEXT: Size: 0x5F
9797
; SEC64-NEXT: RawDataOffset: 0x200
98-
; SEC64-NEXT: RelocationPointer: 0x2E4
98+
; SEC64-NEXT: RelocationPointer: 0x2B8
9999
; SEC-NEXT: LineNumberPointer: 0x0
100100
; SEC-NEXT: NumberOfRelocations: 4
101101
; SEC-NEXT: NumberOfLineNumbers: 0
@@ -109,9 +109,9 @@ entry:
109109
; SEC32-NEXT: Size: 0x36
110110
; SEC32-NEXT: RawDataOffset: 0x1BC
111111
; SEC32-NEXT: RelocationPointer: 0x230
112-
; SEC64-NEXT: Size: 0x46
113-
; SEC64-NEXT: RawDataOffset: 0x280
114-
; SEC64-NEXT: RelocationPointer: 0x31C
112+
; SEC64-NEXT: Size: 0x3A
113+
; SEC64-NEXT: RawDataOffset: 0x260
114+
; SEC64-NEXT: RelocationPointer: 0x2F0
115115
; SEC-NEXT: LineNumberPointer: 0x0
116116
; SEC-NEXT: NumberOfRelocations: 1
117117
; SEC-NEXT: NumberOfLineNumbers: 0
@@ -131,10 +131,10 @@ entry:
131131

132132
; RELO64: RELOCATION RECORDS FOR [.dwinfo]:
133133
; RELO64-NEXT: OFFSET TYPE VALUE
134-
; RELO64-NEXT: 000000000000000e R_POS .dwabrev
135-
; RELO64-NEXT: 000000000000000b R_POS .dwline
136-
; RELO64-NEXT: 0000000000000041 R_POS .text
137-
; RELO64-NEXT: 000000000000004e R_POS .text
134+
; RELO64-NEXT: 0000000000000006 R_POS .dwabrev
135+
; RELO64-NEXT: 0000000000000027 R_POS .dwline
136+
; RELO64-NEXT: 0000000000000009 R_POS .text
137+
; RELO64-NEXT: 0000000000000016 R_POS .text
138138
; RELO64: RELOCATION RECORDS FOR [.dwline]:
139139
; RELO64-NEXT: OFFSET TYPE VALUE
140-
; RELO64-NEXT: 000000000000000c R_POS .text
140+
; RELO64-NEXT: 0000000000000000 R_POS .text

llvm/test/CodeGen/PowerPC/aix-xcoff-exception-section-debug.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
; Exception auxilliary entries are present in the 64-bit tests because 64-bit && debug enabled are the requirements.
44
; RUN: llc -mtriple=powerpc-ibm-aix-xcoff -filetype=obj -o %t_32.o < %s
55
; RUN: llvm-readobj --syms %t_32.o | FileCheck %s --check-prefix=SYMS32
6-
; RUN: llc -mtriple=powerpc64-unknown-aix -filetype=obj -o %t_32.o < %s
7-
; RUN: llvm-readobj --syms %t_32.o | FileCheck %s --check-prefix=SYMS64
6+
; RUN: llc -mtriple=powerpc64-unknown-aix -filetype=obj -o %t_64.o < %s
7+
; RUN: llvm-readobj --syms %t_64.o | FileCheck %s --check-prefix=SYMS64
88

99
; If any debug information is included in a module and is XCOFF64, exception auxilliary entries are emitted
1010

@@ -93,7 +93,7 @@ define dso_local void @test__trap_annotation_debug(i32 %a) !dbg !4 {
9393
; SYMS64-NEXT: NumberOfAuxEntries: 3
9494
; SYMS64-NEXT: Exception Auxiliary Entry {
9595
; SYMS64-NEXT: Index: [[#IND+1]]
96-
; SYMS64-NEXT: OffsetToExceptionTable: 0x398
96+
; SYMS64-NEXT: OffsetToExceptionTable: 0x38C
9797
; SYMS64-NEXT: SizeOfFunction: 0x18
9898
; SYMS64-NEXT: SymbolIndexOfNextBeyond: [[#IND+4]]
9999
; SYMS64-NEXT: Auxiliary Type: AUX_EXCEPT (0xFF)
@@ -126,7 +126,7 @@ define dso_local void @test__trap_annotation_debug(i32 %a) !dbg !4 {
126126
; SYMS64-NEXT: NumberOfAuxEntries: 3
127127
; SYMS64-NEXT: Exception Auxiliary Entry {
128128
; SYMS64-NEXT: Index: [[#IND+5]]
129-
; SYMS64-NEXT: OffsetToExceptionTable: 0x3AC
129+
; SYMS64-NEXT: OffsetToExceptionTable: 0x3A0
130130
; SYMS64-NEXT: SizeOfFunction: 0x68
131131
; SYMS64-NEXT: SymbolIndexOfNextBeyond: [[#IND+8]]
132132
; SYMS64-NEXT: Auxiliary Type: AUX_EXCEPT (0xFF)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -filetype=obj %s -o - \
2+
; RUN: | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK
3+
4+
; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -filetype=obj -dwarf64 %s -o - \
5+
; RUN: | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK64
6+
7+
; CHECK: file format aix5coff64-rs6000
8+
; CHECK: format: DWARF32
9+
10+
; CHECK64: file format aix5coff64-rs6000
11+
; CHECK64: format: DWARF64
12+
13+
source_filename = "1.c"
14+
target datalayout = "E-m:a-p:32:32-Fi32-i64:64-n32"
15+
16+
@foo = global i32 0, align 4, !dbg !0
17+
18+
!llvm.dbg.cu = !{!2}
19+
!llvm.module.flags = !{!6, !7, !8, !9, !10}
20+
!llvm.ident = !{!11}
21+
22+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
23+
!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true)
24+
!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)
25+
!3 = !DIFile(filename: "1.c", directory: "llvm-project")
26+
!4 = !{!0}
27+
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
28+
!6 = !{i32 7, !"Dwarf Version", i32 3}
29+
!7 = !{i32 2, !"Debug Info Version", i32 3}
30+
!8 = !{i32 1, !"wchar_size", i32 2}
31+
!9 = !{i32 8, !"PIC Level", i32 2}
32+
!10 = !{i32 7, !"frame-pointer", i32 2}
33+
!11 = !{!"clang version 17.0.0"}

0 commit comments

Comments
 (0)