Skip to content

Commit

Permalink
[PS4][clang] Fix the format of the LTO debug options passed to orbis-ld
Browse files Browse the repository at this point in the history
Currently, we pass multiple LTO debug options to orbis-ld like this:

orbis-ld --lto=thin --lto-thin-debug-options=<arg1> --lto-thin-debug-options=<arg2> ...

When it should be like this:

orbis-ld --lto=thin "--lto-thin-debug-options= <arg1> <arg2>" ...

Differential Revision: https://reviews.llvm.org/D147546
  • Loading branch information
ormris committed Apr 5, 2023
1 parent 65c0134 commit c37b95b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
26 changes: 16 additions & 10 deletions clang/lib/Driver/ToolChains/PS4CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,12 @@ void tools::PScpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const bool IsPS5 = TC.getTriple().isPS5();
assert(IsPS4 || IsPS5);

const char *PS4LTOArgs = "";
auto AddCodeGenFlag = [&](Twine Flag) {
const char *Prefix = nullptr;
if (IsPS4 && D.getLTOMode() == LTOK_Thin)
Prefix = "-lto-thin-debug-options=";
else if (IsPS4 && D.getLTOMode() == LTOK_Full)
Prefix = "-lto-debug-options=";
if (IsPS4)
PS4LTOArgs = Args.MakeArgString(Twine(PS4LTOArgs) + " " + Flag);
else if (IsPS5)
Prefix = "-plugin-opt=";
else
llvm_unreachable("new LTO mode?");

CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + Flag));
CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=") + Flag));
};

if (UseLTO) {
Expand All @@ -185,6 +179,18 @@ void tools::PScpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,

if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
AddCodeGenFlag(Twine("-crash-diagnostics-dir=") + A->getValue());

if (IsPS4) {
const char *Prefix = nullptr;
if (D.getLTOMode() == LTOK_Thin)
Prefix = "-lto-thin-debug-options=";
else if (D.getLTOMode() == LTOK_Full)
Prefix = "-lto-debug-options=";
else
llvm_unreachable("new LTO mode?");

CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + PS4LTOArgs));
}
}

if (IsPS5 && UseLTO) {
Expand Down
8 changes: 4 additions & 4 deletions clang/test/Driver/ps4-ps5-linker.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// 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-THIN-LTO: -lto-thin-debug-options=-enable-jmc-instrument
// CHECK-PS4-FULL-LTO: -lto-debug-options=-enable-jmc-instrument
// CHECK-PS4-THIN-LTO: "-lto-thin-debug-options= -generate-arange-section -enable-jmc-instrument"
// CHECK-PS4-FULL-LTO: "-lto-debug-options= -generate-arange-section -enable-jmc-instrument"
// CHECK-PS5-NOT: -plugin-opt=-enable-jmc-instrument
// CHECK-PS5-LTO: -plugin-opt=-enable-jmc-instrument

Expand All @@ -23,7 +23,7 @@
// RUN: %clang --target=x86_64-scei-ps5 -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-PS5 %s
// RUN: %clang --target=x86_64-scei-ps5 -flto -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-PS5-LTO %s

// CHECK-DIAG-PS4-THIN-LTO: -lto-thin-debug-options=-crash-diagnostics-dir=mydumps
// CHECK-DIAG-PS4-FULL-LTO: -lto-debug-options=-crash-diagnostics-dir=mydumps
// CHECK-DIAG-PS4-THIN-LTO: "-lto-thin-debug-options= -generate-arange-section -crash-diagnostics-dir=mydumps"
// CHECK-DIAG-PS4-FULL-LTO: "-lto-debug-options= -generate-arange-section -crash-diagnostics-dir=mydumps"
// CHECK-DIAG-PS5-NOT: -plugin-opt=-crash-diagnostics-dir=mydumps
// CHECK-DIAG-PS5-LTO: -plugin-opt=-crash-diagnostics-dir=mydumps

0 comments on commit c37b95b

Please sign in to comment.