[PATCH] D131820: [PS4][driver] make -fjmc work with LTO driver linking stage

Yuanfang Chen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 12 17:39:55 PDT 2022


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.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131820

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


Index: clang/test/Driver/ps4-ps5-linker-jmc.c
===================================================================
--- /dev/null
+++ clang/test/Driver/ps4-ps5-linker-jmc.c
@@ -0,0 +1,22 @@
+// REQUIRES: x86-registered-target
+
+// 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-PS4,CHECK-PS4-LIB %s
+// RUN: %clang -target x86_64-scei-ps4 -flto=thin -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PS4-THIN-LTO,CHECK-PS4-LIB %s
+// RUN: %clang -target x86_64-scei-ps4 -flto=full -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PS4-FULL-LTO,CHECK-PS4-LIB %s
+// RUN: %clang -target x86_64-scei-ps5 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PS5,CHECK-PS5-LIB %s
+// 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 the default library name.
+// CHECK-PS4-LIB: "--whole-archive" "-lSceDbgJmc" "--no-whole-archive"
+// CHECK-PS5-LIB: "--whole-archive" "-lSceJmc_nosubmission" "--no-whole-archive"
Index: clang/lib/Driver/ToolChains/PS4CPU.cpp
===================================================================
--- clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -152,6 +152,26 @@
     assert(Output.isNothing() && "Invalid output.");
   }
 
+  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 bool IsPS5 = TC.getTriple().isPS5();
+  assert(IsPS4 || IsPS5);
+
+  // This tells LTO to perform JustMyCode instrumentation.
+  if (UseLTO && UseJMC) {
+    if (IsPS4 && D.getLTOMode() == LTOK_Thin) {
+      CmdArgs.push_back("-lto-thin-debug-options=-enable-jmc-instrument");
+    } else if (IsPS4 && D.getLTOMode() == LTOK_Full) {
+      CmdArgs.push_back("-lto-debug-options=-enable-jmc-instrument");
+    } else if (IsPS5) {
+      CmdArgs.push_back("-mllvm");
+      CmdArgs.push_back("-enable-jmc-instrument");
+    } else
+      llvm_unreachable("new LTO mode?");
+  }
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
     TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
@@ -171,6 +191,15 @@
     CmdArgs.push_back("-lpthread");
   }
 
+  if (UseJMC) {
+    CmdArgs.push_back("--whole-archive");
+    if (IsPS4)
+      CmdArgs.push_back("-lSceDbgJmc");
+    else
+      CmdArgs.push_back("-lSceJmc_nosubmission");
+    CmdArgs.push_back("--no-whole-archive");
+  }
+
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
     D.Diag(diag::err_drv_unsupported_opt_for_target)
         << "-fuse-ld" << TC.getTriple().str();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131820.452337.patch
Type: text/x-patch
Size: 3030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220813/f30ae742/attachment.bin>


More information about the cfe-commits mailing list