[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-11-01 Thread Edd Dawson via cfe-commits

https://github.com/playstation-edd closed 
https://github.com/llvm/llvm-project/pull/114435
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-11-01 Thread Paul T Robinson via cfe-commits

https://github.com/pogo59 approved this pull request.


https://github.com/llvm/llvm-project/pull/114435
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-11-01 Thread Edd Dawson via cfe-commits

https://github.com/playstation-edd updated 
https://github.com/llvm/llvm-project/pull/114435

>From ebbb513f4f938c8d17a21b6061a815ffc7d8b004 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 31 Oct 2024 16:09:30 +
Subject: [PATCH 1/4] [PS5][Driver] Pass layout metrics to the linker

Until now, these have been hardcoded as a downstream patches in lld. Add them
to the driver so that the private patch can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in
the proprietary linker.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 14 --
 clang/test/Driver/ps5-linker.c | 18 ++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index aaba95951c5060..3b1ffee7fb6b43 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -248,8 +248,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   // Default to PIE for non-static executables.
-  const bool PIE = !Relocatable && !Shared && !Static;
-  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
+  const bool PIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie,
+!Relocatable && !Shared && !Static);
+  if (PIE)
 CmdArgs.push_back("-pie");
 
   if (!Relocatable) {
@@ -276,6 +277,12 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("-z");
 CmdArgs.push_back("start-stop-visibility=hidden");
 
+CmdArgs.push_back("-z");
+CmdArgs.push_back("common-page-size=16384");
+
+CmdArgs.push_back("-z");
+CmdArgs.push_back("max-page-size=16384");
+
 // Patch relocated regions of DWARF whose targets are eliminated at link
 // time with specific tombstones, such that they're recognisable by the
 // PlayStation debugger.
@@ -295,6 +302,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Shared)
 CmdArgs.push_back("--shared");
 
+  if (!Relocatable && !Shared && !PIE)
+CmdArgs.push_back("--image-base=0x40");
+
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 5175d8dbca567a..8dcd32ec1ebd87 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -21,6 +21,22 @@
 // CHECK-NO-PIE-NOT: "-pie"
 // CHECK-SHARED: "--shared"
 
+// Test the driver supplies an --image-base to the linker only for non-pie
+// executables.
+
+// RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+
+// CHECK-BASE: {{ld(\.exe)?}}"
+// CHECK-BASE-SAME: "--image-base=0x40"
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+
+// CHECK-NO-BASE: {{ld(\.exe)?}}"
+// CHECK-NO-BASE-NOT: "--image-base=0x40"
+
 // Test the driver passes PlayStation-specific options to the linker that are
 // appropriate for the type of output. Many options don't apply for relocatable
 // output (-r).
@@ -37,6 +53,8 @@
 // CHECK-EXE-SAME: "--unresolved-symbols=report-all"
 // CHECK-EXE-SAME: "-z" "now"
 // CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
+// CHECK-EXE-SAME: "-z" "common-page-size=16384"
+// CHECK-EXE-SAME: "-z" "max-page-size=16384"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_*=0x"
 // CHECK-EXE-SAME: "-z" 
"dead-reloc-in-nonalloc=.debug_ranges=0xfffe"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffe"

>From ee87f5958f616fa97f6468e8a35f985086f4f717 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Fri, 1 Nov 2024 09:42:35 +
Subject: [PATCH 2/4] Confirm the complete absense of --image-base, when
 appropriate

---
 clang/test/Driver/ps5-linker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 8dcd32ec1ebd87..5eeb25cb2044a3 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -35,7 +35,7 @@
 // RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
 
 // CHECK-NO-BASE: {{ld(\.exe)?}}"
-// CHECK-NO-BASE-NOT: "--image-base=0x40"
+// CHECK-NO-BASE-NOT: --image-base
 
 // Test the driver passes PlayStation-specific options to the linker that are
 // appropri

