Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions clang/lib/Driver/ToolChains/PS4CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,18 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
// whether or not that will be the case at this point. So, unconditionally
// pass LTO options to ensure proper codegen, metadata production, etc if
// LTO indeed occurs.

if (const Arg *A = Args.getLastArg(options::OPT_fthinlto_distributor_EQ)) {
CmdArgs.push_back(
Args.MakeArgString("--thinlto-distributor=" + Twine(A->getValue())));
CmdArgs.push_back(Args.MakeArgString("--thinlto-remote-compiler=" +
Twine(D.getClangProgramPath())));

for (const auto &A :
Args.getAllArgValues(options::OPT_Xthinlto_distributor_EQ))
CmdArgs.push_back(Args.MakeArgString("--thinlto-distributor-arg=" + A));
}

if (Args.hasFlag(options::OPT_funified_lto, options::OPT_fno_unified_lto,
true))
CmdArgs.push_back(D.getLTOMode() == LTOK_Thin ? "--lto=thin"
Expand Down
45 changes: 45 additions & 0 deletions clang/test/Driver/DTLTO/ps5-dtlto.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// REQUIRES: lld

/// Check DTLTO options are forwarded to the linker.

/// Check that options are forwarded as expected with --thinlto-distributor=.
// RUN: %clang -flto=thin %s -### --target=x86_64-sie-ps5 \
// RUN: -Xthinlto-distributor=a1 -Xthinlto-distributor=a2,a3 \
// RUN: -fthinlto-distributor=d.exe -Werror 2>&1 | \
// RUN: FileCheck %s --check-prefix=FORWARD

// FORWARD: prospero-lld
// FORWARD-SAME: "--thinlto-distributor=d.exe"
// FORWARD-SAME: "--thinlto-remote-compiler={{[^"]+}}"
// FORWARD-SAME: "--thinlto-distributor-arg=a1"
// FORWARD-SAME: "--thinlto-distributor-arg=a2"
// FORWARD-SAME: "--thinlto-distributor-arg=a3"

/// Check that options are not added without --thinlto-distributor= and
/// that a warning is issued for unused -Xthinlto-distributor options.
// RUN: %clang -flto=thin %s -### --target=x86_64-sie-ps5 \
// RUN: -Xthinlto-distributor=a1 -Xthinlto-distributor=a2,a3 2>&1 | \
// RUN: FileCheck %s --check-prefix=NODIST --implicit-check-not=distributor \
// RUN: --implicit-check-not=remote-compiler

// NODIST: warning: argument unused during compilation: '-Xthinlto-distributor=a1'
// NODIST: warning: argument unused during compilation: '-Xthinlto-distributor=a2,a3'
// NODIST: prospero-lld

/// Check the expected arguments are forwarded by default with only
/// --thinlto-distributor=.
// RUN: %clang -flto=thin %s -### --target=x86_64-sie-ps5 \
// RUN: -fthinlto-distributor=d.exe -Werror 2>&1 | \
// RUN: FileCheck %s --check-prefix=DEFAULT --implicit-check-not=distributor \
// RUN: --implicit-check-not=remote-compiler

// DEFAULT: prospero-lld
// DEFAULT-SAME: "--thinlto-distributor=d.exe"
// DEFAULT-SAME: "--thinlto-remote-compiler={{.*}}clang{{[^\"]*}}"

/// Check that the arguments are forwarded unconditionally even when the
/// compiler is not in LTO mode.
Comment on lines +40 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will "unused argument" warnings be produced, and should we check for them?

Copy link
Collaborator Author

@bd1976bris bd1976bris Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Unlike most drivers we consume the arguments even if we are not in LTO mode (-flto is not specified). -Xthinlto-distributor= arguments are not consumed if '-fthinlto-distributor=' is not supplied but we check for that on line 25 of this test. These arguments are not consumed if we are not linking e.g. -c is specified, but that's in common with all the arguments that are processed here in Linker::ConstructJob.

// RUN: %clang %s -### --target=x86_64-sie-ps5 \
// RUN: -fthinlto-distributor=d.exe -Werror 2>&1 | \
// RUN: FileCheck %s --check-prefix=DEFAULT --implicit-check-not=distributor \
// RUN: --implicit-check-not=remote-compiler