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
24 changes: 24 additions & 0 deletions clang/lib/Driver/ToolChains/PS4CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const Driver &D = TC.getDriver();
ArgStringList CmdArgs;

const bool Relocatable = Args.hasArg(options::OPT_r);

// Silence warning for "clang -g foo.o -o foo"
Args.ClaimAllArgs(options::OPT_g_Group);
// and "clang -emit-llvm foo.o -o foo"
Expand All @@ -246,6 +248,28 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
CmdArgs.push_back("-pie");

if (!Relocatable) {
// Lazy binding of PLTs is not supported on PlayStation. They are placed in
// the RelRo segment.
CmdArgs.push_back("-z");
CmdArgs.push_back("now");

// Don't export linker-generated __start/stop... section bookends.
CmdArgs.push_back("-z");
CmdArgs.push_back("start-stop-visibility=hidden");

// Patch relocated regions of DWARF whose targets are eliminated at link
// time with specific tombstones, such that they're recognisable by the
// PlayStation debugger.
CmdArgs.push_back("-z");
CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_*=0xffffffffffffffff");
CmdArgs.push_back("-z");
CmdArgs.push_back(
"dead-reloc-in-nonalloc=.debug_ranges=0xfffffffffffffffe");
CmdArgs.push_back("-z");
CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_loc=0xfffffffffffffffe");
}

if (Args.hasArg(options::OPT_static))
CmdArgs.push_back("-static");
if (Args.hasArg(options::OPT_rdynamic))
Expand Down
16 changes: 16 additions & 0 deletions clang/test/Driver/ps5-linker.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
// CHECK-NO-PIE-NOT: "-pie"
// CHECK-SHARED: "--shared"

// Test the driver passes PlayStation-specific -z options to the linker.

// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-Z %s

// CHECK-Z: {{ld(\.exe)?}}"
// CHECK-Z-SAME: "-z" "now"
// CHECK-Z-SAME: "-z" "start-stop-visibility=hidden"
// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_*=0xffffffffffffffff"
// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_ranges=0xfffffffffffffffe"
// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffffffffffffffe"

// RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-Z %s

// CHECK-NO-Z: {{ld(\.exe)?}}"
// CHECK-NO-Z-NOT: "-z"

// Test that -static is forwarded to the linker

// RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s
Expand Down
Loading