ychen created this revision.
ychen added a reviewer: probinson.
Herald added a subscriber: inglorion.
Herald added a project: All.
ychen requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Also refactor the existing code a little bit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134673

Files:
  clang/lib/Driver/ToolChains/PS4CPU.cpp
  clang/test/Driver/debug-options.c
  clang/test/Driver/ps4-ps5-linker-jmc.c
  clang/test/Driver/ps4-ps5-linker.c

Index: clang/test/Driver/ps4-ps5-linker.c
===================================================================
--- clang/test/Driver/ps4-ps5-linker.c
+++ 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
Index: clang/test/Driver/debug-options.c
===================================================================
--- clang/test/Driver/debug-options.c
+++ 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"
 
Index: clang/lib/Driver/ToolChains/PS4CPU.cpp
===================================================================
--- clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -158,34 +158,32 @@
   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))
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to