Skip to content

Commit 22eb290

Browse files
[PS4/PS5][Driver][DWARF] Always emit .debug_aranges for SCE tuning (llvm#99629)
Some of SIE's post-mortem analysis infrastructure currently makes use of .debug_aranges, so we'd like to ensure the section's presence in PlayStation binaries. The simplest way to do this is force emission when the debugger tuning is set to SCE (which is in turn typically initialized from the target triple). This also simplifies the driver. SIE tracker: TOOLCHAIN-16951
1 parent 04760bf commit 22eb290

File tree

8 files changed

+57
-30
lines changed

8 files changed

+57
-30
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4659,11 +4659,8 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T,
46594659

46604660
// -gdwarf-aranges turns on the emission of the aranges section in the
46614661
// backend.
4662-
// Always enabled for SCE tuning.
4663-
bool NeedAranges = DebuggerTuning == llvm::DebuggerKind::SCE;
4664-
if (const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges))
4665-
NeedAranges = checkDebugInfoOption(A, Args, D, TC) || NeedAranges;
4666-
if (NeedAranges) {
4662+
if (const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges);
4663+
A && checkDebugInfoOption(A, Args, D, TC)) {
46674664
CmdArgs.push_back("-mllvm");
46684665
CmdArgs.push_back("-generate-arange-section");
46694666
}

clang/lib/Driver/ToolChains/PS4CPU.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
162162
};
163163

164164
if (UseLTO) {
165-
// We default to creating the arange section, but LTO does not. Enable it
166-
// here.
167-
AddCodeGenFlag("-generate-arange-section");
168-
169165
// This tells LTO to perform JustMyCode instrumentation.
170166
if (UseJMC)
171167
AddCodeGenFlag("-enable-jmc-instrument");
@@ -272,10 +268,6 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
272268
};
273269

