[clang] [PS4,PS5][Driver] Check for absent SDK when -nostdlib/-nodefaultlibs (PR #107112)

2024-09-04 Thread Edd Dawson via cfe-commits

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


[clang] [PS4, PS5][Driver] Detangle --sysroot and -isysroot (PR #107410)

2024-09-05 Thread Edd Dawson via cfe-commits

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

The following discrepancies concerning `-isysroot` and `--sysroot` motivated 
this change:

- The SDK directory can be specified via `-isysroot`, but `--sysroot` has no 
influence over this. Yet, we check for the presence of either switch to 
determine whether we ought to warn about a missing SDK *headers*.

- The presence of `-isysroot` is ignored when deciding whether to warn about 
missing SDK *libraries*, depsite it being the only switch capable of specifying 
a non-default SDK location.

- The `--sysroot`s passed to the PlayStation linkers by the driver are 
unrelated to the SDK directory resolved in the PS4PS5Base constructor.

(We also ought to pass a sysroot-relative library search path to the linker via 
`-L=/target/lib`, but that's for another PR).

So we're half way between two worlds, currently:

- World 1: `-isysroot` and `--sysroot=` mean the same thing and each may
 override the SDK directory, from which both header and library
 search paths are derived.
- World 2: `-isysroot` influences header search paths and `--sysroot=`
 influences library search paths. Each independently defaults
 to the SDK directory.

This change commits to world 2, which seems to offer more flexibility for the 
user and better adheres to the principle of least surprise for those familiar 
with these options outside of a PlayStation development environment.

The test updates to ps{4,5}-sdk-root.c were of the scale of a rewrite so I also 
took the opportunity to clarify the purpose of each part, eliminate some 
redundancy and add some missing coverage.

SIE tracker: TOOLCHAIN-16704

>From a20158570f15b4200937650b90e07b99e230e3df Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 4 Sep 2024 12:30:11 +0100
Subject: [PATCH] [PS4,PS5][Driver] Detangle --sysroot and -isysroot

The following discrepancies concerning `-isysroot` and `--sysroot`
motivated this change:

- The SDK directory can be specified via `-isysroot`, but `--sysroot`
  has no influence over this. Yet, we check for the presence of either
  switch to determine whether we ought to warn about a missing SDK
  *headers*.

- The presence of `-isysroot` is ignored when deciding whether to warn
  about missing SDK *libraries*, depsite it being the only switch
  capable of specifying a non-default SDK location.

- The `--sysroot`s passed to the PlayStation linkers by the driver are
  unrelated to the SDK directory resolved in the PS4PS5Base constructor.

(We also ought to pass a sysroot-relative library search path to the
linker via `-L=/target/lib`, but that's for another PR).

So we're half way between two worlds, currently:

World 1: `-isysroot` and `--sysroot=` mean the same thing and each may
 override the SDK directory, from which both header and library
 search paths are derived.
World 2: `-isysroot` influences header search paths and `--sysroot=`
 influences library search paths. Each independently defaults
 to the SDK directory.

This change commits to world 2, which seems to offer more flexibility
for the user and better adheres to the principle of least surprise for
those familiar with these options outside of a PlayStation development
environment.

The test updates to ps{4,5}-sdk-root.c were of the scale of a rewrite so
I also took the opportunity to clarify the purpose of each part,
eliminate some redundancy and add some missing coverage.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp| 81 -
 clang/lib/Driver/ToolChains/PS4CPU.h  |  7 +-
 clang/test/Driver/ps4-linker.c|  9 +++
 clang/test/Driver/ps4-ps5-header-search.c |  4 +-
 clang/test/Driver/ps4-sdk-root.c  | 89 +--
 clang/test/Driver/ps5-linker.c|  9 +++
 clang/test/Driver/ps5-sdk-root.c  | 89 +--
 7 files changed, 175 insertions(+), 113 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 54ec59e6398f85..ddb5917b86a7c7 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -135,8 +135,8 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
-  if (!D.SysRoot.empty())
-CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+  CmdArgs.push_back(
+  Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
@@ -234,8 +234,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
-  if (!D.SysRoot.empty())
-CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+  CmdArgs.push_back(
+  Args.MakeArgString("--

[clang] [PS4, PS5][Driver] Detangle --sysroot and -isysroot (PR #107410)

2024-09-05 Thread Edd Dawson via cfe-commits

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


[clang] [PS4, PS5][Driver] Detangle --sysroot and -isysroot (PR #107410)

2024-09-06 Thread Edd Dawson via cfe-commits

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

>From a20158570f15b4200937650b90e07b99e230e3df Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 4 Sep 2024 12:30:11 +0100
Subject: [PATCH 1/2] [PS4,PS5][Driver] Detangle --sysroot and -isysroot

The following discrepancies concerning `-isysroot` and `--sysroot`
motivated this change:

- The SDK directory can be specified via `-isysroot`, but `--sysroot`
  has no influence over this. Yet, we check for the presence of either
  switch to determine whether we ought to warn about a missing SDK
  *headers*.

- The presence of `-isysroot` is ignored when deciding whether to warn
  about missing SDK *libraries*, depsite it being the only switch
  capable of specifying a non-default SDK location.

- The `--sysroot`s passed to the PlayStation linkers by the driver are
  unrelated to the SDK directory resolved in the PS4PS5Base constructor.

(We also ought to pass a sysroot-relative library search path to the
linker via `-L=/target/lib`, but that's for another PR).

So we're half way between two worlds, currently:

World 1: `-isysroot` and `--sysroot=` mean the same thing and each may
 override the SDK directory, from which both header and library
 search paths are derived.
World 2: `-isysroot` influences header search paths and `--sysroot=`
 influences library search paths. Each independently defaults
 to the SDK directory.

This change commits to world 2, which seems to offer more flexibility
for the user and better adheres to the principle of least surprise for
those familiar with these options outside of a PlayStation development
environment.

The test updates to ps{4,5}-sdk-root.c were of the scale of a rewrite so
I also took the opportunity to clarify the purpose of each part,
eliminate some redundancy and add some missing coverage.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp| 81 -
 clang/lib/Driver/ToolChains/PS4CPU.h  |  7 +-
 clang/test/Driver/ps4-linker.c|  9 +++
 clang/test/Driver/ps4-ps5-header-search.c |  4 +-
 clang/test/Driver/ps4-sdk-root.c  | 89 +--
 clang/test/Driver/ps5-linker.c|  9 +++
 clang/test/Driver/ps5-sdk-root.c  | 89 +--
 7 files changed, 175 insertions(+), 113 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 54ec59e6398f85..ddb5917b86a7c7 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -135,8 +135,8 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
-  if (!D.SysRoot.empty())
-CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+  CmdArgs.push_back(
+  Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
@@ -234,8 +234,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
-  if (!D.SysRoot.empty())
-CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+  CmdArgs.push_back(
+  Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   // Default to PIE for non-static executables.
   const bool PIE =
@@ -323,46 +323,57 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
const ArgList &Args, StringRef Platform,
const char *EnvVar)
 : Generic_ELF(D, Triple, Args) {
-  // Determine where to find the PS4/PS5 libraries.
-  // If -isysroot was passed, use that as the SDK base path.
-  // If not, we use the EnvVar if it exists; otherwise use the driver's
-  // installation path, which should be /host_tools/bin.
+  // Determine the baseline SDK directory from the environment, else
+  // the driver's location, which should be /host_tools/bin.
+  SmallString<128> SDKRootDir;
   SmallString<80> Whence;
-  if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
-SDKRootDir = A->getValue();
-if (!llvm::sys::fs::exists(SDKRootDir))
-  D.Diag(clang::diag::warn_missing_sysroot) << SDKRootDir;
-Whence = A->getSpelling();
-  } else if (const char *EnvValue = getenv(EnvVar)) {
+  if (const char *EnvValue = getenv(EnvVar)) {
 SDKRootDir = EnvValue;
-Whence = { "environment variable '", EnvVar, "'" };
+Whence = {"environment variable '", EnvVar, "'"};
   } else {
 SDKRootDir = D.Dir + "/../../";
 Whence = "compiler's location";
   }
 
-  SmallString<512> SDKIncludeDir(SDKRootDir);
-  llvm::sys::path::append(SDKIncludeDir, "target/include");
-  if (!Args.hasArg(options::OPT_nostdinc) &&
-  !Args.hasArg(options::OPT_nostdlibinc) &&
-  !Args.hasArg(optio

[clang] [PS4, PS5][Driver] Detangle --sysroot and -isysroot (PR #107410)

2024-09-06 Thread Edd Dawson via cfe-commits

playstation-edd wrote:

> According to [gcc 
> docs](https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html) `--sysroot` 
> applies to headers and libraries, and `-isysroot` overrides it for headers 
> only. This is different from the "independence" described for World 2. That 
> is, if we have only `--sysroot` it should apply to both.

I'm not sure what resource is (mis)read to come to the conclusion that world 2 
was normal. Thanks for checking!

I have pushed an update which has `--sysroot` apply to both header and 
libraries, unless both `--sysroot` and `-isysroot` are supplied, win which case 
the former applies to libraries and the latter to headers.


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


[clang] [PS4, PS5][Driver] Detangle --sysroot and -isysroot (PR #107410)

2024-09-06 Thread Edd Dawson via cfe-commits


@@ -323,46 +323,63 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
const ArgList &Args, StringRef Platform,
const char *EnvVar)
 : Generic_ELF(D, Triple, Args) {
-  // Determine where to find the PS4/PS5 libraries.
-  // If -isysroot was passed, use that as the SDK base path.
-  // If not, we use the EnvVar if it exists; otherwise use the driver's
-  // installation path, which should be /host_tools/bin.
+  // Determine the baseline SDK directory from the environment, else
+  // the driver's location, which should be /host_tools/bin.
+  SmallString<128> SDKRootDir;
   SmallString<80> Whence;
-  if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
-SDKRootDir = A->getValue();
-if (!llvm::sys::fs::exists(SDKRootDir))
-  D.Diag(clang::diag::warn_missing_sysroot) << SDKRootDir;
-Whence = A->getSpelling();
-  } else if (const char *EnvValue = getenv(EnvVar)) {
+  if (const char *EnvValue = getenv(EnvVar)) {
 SDKRootDir = EnvValue;
-Whence = { "environment variable '", EnvVar, "'" };
+Whence = {"environment variable '", EnvVar, "'"};
   } else {
 SDKRootDir = D.Dir + "/../../";
 Whence = "compiler's location";
   }
 
-  SmallString<512> SDKIncludeDir(SDKRootDir);
-  llvm::sys::path::append(SDKIncludeDir, "target/include");
-  if (!Args.hasArg(options::OPT_nostdinc) &&
-  !Args.hasArg(options::OPT_nostdlibinc) &&
-  !Args.hasArg(options::OPT_isysroot) &&
-  !Args.hasArg(options::OPT__sysroot_EQ) &&
-  !llvm::sys::fs::exists(SDKIncludeDir)) {
-D.Diag(clang::diag::warn_drv_unable_to_find_directory_expected)
-<< Twine(Platform, " system headers").str() << SDKIncludeDir << Whence;
-  }
+  // Allow --sysroot= to override the root directory for header and library
+  // search, and -sysroot to override header search. If both are specified,
+  // -isysroot overrides --sysroot for header search.
+  auto OverrideRoot = [&](const options::ID &Opt, std::string &Root,
+  StringRef Default) {
+if (const Arg *A = Args.getLastArg(Opt)) {
+  Root = A->getValue();
+  if (!llvm::sys::fs::exists(Root))
+D.Diag(clang::diag::warn_missing_sysroot) << Root;
+  return true;
+}
+Root = Default.str();
+return false;
+  };
 
-  SmallString<512> SDKLibDir(SDKRootDir);
-  llvm::sys::path::append(SDKLibDir, "target/lib");
-  if (!Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) &&
-  !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) &&
-  !Args.hasArg(options::OPT_emit_ast) &&
-  !llvm::sys::fs::exists(SDKLibDir)) {
+  bool CustomSysroot =
+  OverrideRoot(options::OPT__sysroot_EQ, SDKLibraryRootDir, SDKRootDir);
+  bool CustomISysroot =
+  OverrideRoot(options::OPT_isysroot, SDKHeaderRootDir, SDKLibraryRootDir);
+
+  // Emit warnings if parts of the SDK are missing, unless the user has taken
+  // control of header or library search. If we're not linking, don't check
+  // for missing libraries.
+  auto CheckSDKPartExists = [&](StringRef Dir, StringRef Desc) {
+if (llvm::sys::fs::exists(Dir))
+  return true;
 D.Diag(clang::diag::warn_drv_unable_to_find_directory_expected)
-<< Twine(Platform, " system libraries").str() << SDKLibDir << Whence;
-return;
+<< (Twine(Platform) + " " + Desc).str() << Dir << Whence;
+return false;
+  };
+
+  bool Linking = !Args.hasArg(options::OPT_E, options::OPT_c, options::OPT_S,
+  options::OPT_emit_ast);
+  if (!CustomSysroot && Linking) {
+SmallString<128> Dir(SDKLibraryRootDir);
+llvm::sys::path::append(Dir, "target/lib");
+if (CheckSDKPartExists(Dir, "system libraries"))
+  getFilePaths().push_back(std::string(Dir));

playstation-edd wrote:

There's an early `return` in a similar place/situation, prior to this PR. So 
this was my attempt at NFC.

But I also don't know much about the FilePaths. I'll do some digging to ensure 
this remains reasonable.

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


[clang] [PS4, PS5][Driver] Detangle --sysroot and -isysroot (PR #107410)

2024-09-06 Thread Edd Dawson via cfe-commits


@@ -323,46 +323,63 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
const ArgList &Args, StringRef Platform,
const char *EnvVar)
 : Generic_ELF(D, Triple, Args) {
-  // Determine where to find the PS4/PS5 libraries.
-  // If -isysroot was passed, use that as the SDK base path.
-  // If not, we use the EnvVar if it exists; otherwise use the driver's
-  // installation path, which should be /host_tools/bin.
+  // Determine the baseline SDK directory from the environment, else
+  // the driver's location, which should be /host_tools/bin.
+  SmallString<128> SDKRootDir;
   SmallString<80> Whence;
-  if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
-SDKRootDir = A->getValue();
-if (!llvm::sys::fs::exists(SDKRootDir))
-  D.Diag(clang::diag::warn_missing_sysroot) << SDKRootDir;
-Whence = A->getSpelling();
-  } else if (const char *EnvValue = getenv(EnvVar)) {
+  if (const char *EnvValue = getenv(EnvVar)) {
 SDKRootDir = EnvValue;
-Whence = { "environment variable '", EnvVar, "'" };
+Whence = {"environment variable '", EnvVar, "'"};
   } else {
 SDKRootDir = D.Dir + "/../../";
 Whence = "compiler's location";
   }
 
-  SmallString<512> SDKIncludeDir(SDKRootDir);
-  llvm::sys::path::append(SDKIncludeDir, "target/include");
-  if (!Args.hasArg(options::OPT_nostdinc) &&
-  !Args.hasArg(options::OPT_nostdlibinc) &&
-  !Args.hasArg(options::OPT_isysroot) &&
-  !Args.hasArg(options::OPT__sysroot_EQ) &&
-  !llvm::sys::fs::exists(SDKIncludeDir)) {
-D.Diag(clang::diag::warn_drv_unable_to_find_directory_expected)
-<< Twine(Platform, " system headers").str() << SDKIncludeDir << Whence;
-  }
+  // Allow --sysroot= to override the root directory for header and library
+  // search, and -sysroot to override header search. If both are specified,
+  // -isysroot overrides --sysroot for header search.
+  auto OverrideRoot = [&](const options::ID &Opt, std::string &Root,
+  StringRef Default) {
+if (const Arg *A = Args.getLastArg(Opt)) {
+  Root = A->getValue();
+  if (!llvm::sys::fs::exists(Root))
+D.Diag(clang::diag::warn_missing_sysroot) << Root;
+  return true;
+}
+Root = Default.str();
+return false;
+  };
 
-  SmallString<512> SDKLibDir(SDKRootDir);
-  llvm::sys::path::append(SDKLibDir, "target/lib");
-  if (!Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) &&
-  !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) &&
-  !Args.hasArg(options::OPT_emit_ast) &&
-  !llvm::sys::fs::exists(SDKLibDir)) {
+  bool CustomSysroot =
+  OverrideRoot(options::OPT__sysroot_EQ, SDKLibraryRootDir, SDKRootDir);
+  bool CustomISysroot =
+  OverrideRoot(options::OPT_isysroot, SDKHeaderRootDir, SDKLibraryRootDir);
+
+  // Emit warnings if parts of the SDK are missing, unless the user has taken
+  // control of header or library search. If we're not linking, don't check
+  // for missing libraries.
+  auto CheckSDKPartExists = [&](StringRef Dir, StringRef Desc) {
+if (llvm::sys::fs::exists(Dir))
+  return true;
 D.Diag(clang::diag::warn_drv_unable_to_find_directory_expected)
-<< Twine(Platform, " system libraries").str() << SDKLibDir << Whence;
-return;
+<< (Twine(Platform) + " " + Desc).str() << Dir << Whence;
+return false;
+  };
+
+  bool Linking = !Args.hasArg(options::OPT_E, options::OPT_c, options::OPT_S,
+  options::OPT_emit_ast);
+  if (!CustomSysroot && Linking) {
+SmallString<128> Dir(SDKLibraryRootDir);
+llvm::sys::path::append(Dir, "target/lib");
+if (CheckSDKPartExists(Dir, "system libraries"))
+  getFilePaths().push_back(std::string(Dir));

playstation-edd wrote:

It's less involved than I was expecting: the contents of the FilePaths are 
turned into `-L` arguments for the linker.

So I guess the idea is:

* If you're passing `--sysroot`, you want full control. You can pass 
`/target/lib` if you want, but it shouldn't be _assumed_ you want 
this library path.
* Otherwise, `/target/lib` should be added to the linker's search 
paths. But only if it exists.

I think I buy it.

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


[clang] [PS4, PS5][Driver] Detangle --sysroot and -isysroot (PR #107410)

2024-09-09 Thread Edd Dawson via cfe-commits

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

>From a20158570f15b4200937650b90e07b99e230e3df Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 4 Sep 2024 12:30:11 +0100
Subject: [PATCH 1/3] [PS4,PS5][Driver] Detangle --sysroot and -isysroot

The following discrepancies concerning `-isysroot` and `--sysroot`
motivated this change:

- The SDK directory can be specified via `-isysroot`, but `--sysroot`
  has no influence over this. Yet, we check for the presence of either
  switch to determine whether we ought to warn about a missing SDK
  *headers*.

- The presence of `-isysroot` is ignored when deciding whether to warn
  about missing SDK *libraries*, depsite it being the only switch
  capable of specifying a non-default SDK location.

- The `--sysroot`s passed to the PlayStation linkers by the driver are
  unrelated to the SDK directory resolved in the PS4PS5Base constructor.

(We also ought to pass a sysroot-relative library search path to the
linker via `-L=/target/lib`, but that's for another PR).

So we're half way between two worlds, currently:

World 1: `-isysroot` and `--sysroot=` mean the same thing and each may
 override the SDK directory, from which both header and library
 search paths are derived.
World 2: `-isysroot` influences header search paths and `--sysroot=`
 influences library search paths. Each independently defaults
 to the SDK directory.

This change commits to world 2, which seems to offer more flexibility
for the user and better adheres to the principle of least surprise for
those familiar with these options outside of a PlayStation development
environment.

The test updates to ps{4,5}-sdk-root.c were of the scale of a rewrite so
I also took the opportunity to clarify the purpose of each part,
eliminate some redundancy and add some missing coverage.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp| 81 -
 clang/lib/Driver/ToolChains/PS4CPU.h  |  7 +-
 clang/test/Driver/ps4-linker.c|  9 +++
 clang/test/Driver/ps4-ps5-header-search.c |  4 +-
 clang/test/Driver/ps4-sdk-root.c  | 89 +--
 clang/test/Driver/ps5-linker.c|  9 +++
 clang/test/Driver/ps5-sdk-root.c  | 89 +--
 7 files changed, 175 insertions(+), 113 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 54ec59e6398f85..ddb5917b86a7c7 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -135,8 +135,8 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
-  if (!D.SysRoot.empty())
-CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+  CmdArgs.push_back(
+  Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
@@ -234,8 +234,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
-  if (!D.SysRoot.empty())
-CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+  CmdArgs.push_back(
+  Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   // Default to PIE for non-static executables.
   const bool PIE =
@@ -323,46 +323,57 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
const ArgList &Args, StringRef Platform,
const char *EnvVar)
 : Generic_ELF(D, Triple, Args) {
-  // Determine where to find the PS4/PS5 libraries.
-  // If -isysroot was passed, use that as the SDK base path.
-  // If not, we use the EnvVar if it exists; otherwise use the driver's
-  // installation path, which should be /host_tools/bin.
+  // Determine the baseline SDK directory from the environment, else
+  // the driver's location, which should be /host_tools/bin.
+  SmallString<128> SDKRootDir;
   SmallString<80> Whence;
-  if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
-SDKRootDir = A->getValue();
-if (!llvm::sys::fs::exists(SDKRootDir))
-  D.Diag(clang::diag::warn_missing_sysroot) << SDKRootDir;
-Whence = A->getSpelling();
-  } else if (const char *EnvValue = getenv(EnvVar)) {
+  if (const char *EnvValue = getenv(EnvVar)) {
 SDKRootDir = EnvValue;
-Whence = { "environment variable '", EnvVar, "'" };
+Whence = {"environment variable '", EnvVar, "'"};
   } else {
 SDKRootDir = D.Dir + "/../../";
 Whence = "compiler's location";
   }
 
-  SmallString<512> SDKIncludeDir(SDKRootDir);
-  llvm::sys::path::append(SDKIncludeDir, "target/include");
-  if (!Args.hasArg(options::OPT_nostdinc) &&
-  !Args.hasArg(options::OPT_nostdlibinc) &&
-  !Args.hasArg(optio

[clang] [PS4, PS5][Driver] Detangle --sysroot and -isysroot (PR #107410)

2024-09-09 Thread Edd Dawson via cfe-commits

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

>From a20158570f15b4200937650b90e07b99e230e3df Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 4 Sep 2024 12:30:11 +0100
Subject: [PATCH 1/4] [PS4,PS5][Driver] Detangle --sysroot and -isysroot

The following discrepancies concerning `-isysroot` and `--sysroot`
motivated this change:

- The SDK directory can be specified via `-isysroot`, but `--sysroot`
  has no influence over this. Yet, we check for the presence of either
  switch to determine whether we ought to warn about a missing SDK
  *headers*.

- The presence of `-isysroot` is ignored when deciding whether to warn
  about missing SDK *libraries*, depsite it being the only switch
  capable of specifying a non-default SDK location.

- The `--sysroot`s passed to the PlayStation linkers by the driver are
  unrelated to the SDK directory resolved in the PS4PS5Base constructor.

(We also ought to pass a sysroot-relative library search path to the
linker via `-L=/target/lib`, but that's for another PR).

So we're half way between two worlds, currently:

World 1: `-isysroot` and `--sysroot=` mean the same thing and each may
 override the SDK directory, from which both header and library
 search paths are derived.
World 2: `-isysroot` influences header search paths and `--sysroot=`
 influences library search paths. Each independently defaults
 to the SDK directory.

This change commits to world 2, which seems to offer more flexibility
for the user and better adheres to the principle of least surprise for
those familiar with these options outside of a PlayStation development
environment.

The test updates to ps{4,5}-sdk-root.c were of the scale of a rewrite so
I also took the opportunity to clarify the purpose of each part,
eliminate some redundancy and add some missing coverage.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp| 81 -
 clang/lib/Driver/ToolChains/PS4CPU.h  |  7 +-
 clang/test/Driver/ps4-linker.c|  9 +++
 clang/test/Driver/ps4-ps5-header-search.c |  4 +-
 clang/test/Driver/ps4-sdk-root.c  | 89 +--
 clang/test/Driver/ps5-linker.c|  9 +++
 clang/test/Driver/ps5-sdk-root.c  | 89 +--
 7 files changed, 175 insertions(+), 113 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 54ec59e6398f85..ddb5917b86a7c7 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -135,8 +135,8 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
-  if (!D.SysRoot.empty())
-CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+  CmdArgs.push_back(
+  Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
@@ -234,8 +234,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
-  if (!D.SysRoot.empty())
-CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+  CmdArgs.push_back(
+  Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   // Default to PIE for non-static executables.
   const bool PIE =
@@ -323,46 +323,57 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
const ArgList &Args, StringRef Platform,
const char *EnvVar)
 : Generic_ELF(D, Triple, Args) {
-  // Determine where to find the PS4/PS5 libraries.
-  // If -isysroot was passed, use that as the SDK base path.
-  // If not, we use the EnvVar if it exists; otherwise use the driver's
-  // installation path, which should be /host_tools/bin.
+  // Determine the baseline SDK directory from the environment, else
+  // the driver's location, which should be /host_tools/bin.
+  SmallString<128> SDKRootDir;
   SmallString<80> Whence;
-  if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
-SDKRootDir = A->getValue();
-if (!llvm::sys::fs::exists(SDKRootDir))
-  D.Diag(clang::diag::warn_missing_sysroot) << SDKRootDir;
-Whence = A->getSpelling();
-  } else if (const char *EnvValue = getenv(EnvVar)) {
+  if (const char *EnvValue = getenv(EnvVar)) {
 SDKRootDir = EnvValue;
-Whence = { "environment variable '", EnvVar, "'" };
+Whence = {"environment variable '", EnvVar, "'"};
   } else {
 SDKRootDir = D.Dir + "/../../";
 Whence = "compiler's location";
   }
 
-  SmallString<512> SDKIncludeDir(SDKRootDir);
-  llvm::sys::path::append(SDKIncludeDir, "target/include");
-  if (!Args.hasArg(options::OPT_nostdinc) &&
-  !Args.hasArg(options::OPT_nostdlibinc) &&
-  !Args.hasArg(optio

[clang] [PS4, PS5][Driver] Detangle --sysroot and -isysroot (PR #107410)

2024-09-09 Thread Edd Dawson via cfe-commits


@@ -1,42 +1,64 @@
-// Check that PS4 clang doesn't report a warning message when locating
-// system header files (either by looking at the value of SCE_ORBIS_SDK_DIR
-// or relative to the location of the compiler driver), if "-nostdinc",
-// "--sysroot" or "-isysroot" option is specified on the command line.
-// Otherwise, check that PS4 clang reports a warning.
-
-// Check that PS4 clang doesn't report a warning message when locating
-// system libraries (either by looking at the value of SCE_ORBIS_SDK_DIR
-// or relative to the location of the compiler driver), if "-c", "-S", "-E"
-// or "--sysroot" option is specified on the command line.
-// Otherwise, check that PS4 clang reports a warning.
-
-// Setting up SCE_ORBIS_SDK_DIR to existing location, which is not a PS4 SDK.
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -target x86_64-scei-ps4 %s 2>&1 | FileCheck -check-prefix=WARN-SYS-HEADERS 
-check-prefix=WARN-SYS-LIBS -check-prefix=NO-WARN %s
-
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -c -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-SYS-HEADERS -check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -S -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-SYS-HEADERS -check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -E -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-SYS-HEADERS -check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -emit-ast -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-SYS-HEADERS -check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -isysroot foo -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-ISYSROOT -check-prefix=WARN-SYS-LIBS -check-prefix=NO-WARN %s
-
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -c -nostdinc -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -S -nostdinc -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -E -nostdinc -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -emit-ast -nostdinc -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=NO-WARN %s
-
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -c --sysroot=foo/ -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -S --sysroot=foo/ -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -E --sysroot=foo/ -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -emit-ast --sysroot=foo/ -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=NO-WARN %s
-
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -c -isysroot foo -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-ISYSROOT -check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -S -isysroot foo -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-ISYSROOT -check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -E -isysroot foo -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-ISYSROOT -check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -emit-ast -isysroot foo -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-ISYSROOT -check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### --sysroot=foo/ -isysroot foo -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-ISYSROOT -check-prefix=NO-WARN %s
+/// PS4 clang emits warnings when SDK headers or libraries are missing, or if a
+/// specified `-isysroot` or `--sysroot` does not exist.
+///
+/// If the user takes control of header or library search, the respective
+/// existence check is skipped. User control of header search is assumed if
+/// `--sysroot`, `-isysroot`, `-nostdinc` or `-nostdlibinc` is supplied. User
+/// control of library search is assumed if `--sysroot` is supplied.

playstation-edd wrote:

Fixed - thanks.

https://github.com/llvm/llvm-project/pull/107410
___
cfe-commits mailing list
cfe-commits@lists.

[clang] [PS4/PS5][Driver] Allow -static in PlayStation drivers (PR #102020)

2024-08-12 Thread Edd Dawson via cfe-commits

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


[clang] [PS5][Driver] Link main components with -pie by default (PR #102901)

2024-08-12 Thread Edd Dawson via cfe-commits

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

The PS5 linker currently forces `-pie` for typical link jobs. Have the driver 
pass `pie` under the same conditions. With this change we can remove our 
private linker patch and also allow `-no-pie` to have an effect.

SIE tracker: TOOLCHAIN-16704

>From 0ca2239d21cb414ce5e6fb9057d442c18f61a32e Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Mon, 12 Aug 2024 14:11:11 +0100
Subject: [PATCH] [PS5][Driver] Link main components with -pie by default

The PS5 linker currently forces `-pie` for typical link jobs. Have the
driver pass `pie` under the same conditions. With this change we can
remove our private linker patch and also allow `-no-pie` to have an
effect.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp |  5 -
 clang/test/Driver/ps5-linker.c | 15 +++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 0175b5eb63e657..73f4c4e2fc7a49 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -237,7 +237,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (Args.hasArg(options::OPT_pie))
+  // Default to PIE for non-static main components.
+  const bool PIE =
+  !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
+  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
 CmdArgs.push_back("-pie");
 
   if (Args.hasArg(options::OPT_static))
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95d64d9017be04..fb954b938c1ab9 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -1,3 +1,18 @@
+// Test that PIE is the default for main components
+
+// RUN: %clang --target=x86_64-scei-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PIE %s
+
+// CHECK-PIE: {{ld(\.exe)?}}"
+// CHECK-PIE-SAME: "-pie"
+
+// RUN: %clang --target=x86_64-scei-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+
+// CHECK-NO-PIE: {{ld(\.exe)?}}"
+// CHECK-NO-PIE-NOT: "-pie"
+
 // Test that -static is forwarded to the linker
 
 // RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-STATIC %s

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


[clang] [llvm] [PS4/PS5][Driver][DWARF] Always emit .debug_aranges for SCE tuning (PR #100160)

2024-07-23 Thread Edd Dawson via cfe-commits

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

Some of SIE's post-mortem analysis infrastructure currently makes use of 
.debug_aranges, so we'd like to ensure the section's presence in PlayStation 
binaries. The simplest way to do this is to force emission when the debugger 
tuning is set to SCE (which is in turn typically initialized from the target 
triple). This also simplifies the driver.

llvm/test/DebugInfo/debuglineinfo-path.ll has been marked as UNSUPPORTED on 
PlayStation. When aranges are emitted, the DWARF in the test case is such that 
relocations need to be applied to the aranges section in order for 
symbolization to work. An alternative approach would be to implement the 
application of relocations in DWARFDebugArangeSet. While experiments show that 
this can be made to work with a modest patch, the test cases would be rather 
contrived. Since I expect the only utility for such a change would be to make 
this test case pass for PlayStation targets, and few - if any - outside of 
PlayStation care about aranges, UNSUPPORTED would seem to be a more practical 
option.

This was originally commited as 22eb290a96 (#99629) and later reverted at 
84658fb82b (#99711) due to test failures on SIE built bots. These failures 
shouldn't recur due to 3b24e5d450 (#99897) and the aforementioned change to 
debuglineinfo-path.ll.

SIE tracker: TOOLCHAIN-16951

>From 3a336780b4c3596863294afc47969967dac5f9bb Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Fri, 19 Jul 2024 17:52:00 +0100
Subject: [PATCH] [PS4/PS5][Driver][DWARF] Always emit .debug_aranges for SCE
 tuning

Some of SIE's post-mortem analysis infrastructure currently makes use of
.debug_aranges, so we'd like to ensure the section's presence in
PlayStation binaries. The simplest way to do this is to force emission
when the debugger tuning is set to SCE (which is in turn typically
initialized from the target triple). This also simplifies the driver.

llvm/test/DebugInfo/debuglineinfo-path.ll has been marked as UNSUPPORTED
on PlayStation. When aranges are emitted, the DWARF in the test case is
such that relocations need to be applied to the aranges section in order
for symbolization to work. An alternative approach would be to implement
the application of relocations in DWARFDebugArangeSet. While experiments
show that this can be made to work with a modest patch, the test cases
would be rather contrived. Since I expect the only utility for such a
change would be to make this test case pass for PlayStation targets, and
few - if any - outside of PlayStation care about aranges, UNSUPPORTED
would seem to be a more practical option.

This was originally commited as 22eb290a96 (#99629) and later reverted
at 84658fb82b (#99711) due to test failures on SIE built bots. These
failures shouldn't recur due to 3b24e5d450 (#99897) and the
aforementioned change to debuglineinfo-path.ll.

SIE tracker: TOOLCHAIN-16951
---
 clang/lib/Driver/ToolChains/Clang.cpp |  7 ++--
 clang/lib/Driver/ToolChains/PS4CPU.cpp|  8 -
 clang/test/Driver/debug-options.c | 21 ++--
 clang/test/Driver/lto-jobs.c  |  2 +-
 clang/test/Driver/ps4-linker.c|  8 ++---
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp|  5 ++-
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h  |  3 ++
 .../DebugInfo/X86/debug-aranges-sce-tuning.ll | 33 +++
 llvm/test/DebugInfo/debuglineinfo-path.ll |  5 +--
 9 files changed, 60 insertions(+), 32 deletions(-)
 create mode 100644 llvm/test/DebugInfo/X86/debug-aranges-sce-tuning.ll

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 78936fd634f33..136db416f5b30 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4718,11 +4718,8 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, 
const llvm::Triple &T,
 
   // -gdwarf-aranges turns on the emission of the aranges section in the
   // backend.
-  // Always enabled for SCE tuning.
-  bool NeedAranges = DebuggerTuning == llvm::DebuggerKind::SCE;
-  if (const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges))
-NeedAranges = checkDebugInfoOption(A, Args, D, TC) || NeedAranges;
-  if (NeedAranges) {
+  if (const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges);
+  A && checkDebugInfoOption(A, Args, D, TC)) {
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back("-generate-arange-section");
   }
diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 974e486a0082b..d6af9388e54a6 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -162,10 +162,6 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   };
 
   if (UseLTO) {
-// We default to creating the arange section, but LTO does not. Enable it
-// here.
-AddCodeGenFlag("-generate-arange-sectio

[clang] [llvm] [PS4/PS5][Driver][DWARF] Always emit .debug_aranges for SCE tuning (PR #100160)

2024-07-23 Thread Edd Dawson via cfe-commits

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

>From 3a336780b4c3596863294afc47969967dac5f9bb Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Fri, 19 Jul 2024 17:52:00 +0100
Subject: [PATCH 1/4] [PS4/PS5][Driver][DWARF] Always emit .debug_aranges for
 SCE tuning

Some of SIE's post-mortem analysis infrastructure currently makes use of
.debug_aranges, so we'd like to ensure the section's presence in
PlayStation binaries. The simplest way to do this is to force emission
when the debugger tuning is set to SCE (which is in turn typically
initialized from the target triple). This also simplifies the driver.

llvm/test/DebugInfo/debuglineinfo-path.ll has been marked as UNSUPPORTED
on PlayStation. When aranges are emitted, the DWARF in the test case is
such that relocations need to be applied to the aranges section in order
for symbolization to work. An alternative approach would be to implement
the application of relocations in DWARFDebugArangeSet. While experiments
show that this can be made to work with a modest patch, the test cases
would be rather contrived. Since I expect the only utility for such a
change would be to make this test case pass for PlayStation targets, and
few - if any - outside of PlayStation care about aranges, UNSUPPORTED
would seem to be a more practical option.

This was originally commited as 22eb290a96 (#99629) and later reverted
at 84658fb82b (#99711) due to test failures on SIE built bots. These
failures shouldn't recur due to 3b24e5d450 (#99897) and the
aforementioned change to debuglineinfo-path.ll.

SIE tracker: TOOLCHAIN-16951
---
 clang/lib/Driver/ToolChains/Clang.cpp |  7 ++--
 clang/lib/Driver/ToolChains/PS4CPU.cpp|  8 -
 clang/test/Driver/debug-options.c | 21 ++--
 clang/test/Driver/lto-jobs.c  |  2 +-
 clang/test/Driver/ps4-linker.c|  8 ++---
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp|  5 ++-
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h  |  3 ++
 .../DebugInfo/X86/debug-aranges-sce-tuning.ll | 33 +++
 llvm/test/DebugInfo/debuglineinfo-path.ll |  5 +--
 9 files changed, 60 insertions(+), 32 deletions(-)
 create mode 100644 llvm/test/DebugInfo/X86/debug-aranges-sce-tuning.ll

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 78936fd634f33..136db416f5b30 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4718,11 +4718,8 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, 
const llvm::Triple &T,
 
   // -gdwarf-aranges turns on the emission of the aranges section in the
   // backend.
-  // Always enabled for SCE tuning.
-  bool NeedAranges = DebuggerTuning == llvm::DebuggerKind::SCE;
-  if (const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges))
-NeedAranges = checkDebugInfoOption(A, Args, D, TC) || NeedAranges;
-  if (NeedAranges) {
+  if (const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges);
+  A && checkDebugInfoOption(A, Args, D, TC)) {
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back("-generate-arange-section");
   }
diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 974e486a0082b..d6af9388e54a6 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -162,10 +162,6 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   };
 
   if (UseLTO) {
-// We default to creating the arange section, but LTO does not. Enable it
-// here.
-AddCodeGenFlag("-generate-arange-section");
-
 // This tells LTO to perform JustMyCode instrumentation.
 if (UseJMC)
   AddCodeGenFlag("-enable-jmc-instrument");
@@ -272,10 +268,6 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   };
 
   if (UseLTO) {
-// We default to creating the arange section, but LTO does not. Enable it
-// here.
-AddCodeGenFlag("-generate-arange-section");
-
 // This tells LTO to perform JustMyCode instrumentation.
 if (UseJMC)
   AddCodeGenFlag("-enable-jmc-instrument");
diff --git a/clang/test/Driver/debug-options.c 
b/clang/test/Driver/debug-options.c
index 0a665f7017d63..21785ba01cb41 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -118,27 +118,28 @@
 // RUN: %clang_cl -### -c -Z7 -target x86_64-windows-msvc -- %s 2>&1 \
 // RUN: | FileCheck -check-prefix=G_NOTUNING %s
 
-// On the PS4/PS5, -g defaults to -gno-column-info, and we always generate the
-// arange section.
+// On the PS4/PS5, -g defaults to -gno-column-info. We default to always
+// generating the arange section, but keyed off SCE DebuggerTuning being in
+// play during codegen, instead of -generate-arange-section.
 // RUN: %clang -### -c %s -target x86_64-scei-ps4 2>&1 \
 // RUN: | FileCheck -check-prefix=NOG_PS %s
 // RU

[clang] [llvm] [PS4/PS5][Driver][DWARF] Always emit .debug_aranges for SCE tuning (PR #100160)

2024-07-23 Thread Edd Dawson via cfe-commits


@@ -0,0 +1,33 @@
+; This checks that .debug_aranges is always generated for the SCE debugger

playstation-edd wrote:

Done!

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


[clang] [llvm] [PS4/PS5][Driver][DWARF] Always emit .debug_aranges for SCE tuning (PR #100160)

2024-07-24 Thread Edd Dawson via cfe-commits

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


[clang] [PS4/PS5][Driver] Always pass LTO options to the linker (PR #100423)

2024-07-24 Thread Edd Dawson via cfe-commits

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

The driver doesn't know if LTO will occur at link time. That's determined by 
the presence or absence of LLVM bitcode objects among those ingested by the 
linker.

For this reason, LTO options for codegen etc must be passed to the linker 
unconditionally. If LTO does not occur, these options have no effect.

Also simplify the way LTO options are supplied to the PS4 linker. 
`-lto-debug-options` and `-lto-thin-debug-options` are combined and routed to 
the same place. So, always use the former, regardless of full/thin LTO mode.

SIE tracker: TOOLCHAIN-16575

>From daa53d8cf7850a4bb11a7780410b969602138565 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 24 Jul 2024 16:39:09 +0100
Subject: [PATCH] [PS4/PS5][Driver] Always pass LTO options to the linker

The driver doesn't know if LTO will occur at link time. That's
determined by the presence or absence of LLVM bitcode objects among
those ingested by the linker.

For this reason, LTO options for codegen etc must be passed to the linker
unconditionally. If LTO does not occur, these options have no effect.

Also simplify the way LTO options are supplied to the PS4 linker.
`-lto-debug-options` and `-lto-thin-debug-options` are combined and
routed to the same place. So always use the former, regardless of
full/thin LTO mode.

SIE tracker: TOOLCHAIN-16575
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 83 +++---
 clang/test/Driver/lto-jobs.c   |  5 +-
 clang/test/Driver/ps4-linker.c | 18 +++---
 clang/test/Driver/ps5-linker.c | 10 ++--
 clang/test/Driver/unified-lto.c| 23 ++-
 5 files changed, 74 insertions(+), 65 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index d6af9388e54a6..958fec5b96361 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -152,48 +152,38 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(Output.getFilename());
   }
 
-  const bool UseLTO = D.isUsingLTO();
   const bool UseJMC =
   Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false);
 
+  const bool UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
+   options::OPT_fno_unified_lto, true);
+
   const char *LTOArgs = "";
-  auto AddCodeGenFlag = [&](Twine Flag) {
+  auto AddLTOFlag = [&](Twine Flag) {
 LTOArgs = Args.MakeArgString(Twine(LTOArgs) + " " + Flag);
   };
 
-  if (UseLTO) {
-// This tells LTO to perform JustMyCode instrumentation.
-if (UseJMC)
-  AddCodeGenFlag("-enable-jmc-instrument");
-
-if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
-  AddCodeGenFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
+  // If the linker sees bitcode objects it will perform LTO. We can't tell
+  // 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 (UnifiedLTO)
+CmdArgs.push_back(D.getLTOMode() == LTOK_Thin ? "--lto=thin"
+  : "--lto=full");
+  if (UseJMC)
+AddLTOFlag("-enable-jmc-instrument");
 
-StringRef Parallelism = getLTOParallelism(Args, D);
-if (!Parallelism.empty())
-  AddCodeGenFlag(Twine("-threads=") + Parallelism);
+  if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
+AddLTOFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
 
-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?");
+  if (StringRef Threads = getLTOParallelism(Args, D); !Threads.empty())
+AddLTOFlag(Twine("-threads=") + Threads);
 
-CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + LTOArgs));
-  }
+  CmdArgs.push_back(Args.MakeArgString(Twine("-lto-debug-options=") + 
LTOArgs));
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
-  if (D.isUsingLTO() && Args.hasArg(options::OPT_funified_lto)) {
-if (D.getLTOMode() == LTOK_Thin)
-  CmdArgs.push_back("--lto=thin");
-else if (D.getLTOMode() == LTOK_Full)
-  CmdArgs.push_back("--lto=full");
-  }
-
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
 
@@ -259,37 +249,36 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(Output.getFilename());
   }
 
-  const bool UseLTO = D.isUsingLTO();
   const bool UseJMC =
   Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false);
 
-  auto AddCodeGenFlag = [&](Twine Flag) {
+  const

[clang] [PS4/PS5][Driver] Always pass LTO options to the linker (PR #100423)

2024-07-24 Thread Edd Dawson via cfe-commits


@@ -152,48 +152,38 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(Output.getFilename());
   }
 
-  const bool UseLTO = D.isUsingLTO();
   const bool UseJMC =
   Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false);
 
+  const bool UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
+   options::OPT_fno_unified_lto, true);
+
   const char *LTOArgs = "";
-  auto AddCodeGenFlag = [&](Twine Flag) {
+  auto AddLTOFlag = [&](Twine Flag) {
 LTOArgs = Args.MakeArgString(Twine(LTOArgs) + " " + Flag);
   };
 
-  if (UseLTO) {
-// This tells LTO to perform JustMyCode instrumentation.
-if (UseJMC)
-  AddCodeGenFlag("-enable-jmc-instrument");
-
-if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
-  AddCodeGenFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
+  // If the linker sees bitcode objects it will perform LTO. We can't tell
+  // 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 (UnifiedLTO)
+CmdArgs.push_back(D.getLTOMode() == LTOK_Thin ? "--lto=thin"
+  : "--lto=full");
+  if (UseJMC)
+AddLTOFlag("-enable-jmc-instrument");
 
-StringRef Parallelism = getLTOParallelism(Args, D);
-if (!Parallelism.empty())
-  AddCodeGenFlag(Twine("-threads=") + Parallelism);
+  if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
+AddLTOFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
 
-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?");
+  if (StringRef Threads = getLTOParallelism(Args, D); !Threads.empty())
+AddLTOFlag(Twine("-threads=") + Threads);
 
-CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + LTOArgs));
-  }
+  CmdArgs.push_back(Args.MakeArgString(Twine("-lto-debug-options=") + 
LTOArgs));

playstation-edd wrote:

Yes, the options from each are combined and fed into the same LTO API endpoint. 
There's a note in the commit message, but perhaps it's worth adding a comment 
here? OTOH, if you don't know about `-lto-thin-debug-options`, its absence 
obviously won't be noticed.

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


[clang] [PS4/PS5][Driver] Always pass LTO options to the linker (PR #100423)

2024-07-24 Thread Edd Dawson via cfe-commits


@@ -152,48 +152,38 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(Output.getFilename());
   }
 
-  const bool UseLTO = D.isUsingLTO();
   const bool UseJMC =
   Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false);
 
+  const bool UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,

playstation-edd wrote:

I believe that `hasArg(options::OPT_fno_unified_lto)` won't have last-one-wins 
behaviour. For example, `... -fno-unified-lto -funified-lto ...` would result 
in `UnifiedLTO` being set to `false`, incorrectly.

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


[clang] [PS4/PS5][Driver] Always pass LTO options to the linker (PR #100423)

2024-07-24 Thread Edd Dawson via cfe-commits

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

>From daa53d8cf7850a4bb11a7780410b969602138565 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 24 Jul 2024 16:39:09 +0100
Subject: [PATCH 1/3] [PS4/PS5][Driver] Always pass LTO options to the linker

The driver doesn't know if LTO will occur at link time. That's
determined by the presence or absence of LLVM bitcode objects among
those ingested by the linker.

For this reason, LTO options for codegen etc must be passed to the linker
unconditionally. If LTO does not occur, these options have no effect.

Also simplify the way LTO options are supplied to the PS4 linker.
`-lto-debug-options` and `-lto-thin-debug-options` are combined and
routed to the same place. So always use the former, regardless of
full/thin LTO mode.

SIE tracker: TOOLCHAIN-16575
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 83 +++---
 clang/test/Driver/lto-jobs.c   |  5 +-
 clang/test/Driver/ps4-linker.c | 18 +++---
 clang/test/Driver/ps5-linker.c | 10 ++--
 clang/test/Driver/unified-lto.c| 23 ++-
 5 files changed, 74 insertions(+), 65 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index d6af9388e54a6..958fec5b96361 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -152,48 +152,38 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(Output.getFilename());
   }
 
-  const bool UseLTO = D.isUsingLTO();
   const bool UseJMC =
   Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false);
 
+  const bool UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
+   options::OPT_fno_unified_lto, true);
+
   const char *LTOArgs = "";
-  auto AddCodeGenFlag = [&](Twine Flag) {
+  auto AddLTOFlag = [&](Twine Flag) {
 LTOArgs = Args.MakeArgString(Twine(LTOArgs) + " " + Flag);
   };
 
-  if (UseLTO) {
-// This tells LTO to perform JustMyCode instrumentation.
-if (UseJMC)
-  AddCodeGenFlag("-enable-jmc-instrument");
-
-if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
-  AddCodeGenFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
+  // If the linker sees bitcode objects it will perform LTO. We can't tell
+  // 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 (UnifiedLTO)
+CmdArgs.push_back(D.getLTOMode() == LTOK_Thin ? "--lto=thin"
+  : "--lto=full");
+  if (UseJMC)
+AddLTOFlag("-enable-jmc-instrument");
 
-StringRef Parallelism = getLTOParallelism(Args, D);
-if (!Parallelism.empty())
-  AddCodeGenFlag(Twine("-threads=") + Parallelism);
+  if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
+AddLTOFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
 
-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?");
+  if (StringRef Threads = getLTOParallelism(Args, D); !Threads.empty())
+AddLTOFlag(Twine("-threads=") + Threads);
 
-CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + LTOArgs));
-  }
+  CmdArgs.push_back(Args.MakeArgString(Twine("-lto-debug-options=") + 
LTOArgs));
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
-  if (D.isUsingLTO() && Args.hasArg(options::OPT_funified_lto)) {
-if (D.getLTOMode() == LTOK_Thin)
-  CmdArgs.push_back("--lto=thin");
-else if (D.getLTOMode() == LTOK_Full)
-  CmdArgs.push_back("--lto=full");
-  }
-
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
 
@@ -259,37 +249,36 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(Output.getFilename());
   }
 
-  const bool UseLTO = D.isUsingLTO();
   const bool UseJMC =
   Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false);
 
-  auto AddCodeGenFlag = [&](Twine Flag) {
+  const bool UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
+   options::OPT_fno_unified_lto, true);
+
+  auto AddLTOFlag = [&](Twine Flag) {
 CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=") + Flag));
   };
 
-  if (UseLTO) {
-// This tells LTO to perform JustMyCode instrumentation.
-if (UseJMC)
-  AddCodeGenFlag("-enable-jmc-instrument");
+  // If the linker sees bitcode objects it will perform LTO. We can't tell
+  // whether or not that will be the case at this point. So unconditionally
+  

[clang] [PS4/PS5][Driver] Always pass LTO options to the linker (PR #100423)

2024-07-24 Thread Edd Dawson via cfe-commits


@@ -152,48 +152,38 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(Output.getFilename());
   }
 
-  const bool UseLTO = D.isUsingLTO();
   const bool UseJMC =
   Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false);
 
+  const bool UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,

playstation-edd wrote:

> This variable is only used once in both functions. You could simplify and 
> just test for the flag in the if expression.

I have done this - thanks!



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


[clang] [PS4/PS5][Driver] Always pass LTO options to the linker (PR #100423)

2024-07-25 Thread Edd Dawson via cfe-commits

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


[clang] [PS5][Driver] Ensure stack sizes are emitted by LTO (PR #100592)

2024-07-25 Thread Edd Dawson via cfe-commits

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

... when requested.

Upstreaming a private patch.

SIE tracker: TOOLCHAIN-16575

>From cc1cbf728c0e7aa13260af2101c0e312ae81 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 25 Jul 2024 16:58:57 +0100
Subject: [PATCH] [PS5][Driver] Ensure stack sizes are emitted by LTO

... when requested.

Upstreaming a private patch.

SIE tracker: TOOLCHAIN-16575
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 4 
 clang/test/Driver/stack-size-section.c | 1 +
 2 files changed, 5 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 813a0fbedd2b1..f883f29f0c8ca 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -266,6 +266,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (UseJMC)
 AddLTOFlag("-enable-jmc-instrument");
 
+  if (Args.hasFlag(options::OPT_fstack_size_section,
+   options::OPT_fno_stack_size_section, false))
+AddLTOFlag("-stack-size-section");
+
   if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
 AddLTOFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
 
diff --git a/clang/test/Driver/stack-size-section.c 
b/clang/test/Driver/stack-size-section.c
index 71b9f85692b99..7cd41e491a817 100644
--- a/clang/test/Driver/stack-size-section.c
+++ b/clang/test/Driver/stack-size-section.c
@@ -14,6 +14,7 @@
 
 // RUN: %clang -### --target=x86_64-linux-gnu -flto -fstack-size-section %s 
2>&1 | FileCheck %s --check-prefix=LTO
 // RUN: %clang -### --target=x86_64-linux-gnu -flto -fstack-size-section 
-fno-stack-size-section %s 2>&1 | FileCheck %s --check-prefix=LTO-NO
+// RUN: %clang -### --target=x86_64-sie-ps5 -fstack-size-section %s 2>&1 | 
FileCheck %s --check-prefix=LTO
 
 // LTO: "-plugin-opt=-stack-size-section"
 // LTO-NO-NOT: "-plugin-opt=-stack-size-section"

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


[clang] [PS5][Driver] Ensure stack sizes are emitted by LTO (PR #100592)

2024-07-26 Thread Edd Dawson via cfe-commits

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


[clang] [PS4/PS5][Driver] Allow unified-lto.c test to find .*ld.exe (PR #101034)

2024-07-29 Thread Edd Dawson via cfe-commits

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

It's common in SIE development environments to have the PlayStation linkers on 
the %PATH%. In such cases, the driver will resolve the linker name to an 
existing executable, replete with ".exe" extension. Update recent modifications 
to clang/test/Driver/unified-lto.c to allow for this.

>From a47358588bd9c16b1a47bc2091e58e1f627dfb29 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Mon, 29 Jul 2024 16:51:16 +0100
Subject: [PATCH] [PS4/PS5][Driver] Allow unified-lto.c test to find .*ld.exe

It's common in SIE development environments to have the PlayStation
linkers on the %PATH%. In such cases, the driver will resolve the linker
name to an existing executable, replete with ".exe" extension. Update
recent modifications to clang/test/Driver/unified-lto.c to allow for
this.
---
 clang/test/Driver/unified-lto.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/unified-lto.c b/clang/test/Driver/unified-lto.c
index 490aaca59939d..445ca0bbf14f1 100644
--- a/clang/test/Driver/unified-lto.c
+++ b/clang/test/Driver/unified-lto.c
@@ -27,7 +27,7 @@
 // RUN: %clang --target=x86_64-sie-ps5 -### %s -fno-unified-lto -flto=full 
2>&1 | FileCheck --check-prefixes=LD,NOLTO %s
 // RUN: %clang --target=x86_64-sie-ps5 -### %s -fno-unified-lto -flto=thin 
2>&1 | FileCheck --check-prefixes=LD,NOLTO %s
 
-// LD: {{.*ld}}"
+// LD: {{.*ld(\.exe)?}}"
 // LTOFULL-SAME: "--lto=full"
 // LTOTHIN-SAME: "--lto=thin"
 // NOLTO-NOT: "--lto

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


[clang] [PS4][Driver] Only pass -lto-debug-options to linker when necessary (PR #101202)

2024-07-30 Thread Edd Dawson via cfe-commits

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

The PS4 linker doesn't accept an empty LTO options string. Passing nothing is 
also consistent with other drivers.

SIE tracker: TOOLCHAIN-16575

>From 4ee96bd211de1c1499c1860988af1f8369e20d93 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Tue, 30 Jul 2024 17:22:42 +0100
Subject: [PATCH] [PS4][Driver] Only pass -lto-debug-options to linker when
 necessary

The PS4 linker doesn't accept an empty LTO options string. Passing
nothing is also consistent with other drivers.

SIE tracker: TOOLCHAIN-16575
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 4 +++-
 clang/test/Driver/ps4-linker.c | 5 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index f883f29f0c8ca..a9e612c44da06 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -177,7 +177,9 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (StringRef Threads = getLTOParallelism(Args, D); !Threads.empty())
 AddLTOFlag(Twine("-threads=") + Threads);
 
-  CmdArgs.push_back(Args.MakeArgString(Twine("-lto-debug-options=") + 
LTOArgs));
+  if (*LTOArgs)
+CmdArgs.push_back(
+Args.MakeArgString(Twine("-lto-debug-options=") + LTOArgs));
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
diff --git a/clang/test/Driver/ps4-linker.c b/clang/test/Driver/ps4-linker.c
index 449da3040e758..2a095d660bf36 100644
--- a/clang/test/Driver/ps4-linker.c
+++ b/clang/test/Driver/ps4-linker.c
@@ -16,3 +16,8 @@
 // RUN: %clang --target=x86_64-scei-ps4 -flto=full 
-fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-DIAG-LTO %s
 
 // CHECK-DIAG-LTO: "-lto-debug-options= -crash-diagnostics-dir=mydumps"
+
+// Test that -lto-debug-options is only supplied to the linker when necessary
+
+// RUN: %clang --target=x86_64-scei-ps4 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-LTO %s
+// CHECK-NO-LTO-NOT: -lto-debug-options

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


[clang] [PS4][Driver] Only pass -lto-debug-options to linker when necessary (PR #101202)

2024-07-30 Thread Edd Dawson via cfe-commits

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


[clang] [llvm] [PS4/PS5][Driver][DWARF] Always emit .debug_aranges for SCE tuning (PR #99629)

2024-07-19 Thread Edd Dawson via cfe-commits

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


[clang] [llvm] Revert "[PS4/PS5][Driver][DWARF] Always emit .debug_aranges for SCE t… (PR #99711)

2024-07-19 Thread Edd Dawson via cfe-commits

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

…uning (#99629)"

This reverts commit 22eb290a9696e2a3fd042096c61e35eca2fcce0c.

>From 9025e82a8b7a560963160ea2a3b180fdaf3fc1d4 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Fri, 19 Jul 2024 22:36:22 +0100
Subject: [PATCH] Revert "[PS4/PS5][Driver][DWARF] Always emit .debug_aranges
 for SCE tuning (#99629)"

This reverts commit 22eb290a9696e2a3fd042096c61e35eca2fcce0c.
---
 clang/lib/Driver/ToolChains/Clang.cpp |  7 ++--
 clang/lib/Driver/ToolChains/PS4CPU.cpp|  8 +
 clang/test/Driver/debug-options.c | 21 ++--
 clang/test/Driver/lto-jobs.c  |  2 +-
 clang/test/Driver/ps4-linker.c|  8 ++---
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp|  5 +--
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h  |  3 --
 .../DebugInfo/X86/debug-aranges-sce-tuning.ll | 33 ---
 8 files changed, 30 insertions(+), 57 deletions(-)
 delete mode 100644 llvm/test/DebugInfo/X86/debug-aranges-sce-tuning.ll

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index abe517f0f5dea..f7b987bf810c1 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4659,8 +4659,11 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, 
const llvm::Triple &T,
 
   // -gdwarf-aranges turns on the emission of the aranges section in the
   // backend.
-  if (const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges);
-  A && checkDebugInfoOption(A, Args, D, TC)) {
+  // Always enabled for SCE tuning.
+  bool NeedAranges = DebuggerTuning == llvm::DebuggerKind::SCE;
+  if (const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges))
+NeedAranges = checkDebugInfoOption(A, Args, D, TC) || NeedAranges;
+  if (NeedAranges) {
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back("-generate-arange-section");
   }
diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index d6af9388e54a6..974e486a0082b 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -162,6 +162,10 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   };
 
   if (UseLTO) {
+// We default to creating the arange section, but LTO does not. Enable it
+// here.
+AddCodeGenFlag("-generate-arange-section");
+
 // This tells LTO to perform JustMyCode instrumentation.
 if (UseJMC)
   AddCodeGenFlag("-enable-jmc-instrument");
@@ -268,6 +272,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   };
 
   if (UseLTO) {
+// We default to creating the arange section, but LTO does not. Enable it
+// here.
+AddCodeGenFlag("-generate-arange-section");
+
 // This tells LTO to perform JustMyCode instrumentation.
 if (UseJMC)
   AddCodeGenFlag("-enable-jmc-instrument");
diff --git a/clang/test/Driver/debug-options.c 
b/clang/test/Driver/debug-options.c
index 21785ba01cb41..0a665f7017d63 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -118,28 +118,27 @@
 // RUN: %clang_cl -### -c -Z7 -target x86_64-windows-msvc -- %s 2>&1 \
 // RUN: | FileCheck -check-prefix=G_NOTUNING %s
 
-// On the PS4/PS5, -g defaults to -gno-column-info. We default to always
-// generating the arange section, but keyed off SCE DebuggerTuning being in
-// play during codegen, instead of -generate-arange-section.
+// On the PS4/PS5, -g defaults to -gno-column-info, and we always generate the
+// arange section.
 // RUN: %clang -### -c %s -target x86_64-scei-ps4 2>&1 \
 // RUN: | FileCheck -check-prefix=NOG_PS %s
 // RUN: %clang -### -c %s -target x86_64-sie-ps5 2>&1 \
 // RUN: | FileCheck -check-prefix=NOG_PS %s
 /// PS4 will stay on v4 even if the generic default version changes.
 // RUN: %clang -### -c %s -g -target x86_64-scei-ps4 2>&1 \
-// RUN: | FileCheck 
-check-prefixes=G_DWARF4,G_SCE,NOCI,FWD_TMPL_PARAMS %s
+// RUN: | FileCheck 
-check-prefixes=G_DWARF4,GARANGE,G_SCE,NOCI,FWD_TMPL_PARAMS %s
 // RUN: %clang -### -c %s -g -target x86_64-sie-ps5 2>&1 \
-// RUN: | FileCheck 
-check-prefixes=G_DWARF5,G_SCE,NOCI,FWD_TMPL_PARAMS %s
+// RUN: | FileCheck 
-check-prefixes=G_DWARF5,GARANGE,G_SCE,NOCI,FWD_TMPL_PARAMS %s
 // RUN: %clang -### -c %s -g -gcolumn-info -target x86_64-scei-ps4 2>&1 \
 // RUN: | FileCheck -check-prefix=CI %s
 // RUN: %clang -### -c %s -gsce -target x86_64-unknown-linux 2>&1 \
 // RUN: | FileCheck -check-prefix=NOCI %s
 // RUN: %clang -### %s -g -flto=thin -target x86_64-scei-ps4 2>&1 \
-// RUN: | FileCheck -check-prefix=LDGARANGE %s
+// RUN: | FileCheck -check-prefix=SNLDTLTOGARANGE %s
 // RUN: %clang -### %s -g -flto=full -target x86_64-scei-ps4 2>&1 \
-// RUN: | FileCh

[clang] [llvm] Revert "[PS4/PS5][Driver][DWARF] Always emit .debug_aranges for SCE t… (PR #99711)

2024-07-19 Thread Edd Dawson via cfe-commits

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


[clang] [llvm] Revert "[PS4/PS5][Driver][DWARF] Always emit .debug_aranges for SCE t… (PR #99711)

2024-07-22 Thread Edd Dawson via cfe-commits

playstation-edd wrote:

Apologies - will do. For the record, there was a failure on builder 
llvm-clang-x86_64-sie-win. 
https://lab.llvm.org/buildbot/#/builders/46/builds/1956

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


[clang] [PS4,PS5][Driver] Check for absent SDK when -nostdlib/-nodefaultlibs (PR #107112)

2024-09-03 Thread Edd Dawson via cfe-commits

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

The PlayStation drivers emit warnings if it looks like SDK libraries are 
missing. Until this point, the check was skipped when either -nostdlib or 
-nodefaultlibs was supplied. I believe the idea is that if you aren't linking 
default libraries, you won't be in need of the SDK.

However, in a situation where these switches are supplied, users may still want 
to pass `-lSomeSDKLib` to the driver/linker with the expectation that 
libSomeSDKLib.a will be sourced from the SDK. That is, -nodefaultlibs and 
-nostdlib affect the libraries passed to the linker, but not the library search 
paths.

So this change removes -nostdlib/-nodefaultlibs from consideration when 
deciding whether or not to probe for the SDK's existence.

N.B. complete behaviour for -nostdlib and -nodefaultlibs is yet to be added to 
the PlayStation compiler drivers. Coming soon.

SIE tracker: TOOLCHAIN-16704

>From 7a8926985b35bffa133c1b9795d9f8dfeb6886fe Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Tue, 3 Sep 2024 13:58:56 +0100
Subject: [PATCH] [PS4,PS5][Driver] Check for absent SDK when
 -nostdlib/-nodefaultlibs

The PlayStation drivers emit warnings if it looks like SDK libraries are
missing. Until this point, the check was skipped when either -nostdlib
or -nodefaultlibs was supplied. I believe the idea is that if you aren't
linking default libraries, you won't be in need of the SDK.

However, in a situation where these switches are supplied, users may
still want to pass `-lSomeSDKLib` to the driver/linker with the
expectation that libSomeSDKLib.a will be sourced from the SDK. That is,
-nodefaultlibs and -nostdlib affect the libraries passed to the linker,
but not the library search paths.

So this change removes -nostdlib/-nodefaultlibs from consideration when
deciding whether or not to probe for the SDK's existence.

N.B. complete behaviour for -nostdlib and -nodefaultlibs is yet to be
added to the PlayStation compiler drivers. Coming soon.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp |  4 +---
 clang/test/Driver/ps4-sdk-root.c   |  8 ++--
 clang/test/Driver/ps5-sdk-root.c   | 10 +++---
 3 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 22103eb50803a5..54ec59e6398f85 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -354,9 +354,7 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
 
   SmallString<512> SDKLibDir(SDKRootDir);
   llvm::sys::path::append(SDKLibDir, "target/lib");
-  if (!Args.hasArg(options::OPT_nostdlib) &&
-  !Args.hasArg(options::OPT_nodefaultlibs) &&
-  !Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) &&
+  if (!Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) &&
   !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) &&
   !Args.hasArg(options::OPT_emit_ast) &&
   !llvm::sys::fs::exists(SDKLibDir)) {
diff --git a/clang/test/Driver/ps4-sdk-root.c b/clang/test/Driver/ps4-sdk-root.c
index e1a04522030c1e..3e02fa9fc3bc29 100644
--- a/clang/test/Driver/ps4-sdk-root.c
+++ b/clang/test/Driver/ps4-sdk-root.c
@@ -6,9 +6,8 @@
 
 // Check that PS4 clang doesn't report a warning message when locating
 // system libraries (either by looking at the value of SCE_ORBIS_SDK_DIR
-// or relative to the location of the compiler driver), if "-c", "-S", "-E",
-// "--sysroot", "-nostdlib" or "-nodefaultlibs" option is specified on
-// the command line.
+// or relative to the location of the compiler driver), if "-c", "-S", "-E"
+// or "--sysroot" option is specified on the command line.
 // Otherwise, check that PS4 clang reports a warning.
 
 // Setting up SCE_ORBIS_SDK_DIR to existing location, which is not a PS4 SDK.
@@ -36,9 +35,6 @@
 // RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -emit-ast -isysroot foo -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-ISYSROOT -check-prefix=NO-WARN %s
 // RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### --sysroot=foo/ -isysroot foo -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-ISYSROOT -check-prefix=NO-WARN %s
 
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -nostdlib -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-SYS-HEADERS -check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -nodefaultlibs -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-SYS-HEADERS -check-prefix=NO-WARN %s
-
 // NO-WARN-NOT: {{warning:|error:}}
 // WARN-SYS-HEADERS: warning: unable to find PS4 system headers directory
 // WARN-ISYSROOT: warning: no such sysroot directory: 'foo'
diff --git a/clang/test/Driver/ps5-sdk-root.c b/cla

[clang] [PS4,PS5][Driver] Check for absent SDK when -nostdlib/-nodefaultlibs (PR #107112)

2024-09-03 Thread Edd Dawson via cfe-commits


@@ -36,9 +35,6 @@
 // RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -emit-ast -isysroot foo -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-ISYSROOT -check-prefix=NO-WARN %s
 // RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### --sysroot=foo/ -isysroot foo -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-ISYSROOT -check-prefix=NO-WARN %s
 
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -nostdlib -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-SYS-HEADERS -check-prefix=NO-WARN %s
-// RUN: env SCE_ORBIS_SDK_DIR=.. %clang -Winvalid-or-nonexistent-directory 
-### -nodefaultlibs -target x86_64-scei-ps4 %s 2>&1 | FileCheck 
-check-prefix=WARN-SYS-HEADERS -check-prefix=NO-WARN %s

playstation-edd wrote:

I generally favaour leaving the test as it would be if the code was like that 
in the first place, as it avoids indefinite accumulation. Assuming the commit 
goes in as thing stands, there's no more reason to check for interaction with 
`-nodefaultlibs` as there is for interaction with `-nolibc` (which the code 
ignores, currently). And so it also avoids hitches for the reader ("well _of 
course_ there's no interaction with xyz... why would be checking it?").

With any luck, near future changes will go on to implement complete behaviour 
for all these `-no...` switches for library control. At which point new 
affirmative checks will be introduced.

With my case made, I'm also content to amend if we want that.

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


[clang] [PS4,PS5][Driver] Check for absent SDK when -nostdlib/-nodefaultlibs (PR #107112)

2024-09-03 Thread Edd Dawson via cfe-commits

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


[clang] [PS4,PS5][Driver] Check for absent SDK when -nostdlib/-nodefaultlibs (PR #107112)

2024-09-03 Thread Edd Dawson via cfe-commits

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


[clang] [PS4/PS5][NFC] Split PScpu::Linker into PS4/PS5 classes (PR #98884)

2024-07-15 Thread Edd Dawson via cfe-commits

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

It has long been the case on PlayStation that the linker itself has taken on 
much of the responsibility that is traditionally the domain of the C language 
driver elsewhere: which linker script to use, selection of CRT objects, and so 
forth.

This is changing on PS5. The driver will assume responsibility for such things. 
However, the situation on PS4 will remain as-is. To accommodate this 
divergence, we must first separate how linker Jobs are created. 
`clang/test/Driver/ps4-linker.c` has been similarly split for related reasons.

In subsequent changes, PS5-specific linking behaviour can be moved from SIE 
private patches in the PS5 linker to the (upstream) driver without affecting 
the behaviour or implementation of PS4.

>From 4df230295ee6e277b4614cb8c5ecb70b048eb74f Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Mon, 15 Jul 2024 10:57:28 +0100
Subject: [PATCH] [PS4/PS5][NFC] Split PScpu::Linker into PS4/PS5 classes

It has long been the case on PlayStation that the linker itself has
taken on much of the responsibility that is traditionally the domain of
the C language driver elsewhere: which linker script to use, selection
of CRT objects, and so forth.

This is changing on PS5. The driver will assume responsibility for such
things. However, the situation on PS4 will remain as-is. To accommodate
this divergence, we must first separate how linker Jobs are created.
`clang/test/Driver/ps4-linker.c` has been similarly split for related
reasons.

In subsequent changes, PS5-specific linking behaviour can be moved from
SIE private patches in the PS5 linker to the (upstream) driver without
affecting the behaviour or implementation of PS4.
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 159 +++--
 clang/lib/Driver/ToolChains/PS4CPU.h   |  27 -
 clang/test/Driver/ps4-linker.c |  20 
 clang/test/Driver/ps4-ps5-linker.c |  29 -
 clang/test/Driver/ps5-linker.c |  18 +++
 5 files changed, 185 insertions(+), 68 deletions(-)
 create mode 100644 clang/test/Driver/ps4-linker.c
 delete mode 100644 clang/test/Driver/ps4-ps5-linker.c
 create mode 100644 clang/test/Driver/ps5-linker.c

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 3fd62d9793093..974e486a0082b 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -118,11 +118,11 @@ void toolchains::PS5CPU::addSanitizerArgs(const ArgList 
&Args,
 CmdArgs.push_back(arg("SceThreadSanitizer_nosubmission_stub_weak"));
 }
 
-void tools::PScpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
-const InputInfo &Output,
-const InputInfoList &Inputs,
-const ArgList &Args,
-const char *LinkingOutput) const {
+void tools::PS4cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
+ const InputInfo &Output,
+ const InputInfoList &Inputs,
+ const ArgList &Args,
+ const char *LinkingOutput) const {
   auto &TC = static_cast(getToolChain());
   const Driver &D = TC.getDriver();
   ArgStringList CmdArgs;
@@ -155,14 +155,120 @@ void tools::PScpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   const bool UseLTO = D.isUsingLTO();
   const bool UseJMC =
   Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false);
-  const bool IsPS4 = TC.getTriple().isPS4();
 
-  const char *PS4LTOArgs = "";
+  const char *LTOArgs = "";
   auto AddCodeGenFlag = [&](Twine Flag) {
-if (IsPS4)
-  PS4LTOArgs = Args.MakeArgString(Twine(PS4LTOArgs) + " " + Flag);
+LTOArgs = Args.MakeArgString(Twine(LTOArgs) + " " + Flag);
+  };
+
+  if (UseLTO) {
+// We default to creating the arange section, but LTO does not. Enable it
+// here.
+AddCodeGenFlag("-generate-arange-section");
+
+// This tells LTO to perform JustMyCode instrumentation.
+if (UseJMC)
+  AddCodeGenFlag("-enable-jmc-instrument");
+
+if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
+  AddCodeGenFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
+
+StringRef Parallelism = getLTOParallelism(Args, D);
+if (!Parallelism.empty())
+  AddCodeGenFlag(Twine("-threads=") + Parallelism);
+
+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
-  CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=") + Flag));
+  llvm_unreachable("new LTO mode?");
+
+CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + LTOArgs));
+  }
+
+  if 

[clang] [PS4/PS5][NFC] Split PScpu::Linker into PS4/PS5 classes (PR #98884)

2024-07-15 Thread Edd Dawson via cfe-commits

playstation-edd wrote:

> If you wish to, you can add reviewers by using the "Reviewers" section on 
> this page.
> 
> If this is not working for you, it is probably because you do not have write 
> permissions for the repository. In which case you can instead tag reviewers 
> by name in a comment by using `@` followed by their GitHub username.

Tagging @pogo59 for review.

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


[clang] [PS4/PS5][NFC] Split PScpu::Linker into PS4/PS5 classes (PR #98884)

2024-07-15 Thread Edd Dawson via cfe-commits

playstation-edd wrote:

> Looks like you don't have write permission so I'll merge it for you.

Thanks!

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


[clang] [PS4/PS5][Driver] Allow -static in PlayStation drivers (PR #102020)

2024-08-05 Thread Edd Dawson via cfe-commits

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

On PlayStation, allow users to supply -static to the linker, via the driver.

An initial step. Later changes will have the PS5 driver supply additional 
options to the linker, if and when -static is passed.

SIE tracker: TOOLCHAIN-16704

>From aa97906cdf1ac08e0b5d607914c28dcb2bbc2545 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Mon, 5 Aug 2024 17:42:55 +0100
Subject: [PATCH] [PS4/PS5][Driver] Allow -static in PlayStation drivers

On PlayStation, allow users to supply -static to the linker, via the
driver.

An initial step. Later changes will have the PS5 driver supply
additional options to the linker, if and when -static is passed.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 9 +
 clang/test/Driver/ps4-linker.c | 7 +++
 clang/test/Driver/ps4-pic.c| 9 -
 clang/test/Driver/ps5-linker.c | 7 +++
 clang/test/Driver/ps5-pic.c| 9 -
 5 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index a9e612c44da06..3da9a280fd129 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -141,6 +141,9 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
 
+
+  if (Args.hasArg(options::OPT_static))
+CmdArgs.push_back("--static");
   if (Args.hasArg(options::OPT_rdynamic))
 CmdArgs.push_back("-export-dynamic");
   if (Args.hasArg(options::OPT_shared))
@@ -238,6 +241,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
 
+  if (Args.hasArg(options::OPT_static))
+CmdArgs.push_back("--static");
   if (Args.hasArg(options::OPT_rdynamic))
 CmdArgs.push_back("-export-dynamic");
   if (Args.hasArg(options::OPT_shared))
@@ -316,10 +321,6 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
const ArgList &Args, StringRef Platform,
const char *EnvVar)
 : Generic_ELF(D, Triple, Args) {
-  if (Args.hasArg(clang::driver::options::OPT_static))
-D.Diag(clang::diag::err_drv_unsupported_opt_for_target)
-<< "-static" << Platform;
-
   // Determine where to find the PS4/PS5 libraries.
   // If -isysroot was passed, use that as the SDK base path.
   // If not, we use the EnvVar if it exists; otherwise use the driver's
diff --git a/clang/test/Driver/ps4-linker.c b/clang/test/Driver/ps4-linker.c
index 2a095d660bf36..47a515158fe81 100644
--- a/clang/test/Driver/ps4-linker.c
+++ b/clang/test/Driver/ps4-linker.c
@@ -1,3 +1,10 @@
+// Test that -static is forwarded to the linker
+
+// RUN: %clang --target=x86_64-scei-ps4 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-STATIC %s
+
+// CHECK-STATIC: {{ld(\.exe)?}}"
+// CHECK-STATIC-SAME: "--static"
+
 // Test the driver's control over the JustMyCode behavior with linker flags.
 
 // RUN: %clang --target=x86_64-scei-ps4 -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LTO,CHECK-LIB %s
diff --git a/clang/test/Driver/ps4-pic.c b/clang/test/Driver/ps4-pic.c
index 0551a79cc1258..3072f379d13c6 100644
--- a/clang/test/Driver/ps4-pic.c
+++ b/clang/test/Driver/ps4-pic.c
@@ -23,8 +23,6 @@
 // CHECK-DIAG-PIE: option '-fno-PIE' was ignored by the PS4 toolchain, using 
'-fPIC'
 // CHECK-DIAG-pic: option '-fno-pic' was ignored by the PS4 toolchain, using 
'-fPIC'
 // CHECK-DIAG-pie: option '-fno-pie' was ignored by the PS4 toolchain, using 
'-fPIC'
-//
-// CHECK-STATIC-ERR: unsupported option '-static' for target 'PS4'
 
 // RUN: %clang -c %s -target x86_64-scei-ps4 -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
@@ -79,9 +77,10 @@
 // RUN: not %clang -c %s --target=x86_64-scei-ps4 -mdynamic-no-pic -fPIC -### 
2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC2
 //
-// -static not supported at all.
-// RUN: not %clang -c %s --target=x86_64-scei-ps4 -static -### 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=CHECK-STATIC-ERR
+// The -static argument *doesn't* override PIC: -static only affects
+// linking, and -fPIC only affects code generation.
+// RUN: %clang -c %s -target x86_64-scei-ps4 -static -fPIC -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
 //
 // -fno-PIC etc. is obeyed if -mcmodel=kernel is also present.
 // RUN: %clang -c %s -target x86_64-scei-ps4 -mcmodel=kernel -fno-PIC -### 
2>&1 \
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index cf39d5bae97ac..01c0e20f970ed 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -1,3 +1,10 @@
+// Test that -static is forwarded to the linker
+
+// RUN: %clang --target=x86_64-scei-ps5

[clang] [PS4/PS5][Driver] Allow -static in PlayStation drivers (PR #102020)

2024-08-06 Thread Edd Dawson via cfe-commits

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

>From aa97906cdf1ac08e0b5d607914c28dcb2bbc2545 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Mon, 5 Aug 2024 17:42:55 +0100
Subject: [PATCH 1/2] [PS4/PS5][Driver] Allow -static in PlayStation drivers

On PlayStation, allow users to supply -static to the linker, via the
driver.

An initial step. Later changes will have the PS5 driver supply
additional options to the linker, if and when -static is passed.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 9 +
 clang/test/Driver/ps4-linker.c | 7 +++
 clang/test/Driver/ps4-pic.c| 9 -
 clang/test/Driver/ps5-linker.c | 7 +++
 clang/test/Driver/ps5-pic.c| 9 -
 5 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index a9e612c44da06..3da9a280fd129 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -141,6 +141,9 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
 
+
+  if (Args.hasArg(options::OPT_static))
+CmdArgs.push_back("--static");
   if (Args.hasArg(options::OPT_rdynamic))
 CmdArgs.push_back("-export-dynamic");
   if (Args.hasArg(options::OPT_shared))
@@ -238,6 +241,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
 
+  if (Args.hasArg(options::OPT_static))
+CmdArgs.push_back("--static");
   if (Args.hasArg(options::OPT_rdynamic))
 CmdArgs.push_back("-export-dynamic");
   if (Args.hasArg(options::OPT_shared))
@@ -316,10 +321,6 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
const ArgList &Args, StringRef Platform,
const char *EnvVar)
 : Generic_ELF(D, Triple, Args) {
-  if (Args.hasArg(clang::driver::options::OPT_static))
-D.Diag(clang::diag::err_drv_unsupported_opt_for_target)
-<< "-static" << Platform;
-
   // Determine where to find the PS4/PS5 libraries.
   // If -isysroot was passed, use that as the SDK base path.
   // If not, we use the EnvVar if it exists; otherwise use the driver's
diff --git a/clang/test/Driver/ps4-linker.c b/clang/test/Driver/ps4-linker.c
index 2a095d660bf36..47a515158fe81 100644
--- a/clang/test/Driver/ps4-linker.c
+++ b/clang/test/Driver/ps4-linker.c
@@ -1,3 +1,10 @@
+// Test that -static is forwarded to the linker
+
+// RUN: %clang --target=x86_64-scei-ps4 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-STATIC %s
+
+// CHECK-STATIC: {{ld(\.exe)?}}"
+// CHECK-STATIC-SAME: "--static"
+
 // Test the driver's control over the JustMyCode behavior with linker flags.
 
 // RUN: %clang --target=x86_64-scei-ps4 -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LTO,CHECK-LIB %s
diff --git a/clang/test/Driver/ps4-pic.c b/clang/test/Driver/ps4-pic.c
index 0551a79cc1258..3072f379d13c6 100644
--- a/clang/test/Driver/ps4-pic.c
+++ b/clang/test/Driver/ps4-pic.c
@@ -23,8 +23,6 @@
 // CHECK-DIAG-PIE: option '-fno-PIE' was ignored by the PS4 toolchain, using 
'-fPIC'
 // CHECK-DIAG-pic: option '-fno-pic' was ignored by the PS4 toolchain, using 
'-fPIC'
 // CHECK-DIAG-pie: option '-fno-pie' was ignored by the PS4 toolchain, using 
'-fPIC'
-//
-// CHECK-STATIC-ERR: unsupported option '-static' for target 'PS4'
 
 // RUN: %clang -c %s -target x86_64-scei-ps4 -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
@@ -79,9 +77,10 @@
 // RUN: not %clang -c %s --target=x86_64-scei-ps4 -mdynamic-no-pic -fPIC -### 
2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC2
 //
-// -static not supported at all.
-// RUN: not %clang -c %s --target=x86_64-scei-ps4 -static -### 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=CHECK-STATIC-ERR
+// The -static argument *doesn't* override PIC: -static only affects
+// linking, and -fPIC only affects code generation.
+// RUN: %clang -c %s -target x86_64-scei-ps4 -static -fPIC -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
 //
 // -fno-PIC etc. is obeyed if -mcmodel=kernel is also present.
 // RUN: %clang -c %s -target x86_64-scei-ps4 -mcmodel=kernel -fno-PIC -### 
2>&1 \
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index cf39d5bae97ac..01c0e20f970ed 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -1,3 +1,10 @@
+// Test that -static is forwarded to the linker
+
+// RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-STATIC %s
+
+// CHECK-STATIC: {{ld(\.exe)?}}"
+// CHECK-STATIC-SAME: "--static"
+
 // Test the driver's control over the JustMyCode behavior with linker flags.
 
 // RUN: %clan

[clang] [PS4/PS5][Driver] Allow -static in PlayStation drivers (PR #102020)

2024-08-06 Thread Edd Dawson via cfe-commits

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

>From aa97906cdf1ac08e0b5d607914c28dcb2bbc2545 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Mon, 5 Aug 2024 17:42:55 +0100
Subject: [PATCH 1/3] [PS4/PS5][Driver] Allow -static in PlayStation drivers

On PlayStation, allow users to supply -static to the linker, via the
driver.

An initial step. Later changes will have the PS5 driver supply
additional options to the linker, if and when -static is passed.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 9 +
 clang/test/Driver/ps4-linker.c | 7 +++
 clang/test/Driver/ps4-pic.c| 9 -
 clang/test/Driver/ps5-linker.c | 7 +++
 clang/test/Driver/ps5-pic.c| 9 -
 5 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index a9e612c44da06..3da9a280fd129 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -141,6 +141,9 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
 
+
+  if (Args.hasArg(options::OPT_static))
+CmdArgs.push_back("--static");
   if (Args.hasArg(options::OPT_rdynamic))
 CmdArgs.push_back("-export-dynamic");
   if (Args.hasArg(options::OPT_shared))
@@ -238,6 +241,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
 
+  if (Args.hasArg(options::OPT_static))
+CmdArgs.push_back("--static");
   if (Args.hasArg(options::OPT_rdynamic))
 CmdArgs.push_back("-export-dynamic");
   if (Args.hasArg(options::OPT_shared))
@@ -316,10 +321,6 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
const ArgList &Args, StringRef Platform,
const char *EnvVar)
 : Generic_ELF(D, Triple, Args) {
-  if (Args.hasArg(clang::driver::options::OPT_static))
-D.Diag(clang::diag::err_drv_unsupported_opt_for_target)
-<< "-static" << Platform;
-
   // Determine where to find the PS4/PS5 libraries.
   // If -isysroot was passed, use that as the SDK base path.
   // If not, we use the EnvVar if it exists; otherwise use the driver's
diff --git a/clang/test/Driver/ps4-linker.c b/clang/test/Driver/ps4-linker.c
index 2a095d660bf36..47a515158fe81 100644
--- a/clang/test/Driver/ps4-linker.c
+++ b/clang/test/Driver/ps4-linker.c
@@ -1,3 +1,10 @@
+// Test that -static is forwarded to the linker
+
+// RUN: %clang --target=x86_64-scei-ps4 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-STATIC %s
+
+// CHECK-STATIC: {{ld(\.exe)?}}"
+// CHECK-STATIC-SAME: "--static"
+
 // Test the driver's control over the JustMyCode behavior with linker flags.
 
 // RUN: %clang --target=x86_64-scei-ps4 -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LTO,CHECK-LIB %s
diff --git a/clang/test/Driver/ps4-pic.c b/clang/test/Driver/ps4-pic.c
index 0551a79cc1258..3072f379d13c6 100644
--- a/clang/test/Driver/ps4-pic.c
+++ b/clang/test/Driver/ps4-pic.c
@@ -23,8 +23,6 @@
 // CHECK-DIAG-PIE: option '-fno-PIE' was ignored by the PS4 toolchain, using 
'-fPIC'
 // CHECK-DIAG-pic: option '-fno-pic' was ignored by the PS4 toolchain, using 
'-fPIC'
 // CHECK-DIAG-pie: option '-fno-pie' was ignored by the PS4 toolchain, using 
'-fPIC'
-//
-// CHECK-STATIC-ERR: unsupported option '-static' for target 'PS4'
 
 // RUN: %clang -c %s -target x86_64-scei-ps4 -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
@@ -79,9 +77,10 @@
 // RUN: not %clang -c %s --target=x86_64-scei-ps4 -mdynamic-no-pic -fPIC -### 
2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC2
 //
-// -static not supported at all.
-// RUN: not %clang -c %s --target=x86_64-scei-ps4 -static -### 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=CHECK-STATIC-ERR
+// The -static argument *doesn't* override PIC: -static only affects
+// linking, and -fPIC only affects code generation.
+// RUN: %clang -c %s -target x86_64-scei-ps4 -static -fPIC -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
 //
 // -fno-PIC etc. is obeyed if -mcmodel=kernel is also present.
 // RUN: %clang -c %s -target x86_64-scei-ps4 -mcmodel=kernel -fno-PIC -### 
2>&1 \
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index cf39d5bae97ac..01c0e20f970ed 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -1,3 +1,10 @@
+// Test that -static is forwarded to the linker
+
+// RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-STATIC %s
+
+// CHECK-STATIC: {{ld(\.exe)?}}"
+// CHECK-STATIC-SAME: "--static"
+
 // Test the driver's control over the JustMyCode behavior with linker flags.
 
 // RUN: %clan

[clang] [PS4/PS5][Driver] Allow -static in PlayStation drivers (PR #102020)

2024-08-06 Thread Edd Dawson via cfe-commits


@@ -141,6 +141,9 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
 
+

playstation-edd wrote:

Oops - thanks. Removed.

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


[clang] [PS4/PS5][Driver] Allow -static in PlayStation drivers (PR #102020)

2024-08-06 Thread Edd Dawson via cfe-commits


@@ -141,6 +141,9 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
 
+
+  if (Args.hasArg(options::OPT_static))
+CmdArgs.push_back("--static");

playstation-edd wrote:

> The linker option is almost always spelled as `-static`.

I have changed this.
FWIW, I took my cue from the `--help` of ld.lld, assuming it would be a 
suitable authority.

> Gnu.cpp:437 
> ([ae623d1](https://github.com/llvm/llvm-project/commit/ae623d16d50c9f12de7ae7ac1aa11c9d6857e081))
>  demonstrates how these options work on Linux

Over coming changes we'll evolve to something more like that, but not exactly. 
The users of `-static` on PlayStation are a small, distinct group, internal to 
SIE. Over the last decade or so `-static` has - for better or worse - evolved 
into something very particular, here. Once all the functionality that should be 
in the PS driver is actually here, there's perhaps a chance that it can be 
rationalized.

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


[clang] [PS5][Driver] Link main components with -pie by default (PR #102901)

2024-08-21 Thread Edd Dawson via cfe-commits

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

>From 0ca2239d21cb414ce5e6fb9057d442c18f61a32e Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Mon, 12 Aug 2024 14:11:11 +0100
Subject: [PATCH 1/3] [PS5][Driver] Link main components with -pie by default

The PS5 linker currently forces `-pie` for typical link jobs. Have the
driver pass `pie` under the same conditions. With this change we can
remove our private linker patch and also allow `-no-pie` to have an
effect.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp |  5 -
 clang/test/Driver/ps5-linker.c | 15 +++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 0175b5eb63e657..73f4c4e2fc7a49 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -237,7 +237,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (Args.hasArg(options::OPT_pie))
+  // Default to PIE for non-static main components.
+  const bool PIE =
+  !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
+  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
 CmdArgs.push_back("-pie");
 
   if (Args.hasArg(options::OPT_static))
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95d64d9017be04..fb954b938c1ab9 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -1,3 +1,18 @@
+// Test that PIE is the default for main components
+
+// RUN: %clang --target=x86_64-scei-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PIE %s
+
+// CHECK-PIE: {{ld(\.exe)?}}"
+// CHECK-PIE-SAME: "-pie"
+
+// RUN: %clang --target=x86_64-scei-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+
+// CHECK-NO-PIE: {{ld(\.exe)?}}"
+// CHECK-NO-PIE-NOT: "-pie"
+
 // Test that -static is forwarded to the linker
 
 // RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-STATIC %s

>From b7ff265805d8f2c5e7cb22e8c7fd1440665599a8 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 21 Aug 2024 08:48:37 +0100
Subject: [PATCH 2/3] "main components" -> "executables"

---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 73f4c4e2fc7a49..22103eb50803a5 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -237,7 +237,7 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  // Default to PIE for non-static main components.
+  // Default to PIE for non-static executables.
   const bool PIE =
   !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
   if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))

>From 7280be4660df554541f0c700d943016ba2d2430d Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 21 Aug 2024 09:00:49 +0100
Subject: [PATCH 3/3] Add check for "--shared", along with lack of "-pie".

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

diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index fb954b938c1ab9..c462e5a178e4a6 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -7,11 +7,12 @@
 
 // RUN: %clang --target=x86_64-scei-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
 // RUN: %clang --target=x86_64-scei-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
-// RUN: %clang --target=x86_64-scei-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE,CHECK-SHARED %s
 // RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
 
 // CHECK-NO-PIE: {{ld(\.exe)?}}"
 // CHECK-NO-PIE-NOT: "-pie"
+// CHECK-SHARED: "--shared"
 
 // Test that -static is forwarded to the linker
 

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


[clang] [PS5][Driver] Link main components with -pie by default (PR #102901)

2024-08-21 Thread Edd Dawson via cfe-commits


@@ -237,7 +237,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (Args.hasArg(options::OPT_pie))
+  // Default to PIE for non-static main components.

playstation-edd wrote:

Done!

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


[clang] [PS5][Driver] Link main components with -pie by default (PR #102901)

2024-08-21 Thread Edd Dawson via cfe-commits


@@ -1,3 +1,18 @@
+// Test that PIE is the default for main components
+
+// RUN: %clang --target=x86_64-scei-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PIE %s
+
+// CHECK-PIE: {{ld(\.exe)?}}"
+// CHECK-PIE-SAME: "-pie"
+
+// RUN: %clang --target=x86_64-scei-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s

playstation-edd wrote:

Done!

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


[clang] [PS5][Driver] Link main components with -pie by default (PR #102901)

2024-08-21 Thread Edd Dawson via cfe-commits

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


[clang] [PS5][clang][test] x86_64-scei-ps5 -> x86_64-sie-ps5 in tests (PR #105810)

2024-08-23 Thread Edd Dawson via cfe-commits

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

`x86_64-sie-ps5` is the triple we share with PS5 toolchain users who have 
reason to care about such things. The vast majority of PS5 checks and tests 
already use this variant. Quashing the handful of stragglers will help prevent 
future copy+paste of the discouraged variant.

>From 497de2a1a1a03ae78a792634853166636bceb63c Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Fri, 23 Aug 2024 10:41:48 +0100
Subject: [PATCH] [PS5][clang][test] x86_64-scei-ps5 -> x86_64-sie-ps5 in tests

`x86_64-sie-ps5` is the triple we share with PS5 toolchain users who
have reason to care about such things. The vast majority of PS5 checks
and tests already use this variant. Quashing the handful of stragglers
will help prevent future copy+paste of the discouraged variant.
---
 clang/test/CodeGen/tls-maxalign-modflag.c |  2 +-
 .../CodeGenCXX/windows-itanium-init-guard.cpp |  6 +++---
 clang/test/Driver/debug-options.c |  4 ++--
 clang/test/Driver/ps5-linker.c| 20 +--
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/clang/test/CodeGen/tls-maxalign-modflag.c 
b/clang/test/CodeGen/tls-maxalign-modflag.c
index 685057c3551a00..26dde569f389c9 100644
--- a/clang/test/CodeGen/tls-maxalign-modflag.c
+++ b/clang/test/CodeGen/tls-maxalign-modflag.c
@@ -2,7 +2,7 @@
 
 // Test that we get the module flag TLSMaxAlign on the PS platforms.
 // RUN: %clang_cc1 -triple x86_64-scei-ps4 -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps5 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 -emit-llvm -o - %s | FileCheck %s
 
 int main(void) {
   return 0;
diff --git a/clang/test/CodeGenCXX/windows-itanium-init-guard.cpp 
b/clang/test/CodeGenCXX/windows-itanium-init-guard.cpp
index 8bcfd272ae8f16..c51ce470061d64 100644
--- a/clang/test/CodeGenCXX/windows-itanium-init-guard.cpp
+++ b/clang/test/CodeGenCXX/windows-itanium-init-guard.cpp
@@ -11,9 +11,9 @@
 // RUN: %clang_cc1 -emit-llvm -triple x86_64-scei-ps4 -fdeclspec %s -O1 
-disable-llvm-passes -o - -DAPI="__declspec(dllexport)" | FileCheck %s 
--check-prefixes=EXPORT
 // RUN: %clang_cc1 -emit-llvm -triple x86_64-scei-ps4 -fdeclspec %s -O1 
-disable-llvm-passes -o - -DAPI="__declspec(dllimport)" | FileCheck %s 
--check-prefixes=IMPORT
 
-// RUN: %clang_cc1 -emit-llvm -triple x86_64-scei-ps5 -fdeclspec %s -O1 
-disable-llvm-passes -o - -DAPI= | FileCheck %s --check-prefixes=NONE
-// RUN: %clang_cc1 -emit-llvm -triple x86_64-scei-ps5 -fdeclspec %s -O1 
-disable-llvm-passes -o - -DAPI="__declspec(dllexport)" | FileCheck %s 
--check-prefixes=EXPORT
-// RUN: %clang_cc1 -emit-llvm -triple x86_64-scei-ps5 -fdeclspec %s -O1 
-disable-llvm-passes -o - -DAPI="__declspec(dllimport)" | FileCheck %s 
--check-prefixes=IMPORT
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-sie-ps5 -fdeclspec %s -O1 
-disable-llvm-passes -o - -DAPI= | FileCheck %s --check-prefixes=NONE
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-sie-ps5 -fdeclspec %s -O1 
-disable-llvm-passes -o - -DAPI="__declspec(dllexport)" | FileCheck %s 
--check-prefixes=EXPORT
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-sie-ps5 -fdeclspec %s -O1 
-disable-llvm-passes -o - -DAPI="__declspec(dllimport)" | FileCheck %s 
--check-prefixes=IMPORT
 
 //NONE: @_ZZN3foo3GetEvE9Singleton = linkonce_odr {{(dso_local )?}}global
 //NONE: @_ZGVZN3foo3GetEvE9Singleton = linkonce_odr {{(dso_local )?}}global
diff --git a/clang/test/Driver/debug-options.c 
b/clang/test/Driver/debug-options.c
index 21785ba01cb410..73f2f402efa97a 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -138,9 +138,9 @@
 // RUN: | FileCheck -check-prefix=LDGARANGE %s
 // RUN: %clang -### %s -g -flto=full -target x86_64-scei-ps4 2>&1 \
 // RUN: | FileCheck -check-prefix=LDGARANGE %s
-// RUN: %clang -### %s -g -flto -target x86_64-scei-ps5 2>&1 \
+// RUN: %clang -### %s -g -flto -target x86_64-sie-ps5 2>&1 \
 // RUN: | FileCheck -check-prefix=LDGARANGE %s
-// RUN: %clang -### %s -g -target x86_64-scei-ps5 2>&1 \
+// RUN: %clang -### %s -g -target x86_64-sie-ps5 2>&1 \
 // RUN: | FileCheck -check-prefix=LDGARANGE %s
 
 // On the AIX, -g defaults to limited debug info.
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index c462e5a178e4a6..84363deb0337f7 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -1,14 +1,14 @@
 // Test that PIE is the default for main components
 
-// RUN: %clang --target=x86_64-scei-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PIE %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PIE %s
 
 // CHECK-PIE: {{ld(\.exe)?}}"
 // CHECK-PIE-SAME: "-pie"
 
-// RUN: %clang --target=x86_64-scei-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
-// RUN: %clang --targ

[clang] [PS5][clang][test] x86_64-scei-ps5 -> x86_64-sie-ps5 in tests (PR #105810)

2024-08-23 Thread Edd Dawson via cfe-commits

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


[clang] [PS5][Driver] Pass default -z options to PS5 linker (PR #113162)

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

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

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

PS5 only. These implementation of these behaviours will remain in the 
proprietary linker on PS4.

SIE tracker: TOOLCHAIN-16704

>From 0d931fb93485472e2e7263496eb6d2bc71a9ae73 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Mon, 21 Oct 2024 13:08:31 +0100
Subject: [PATCH] [PS5][Driver] Pass default -z options to PS5 linker

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

PS5 only. These implementation of these behaviours will remain in the
proprietary linker on PS4.

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

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 7c028f18c0308f..a6a3501394afae 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -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"
@@ -240,11 +242,32 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   CmdArgs.push_back(
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
-  // Default to PIE for non-static executables.
-  const bool PIE =
-  !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
-  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
-CmdArgs.push_back("-pie");
+  if (!Relocatable) {
+// Default to PIE for non-static executables.
+const bool PIE = !Args.hasArg(options::OPT_shared, options::OPT_static);
+if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
+  CmdArgs.push_back("-pie");
+
+// 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*=0x");
+CmdArgs.push_back("-z");
+CmdArgs.push_back(
+"dead-reloc-in-nonalloc=.debug_ranges=0xfffe");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_loc=0xfffe");
+  }
 
   if (Args.hasArg(options::OPT_static))
 CmdArgs.push_back("-static");
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 4ae65963e361aa..2b9e673c0a23e2 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -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*=0x"
+// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_ranges=0xfffe"
+// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffe"
+
+// 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

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


[clang] [PS5][Driver] Pass default -z options to PS5 linker (PR #113162)

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

playstation-edd wrote:

@pogo59 - I recall you expressed an interest in being subscribed to such PRs. 
Please do let me know if it gets tiresome!

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


[clang] [PS5][Driver] Pass default -z options to PS5 linker (PR #113162)

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

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

>From 0d931fb93485472e2e7263496eb6d2bc71a9ae73 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Mon, 21 Oct 2024 13:08:31 +0100
Subject: [PATCH 1/3] [PS5][Driver] Pass default -z options to PS5 linker

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

PS5 only. These implementation of these behaviours will remain in the
proprietary linker on PS4.

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

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 7c028f18c0308f..a6a3501394afae 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -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"
@@ -240,11 +242,32 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   CmdArgs.push_back(
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
-  // Default to PIE for non-static executables.
-  const bool PIE =
-  !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
-  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
-CmdArgs.push_back("-pie");
+  if (!Relocatable) {
+// Default to PIE for non-static executables.
+const bool PIE = !Args.hasArg(options::OPT_shared, options::OPT_static);
+if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
+  CmdArgs.push_back("-pie");
+
+// 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*=0x");
+CmdArgs.push_back("-z");
+CmdArgs.push_back(
+"dead-reloc-in-nonalloc=.debug_ranges=0xfffe");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_loc=0xfffe");
+  }
 
   if (Args.hasArg(options::OPT_static))
 CmdArgs.push_back("-static");
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 4ae65963e361aa..2b9e673c0a23e2 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -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*=0x"
+// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_ranges=0xfffe"
+// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffe"
+
+// 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

>From ec25e40d6cc54933b68eff780c972fd2592359d9 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Tue, 22 Oct 2024 10:45:35 +0100
Subject: [PATCH 2/3] Match `.debug_*` instead of `.debug*` in fallback
 pattern.

---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 2 +-
 clang/test/Driver/ps5-linker.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index a6a3501394afae..d8f340606a1768 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -261,7 +261,7 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 // 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*=0x");
+CmdAr

[clang] [PS5][Driver] Pass default -z options to PS5 linker (PR #113162)

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


@@ -240,11 +242,32 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   CmdArgs.push_back(
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
-  // Default to PIE for non-static executables.
-  const bool PIE =
-  !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
-  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
-CmdArgs.push_back("-pie");
+  if (!Relocatable) {
+// Default to PIE for non-static executables.
+const bool PIE = !Args.hasArg(options::OPT_shared, options::OPT_static);
+if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
+  CmdArgs.push_back("-pie");

playstation-edd wrote:

I have undone this part of the change. Thanks for spotting it.

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


[clang] [PS5][Driver] Pass default -z options to PS5 linker (PR #113162)

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


@@ -240,11 +242,32 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   CmdArgs.push_back(
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
-  // Default to PIE for non-static executables.
-  const bool PIE =
-  !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
-  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
-CmdArgs.push_back("-pie");
+  if (!Relocatable) {
+// Default to PIE for non-static executables.
+const bool PIE = !Args.hasArg(options::OPT_shared, options::OPT_static);
+if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
+  CmdArgs.push_back("-pie");

playstation-edd wrote:

The inclusion was deliberate. I took the opportunity to perform the check for 
`OPT_r` in one place. But I didn't spot the edge-case change in behaviour that 
you mention, forgetting that `hasArg()` had a side-effect - sorry!

Would we prefer that undo this bit and defer to a separate PR? Or update the 
final commit message and perhaps add a test case for the behaviour change?

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


[clang] [PS5][Driver] Pass default -z options to PS5 linker (PR #113162)

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

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


[clang] [PS5][Driver] Pass default -z options to PS5 linker (PR #113162)

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

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

>From 0d931fb93485472e2e7263496eb6d2bc71a9ae73 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Mon, 21 Oct 2024 13:08:31 +0100
Subject: [PATCH 1/2] [PS5][Driver] Pass default -z options to PS5 linker

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

PS5 only. These implementation of these behaviours will remain in the
proprietary linker on PS4.

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

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 7c028f18c0308f..a6a3501394afae 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -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"
@@ -240,11 +242,32 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   CmdArgs.push_back(
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
-  // Default to PIE for non-static executables.
-  const bool PIE =
-  !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
-  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
-CmdArgs.push_back("-pie");
+  if (!Relocatable) {
+// Default to PIE for non-static executables.
+const bool PIE = !Args.hasArg(options::OPT_shared, options::OPT_static);
+if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
+  CmdArgs.push_back("-pie");
+
+// 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*=0x");
+CmdArgs.push_back("-z");
+CmdArgs.push_back(
+"dead-reloc-in-nonalloc=.debug_ranges=0xfffe");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_loc=0xfffe");
+  }
 
   if (Args.hasArg(options::OPT_static))
 CmdArgs.push_back("-static");
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 4ae65963e361aa..2b9e673c0a23e2 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -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*=0x"
+// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_ranges=0xfffe"
+// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffe"
+
+// 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

>From ec25e40d6cc54933b68eff780c972fd2592359d9 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Tue, 22 Oct 2024 10:45:35 +0100
Subject: [PATCH 2/2] Match `.debug_*` instead of `.debug*` in fallback
 pattern.

---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 2 +-
 clang/test/Driver/ps5-linker.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index a6a3501394afae..d8f340606a1768 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -261,7 +261,7 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 // 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*=0x");
+CmdAr

[clang] [PS5][Driver] Pass default -z options to PS5 linker (PR #113162)

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

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


[clang] [PS4/PS5][Driver] Apply clang-format to PS4CPU.cpp (NFC) (PR #114038)

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

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

None

>From cb44afa8945af89dada57335eb410ba2fc802188 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Tue, 29 Oct 2024 11:52:43 +
Subject: [PATCH] [PS4/PS5][Driver] Apply clang-format to PS4CPU.cpp (NFC)

---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 719bba41436a57..9daafbe703f68e 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -430,8 +430,7 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
 }
 
 void toolchains::PS4PS5Base::AddClangSystemIncludeArgs(
-const ArgList &DriverArgs,
-ArgStringList &CC1Args) const {
+const ArgList &DriverArgs, ArgStringList &CC1Args) const {
   const Driver &D = getDriver();
 
   if (DriverArgs.hasArg(options::OPT_nostdinc))

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


[clang] [PS5][Driver] Pass default -z options to PS5 linker (PR #113162)

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

playstation-edd wrote:

Note to self: fix typo in comment on submission ("The~se~ implementation ...").

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


[clang] [PS5][Driver] Update default linking options for `-r` (PR #113595)

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

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

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

PS5 only. On PS4, the proprietary linker will continue to perform the 
equivalent behaviours itself.

SIE tracker: TOOLCHAIN-16704

>From 59d1ec471340f3781db5034d1fc0ee0b46e5f8f5 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 24 Oct 2024 10:15:16 +0100
Subject: [PATCH] [PS5][Driver] Update default linking options for `-r`

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

PS5 only. On PS4, the proprietary linker will continue to perform the
equivalent behaviours itself.

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

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index a50333223ff5c4..719bba41436a57 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -250,6 +250,20 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("-pie");
 
   if (!Relocatable) {
+CmdArgs.push_back("--eh-frame-hdr");
+CmdArgs.push_back("--hash-style=sysv");
+
+// Add a build-id by default to allow the PlayStation symbol server to
+// index the symbols. `uuid` is the cheapest fool-proof method.
+// (The non-determinism and alternative methods are noted in the downstream
+// PlayStation docs).
+CmdArgs.push_back("--build-id=uuid");
+
+// All references are expected to be resolved at static link time for both
+// executables and dynamic libraries. This has been the default linking
+// behaviour for numerous PlayStation generations.
+CmdArgs.push_back("--unresolved-symbols=report-all");
+
 // Lazy binding of PLTs is not supported on PlayStation. They are placed in
 // the RelRo segment.
 CmdArgs.push_back("-z");
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index d18309a650726d..2080f4dc91a7fb 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -14,21 +14,32 @@
 // 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_*=0x"
-// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_ranges=0xfffe"
-// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffe"
-
-// 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 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).
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-EXE %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck 
--check-prefixes=CHECK-EXE %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -static -### 2>&1 | FileCheck 
--check-prefixes=CHECK-EXE %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-EXE %s
+
+// CHECK-EXE: {{ld(\.exe)?}}"
+// CHECK-EXE-SAME: "--eh-frame-hdr"
+// CHECK-EXE-SAME: "--hash-style=sysv"
+// CHECK-EXE-SAME: "--build-id=uuid"
+// CHECK-EXE-SAME: "--unresolved-symbols=report-all"
+// CHECK-EXE-SAME: "-z" "now"
+// CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
+// 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"
+
+// CHECK-NO-EXE: {{ld(\.exe)?}}"
+// CHECK-NO-EXE-NOT: "--eh-frame-hdr"
+// CHECK-NO-EXE-NOT: "--hash-style
+// CHECK-NO-EXE-NOT: "--build-id
+// CHECK-NO-EXE-NOT: "--unresolved-symbols
+// CHECK-NO-EXE-NOT: "-z"
 
 // Test that -static is forwarded to the linker
 

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


[clang] [PS5][Driver] Update default linking options when `-r` omitted. (PR #113595)

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

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


[clang] [PS5][Driver] Pass a target emulation to the linker (PR #114060)

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

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

Until now, this has been hardcoded as a downstream patch in lld. Add it 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 61dda6647ffc73f836ddd8c4e15204eff6d2c53e Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Fri, 25 Oct 2024 14:10:10 +0100
Subject: [PATCH] [PS5][Driver] Pass a target emulation to the linker

Until now, this has been hardcoded as a downstream patch in lld. Add it
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 | 3 +++
 clang/test/Driver/ps5-linker.c | 7 +++
 2 files changed, 10 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 9daafbe703f68e..aaba95951c5060 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -241,6 +241,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
+  CmdArgs.push_back("-m");
+  CmdArgs.push_back("elf_x86_64_fbsd");
+
   CmdArgs.push_back(
   Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 2080f4dc91a7fb..5175d8dbca567a 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -1,3 +1,10 @@
+// Test that a target emulation is supplied to the linker
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-EMU %s
+
+// CHECK-EMU: {{ld(\.exe)?}}"
+// CHECK-EMU-SAME: "-m" "elf_x86_64_fbsd"
+
 // Test that PIE is the default for main components
 
 // RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PIE %s

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


[clang] [PS5][Driver] Update default linking options when `-r` omitted. (PR #113595)

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

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


[clang] [PS5][Driver] Supply default linker scripts (PR #114546)

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

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


[clang] [PS5][Driver] Pass `-z rodynamic` to the linker (PR #115009)

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

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

Until now, suppression of `DT_DEBUG` has been hardcoded as a downstream patch 
in lld. This can instead be achieved by passing `-z rodynamic`. Have the driver 
do this so that the private patch can be removed.

If the scope of lld's `-z rodynamic` is broadened (within reason) to do more in 
future, that's likely to be fine as `PT_DYNAMIC` isn't writable on PlayStation.

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

SIE tracker: TOOLCHAIN-16704

>From e171d531a2d39998e8e82dd5fbd96315c0581fd7 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Tue, 5 Nov 2024 14:51:36 +
Subject: [PATCH] [PS5][Driver] Pass `-z rodynamic` to the linker

Until now, suppression of `DT_DEBUG` has been hardcoded as a downstream
patch in lld. This can instead be achieved by passing `-z rodynamic`.
Have the driver do this so that the private patch can be removed.

If the scope of lld's `-z rodynamic` is broadened (within reason) to do
more in future, that's likely to be fine as `PT_DYNAMIC` isn't writable
on PlayStation.

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

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 4 
 clang/test/Driver/ps5-linker.c | 1 +
 2 files changed, 5 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index c5299d606f2386..261c136de782e7 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -277,6 +277,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("-z");
 CmdArgs.push_back("start-stop-visibility=hidden");
 
+// DT_DEBUG is not supported on PlayStation.
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rodynamic");
+
 CmdArgs.push_back("-z");
 CmdArgs.push_back("common-page-size=0x4000");
 
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 363c431b6937eb..8a0ade91871295 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -53,6 +53,7 @@
 // CHECK-EXE-SAME: "--unresolved-symbols=report-all"
 // CHECK-EXE-SAME: "-z" "now"
 // CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
+// CHECK-EXE-SAME: "-z" "rodynamic"
 // CHECK-EXE-SAME: "-z" "common-page-size=0x4000"
 // CHECK-EXE-SAME: "-z" "max-page-size=0x4000"
 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_*=0x"

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


[clang] [PS5][Driver] Pass `-z rodynamic` to the linker (PR #115009)

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

https://github.com/playstation-edd closed 
https://github.com/llvm/llvm-project/pull/115009
___
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


[clang] [PS5][Driver] Supply default linker scripts (PR #114546)

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

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

Until now, this has been hardcoded as a downstream patch in lld. Add it 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 2ac204256b19afc6cb954a9072e99da533ccc1e5 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Mon, 28 Oct 2024 14:28:39 +
Subject: [PATCH] [PS5][Driver] Supply default linker scripts

Until now, this has been hardcoded as a downstream patch in lld. Add it
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 | 10 ++
 clang/test/Driver/ps5-linker.c | 13 +
 2 files changed, 23 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 877cb4e7b1261f..c5299d606f2386 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -293,6 +293,16 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 "dead-reloc-in-nonalloc=.debug_ranges=0xfffe");
 CmdArgs.push_back("-z");
 CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_loc=0xfffe");
+
+// The PlayStation loader expects linked objects to be laid out in a
+// particular way. This is achieved by linker scripts that are supplied
+// with the SDK. The scripts are inside /target/lib, which is
+// added as a search path elsewhere.
+// "PRX" has long stood for "PlayStation Relocatable eXecutable".
+CmdArgs.push_back("--default-script");
+CmdArgs.push_back(Static   ? "static.script"
+  : Shared ? "prx.script"
+   : "main.script");
   }
 
   if (Static)
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 0fcc0f02f5a901..363c431b6937eb 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -66,6 +66,19 @@
 // CHECK-NO-EXE-NOT: "--unresolved-symbols
 // CHECK-NO-EXE-NOT: "-z"
 
+// Test that an appropriate linker script is supplied by the driver.
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-SCRIPT -DSCRIPT=main %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck 
--check-prefixes=CHECK-SCRIPT -DSCRIPT=prx %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -static -### 2>&1 | FileCheck 
--check-prefixes=CHECK-SCRIPT -DSCRIPT=static %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-SCRIPT %s
+
+// CHECK-SCRIPT: {{ld(\.exe)?}}"
+// CHECK-SCRIPT-SAME: "--default-script" "[[SCRIPT]].script"
+
+// CHECK-NO-SCRIPT: {{ld(\.exe)?}}"
+// CHECK-NO-SCRIPT-NOT: "--default-script"
+
 // 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

___
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 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] Query `OPT_r`/`OPT_shared`/`OPT_static` just once (NFC) (PR #113452)

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

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


[clang] [PS5][Driver] Query `OPT_r`/`OPT_shared`/`OPT_static` just once (NFC) (PR #113452)

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

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

None

>From 3552f590214267e5f81719d94c43be545e474cb3 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 23 Oct 2024 13:42:49 +0100
Subject: [PATCH] [PS5][Driver] Query `OPT_r`/`OPT_shared`/`OPT_static` just
 once (NFC)

---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 02b1e034c28789..a50333223ff5c4 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -230,6 +230,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   ArgStringList CmdArgs;
 
   const bool Relocatable = Args.hasArg(options::OPT_r);
+  const bool Shared = Args.hasArg(options::OPT_shared);
+  const bool Static = Args.hasArg(options::OPT_static);
 
   // Silence warning for "clang -g foo.o -o foo"
   Args.ClaimAllArgs(options::OPT_g_Group);
@@ -243,8 +245,7 @@ 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 =
-  !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
+  const bool PIE = !Relocatable && !Shared && !Static;
   if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
 CmdArgs.push_back("-pie");
 
@@ -270,11 +271,11 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_loc=0xfffe");
   }
 
-  if (Args.hasArg(options::OPT_static))
+  if (Static)
 CmdArgs.push_back("-static");
   if (Args.hasArg(options::OPT_rdynamic))
 CmdArgs.push_back("-export-dynamic");
-  if (Args.hasArg(options::OPT_shared))
+  if (Shared)
 CmdArgs.push_back("--shared");
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");

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


[clang] [PS5][Driver] Supply libraries and CRT objects to the linker (PR #115497)

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

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

>From 112e3e7ca9e3fd041fb0a1a0b7d97aa26740a908 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 7 Nov 2024 13:57:45 +
Subject: [PATCH 1/4] [PS5][Driver] Supply libraries and CRT objects to the
 linker

Until now, these have been hardcoded as a downstream patches in lld. Add
them to the driver so that the private patches 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 | 66 +-
 clang/test/Driver/ps5-linker.c | 59 ++-
 2 files changed, 113 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index df43da93d77555..79cb31d10cdf04 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -183,6 +183,7 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-lto-debug-options=") + LTOArgs));
 
+  // Sanitizer runtimes must be supplied before all other objects and libs.
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
@@ -358,9 +359,6 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (StringRef Jobs = getLTOParallelism(Args, D); !Jobs.empty())
 AddLTOFlag(Twine("jobs=") + Jobs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
-TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
-
   TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
@@ -368,17 +366,63 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
 CmdArgs.push_back("--no-demangle");
 
-  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+  // Sanitizer runtimes must be supplied before all other objects and libs.
+  if (!Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib))
+TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
-  if (Args.hasArg(options::OPT_pthread)) {
-CmdArgs.push_back("-lpthread");
+  const bool AddStartFiles =
+  !Relocatable &&
+  !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib);
+
+  auto AddCRTObject = [&](const char *Name) {
+CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(Name)));
+  };
+
+  if (AddStartFiles) {
+if (!Shared)
+  AddCRTObject("crt1.o");
+AddCRTObject("crti.o");
+AddCRTObject(Shared   ? "crtbeginS.o"
+ : Static ? "crtbeginT.o"
+  : "crtbegin.o");
   }
 
-  if (UseJMC) {
-CmdArgs.push_back("--push-state");
-CmdArgs.push_back("--whole-archive");
-CmdArgs.push_back("-lSceJmc_nosubmission");
-CmdArgs.push_back("--pop-state");
+  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+
+  if (!Relocatable &&
+  !Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib)) {
+
+if (UseJMC) {
+  CmdArgs.push_back("--push-state");
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back("-lSceJmc_nosubmission");
+  CmdArgs.push_back("--pop-state");
+}
+
+if (Args.hasArg(options::OPT_pthread))
+  CmdArgs.push_back("-lpthread");
+
+if (Static) {
+  if (!Args.hasArg(options::OPT_nostdlibxx))
+CmdArgs.push_back("-lstdc++");
+  if (!Args.hasArg(options::OPT_nolibc)) {
+CmdArgs.push_back("-lm");
+CmdArgs.push_back("-lc");
+  }
+
+  CmdArgs.push_back("-lcompiler_rt");
+  CmdArgs.push_back("-lkernel");
+} else {
+  // The C and C++ libraries are combined.
+  if (!Args.hasArg(options::OPT_nolibc, options::OPT_nostdlibxx))
+CmdArgs.push_back("-lc_stub_weak");
+
+  CmdArgs.push_back("-lkernel_stub_weak");
+}
+  }
+  if (AddStartFiles) {
+AddCRTObject(Shared ? "crtendS.o" : "crtend.o");
+AddCRTObject("crtn.o");
   }
 
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95267942edc172..7a4b2afdf04e9c 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -97,6 +97,60 @@
 // Check the default library name.
 // CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
 
+// Test that CRT objects and libraries are supplied to the linker and can be
+// omitted with -noxxx options. These switches have some interaction with
+// sanitizer RT libraries. That's checked in fsanitize.c
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --targe

[clang] [PS5][Driver] Supply libraries and CRT objects to the linker (PR #115497)

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

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

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

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

SIE tracker: TOOLCHAIN-16704

>From 112e3e7ca9e3fd041fb0a1a0b7d97aa26740a908 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 7 Nov 2024 13:57:45 +
Subject: [PATCH] [PS5][Driver] Supply libraries and CRT objects to the linker

Until now, these have been hardcoded as a downstream patches in lld. Add
them to the driver so that the private patches 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 | 66 +-
 clang/test/Driver/ps5-linker.c | 59 ++-
 2 files changed, 113 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index df43da93d77555..79cb31d10cdf04 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -183,6 +183,7 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-lto-debug-options=") + LTOArgs));
 
+  // Sanitizer runtimes must be supplied before all other objects and libs.
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
@@ -358,9 +359,6 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (StringRef Jobs = getLTOParallelism(Args, D); !Jobs.empty())
 AddLTOFlag(Twine("jobs=") + Jobs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
-TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
-
   TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
@@ -368,17 +366,63 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
 CmdArgs.push_back("--no-demangle");
 
-  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+  // Sanitizer runtimes must be supplied before all other objects and libs.
+  if (!Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib))
+TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
-  if (Args.hasArg(options::OPT_pthread)) {
-CmdArgs.push_back("-lpthread");
+  const bool AddStartFiles =
+  !Relocatable &&
+  !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib);
+
+  auto AddCRTObject = [&](const char *Name) {
+CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(Name)));
+  };
+
+  if (AddStartFiles) {
+if (!Shared)
+  AddCRTObject("crt1.o");
+AddCRTObject("crti.o");
+AddCRTObject(Shared   ? "crtbeginS.o"
+ : Static ? "crtbeginT.o"
+  : "crtbegin.o");
   }
 
-  if (UseJMC) {
-CmdArgs.push_back("--push-state");
-CmdArgs.push_back("--whole-archive");
-CmdArgs.push_back("-lSceJmc_nosubmission");
-CmdArgs.push_back("--pop-state");
+  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+
+  if (!Relocatable &&
+  !Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib)) {
+
+if (UseJMC) {
+  CmdArgs.push_back("--push-state");
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back("-lSceJmc_nosubmission");
+  CmdArgs.push_back("--pop-state");
+}
+
+if (Args.hasArg(options::OPT_pthread))
+  CmdArgs.push_back("-lpthread");
+
+if (Static) {
+  if (!Args.hasArg(options::OPT_nostdlibxx))
+CmdArgs.push_back("-lstdc++");
+  if (!Args.hasArg(options::OPT_nolibc)) {
+CmdArgs.push_back("-lm");
+CmdArgs.push_back("-lc");
+  }
+
+  CmdArgs.push_back("-lcompiler_rt");
+  CmdArgs.push_back("-lkernel");
+} else {
+  // The C and C++ libraries are combined.
+  if (!Args.hasArg(options::OPT_nolibc, options::OPT_nostdlibxx))
+CmdArgs.push_back("-lc_stub_weak");
+
+  CmdArgs.push_back("-lkernel_stub_weak");
+}
+  }
+  if (AddStartFiles) {
+AddCRTObject(Shared ? "crtendS.o" : "crtend.o");
+AddCRTObject("crtn.o");
   }
 
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95267942edc172..7a4b2afdf04e9c 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -97,6 +97,60 @@
 // Check the default library name.
 // CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
 
+// Test that CRT objects and libraries are supplied to the linker and can be
+// omitted with -noxxx options. These switches hav

[clang] [PS5][Driver] Supply libraries and CRT objects to the linker (PR #115497)

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

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

>From 112e3e7ca9e3fd041fb0a1a0b7d97aa26740a908 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 7 Nov 2024 13:57:45 +
Subject: [PATCH 1/2] [PS5][Driver] Supply libraries and CRT objects to the
 linker

Until now, these have been hardcoded as a downstream patches in lld. Add
them to the driver so that the private patches 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 | 66 +-
 clang/test/Driver/ps5-linker.c | 59 ++-
 2 files changed, 113 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index df43da93d77555..79cb31d10cdf04 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -183,6 +183,7 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-lto-debug-options=") + LTOArgs));
 
+  // Sanitizer runtimes must be supplied before all other objects and libs.
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
@@ -358,9 +359,6 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (StringRef Jobs = getLTOParallelism(Args, D); !Jobs.empty())
 AddLTOFlag(Twine("jobs=") + Jobs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
-TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
-
   TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
@@ -368,17 +366,63 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
 CmdArgs.push_back("--no-demangle");
 
-  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+  // Sanitizer runtimes must be supplied before all other objects and libs.
+  if (!Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib))
+TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
-  if (Args.hasArg(options::OPT_pthread)) {
-CmdArgs.push_back("-lpthread");
+  const bool AddStartFiles =
+  !Relocatable &&
+  !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib);
+
+  auto AddCRTObject = [&](const char *Name) {
+CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(Name)));
+  };
+
+  if (AddStartFiles) {
+if (!Shared)
+  AddCRTObject("crt1.o");
+AddCRTObject("crti.o");
+AddCRTObject(Shared   ? "crtbeginS.o"
+ : Static ? "crtbeginT.o"
+  : "crtbegin.o");
   }
 
-  if (UseJMC) {
-CmdArgs.push_back("--push-state");
-CmdArgs.push_back("--whole-archive");
-CmdArgs.push_back("-lSceJmc_nosubmission");
-CmdArgs.push_back("--pop-state");
+  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+
+  if (!Relocatable &&
+  !Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib)) {
+
+if (UseJMC) {
+  CmdArgs.push_back("--push-state");
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back("-lSceJmc_nosubmission");
+  CmdArgs.push_back("--pop-state");
+}
+
+if (Args.hasArg(options::OPT_pthread))
+  CmdArgs.push_back("-lpthread");
+
+if (Static) {
+  if (!Args.hasArg(options::OPT_nostdlibxx))
+CmdArgs.push_back("-lstdc++");
+  if (!Args.hasArg(options::OPT_nolibc)) {
+CmdArgs.push_back("-lm");
+CmdArgs.push_back("-lc");
+  }
+
+  CmdArgs.push_back("-lcompiler_rt");
+  CmdArgs.push_back("-lkernel");
+} else {
+  // The C and C++ libraries are combined.
+  if (!Args.hasArg(options::OPT_nolibc, options::OPT_nostdlibxx))
+CmdArgs.push_back("-lc_stub_weak");
+
+  CmdArgs.push_back("-lkernel_stub_weak");
+}
+  }
+  if (AddStartFiles) {
+AddCRTObject(Shared ? "crtendS.o" : "crtend.o");
+AddCRTObject("crtn.o");
   }
 
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95267942edc172..7a4b2afdf04e9c 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -97,6 +97,60 @@
 // Check the default library name.
 // CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
 
+// Test that CRT objects and libraries are supplied to the linker and can be
+// omitted with -noxxx options. These switches have some interaction with
+// sanitizer RT libraries. That's checked in fsanitize.c
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --targe

[clang] [PS5][Driver] Supply libraries and CRT objects to the linker (PR #115497)

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

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

>From 112e3e7ca9e3fd041fb0a1a0b7d97aa26740a908 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 7 Nov 2024 13:57:45 +
Subject: [PATCH 1/3] [PS5][Driver] Supply libraries and CRT objects to the
 linker

Until now, these have been hardcoded as a downstream patches in lld. Add
them to the driver so that the private patches 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 | 66 +-
 clang/test/Driver/ps5-linker.c | 59 ++-
 2 files changed, 113 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index df43da93d77555..79cb31d10cdf04 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -183,6 +183,7 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-lto-debug-options=") + LTOArgs));
 
+  // Sanitizer runtimes must be supplied before all other objects and libs.
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
@@ -358,9 +359,6 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (StringRef Jobs = getLTOParallelism(Args, D); !Jobs.empty())
 AddLTOFlag(Twine("jobs=") + Jobs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
-TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
-
   TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
@@ -368,17 +366,63 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
 CmdArgs.push_back("--no-demangle");
 
-  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+  // Sanitizer runtimes must be supplied before all other objects and libs.
+  if (!Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib))
+TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
-  if (Args.hasArg(options::OPT_pthread)) {
-CmdArgs.push_back("-lpthread");
+  const bool AddStartFiles =
+  !Relocatable &&
+  !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib);
+
+  auto AddCRTObject = [&](const char *Name) {
+CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(Name)));
+  };
+
+  if (AddStartFiles) {
+if (!Shared)
+  AddCRTObject("crt1.o");
+AddCRTObject("crti.o");
+AddCRTObject(Shared   ? "crtbeginS.o"
+ : Static ? "crtbeginT.o"
+  : "crtbegin.o");
   }
 
-  if (UseJMC) {
-CmdArgs.push_back("--push-state");
-CmdArgs.push_back("--whole-archive");
-CmdArgs.push_back("-lSceJmc_nosubmission");
-CmdArgs.push_back("--pop-state");
+  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+
+  if (!Relocatable &&
+  !Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib)) {
+
+if (UseJMC) {
+  CmdArgs.push_back("--push-state");
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back("-lSceJmc_nosubmission");
+  CmdArgs.push_back("--pop-state");
+}
+
+if (Args.hasArg(options::OPT_pthread))
+  CmdArgs.push_back("-lpthread");
+
+if (Static) {
+  if (!Args.hasArg(options::OPT_nostdlibxx))
+CmdArgs.push_back("-lstdc++");
+  if (!Args.hasArg(options::OPT_nolibc)) {
+CmdArgs.push_back("-lm");
+CmdArgs.push_back("-lc");
+  }
+
+  CmdArgs.push_back("-lcompiler_rt");
+  CmdArgs.push_back("-lkernel");
+} else {
+  // The C and C++ libraries are combined.
+  if (!Args.hasArg(options::OPT_nolibc, options::OPT_nostdlibxx))
+CmdArgs.push_back("-lc_stub_weak");
+
+  CmdArgs.push_back("-lkernel_stub_weak");
+}
+  }
+  if (AddStartFiles) {
+AddCRTObject(Shared ? "crtendS.o" : "crtend.o");
+AddCRTObject("crtn.o");
   }
 
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95267942edc172..7a4b2afdf04e9c 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -97,6 +97,60 @@
 // Check the default library name.
 // CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
 
+// Test that CRT objects and libraries are supplied to the linker and can be
+// omitted with -noxxx options. These switches have some interaction with
+// sanitizer RT libraries. That's checked in fsanitize.c
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --targe

[clang] [PS5][Driver] Supply libraries and CRT objects to the linker (PR #115497)

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


@@ -97,6 +97,60 @@
 // Check the default library name.
 // CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
 
+// Test that CRT objects and libraries are supplied to the linker and can be
+// omitted with -noxxx options. These switches have some interaction with
+// sanitizer RT libraries. That's checked in fsanitize.c
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-SHARED-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -static -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-STATIC-CRT,CHECK-STATIC-LIBCPP,CHECK-STATIC-LIBC,CHECK-STATIC-CORE-LIBS
 %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-NO-LIBS %s
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -pthread -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-PTHREAD %s
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -nostartfiles -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -nostartfiles -shared -### 2>&1 | 
FileCheck 
--check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -nostartfiles -static -### 2>&1 | 
FileCheck 
--check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-STATIC-LIBCPP,CHECK-STATIC-LIBC,CHECK-STATIC-CORE-LIBS
 %s
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -nodefaultlibs -pthread -fjmc -### 
2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-NO-LIBS %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -nodefaultlibs -pthread -fjmc 
-shared -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-SHARED-CRT,CHECK-NO-LIBS %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -nodefaultlibs -pthread -fjmc 
-static -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-STATIC-CRT,CHECK-NO-LIBS %s
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib -pthread -fjmc -### 2>&1 | 
FileCheck --check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-NO-LIBS %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib -pthread -fjmc -shared 
-### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-NO-LIBS %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib -pthread -fjmc -static 
-### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-NO-LIBS %s
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -nolibc -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-NO-LIBC,CHECK-DYNAMIC-CORE-LIBS 
%s
+// RUN: %clang --target=x86_64-sie-ps5 %s -nolibc -shared -### 2>&1 | 
FileCheck 
--check-prefixes=CHECK-LD,CHECK-SHARED-CRT,CHECK-NO-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -nolibc -static -### 2>&1 | 
FileCheck 
--check-prefixes=CHECK-LD,CHECK-STATIC-CRT,CHECK-STATIC-LIBCPP,CHECK-NO-LIBC,CHECK-STATIC-CORE-LIBS
 %s
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib++ -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-NO-LIBCPP,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib++ -shared -### 2>&1 | 
FileCheck 
--check-prefixes=CHECK-LD,CHECK-SHARED-CRT,CHECK-NO-LIBCPP,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib++ -static -### 2>&1 | 
FileCheck 
--check-prefixes=CHECK-LD,CHECK-STATIC-CRT,CHECK-NO-LIBCPP,CHECK-STATIC-LIBC,CHECK-STATIC-CORE-LIBS
 %s
+
+// CHECK-LD: {{ld(\.exe)?}}"
+// CHECK-MAIN-CRT-SAME: "crt1.o" "crti.o" "crtbegin.o"
+// CHECK-SHARED-CRT-SAME: "crti.o" "crtbeginS.o"
+// CHECK-STATIC-CRT-SAMW: "crt1.o" "crti.o" "crtbeginT.o"

playstation-edd wrote:

Thank you - fixed.

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


[clang] [PS5][Driver] Supply libraries and CRT objects to the linker (PR #115497)

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

playstation-edd wrote:

> Just to check my understanding, things like CHECK-MAIN-CRT-SAME are going to 
> shift the match-position that FileCheck is looking at forwards, so that we 
> have to match in the correct order, yes?

Yep!

> I get the feeling that given how much of the construct-a-job logic filters 
> for `!Relocatable` it might be worth having that as an early exit. On the 
> other hand, the logic here is already a complicated matrix of expectations, 
> no need to make it more complicated in the name of lines-of-code.

There's are bits of `Relocatable`-agnostic stuff in the middle 
(`AddLinkerInputs()`) and at the end, so I don't know how much tidier or 
smaller it can be made. I'm don't find it's current state especially offensive, 
but I could have a go at moving the new stuff to some helper functions, perhaps?

> For the CHECK-NO... flavour of checklines, would they be better as 
> `--check-implicit-not` arguments to FileCheck, or is it alright to rely on 
> them being in a rigid order? (No strong opinion).

Thanks - `--check-implicit-not` would indeed be better from a strictness point 
of view. So I have pushed this change for your consideration. After doing it, 
I'm not so sure it's overall better, as the regular expressions are now 
repeated in a number of places and I have had to carefully quote them so that 
lit's command parser doesn't e.g. interpret `*` as glob, and instead leaves it 
for `FileCheck` to interpret as a part of a regex. I have a very slight 
preference to revert this particular commit as I feel there's slightly more 
chance for error now, though I did validate with some experiments. Let me know 
what you think.



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


[clang] [PS5][Driver] Supply libraries and CRT objects to the linker (PR #115497)

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

playstation-edd wrote:

> Does the flipped order of library-option-names in 
> [100c3c2](https://github.com/llvm/llvm-project/commit/100c3c271437b3b6181a5a57381363f4b6e9e841)
>  have an actual effect on behaviour? Just curious.

No effect. I accidentally flipped the order it in the initial commit - 
presumably the result of iterating and experimenting along the way. The 
follow-up commit was to flip it back. Sorry for the distraction.


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


[clang] [PS5][Driver] Supply libraries and CRT objects to the linker (PR #115497)

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

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

>From 112e3e7ca9e3fd041fb0a1a0b7d97aa26740a908 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 7 Nov 2024 13:57:45 +
Subject: [PATCH 1/5] [PS5][Driver] Supply libraries and CRT objects to the
 linker

Until now, these have been hardcoded as a downstream patches in lld. Add
them to the driver so that the private patches 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 | 66 +-
 clang/test/Driver/ps5-linker.c | 59 ++-
 2 files changed, 113 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index df43da93d77555..79cb31d10cdf04 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -183,6 +183,7 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-lto-debug-options=") + LTOArgs));
 
+  // Sanitizer runtimes must be supplied before all other objects and libs.
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
@@ -358,9 +359,6 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (StringRef Jobs = getLTOParallelism(Args, D); !Jobs.empty())
 AddLTOFlag(Twine("jobs=") + Jobs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
-TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
-
   TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
@@ -368,17 +366,63 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
 CmdArgs.push_back("--no-demangle");
 
-  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+  // Sanitizer runtimes must be supplied before all other objects and libs.
+  if (!Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib))
+TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
-  if (Args.hasArg(options::OPT_pthread)) {
-CmdArgs.push_back("-lpthread");
+  const bool AddStartFiles =
+  !Relocatable &&
+  !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib);
+
+  auto AddCRTObject = [&](const char *Name) {
+CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(Name)));
+  };
+
+  if (AddStartFiles) {
+if (!Shared)
+  AddCRTObject("crt1.o");
+AddCRTObject("crti.o");
+AddCRTObject(Shared   ? "crtbeginS.o"
+ : Static ? "crtbeginT.o"
+  : "crtbegin.o");
   }
 
-  if (UseJMC) {
-CmdArgs.push_back("--push-state");
-CmdArgs.push_back("--whole-archive");
-CmdArgs.push_back("-lSceJmc_nosubmission");
-CmdArgs.push_back("--pop-state");
+  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+
+  if (!Relocatable &&
+  !Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib)) {
+
+if (UseJMC) {
+  CmdArgs.push_back("--push-state");
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back("-lSceJmc_nosubmission");
+  CmdArgs.push_back("--pop-state");
+}
+
+if (Args.hasArg(options::OPT_pthread))
+  CmdArgs.push_back("-lpthread");
+
+if (Static) {
+  if (!Args.hasArg(options::OPT_nostdlibxx))
+CmdArgs.push_back("-lstdc++");
+  if (!Args.hasArg(options::OPT_nolibc)) {
+CmdArgs.push_back("-lm");
+CmdArgs.push_back("-lc");
+  }
+
+  CmdArgs.push_back("-lcompiler_rt");
+  CmdArgs.push_back("-lkernel");
+} else {
+  // The C and C++ libraries are combined.
+  if (!Args.hasArg(options::OPT_nolibc, options::OPT_nostdlibxx))
+CmdArgs.push_back("-lc_stub_weak");
+
+  CmdArgs.push_back("-lkernel_stub_weak");
+}
+  }
+  if (AddStartFiles) {
+AddCRTObject(Shared ? "crtendS.o" : "crtend.o");
+AddCRTObject("crtn.o");
   }
 
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95267942edc172..7a4b2afdf04e9c 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -97,6 +97,60 @@
 // Check the default library name.
 // CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
 
+// Test that CRT objects and libraries are supplied to the linker and can be
+// omitted with -noxxx options. These switches have some interaction with
+// sanitizer RT libraries. That's checked in fsanitize.c
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --targe

[clang] [PS5][Driver] Update default linking options for `-r` (PR #113595)

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

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

>From 5c5a6f89ca752bf9d0452f486648f2608b7bc609 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 24 Oct 2024 10:15:16 +0100
Subject: [PATCH] [PS5][Driver] Update default linking options when `-r`
 omitted.

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

PS5 only. On PS4, the proprietary linker will continue to perform the
equivalent behaviours itself.

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

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index a50333223ff5c4..719bba41436a57 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -250,6 +250,20 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("-pie");
 
   if (!Relocatable) {
+CmdArgs.push_back("--eh-frame-hdr");
+CmdArgs.push_back("--hash-style=sysv");
+
+// Add a build-id by default to allow the PlayStation symbol server to
+// index the symbols. `uuid` is the cheapest fool-proof method.
+// (The non-determinism and alternative methods are noted in the downstream
+// PlayStation docs).
+CmdArgs.push_back("--build-id=uuid");
+
+// All references are expected to be resolved at static link time for both
+// executables and dynamic libraries. This has been the default linking
+// behaviour for numerous PlayStation generations.
+CmdArgs.push_back("--unresolved-symbols=report-all");
+
 // Lazy binding of PLTs is not supported on PlayStation. They are placed in
 // the RelRo segment.
 CmdArgs.push_back("-z");
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index d18309a650726d..2080f4dc91a7fb 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -14,21 +14,32 @@
 // 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_*=0x"
-// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_ranges=0xfffe"
-// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffe"
-
-// 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 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).
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-EXE %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck 
--check-prefixes=CHECK-EXE %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -static -### 2>&1 | FileCheck 
--check-prefixes=CHECK-EXE %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-EXE %s
+
+// CHECK-EXE: {{ld(\.exe)?}}"
+// CHECK-EXE-SAME: "--eh-frame-hdr"
+// CHECK-EXE-SAME: "--hash-style=sysv"
+// CHECK-EXE-SAME: "--build-id=uuid"
+// CHECK-EXE-SAME: "--unresolved-symbols=report-all"
+// CHECK-EXE-SAME: "-z" "now"
+// CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
+// 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"
+
+// CHECK-NO-EXE: {{ld(\.exe)?}}"
+// CHECK-NO-EXE-NOT: "--eh-frame-hdr"
+// CHECK-NO-EXE-NOT: "--hash-style
+// CHECK-NO-EXE-NOT: "--build-id
+// CHECK-NO-EXE-NOT: "--unresolved-symbols
+// CHECK-NO-EXE-NOT: "-z"
 
 // Test that -static is forwarded to the linker
 

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


[clang] [PS5][Driver] Allow `-T` to override `--default-script` (PR #116074)

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


@@ -67,19 +67,24 @@
 // CHECK-NO-EXE-NOT: "--unresolved-symbols
 // CHECK-NO-EXE-NOT: "-z"
 
-// Test that an appropriate linker script is supplied by the driver.
+// Test that an appropriate linker script is supplied by the driver, but can
+// be overridden with -T.

playstation-edd wrote:

There's no `--script` on `clang`. I may not understand your comment.

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


[clang] [PS5][Driver] Allow `-T` to override `--default-script` (PR #116074)

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

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


[clang] [PS5][Driver] Allow `-T` to override `--default-script` (PR #116074)

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

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

If a linker script is explicitly supplied, there's no benefit to supplying a 
default script.

SIE tracker: TOOLCHAIN-17524

>From a843f4fcd5bc0c43ad0177cb3e284efe65676138 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 13 Nov 2024 15:51:48 +
Subject: [PATCH] [PS5][Driver] Allow `-T` to override `--default-script`

If a linker script is supplied, there's no benefit to supplying a default
script.

SIE tracker: TOOLCHAIN-17524
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 10 ++
 clang/test/Driver/ps5-linker.c |  7 ++-
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index df43da93d77555..03445375796533 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -303,10 +303,12 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 // with the SDK. The scripts are inside /target/lib, which is
 // added as a search path elsewhere.
 // "PRX" has long stood for "PlayStation Relocatable eXecutable".
-CmdArgs.push_back("--default-script");
-CmdArgs.push_back(Static   ? "static.script"
-  : Shared ? "prx.script"
-   : "main.script");
+if (!Args.hasArgNoClaim(options::OPT_T)) {
+  CmdArgs.push_back("--default-script");
+  CmdArgs.push_back(Static   ? "static.script"
+: Shared ? "prx.script"
+ : "main.script");
+}
   }
 
   if (Static)
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95267942edc172..216b11a8c52d71 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -67,12 +67,14 @@
 // CHECK-NO-EXE-NOT: "--unresolved-symbols
 // CHECK-NO-EXE-NOT: "-z"
 
-// Test that an appropriate linker script is supplied by the driver.
+// Test that an appropriate linker script is supplied by the driver, but can
+// be overridden with -T.
 
 // RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-SCRIPT -DSCRIPT=main %s
 // RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck 
--check-prefixes=CHECK-SCRIPT -DSCRIPT=prx %s
 // RUN: %clang --target=x86_64-sie-ps5 %s -static -### 2>&1 | FileCheck 
--check-prefixes=CHECK-SCRIPT -DSCRIPT=static %s
 // RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-SCRIPT %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -T custom.script -### 2>&1 | 
FileCheck --check-prefixes=CHECK-CUSTOM-SCRIPT --implicit-check-not 
"\"{{-T|--script|--default-script}}\"" %s
 
 // CHECK-SCRIPT: {{ld(\.exe)?}}"
 // CHECK-SCRIPT-SAME: "--default-script" "[[SCRIPT]].script"
@@ -80,6 +82,9 @@
 // CHECK-NO-SCRIPT: {{ld(\.exe)?}}"
 // CHECK-NO-SCRIPT-NOT: "--default-script"
 
+// CHECK-CUSTOM-SCRIPT: {{ld(\.exe)?}}"
+// CHECK-CUSTOM-SCRIPT-SAME: "-T" "custom.script"
+
 // 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

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


[clang] [PS5][Driver] Pass a target emulation to the linker (PR #114060)

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

https://github.com/playstation-edd closed 
https://github.com/llvm/llvm-project/pull/114060
___
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/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

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-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


@@ -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

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] [PS4, PS5][Driver] Pass `-L<...>/target/lib -L.` to linker (PR #109796)

2024-09-24 Thread Edd Dawson via cfe-commits

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

>From 89ff568fda0062a89ed690cdb0267fc41a89325c Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Tue, 24 Sep 2024 13:05:39 +0100
Subject: [PATCH 1/2] [PS4,PS5][Driver] Pass `-L<...>/target/lib -L.` to linker

The proprietary PS4 linker implicitly adds `=/target/lib` and `.` as
library search paths. This behaviour was added to the PS5 linker via a
downstream patch in LLD. This really belongs in the driver, instead.
This change adds the driver behaviour to allow removal of the downstream
patch in LLD.

There are no plans to update the PS4 linker behaviour in the analogous
way, so do not pass the same search paths to the PS4 linker.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp |  6 ++
 clang/test/Driver/ps5-linker.c | 23 +++
 2 files changed, 29 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 647580e4e235dc..0a43ab19b434c5 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -186,6 +186,9 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
+  // Other drivers typically add library search paths (`-L`) here via
+  // TC.AddFilePathLibArgs(). We don't do that on PS4 as the PS4 linker
+  // searches those locations by default.
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
 
@@ -290,6 +293,7 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
+  TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
 
@@ -382,6 +386,8 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
 llvm::sys::path::append(Dir, "target/include");
 CheckSDKPartExists(Dir, "system headers");
   }
+
+  getFilePaths().push_back(".");
 }
 
 void toolchains::PS4PS5Base::AddClangSystemIncludeArgs(
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index c0cf0b864028c8..852659ae86d5cf 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -46,3 +46,26 @@
 
 // CHECK-SYSROOT: {{ld(\.exe)?}}"
 // CHECK-SYSROOT-SAME: "--sysroot=mysdk"
+
+// Test that "." is always added to library search paths. This is long-standing
+// behavior, unique to PlayStation toolchains.
+
+// RUN: %clang --target=x64_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LDOT %s
+
+// CHECK-LDOT: {{ld(\.exe)?}}"
+// CHECK-LDOT-SAME: "-L."
+
+// Test that /target/lib is added to library search paths, if it
+// exists and no --sysroot is specified.
+
+// RUN: rm -rf %t.dir && mkdir -p %t.dir/target/lib
+// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 
2>&1 | FileCheck --check-prefixes=CHECK-TARGETLIB %s
+
+// CHECK-TARGETLIB: {{ld(\.exe)?}}"
+// CHECK-TARGETLIB-SAME: "-L{{.*[/\\]}}target/lib"
+
+// RUN: env SCE_PROSPERO_SDK_DIR=missing %clang --target=x64_64-sie-ps5 %s 
-### 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
+// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 
--sysroot=missing 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
+
+// CHECK-NO-TARGETLIB: {{ld(\.exe)?}}"
+// CHECK-NO-TARGETLIB-NOT: "-L{{.*[/\\]}}target/lib"

>From 1a6dc7d8060722400032f6ad149b940f0197bc4d Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Tue, 24 Sep 2024 16:52:25 +0100
Subject: [PATCH 2/2] Rewrite test cases to remove assumed non-existence of
 'missing' directory

---
 clang/test/Driver/ps5-linker.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 852659ae86d5cf..4ae65963e361aa 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -58,14 +58,15 @@
 // Test that /target/lib is added to library search paths, if it
 // exists and no --sysroot is specified.
 
-// RUN: rm -rf %t.dir && mkdir -p %t.dir/target/lib
+// RUN: rm -rf %t.dir && mkdir %t.dir
+// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 
2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
+// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 
--sysroot=%t.dir 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
+
+// CHECK-NO-TARGETLIB: {{ld(\.exe)?}}"
+// CHECK-NO-TARGETLIB-NOT: "-L{{.*[/\\]}}target/lib"
+
+// RUN: mkdir -p %t.dir/target/lib
 // RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64

[clang] [PS4, PS5][Driver] Pass `-L<...>/target/lib -L.` to linker (PR #109796)

2024-09-24 Thread Edd Dawson via cfe-commits

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

The proprietary PS4 linker implicitly adds `=/target/lib` and `.` as library 
search paths. This behaviour was added to the PS5 linker via a downstream patch 
in LLD. This really belongs in the driver, instead. This change adds the driver 
behaviour to allow removal of the downstream patch in LLD.

There are no plans to update the PS4 linker behaviour in the analogous way, so 
do not pass the same search paths to the PS4 linker.

SIE tracker: TOOLCHAIN-16704

>From 89ff568fda0062a89ed690cdb0267fc41a89325c Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Tue, 24 Sep 2024 13:05:39 +0100
Subject: [PATCH] [PS4,PS5][Driver] Pass `-L<...>/target/lib -L.` to linker

The proprietary PS4 linker implicitly adds `=/target/lib` and `.` as
library search paths. This behaviour was added to the PS5 linker via a
downstream patch in LLD. This really belongs in the driver, instead.
This change adds the driver behaviour to allow removal of the downstream
patch in LLD.

There are no plans to update the PS4 linker behaviour in the analogous
way, so do not pass the same search paths to the PS4 linker.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp |  6 ++
 clang/test/Driver/ps5-linker.c | 23 +++
 2 files changed, 29 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 647580e4e235dc..0a43ab19b434c5 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -186,6 +186,9 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
+  // Other drivers typically add library search paths (`-L`) here via
+  // TC.AddFilePathLibArgs(). We don't do that on PS4 as the PS4 linker
+  // searches those locations by default.
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
 
@@ -290,6 +293,7 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
+  TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
 
@@ -382,6 +386,8 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
 llvm::sys::path::append(Dir, "target/include");
 CheckSDKPartExists(Dir, "system headers");
   }
+
+  getFilePaths().push_back(".");
 }
 
 void toolchains::PS4PS5Base::AddClangSystemIncludeArgs(
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index c0cf0b864028c8..852659ae86d5cf 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -46,3 +46,26 @@
 
 // CHECK-SYSROOT: {{ld(\.exe)?}}"
 // CHECK-SYSROOT-SAME: "--sysroot=mysdk"
+
+// Test that "." is always added to library search paths. This is long-standing
+// behavior, unique to PlayStation toolchains.
+
+// RUN: %clang --target=x64_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LDOT %s
+
+// CHECK-LDOT: {{ld(\.exe)?}}"
+// CHECK-LDOT-SAME: "-L."
+
+// Test that /target/lib is added to library search paths, if it
+// exists and no --sysroot is specified.
+
+// RUN: rm -rf %t.dir && mkdir -p %t.dir/target/lib
+// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 
2>&1 | FileCheck --check-prefixes=CHECK-TARGETLIB %s
+
+// CHECK-TARGETLIB: {{ld(\.exe)?}}"
+// CHECK-TARGETLIB-SAME: "-L{{.*[/\\]}}target/lib"
+
+// RUN: env SCE_PROSPERO_SDK_DIR=missing %clang --target=x64_64-sie-ps5 %s 
-### 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
+// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 
--sysroot=missing 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
+
+// CHECK-NO-TARGETLIB: {{ld(\.exe)?}}"
+// CHECK-NO-TARGETLIB-NOT: "-L{{.*[/\\]}}target/lib"

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


[clang] [PS4, PS5][Driver] Pass `-L<...>/target/lib -L.` to linker (PR #109796)

2024-09-24 Thread Edd Dawson via cfe-commits


@@ -46,3 +46,26 @@
 
 // CHECK-SYSROOT: {{ld(\.exe)?}}"
 // CHECK-SYSROOT-SAME: "--sysroot=mysdk"
+
+// Test that "." is always added to library search paths. This is long-standing
+// behavior, unique to PlayStation toolchains.
+
+// RUN: %clang --target=x64_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LDOT %s
+
+// CHECK-LDOT: {{ld(\.exe)?}}"
+// CHECK-LDOT-SAME: "-L."
+
+// Test that /target/lib is added to library search paths, if it
+// exists and no --sysroot is specified.
+
+// RUN: rm -rf %t.dir && mkdir -p %t.dir/target/lib
+// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 
2>&1 | FileCheck --check-prefixes=CHECK-TARGETLIB %s
+
+// CHECK-TARGETLIB: {{ld(\.exe)?}}"
+// CHECK-TARGETLIB-SAME: "-L{{.*[/\\]}}target/lib"
+
+// RUN: env SCE_PROSPERO_SDK_DIR=missing %clang --target=x64_64-sie-ps5 %s 
-### 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s

playstation-edd wrote:

Yes, much better. Done. Thanks.

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


[clang] [PS4, PS5][Driver] Pass `-L<...>/target/lib -L.` to linker (PR #109796)

2024-09-24 Thread Edd Dawson via cfe-commits


@@ -46,3 +46,26 @@
 
 // CHECK-SYSROOT: {{ld(\.exe)?}}"
 // CHECK-SYSROOT-SAME: "--sysroot=mysdk"
+
+// Test that "." is always added to library search paths. This is long-standing
+// behavior, unique to PlayStation toolchains.
+
+// RUN: %clang --target=x64_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LDOT %s
+
+// CHECK-LDOT: {{ld(\.exe)?}}"
+// CHECK-LDOT-SAME: "-L."
+
+// Test that /target/lib is added to library search paths, if it
+// exists and no --sysroot is specified.

playstation-edd wrote:

This is what the RUN on line 63 does ... I hope! (Prior to 1a6dc7d, this was on 
line 68).

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


[clang] [PS4, PS5][Driver] Pass `-L<...>/target/lib -L.` to linker (PR #109796)

2024-09-25 Thread Edd Dawson via cfe-commits

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


[clang] [PS4,PS5][Driver] Fix typo in comment (NFC) (PR #109980)

2024-09-25 Thread Edd Dawson via cfe-commits

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

None

>From 2a333786d415215f722796587c0a37b676d506a5 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 25 Sep 2024 14:27:43 +0100
Subject: [PATCH] [PS4,PS5][Driver] Fix typo in comment (NFC)

---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 647580e4e235dc..db77d058bcc597 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -338,7 +338,7 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
   }
 
   // Allow --sysroot= to override the root directory for header and library
-  // search, and -sysroot to override header search. If both are specified,
+  // search, and -isysroot to override header search. If both are specified,
   // -isysroot overrides --sysroot for header search.
   auto OverrideRoot = [&](const options::ID &Opt, std::string &Root,
   StringRef Default) {

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


[clang] [PS5][Driver] Restore whole-archive state when `-fjmc` (PR #115181)

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

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

`--whole-archive` is passed to the linker to have it consume all objects within 
the SIE Just My Code library, rather than just those that fulfil outstanding 
references.

Prior to this change, `--no-whole-archive` was used to reset the associated 
archive handling state in the linker, under the assumption that 
`--whole-archive` wasn't already in effect. But that assumption may be 
incorrect. So use `--push/pop-state` to restore the previous state, whatever 
that may be.

Given the position of these switches on the link line, the problem described 
with the outgoing code is unlikely to cause an issue in practice. But push/pop 
protect against accidents due to future additions to and reorderings of 
arguments.

PS5 only. The proprietary PS4 linker doesn't support `--push/pop-state`, or an 
equivalent.

SIE tracker: TOOLCHAIN-16704.

>From c2eec3d06ad920ef2b7826fe9b76f1b45574e036 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 6 Nov 2024 16:24:46 +
Subject: [PATCH] [PS5][Driver] Restore whole-archive state when `-fjmc`

`--whole-archive` is passed to the linker to have it consume all objects
within the SIE Just My Code library, rather than just those that fulfil
outstanding references.

Prior to this change, `--no-whole-archive` was used to reset the
associated archive handling state in the linker, under the assumption
that `--whole-archive` wasn't already in effect. But that assumption may
be incorrect. So use `--push/pop-state` to restore the previous state,
whatever that may be.

Given the position of these switches on the link line, the problem
described with the outgoing code is unlikely to cause an issue in
practice. But push/pop protect against accidents due to future additions
to and reorderings of arguments.

PS5 only. The proprietary PS4 linker doesn't support `--push/pop-state`,
or an equivalent.

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

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 261c136de782e7..df43da93d77555 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -375,9 +375,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   }
 
   if (UseJMC) {
+CmdArgs.push_back("--push-state");
 CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lSceJmc_nosubmission");
-CmdArgs.push_back("--no-whole-archive");
+CmdArgs.push_back("--pop-state");
   }
 
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 8a0ade91871295..fb5f8a9ec5cee5 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -95,7 +95,7 @@
 // CHECK: -plugin-opt=-enable-jmc-instrument
 
 // Check the default library name.
-// CHECK-LIB: "--whole-archive" "-lSceJmc_nosubmission" "--no-whole-archive"
+// CHECK-LIB: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
 
 // Test the driver's control over the -fcrash-diagnostics-dir behavior with 
linker flags.
 

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


[clang] [PS5][Driver] Restore whole-archive state when `-fjmc` (PR #115181)

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

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

>From c2eec3d06ad920ef2b7826fe9b76f1b45574e036 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 6 Nov 2024 16:24:46 +
Subject: [PATCH 1/2] [PS5][Driver] Restore whole-archive state when `-fjmc`

`--whole-archive` is passed to the linker to have it consume all objects
within the SIE Just My Code library, rather than just those that fulfil
outstanding references.

Prior to this change, `--no-whole-archive` was used to reset the
associated archive handling state in the linker, under the assumption
that `--whole-archive` wasn't already in effect. But that assumption may
be incorrect. So use `--push/pop-state` to restore the previous state,
whatever that may be.

Given the position of these switches on the link line, the problem
described with the outgoing code is unlikely to cause an issue in
practice. But push/pop protect against accidents due to future additions
to and reorderings of arguments.

PS5 only. The proprietary PS4 linker doesn't support `--push/pop-state`,
or an equivalent.

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

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 261c136de782e7..df43da93d77555 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -375,9 +375,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   }
 
   if (UseJMC) {
+CmdArgs.push_back("--push-state");
 CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lSceJmc_nosubmission");
-CmdArgs.push_back("--no-whole-archive");
+CmdArgs.push_back("--pop-state");
   }
 
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 8a0ade91871295..fb5f8a9ec5cee5 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -95,7 +95,7 @@
 // CHECK: -plugin-opt=-enable-jmc-instrument
 
 // Check the default library name.
-// CHECK-LIB: "--whole-archive" "-lSceJmc_nosubmission" "--no-whole-archive"
+// CHECK-LIB: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
 
 // Test the driver's control over the -fcrash-diagnostics-dir behavior with 
linker flags.
 

>From e8f465066edc9f7230f6751b94de90b71a2eb56a Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 6 Nov 2024 18:17:57 +
Subject: [PATCH 2/2] CHECK-LIB -> CHECK-JMC

---
 clang/test/Driver/ps5-linker.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index fb5f8a9ec5cee5..95267942edc172 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -89,13 +89,13 @@
 
 // Test the driver's control over the JustMyCode behavior with linker flags.
 
-// RUN: %clang --target=x86_64-sie-ps5 -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK,CHECK-LIB %s
-// RUN: %clang --target=x86_64-sie-ps5 -flto -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK,CHECK-LIB %s
+// RUN: %clang --target=x86_64-sie-ps5 -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK,CHECK-JMC %s
+// RUN: %clang --target=x86_64-sie-ps5 -flto -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK,CHECK-JMC %s
 
 // CHECK: -plugin-opt=-enable-jmc-instrument
 
 // Check the default library name.
-// CHECK-LIB: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
+// CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
 
 // Test the driver's control over the -fcrash-diagnostics-dir behavior with 
linker flags.
 

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


[clang] [PS5][Driver] Restore whole-archive state when `-fjmc` (PR #115181)

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

playstation-edd wrote:

> LGTM, although maybe CHECK_JMC instead of CHECK_LIB as it seems very JMC 
> specific? No strong opinion.

Done - thanks.

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


[clang] [PS5][Driver] Restore whole-archive state when `-fjmc` (PR #115181)

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

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


[clang] [PS4, PS5][Driver] Detangle --sysroot and -isysroot (PR #107410)

2024-09-17 Thread Edd Dawson via cfe-commits

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


  1   2   >