[PS4] Always enable the .debug_aranges section when using LTO

This flag enables the .debug_aranges section by passing a flag to LLD
and our internal linker. This also adds a new routine that will generate
the correct flag for our internal linker or set of flags for LLD when
given a list of LLVM options. That ensures multiple LLVM codegen options
can be passed to either linker consistently.

Differential Revision: https://reviews.llvm.org/D134296
This commit is contained in:
Matthew Voss 2022-09-20 14:44:56 -07:00
parent 7b31756393
commit 45c7da241f
3 changed files with 43 additions and 13 deletions

View File

@ -159,17 +159,32 @@ void tools::PScpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const bool IsPS5 = TC.getTriple().isPS5(); const bool IsPS5 = TC.getTriple().isPS5();
assert(IsPS4 || IsPS5); assert(IsPS4 || IsPS5);
ArgStringList DbgOpts;
// This tells LTO to perform JustMyCode instrumentation. // This tells LTO to perform JustMyCode instrumentation.
if (UseLTO && UseJMC) { if (UseLTO && UseJMC)
if (IsPS4 && D.getLTOMode() == LTOK_Thin) { DbgOpts.push_back("-enable-jmc-instrument");
CmdArgs.push_back("-lto-thin-debug-options=-enable-jmc-instrument");
} else if (IsPS4 && D.getLTOMode() == LTOK_Full) { // We default to creating the arange section, but LTO does not. Enable it
CmdArgs.push_back("-lto-debug-options=-enable-jmc-instrument"); // here.
} else if (IsPS5) { if (UseLTO)
CmdArgs.push_back("-mllvm"); DbgOpts.push_back("-generate-arange-section");
CmdArgs.push_back("-enable-jmc-instrument");
} else if (UseLTO) {
llvm_unreachable("new LTO mode?"); if (IsPS4) {
StringRef F = (D.getLTOMode() == LTOK_Thin) ?
"-lto-thin-debug-options=" : "-lto-debug-options=";
F = makeArgString(Args, F.data(), DbgOpts.front(), "");
DbgOpts.erase(DbgOpts.begin());
for (auto X : DbgOpts)
F = makeArgString(Args, F.data(), " ", X);
CmdArgs.push_back(F.data());
} else {
for (auto D : DbgOpts) {
CmdArgs.push_back("-mllvm");
CmdArgs.push_back(D);
}
}
} }
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))

View File

@ -107,6 +107,14 @@
// RUN: | FileCheck -check-prefix=CI %s // RUN: | FileCheck -check-prefix=CI %s
// RUN: %clang -### -c %s -gsce -target x86_64-unknown-linux 2>&1 \ // RUN: %clang -### -c %s -gsce -target x86_64-unknown-linux 2>&1 \
// RUN: | FileCheck -check-prefix=NOCI %s // RUN: | FileCheck -check-prefix=NOCI %s
// RUN: %clang -### %s -g -flto=thin -target x86_64-scei-ps4 2>&1 \
// RUN: | FileCheck -check-prefix=SNLDTLTOGARANGE %s
// RUN: %clang -### %s -g -flto=full -target x86_64-scei-ps4 2>&1 \
// RUN: | FileCheck -check-prefix=SNLDFLTOGARANGE %s
// RUN: %clang -### %s -g -flto -target x86_64-scei-ps5 2>&1 \
// RUN: | FileCheck -check-prefix=LLDGARANGE %s
// RUN: %clang -### %s -g -target x86_64-scei-ps5 2>&1 \
// RUN: | FileCheck -check-prefix=LDGARANGE %s
// On the AIX, -g defaults to -gdbx and limited debug info. // On the AIX, -g defaults to -gdbx and limited debug info.
// RUN: %clang -### -c -g %s -target powerpc-ibm-aix-xcoff 2>&1 \ // RUN: %clang -### -c -g %s -target powerpc-ibm-aix-xcoff 2>&1 \
@ -365,6 +373,13 @@
// NOPUB-NOT: -ggnu-pubnames // NOPUB-NOT: -ggnu-pubnames
// NOPUB-NOT: -gpubnames // NOPUB-NOT: -gpubnames
// //
// LDGARANGE: {{".*ld.*"}} {{.*}}
// LDGARANGE-NOT: "-generate-arange-section"
// LLDGARANGE: {{".*lld.*"}} {{.*}} "-generate-arange-section"
// SNLDTLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} "-lto-thin-debug-options=-generate-arange-section"
// SNLDFLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} "-lto-debug-options=-generate-arange-section"
// PUB: -gpubnames // PUB: -gpubnames
// //
// RNGBSE: -fdebug-ranges-base-address // RNGBSE: -fdebug-ranges-base-address

View File

@ -6,10 +6,10 @@
// RUN: %clang --target=x86_64-scei-ps5 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PS5,CHECK-PS5-LIB %s // RUN: %clang --target=x86_64-scei-ps5 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PS5,CHECK-PS5-LIB %s
// RUN: %clang --target=x86_64-scei-ps5 -flto -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PS5-LTO,CHECK-PS5-LIB %s // RUN: %clang --target=x86_64-scei-ps5 -flto -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PS5-LTO,CHECK-PS5-LIB %s
// CHECK-PS4-NOT: "-enable-jmc-instrument" // CHECK-PS4-NOT: -enable-jmc-instrument
// CHECK-PS4-THIN-LTO: "-lto-thin-debug-options=-enable-jmc-instrument" // CHECK-PS4-THIN-LTO: -lto-thin-debug-options=-enable-jmc-instrument
// CHECK-PS4-FULL-LTO: "-lto-debug-options=-enable-jmc-instrument" // CHECK-PS4-FULL-LTO: -lto-debug-options=-enable-jmc-instrument
// CHECK-PS5-NOT: "-enable-jmc-instrument" // CHECK-PS5-NOT: "-enable-jmc-instrument"