[clang] 55cd5bc - [Driver][PS4] pass -fcrash-diagnostics-dir to LTO

Yuanfang Chen via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 27 13:14:31 PDT 2022


Author: Yuanfang Chen
Date: 2022-09-27T13:14:16-07:00
New Revision: 55cd5bc50964449627f6f1fa82ce8268d0629d9e

URL: https://github.com/llvm/llvm-project/commit/55cd5bc50964449627f6f1fa82ce8268d0629d9e
DIFF: https://github.com/llvm/llvm-project/commit/55cd5bc50964449627f6f1fa82ce8268d0629d9e.diff

LOG: [Driver][PS4] pass -fcrash-diagnostics-dir to LTO

Also refactor the existing code a little bit.

Reviewed By: probinson

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

Added: 
    clang/test/Driver/ps4-ps5-linker.c

Modified: 
    clang/lib/Driver/ToolChains/PS4CPU.cpp
    clang/test/Driver/debug-options.c

Removed: 
    clang/test/Driver/ps4-ps5-linker-jmc.c


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 989bdb4065eaa..643f815c5835a 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -158,34 +158,32 @@ void tools::PScpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
   const bool IsPS4 = TC.getTriple().isPS4();
   const bool IsPS5 = TC.getTriple().isPS5();
   assert(IsPS4 || IsPS5);
-  (void)IsPS5;
 
-  ArgStringList DbgOpts;
-
-  // This tells LTO to perform JustMyCode instrumentation.
-  if (UseLTO && UseJMC)
-    DbgOpts.push_back("-enable-jmc-instrument");
+  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=";
+    else if (IsPS5)
+      Prefix = "-plugin-opt=";
+    else
+      llvm_unreachable("new LTO mode?");
 
-  // We default to creating the arange section, but LTO does not. Enable it
-  // here.
-  if (UseLTO)
-    DbgOpts.push_back("-generate-arange-section");
+    CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + Flag));
+  };
 
   if (UseLTO) {
-    if (IsPS4) {
-      StringRef F = (D.getLTOMode() == LTOK_Thin) ?
-                      "-lto-thin-debug-options=" : "-lto-debug-options=";
-      F = makeArgString(Args, F.data(), DbgOpts.front(), "");
-      DbgOpts.erase(DbgOpts.begin());
-      for (auto X : DbgOpts)
-        F = makeArgString(Args, F.data(), " ", X);
-      CmdArgs.push_back(F.data());
-    } else {
-      for (auto D : DbgOpts) {
-        CmdArgs.push_back("-mllvm");
-        CmdArgs.push_back(D);
-      }
-    }
+    // 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());
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))

diff  --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c
index bd13a63162c8e..7e33d8d393eb2 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -375,8 +375,8 @@
 //
 
 // LDGARANGE: {{".*ld.*"}} {{.*}}
-// LDGARANGE-NOT: "-generate-arange-section"
-// LLDGARANGE: {{".*lld.*"}} {{.*}} "-generate-arange-section"
+// LDGARANGE-NOT: "-plugin-opt=-generate-arange-section"
+// LLDGARANGE: {{".*lld.*"}} {{.*}} "-plugin-opt=-generate-arange-section"
 // SNLDTLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} "-lto-thin-debug-options=-generate-arange-section"
 // SNLDFLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} "-lto-debug-options=-generate-arange-section"
 

diff  --git a/clang/test/Driver/ps4-ps5-linker-jmc.c b/clang/test/Driver/ps4-ps5-linker.c
similarity index 50%
rename from clang/test/Driver/ps4-ps5-linker-jmc.c
rename to clang/test/Driver/ps4-ps5-linker.c
index f5accd14291c4..ee8e96bbfbd02 100644
--- a/clang/test/Driver/ps4-ps5-linker-jmc.c
+++ b/clang/test/Driver/ps4-ps5-linker.c
@@ -7,14 +7,23 @@
 // 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-PS5-NOT: "-enable-jmc-instrument"
-
-// CHECK-PS5-LTO: "-mllvm" "-enable-jmc-instrument"
+// CHECK-PS5-NOT: -plugin-opt=-enable-jmc-instrument
+// CHECK-PS5-LTO: -plugin-opt=-enable-jmc-instrument
 
 // Check the default library name.
 // CHECK-PS4-LIB: "--whole-archive" "-lSceDbgJmc" "--no-whole-archive"
 // CHECK-PS5-LIB: "--whole-archive" "-lSceJmc_nosubmission" "--no-whole-archive"
+
+// Test the driver's control over the -fcrash-diagnostics-dir behavior with linker flags.
+
+// RUN: %clang --target=x86_64-scei-ps4 -flto=thin -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-PS4-THIN-LTO %s
+// RUN: %clang --target=x86_64-scei-ps4 -flto=full -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-PS4-FULL-LTO %s
+// 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-PS5-NOT: -plugin-opt=-crash-diagnostics-dir=mydumps
+// CHECK-DIAG-PS5-LTO: -plugin-opt=-crash-diagnostics-dir=mydumps


        


More information about the cfe-commits mailing list