[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-11-01 Thread Edd Dawson via cfe-commits

https://github.com/playstation-edd updated 
https://github.com/llvm/llvm-project/pull/114435

>From ebbb513f4f938c8d17a21b6061a815ffc7d8b004 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 31 Oct 2024 16:09:30 +
Subject: [PATCH 1/3] [PS5][Driver] Pass layout metrics to the linker

Until now, these have been hardcoded as a downstream patches in lld. Add them
to the driver so that the private patch can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in
the proprietary linker.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 14 --
 clang/test/Driver/ps5-linker.c | 18 ++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index aaba95951c5060..3b1ffee7fb6b43 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -248,8 +248,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   // Default to PIE for non-static executables.
-  const bool PIE = !Relocatable && !Shared && !Static;
-  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
+  const bool PIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie,
+!Relocatable && !Shared && !Static);
+  if (PIE)
 CmdArgs.push_back("-pie");
 
   if (!Relocatable) {
@@ -276,6 +277,12 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("-z");
 CmdArgs.push_back("start-stop-visibility=hidden");
 
+CmdArgs.push_back("-z");
+CmdArgs.push_back("common-page-size=16384");
+
+CmdArgs.push_back("-z");
+CmdArgs.push_back("max-page-size=16384");
+
 // Patch relocated regions of DWARF whose targets are eliminated at link
 // time with specific tombstones, such that they're recognisable by the
 // PlayStation debugger.
@@ -295,6 +302,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Shared)
 CmdArgs.push_back("--shared");
 
+  if (!Relocatable && !Shared && !PIE)
+CmdArgs.push_back("--image-base=0x40");
+
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 5175d8dbca567a..8dcd32ec1ebd87 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -21,6 +21,22 @@
 // CHECK-NO-PIE-NOT: "-pie"
 // CHECK-SHARED: "--shared"
 
+// Test the driver supplies an --image-base to the linker only for non-pie
+// executables.
+
+// RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+
+// CHECK-BASE: {{ld(\.exe)?}}"
+// CHECK-BASE-SAME: "--image-base=0x40"
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+
+// CHECK-NO-BASE: {{ld(\.exe)?}}"
+// CHECK-NO-BASE-NOT: "--image-base=0x40"
+
 // Test the driver passes PlayStation-specific options to the linker that are
 // appropriate for the type of output. Many options don't apply for relocatable
 // output (-r).
@@ -37,6 +53,8 @@
 // CHECK-EXE-SAME: "--unresolved-symbols=report-all"
 // CHECK-EXE-SAME: "-z" "now"
 // CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
+// CHECK-EXE-SAME: "-z" "common-page-size=16384"
+// CHECK-EXE-SAME: "-z" "max-page-size=16384"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_*=0x"
 // CHECK-EXE-SAME: "-z" 
"dead-reloc-in-nonalloc=.debug_ranges=0xfffe"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffe"

>From ee87f5958f616fa97f6468e8a35f985086f4f717 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Fri, 1 Nov 2024 09:42:35 +
Subject: [PATCH 2/3] Confirm the complete absense of --image-base, when
 appropriate

---
 clang/test/Driver/ps5-linker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 8dcd32ec1ebd87..5eeb25cb2044a3 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -35,7 +35,7 @@
 // RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
 
 // CHECK-NO-BASE: {{ld(\.exe)?}}"
-// CHECK-NO-BASE-NOT: "--image-base=0x40"
+// CHECK-NO-BASE-NOT: --image-base
 
 // Test the driver passes PlayStation-specific options to the linker that are
 // appropri

[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-11-01 Thread Edd Dawson via cfe-commits


@@ -295,6 +302,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Shared)
 CmdArgs.push_back("--shared");
 
+  if (!Relocatable && !Shared && !PIE)

playstation-edd wrote:

The intention is to supply a base for non-PIE executables, which by default 
includes `-static`. I'll add a comment to ensure it doesn't appear accidental.

