[PS4][clang] Fix the format of the LTO debug options passed to orbis-ld
authorMatthew Voss <matthew.voss@sony.com>
Wed, 5 Apr 2023 19:57:21 +0000 (12:57 -0700)
committerMatthew Voss <matthew.voss@sony.com>
Wed, 5 Apr 2023 19:57:21 +0000 (12:57 -0700)
Currently, we pass multiple LTO debug options to orbis-ld like this:

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

When it should be like this:

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

Differential Revision: https://reviews.llvm.org/D147546

clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/test/Driver/ps4-ps5-linker.c

index 8c8b7c7..71c6b65 100644 (file)
@@ -160,18 +160,12 @@ void tools::PScpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
   const bool IsPS5 = TC.getTriple().isPS5();
   assert(IsPS4 || IsPS5);
 
+  const char *PS4LTOArgs = "";
   auto AddCodeGenFlag = [&](Twine Flag) {
-    const char *Prefix = nullptr;
-    if (IsPS4 && D.getLTOMode() == LTOK_Thin)
-      Prefix = "-lto-thin-debug-options=";
-    else if (IsPS4 && D.getLTOMode() == LTOK_Full)
-      Prefix = "-lto-debug-options=";
+    if (IsPS4)
+      PS4LTOArgs = Args.MakeArgString(Twine(PS4LTOArgs) + " " + Flag);
     else if (IsPS5)
-      Prefix = "-plugin-opt=";
-    else
-      llvm_unreachable("new LTO mode?");
-
-    CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + Flag));
+      CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=") + Flag));
   };
 
   if (UseLTO) {
@@ -185,6 +179,18 @@ void tools::PScpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
 
     if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
       AddCodeGenFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
+
+    if (IsPS4) {
+      const char *Prefix = nullptr;
+      if (D.getLTOMode() == LTOK_Thin)
+        Prefix = "-lto-thin-debug-options=";
+      else if (D.getLTOMode() == LTOK_Full)
+        Prefix = "-lto-debug-options=";
+      else
+        llvm_unreachable("new LTO mode?");
+
+      CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + PS4LTOArgs));
+    }
   }
 
   if (IsPS5 && UseLTO) {
index ee8e96b..8aae94c 100644 (file)
@@ -7,8 +7,8 @@
 // RUN: %clang --target=x86_64-scei-ps5 -flto -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PS5-LTO,CHECK-PS5-LIB %s
 
 // CHECK-PS4-NOT: -enable-jmc-instrument
-// CHECK-PS4-THIN-LTO: -lto-thin-debug-options=-enable-jmc-instrument
-// CHECK-PS4-FULL-LTO: -lto-debug-options=-enable-jmc-instrument
+// CHECK-PS4-THIN-LTO: "-lto-thin-debug-options= -generate-arange-section -enable-jmc-instrument"
+// CHECK-PS4-FULL-LTO: "-lto-debug-options= -generate-arange-section -enable-jmc-instrument"
 // CHECK-PS5-NOT: -plugin-opt=-enable-jmc-instrument
 // CHECK-PS5-LTO: -plugin-opt=-enable-jmc-instrument
 
@@ -23,7 +23,7 @@
 // RUN: %clang --target=x86_64-scei-ps5 -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-PS5 %s
 // RUN: %clang --target=x86_64-scei-ps5 -flto -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-PS5-LTO %s
 
-// CHECK-DIAG-PS4-THIN-LTO: -lto-thin-debug-options=-crash-diagnostics-dir=mydumps
-// CHECK-DIAG-PS4-FULL-LTO: -lto-debug-options=-crash-diagnostics-dir=mydumps
+// CHECK-DIAG-PS4-THIN-LTO: "-lto-thin-debug-options= -generate-arange-section -crash-diagnostics-dir=mydumps"
+// CHECK-DIAG-PS4-FULL-LTO: "-lto-debug-options= -generate-arange-section -crash-diagnostics-dir=mydumps"
 // CHECK-DIAG-PS5-NOT: -plugin-opt=-crash-diagnostics-dir=mydumps
 // CHECK-DIAG-PS5-LTO: -plugin-opt=-crash-diagnostics-dir=mydumps