Skip to content

Commit

Permalink
[XCOFF][DWARF] XCOFF64 should be able to select the dwarf format in i…
Browse files Browse the repository at this point in the history
…ntergrated-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
  • Loading branch information
EsmeYi committed May 16, 2023
1 parent b9c0e59 commit 4054c68
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 25 deletions.
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/debug-options-as.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/debug-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
22 changes: 11 additions & 11 deletions llvm/test/CodeGen/PowerPC/aix-dwarf.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions llvm/test/DebugInfo/XCOFF/dwarf-format.ll
Original file line number Diff line number Diff line change
@@ -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"}

0 comments on commit 4054c68

Please sign in to comment.