274270
if (UseLTO) {
275-
// We default to creating the arange section, but LTO does not. Enable it
276-
// here.
277-
AddCodeGenFlag("-generate-arange-section");
278-
279271
// This tells LTO to perform JustMyCode instrumentation.
280272
if (UseJMC)
281273
AddCodeGenFlag("-enable-jmc-instrument");

clang/test/Driver/debug-options.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,27 +118,28 @@
118118
// RUN: %clang_cl -### -c -Z7 -target x86_64-windows-msvc -- %s 2>&1 \
119119
// RUN: | FileCheck -check-prefix=G_NOTUNING %s
120120

121-
// On the PS4/PS5, -g defaults to -gno-column-info, and we always generate the
122-
// arange section.
121+
// On the PS4/PS5, -g defaults to -gno-column-info. We default to always
122+
// generating the arange section, but keyed off SCE DebuggerTuning being in
123+
// play during codegen, instead of -generate-arange-section.
123124
// RUN: %clang -### -c %s -target x86_64-scei-ps4 2>&1 \
124125
// RUN: | FileCheck -check-prefix=NOG_PS %s
125126
// RUN: %clang -### -c %s -target x86_64-sie-ps5 2>&1 \
126127
// RUN: | FileCheck -check-prefix=NOG_PS %s
127128
/// PS4 will stay on v4 even if the generic default version changes.
128129
// RUN: %clang -### -c %s -g -target x86_64-scei-ps4 2>&1 \
129-
// RUN: | FileCheck -check-prefixes=G_DWARF4,GARANGE,G_SCE,NOCI,FWD_TMPL_PARAMS %s
130+
// RUN: | FileCheck -check-prefixes=G_DWARF4,G_SCE,NOCI,FWD_TMPL_PARAMS %s
130131
// RUN: %clang -### -c %s -g -target x86_64-sie-ps5 2>&1 \
131-
// RUN: | FileCheck -check-prefixes=G_DWARF5,GARANGE,G_SCE,NOCI,FWD_TMPL_PARAMS %s
132+
// RUN: | FileCheck -check-prefixes=G_DWARF5,G_SCE,NOCI,FWD_TMPL_PARAMS %s
132133
// RUN: %clang -### -c %s -g -gcolumn-info -target x86_64-scei-ps4 2>&1 \
133134
// RUN: | FileCheck -check-prefix=CI %s
134135
// RUN: %clang -### -c %s -gsce -target x86_64-unknown-linux 2>&1 \
135136
// RUN: | FileCheck -check-prefix=NOCI %s
136137
// RUN: %clang -### %s -g -flto=thin -target x86_64-scei-ps4 2>&1 \
137-
// RUN: | FileCheck -check-prefix=SNLDTLTOGARANGE %s
138+
// RUN: | FileCheck -check-prefix=LDGARANGE %s
138139
// RUN: %clang -### %s -g -flto=full -target x86_64-scei-ps4 2>&1 \
139-
// RUN: | FileCheck -check-prefix=SNLDFLTOGARANGE %s
140+
// RUN: | FileCheck -check-prefix=LDGARANGE %s
140141
// RUN: %clang -### %s -g -flto -target x86_64-scei-ps5 2>&1 \
141-
// RUN: | FileCheck -check-prefix=LLDGARANGE %s
142+
// RUN: | FileCheck -check-prefix=LDGARANGE %s
142143
// RUN: %clang -### %s -g -target x86_64-scei-ps5 2>&1 \
143144
// RUN: | FileCheck -check-prefix=LDGARANGE %s
144145

@@ -321,8 +322,7 @@
321322
//
322323
// NOG_PS: "-cc1"
323324
// NOG_PS-NOT: "-dwarf-version=
324-
// NOG_PS: "-generate-arange-section"
325-
// NOG_PS-NOT: "-dwarf-version=
325+
// NOG_PS-NOT: "-generate-arange-section"
326326
//
327327
// G_ERR: error: unknown argument:
328328
//
@@ -402,8 +402,7 @@
402402
//
403403

404404
// LDGARANGE: {{".*ld.*"}} {{.*}}
405-
// LDGARANGE-NOT: "-plugin-opt=-generate-arange-section"
406-
// LLDGARANGE: {{".*lld.*"}} {{.*}} "-plugin-opt=-generate-arange-section"
405+
// LDGARANGE-NOT: -generate-arange-section"
407406
// SNLDTLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} "-lto-thin-debug-options= -generate-arange-section"
408407
// SNLDFLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} "-lto-debug-options= -generate-arange-section"
409408

clang/test/Driver/lto-jobs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// RUN: %clang --target=x86_64-scei-ps4 -### %s -flto=thin -flto-jobs=5 2> %t
1212
// RUN: FileCheck -check-prefix=CHECK-PS4-LINK-THIN-JOBS-ACTION < %t %s
1313
//
14-
// CHECK-PS4-LINK-THIN-JOBS-ACTION: "-lto-thin-debug-options= -generate-arange-section -threads=5"
14+
// CHECK-PS4-LINK-THIN-JOBS-ACTION: "-lto-thin-debug-options= -threads=5"
1515

1616
// RUN: %clang --target=x86_64-apple-darwin13.3.0 -### %s -flto=thin -flto-jobs=5 2> %t
1717
// RUN: FileCheck -check-prefix=CHECK-LINK-THIN-JOBS2-ACTION < %t %s

clang/test/Driver/ps4-linker.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// RUN: %clang --target=x86_64-scei-ps4 -flto=full -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-FULL-LTO,CHECK-LIB %s
66

77
// CHECK-NOT: -enable-jmc-instrument
8-
// CHECK-THIN-LTO: "-lto-thin-debug-options= -generate-arange-section -enable-jmc-instrument"
9-
// CHECK-FULL-LTO: "-lto-debug-options= -generate-arange-section -enable-jmc-instrument"
8+
// CHECK-THIN-LTO: "-lto-thin-debug-options= -enable-jmc-instrument"
9+
// CHECK-FULL-LTO: "-lto-debug-options= -enable-jmc-instrument"
1010

1111
// Check the default library name.
1212
// CHECK-LIB: "--whole-archive" "-lSceDbgJmc" "--no-whole-archive"
@@ -16,5 +16,5 @@
1616
// RUN: %clang --target=x86_64-scei-ps4 -flto=thin -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-THIN-LTO %s
1717
// RUN: %clang --target=x86_64-scei-ps4 -flto=full -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-FULL-LTO %s
1818

19-
// CHECK-DIAG-THIN-LTO: "-lto-thin-debug-options= -generate-arange-section -crash-diagnostics-dir=mydumps"
20-
// CHECK-DIAG-FULL-LTO: "-lto-debug-options= -generate-arange-section -crash-diagnostics-dir=mydumps"
19+
// CHECK-DIAG-THIN-LTO: "-lto-thin-debug-options= -crash-diagnostics-dir=mydumps"
20+
// CHECK-DIAG-FULL-LTO: "-lto-debug-options= -crash-diagnostics-dir=mydumps"

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ DwarfDebug::DwarfDebug(AsmPrinter *A)
354354

355355
UseLocSection = !TT.isNVPTX();
356356

357+
// Always emit .debug_aranges for SCE tuning.
358+
UseARangesSection = GenerateARangeSection || tuneForSCE();
359+
357360
HasAppleExtensionAttributes = tuneForLLDB();
358361

359362
// Handle split DWARF.
@@ -1450,7 +1453,7 @@ void DwarfDebug::endModule() {
14501453
emitDebugInfo();
14511454

14521455
// Emit info into a debug aranges section.
1453-
if (GenerateARangeSection)
1456+
if (UseARangesSection)
14541457
emitDebugARanges();
14551458

14561459
// Emit info into a debug ranges section.

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ class DwarfDebug : public DebugHandlerBase {
435435
///Allow emission of the .debug_loc section.
436436
bool UseLocSection = true;
437437

438+
/// Allow emission of .debug_aranges section
439+
bool UseARangesSection = false;
440+
438441
/// Generate DWARF v4 type units.
439442
bool GenerateTypeUnits;
440443

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; This checks that .debug_aranges is always generated for the SCE debugger
2+
; tuning.
3+
4+
; RUN: llc -mtriple=x86_64 -debugger-tune=sce -filetype=obj %s -o %t
5+
; RUN: llvm-dwarfdump -debug-aranges %t | FileCheck %s
6+
7+
; CHECK: .debug_aranges contents:
8+
; CHECK-NEXT: Address Range Header:
9+
; CHECK-SAME: length = 0x0000002c,
10+
11+
; IR generated and reduced from:
12+
; $ cat foo.c
13+
; int foo;
14+
; $ clang -g -S -emit-llvm foo.c -o foo.ll
15+
16+
target triple = "x86_64-unknown-linux-gnu"
17+
18+
@foo = dso_local global i32 0, align 4, !dbg !0
19+
20+
!llvm.dbg.cu = !{!2}
21+
!llvm.module.flags = !{!6, !7, !8}
22+
!llvm.ident = !{!9}
23+
24+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
25+
!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true)
26+
!2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "clang version 19.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
27+
!3 = !DIFile(filename: "foo.c", directory: "/tmp")
28+
!4 = !{!0}
29+
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
30+
!6 = !{i32 7, !"Dwarf Version", i32 5}
31+
!7 = !{i32 2, !"Debug Info Version", i32 3}
32+
!8 = !{i32 1, !"wchar_size", i32 4}
33+
!9 = !{!"clang version 19.0.0"}

0 commit comments

Comments
 (0)