We have a distinct linker script for `-static` executables (which isn't visible 
here just yet, but soon). That script currently hardcodes a base address, but 
with this change it will be possible to remove that and allow the base to be 
overridden from the command line, while still having the same default.

https://github.com/llvm/llvm-project/pull/114435
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-11-01 Thread Edd Dawson via cfe-commits


@@ -21,6 +21,22 @@
 // CHECK-NO-PIE-NOT: "-pie"
 // CHECK-SHARED: "--shared"
 
+// Test the driver supplies an --image-base to the linker only for non-pie
+// executables.
+
+// RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+
+// CHECK-BASE: {{ld(\.exe)?}}"
+// CHECK-BASE-SAME: "--image-base=0x40"
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+
+// CHECK-NO-BASE: {{ld(\.exe)?}}"
+// CHECK-NO-BASE-NOT: "--image-base=0x40"

playstation-edd wrote:

Done - thanks!

https://github.com/llvm/llvm-project/pull/114435
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-11-01 Thread Edd Dawson via cfe-commits

https://github.com/playstation-edd updated 
https://github.com/llvm/llvm-project/pull/114435

>From ebbb513f4f938c8d17a21b6061a815ffc7d8b004 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 31 Oct 2024 16:09:30 +
Subject: [PATCH 1/2] [PS5][Driver] Pass layout metrics to the linker

Until now, these have been hardcoded as a downstream patches in lld. Add them
to the driver so that the private patch can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in
the proprietary linker.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 14 --
 clang/test/Driver/ps5-linker.c | 18 ++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index aaba95951c5060..3b1ffee7fb6b43 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -248,8 +248,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   // Default to PIE for non-static executables.
-  const bool PIE = !Relocatable && !Shared && !Static;
-  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
+  const bool PIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie,
+!Relocatable && !Shared && !Static);
+  if (PIE)
 CmdArgs.push_back("-pie");
 
   if (!Relocatable) {
@@ -276,6 +277,12 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("-z");
 CmdArgs.push_back("start-stop-visibility=hidden");
 
+CmdArgs.push_back("-z");
+CmdArgs.push_back("common-page-size=16384");
+
+CmdArgs.push_back("-z");
+CmdArgs.push_back("max-page-size=16384");
+
 // Patch relocated regions of DWARF whose targets are eliminated at link
 // time with specific tombstones, such that they're recognisable by the
 // PlayStation debugger.
@@ -295,6 +302,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Shared)
 CmdArgs.push_back("--shared");
 
+  if (!Relocatable && !Shared && !PIE)
+CmdArgs.push_back("--image-base=0x40");
+
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 5175d8dbca567a..8dcd32ec1ebd87 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -21,6 +21,22 @@
 // CHECK-NO-PIE-NOT: "-pie"
 // CHECK-SHARED: "--shared"
 
+// Test the driver supplies an --image-base to the linker only for non-pie
+// executables.
+
+// RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+
+// CHECK-BASE: {{ld(\.exe)?}}"
+// CHECK-BASE-SAME: "--image-base=0x40"
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+
+// CHECK-NO-BASE: {{ld(\.exe)?}}"
+// CHECK-NO-BASE-NOT: "--image-base=0x40"
+
 // Test the driver passes PlayStation-specific options to the linker that are
 // appropriate for the type of output. Many options don't apply for relocatable
 // output (-r).
@@ -37,6 +53,8 @@
 // CHECK-EXE-SAME: "--unresolved-symbols=report-all"
 // CHECK-EXE-SAME: "-z" "now"
 // CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
+// CHECK-EXE-SAME: "-z" "common-page-size=16384"
+// CHECK-EXE-SAME: "-z" "max-page-size=16384"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_*=0x"
 // CHECK-EXE-SAME: "-z" 
"dead-reloc-in-nonalloc=.debug_ranges=0xfffe"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffe"

