Skip to content

Commit 4c9d326

Browse files
playstation-eddyuxuanchen1997
authored andcommitted
[PS4/PS5][Driver][DWARF] Always emit .debug_aranges for SCE tuning (#100160)
Summary: 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 to 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. llvm/test/DebugInfo/debuglineinfo-path.ll has been marked as UNSUPPORTED on PlayStation. When aranges are emitted, the DWARF in the test case is such that relocations need to be applied to the aranges section in order for symbolization to work. An alternative approach would be to implement the application of relocations in DWARFDebugArangeSet. While experiments show that this can be made to work with a modest patch, the test cases would be rather contrived. Since I expect the only utility for such a change would be to make this test case pass for PlayStation targets, and few - if any - outside of PlayStation care about aranges, UNSUPPORTED would seem to be a more practical option. This was originally commited as 22eb290 (#99629) and later reverted at 84658fb (#99711) due to test failures on SIE built bots. These failures shouldn't recur due to 3b24e5d (#99897) and the aforementioned change to debuglineinfo-path.ll. SIE tracker: TOOLCHAIN-16951 Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250743
1 parent 6249206 commit 4c9d326

File tree

9 files changed

+68
-32
lines changed

9 files changed

+68
-32
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

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

47184718
// -gdwarf-aranges turns on the emission of the aranges section in the
47194719
// backend.
4720-
// Always enabled for SCE tuning.
4721-
bool NeedAranges = DebuggerTuning == llvm::DebuggerKind::SCE;
4722-
if (const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges))
4723-
NeedAranges = checkDebugInfoOption(A, Args, D, TC) || NeedAranges;
4724-
if (NeedAranges) {
4720+
if (const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges);
4721+
A && checkDebugInfoOption(A, Args, D, TC)) {
47254722
CmdArgs.push_back("-mllvm");
47264723
CmdArgs.push_back("-generate-arange-section");
47274724
}

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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This checks that .debug_aranges is always generated for the SCE debugger
2+
# tuning.
3+
4+
RUN: rm -rf %t && split-file %s %t && cd %t
5+
RUN: llc -debugger-tune=sce -filetype=obj foo.ll -o foo.o
6+
RUN: llvm-dwarfdump -debug-aranges foo.o | FileCheck %s
7+
8+
CHECK: .debug_aranges contents:
9+
CHECK-NEXT: Address Range Header:
10+
CHECK-SAME: length = 0x0000002c,
11+
12+
#--- foo.c
13+
int foo;
14+
15+
#--- gen
16+
clang --target=x86_64-linux-gnu -g -S -emit-llvm foo.c -o -
17+
18+
#--- foo.ll
19+
; ModuleID = 'foo.c'
20+
source_filename = "foo.c"
21+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
22+
target triple = "x86_64-unknown-linux-gnu"
23+
24+
@foo = dso_local global i32 0, align 4, !dbg !0
25+
26+
!llvm.dbg.cu = !{!2}
27+
!llvm.module.flags = !{!6, !7, !8, !9, !10, !11, !12}
28+
29+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
30+
!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true)
31+
!2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
32+
!3 = !DIFile(filename: "foo.c", directory: "/proc/self/cwd", checksumkind: CSK_MD5, checksum: "e0f2c326d820c28d30f9b0ea95178f64")
33+
!4 = !{!0}
34+
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
35+
!6 = !{i32 7, !"Dwarf Version", i32 5}
36+
!7 = !{i32 2, !"Debug Info Version", i32 3}
37+
!8 = !{i32 1, !"wchar_size", i32 4}
38+
!9 = !{i32 8, !"PIC Level", i32 2}
39+
!10 = !{i32 7, !"PIE Level", i32 2}
40+
!11 = !{i32 7, !"uwtable", i32 2}
41+
!12 = !{i32 7, !"frame-pointer", i32 2}

llvm/test/DebugInfo/debuglineinfo-path.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
; Make sure that absolute source dir is detected correctly regardless of the platform.
22

33
; On powerpc llvm-nm describes win_func as a global variable, not a function. It breaks the test.
4-
; It is not essential to DWARF path handling code we're testing here.
5-
; UNSUPPORTED: target=powerpc{{.*}}
4+
; On PlayStation, (pre-relocated) .debug_aranges cause symbolization to fail, also breaking the test.
5+
; These are not essential to DWARF path handling code we're testing here.
6+
; UNSUPPORTED: target=powerpc{{.*}}, target=x86_64-{{.*-ps[45]}}
67
; REQUIRES: object-emission
78
; RUN: %llc_dwarf -O0 -filetype=obj -o %t < %s
89
; RUN: llvm-nm --radix=o %t | grep posix_absolute_func > %t.posix_absolute_func

0 commit comments

Comments
 (0)