>From ee87f5958f616fa97f6468e8a35f985086f4f717 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Fri, 1 Nov 2024 09:42:35 +
Subject: [PATCH 2/2] Confirm the complete absense of --image-base, when
 appropriate

---
 clang/test/Driver/ps5-linker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 8dcd32ec1ebd87..5eeb25cb2044a3 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -35,7 +35,7 @@
 // RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
 
 // CHECK-NO-BASE: {{ld(\.exe)?}}"
-// CHECK-NO-BASE-NOT: "--image-base=0x40"
+// CHECK-NO-BASE-NOT: --image-base
 
 // Test the driver passes PlayStation-specific options to the linker that are
 // appropri

[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-10-31 Thread Paul T Robinson via cfe-commits


@@ -21,6 +21,22 @@
 // CHECK-NO-PIE-NOT: "-pie"
 // CHECK-SHARED: "--shared"
 
+// Test the driver supplies an --image-base to the linker only for non-pie
+// executables.
+
+// RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+
+// CHECK-BASE: {{ld(\.exe)?}}"
+// CHECK-BASE-SAME: "--image-base=0x40"
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+
+// CHECK-NO-BASE: {{ld(\.exe)?}}"
+// CHECK-NO-BASE-NOT: "--image-base=0x40"

pogo59 wrote:

```suggestion
// CHECK-NO-BASE-NOT: --image-base
```
so it will still fail if the number changes.

https://github.com/llvm/llvm-project/pull/114435
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-10-31 Thread Paul T Robinson via cfe-commits


@@ -295,6 +302,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Shared)
 CmdArgs.push_back("--shared");
 
+  if (!Relocatable && !Shared && !PIE)

pogo59 wrote:

Does this want to consider `Static` as well? Just wondering, no opinion either 
way.

https://github.com/llvm/llvm-project/pull/114435
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-10-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Edd Dawson (playstation-edd)


Changes

Until now, these have been hardcoded as a downstream patches in lld. Add them 
to the driver so that the private patch can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in the 
proprietary linker.

SIE tracker: TOOLCHAIN-16704

---
Full diff: https://github.com/llvm/llvm-project/pull/114435.diff


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/PS4CPU.cpp (+12-2) 
- (modified) clang/test/Driver/ps5-linker.c (+18) 


``diff
diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index aaba95951c5060..3b1ffee7fb6b43 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -248,8 +248,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   // Default to PIE for non-static executables.
-  const bool PIE = !Relocatable && !Shared && !Static;
-  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
+  const bool PIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie,
+!Relocatable && !Shared && !Static);
+  if (PIE)
 CmdArgs.push_back("-pie");
 
   if (!Relocatable) {
@@ -276,6 +277,12 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("-z");
 CmdArgs.push_back("start-stop-visibility=hidden");
 
+CmdArgs.push_back("-z");
+CmdArgs.push_back("common-page-size=16384");
+
+CmdArgs.push_back("-z");
+CmdArgs.push_back("max-page-size=16384");
+
 // Patch relocated regions of DWARF whose targets are eliminated at link
 // time with specific tombstones, such that they're recognisable by the
 // PlayStation debugger.
@@ -295,6 +302,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Shared)
 CmdArgs.push_back("--shared");
 
+  if (!Relocatable && !Shared && !PIE)
+CmdArgs.push_back("--image-base=0x40");
+
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 5175d8dbca567a..8dcd32ec1ebd87 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -21,6 +21,22 @@
 // CHECK-NO-PIE-NOT: "-pie"
 // CHECK-SHARED: "--shared"
 
+// Test the driver supplies an --image-base to the linker only for non-pie
+// executables.
+
+// RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+
+// CHECK-BASE: {{ld(\.exe)?}}"
+// CHECK-BASE-SAME: "--image-base=0x40"
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+
+// CHECK-NO-BASE: {{ld(\.exe)?}}"
+// CHECK-NO-BASE-NOT: "--image-base=0x40"
+
 // Test the driver passes PlayStation-specific options to the linker that are
 // appropriate for the type of output. Many options don't apply for relocatable
 // output (-r).
@@ -37,6 +53,8 @@
 // CHECK-EXE-SAME: "--unresolved-symbols=report-all"
 // CHECK-EXE-SAME: "-z" "now"
 // CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
+// CHECK-EXE-SAME: "-z" "common-page-size=16384"
+// CHECK-EXE-SAME: "-z" "max-page-size=16384"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_*=0x"
 // CHECK-EXE-SAME: "-z" 
"dead-reloc-in-nonalloc=.debug_ranges=0xfffe"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffe"

``




https://github.com/llvm/llvm-project/pull/114435
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [PS5][Driver] Pass layout metrics to the linker (PR #114435)

2024-10-31 Thread Edd Dawson via cfe-commits

https://github.com/playstation-edd created 
https://github.com/llvm/llvm-project/pull/114435

Until now, these have been hardcoded as a downstream patches in lld. Add them 
to the driver so that the private patch can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in the 
proprietary linker.

SIE tracker: TOOLCHAIN-16704

>From ebbb513f4f938c8d17a21b6061a815ffc7d8b004 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 31 Oct 2024 16:09:30 +
Subject: [PATCH] [PS5][Driver] Pass layout metrics to the linker

Until now, these have been hardcoded as a downstream patches in lld. Add them
to the driver so that the private patch can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in
the proprietary linker.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 14 --
 clang/test/Driver/ps5-linker.c | 18 ++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index aaba95951c5060..3b1ffee7fb6b43 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -248,8 +248,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   // Default to PIE for non-static executables.
-  const bool PIE = !Relocatable && !Shared && !Static;
-  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
+  const bool PIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie,
+!Relocatable && !Shared && !Static);
+  if (PIE)
 CmdArgs.push_back("-pie");
 
   if (!Relocatable) {
@@ -276,6 +277,12 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("-z");
 CmdArgs.push_back("start-stop-visibility=hidden");
 
+CmdArgs.push_back("-z");
+CmdArgs.push_back("common-page-size=16384");
+
+CmdArgs.push_back("-z");
+CmdArgs.push_back("max-page-size=16384");
+
 // Patch relocated regions of DWARF whose targets are eliminated at link
 // time with specific tombstones, such that they're recognisable by the
 // PlayStation debugger.
@@ -295,6 +302,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Shared)
 CmdArgs.push_back("--shared");
 
+  if (!Relocatable && !Shared && !PIE)
+CmdArgs.push_back("--image-base=0x40");
+
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 5175d8dbca567a..8dcd32ec1ebd87 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -21,6 +21,22 @@
 // CHECK-NO-PIE-NOT: "-pie"
 // CHECK-SHARED: "--shared"
 
+// Test the driver supplies an --image-base to the linker only for non-pie
+// executables.
+
+// RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-BASE %s
+
+// CHECK-BASE: {{ld(\.exe)?}}"
+// CHECK-BASE-SAME: "--image-base=0x40"
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+// RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-BASE %s
+
+// CHECK-NO-BASE: {{ld(\.exe)?}}"
+// CHECK-NO-BASE-NOT: "--image-base=0x40"
+
 // Test the driver passes PlayStation-specific options to the linker that are
 // appropriate for the type of output. Many options don't apply for relocatable
 // output (-r).
@@ -37,6 +53,8 @@
 // CHECK-EXE-SAME: "--unresolved-symbols=report-all"
 // CHECK-EXE-SAME: "-z" "now"
 // CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
+// CHECK-EXE-SAME: "-z" "common-page-size=16384"
+// CHECK-EXE-SAME: "-z" "max-page-size=16384"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_*=0x"
 // CHECK-EXE-SAME: "-z" 
"dead-reloc-in-nonalloc=.debug_ranges=0xfffe"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffe"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits