[clang] 45c7da2 - [PS4] Always enable the .debug_aranges section when using LTO

Matthew Voss via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 20 14:47:36 PDT 2022


Author: Matthew Voss
Date: 2022-09-20T14:44:56-07:00
New Revision: 45c7da241f124d49abdc0598d381d96d15918834

URL: https://github.com/llvm/llvm-project/commit/45c7da241f124d49abdc0598d381d96d15918834
DIFF: https://github.com/llvm/llvm-project/commit/45c7da241f124d49abdc0598d381d96d15918834.diff

LOG: [PS4] Always enable the .debug_aranges section when using LTO

This flag enables the .debug_aranges section by passing a flag to LLD
and our internal linker. This also adds a new routine that will generate
the correct flag for our internal linker or set of flags for LLD when
given a list of LLVM options. That ensures multiple LLVM codegen options
can be passed to either linker consistently.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 97688470008f..fc905ff74fd7 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -159,17 +159,32 @@ void tools::PScpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
   const bool IsPS5 = TC.getTriple().isPS5();
   assert(IsPS4 || IsPS5);
 
+  ArgStringList DbgOpts;
+
   // 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 (UseLTO && UseJMC)
+    DbgOpts.push_back("-enable-jmc-instrument");
+
+  // We default to creating the arange section, but LTO does not. Enable it
+  // here.
+  if (UseLTO)
+    DbgOpts.push_back("-generate-arange-section");
+
+  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);
+      }
+    }
   }
 
   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 04004716aa50..96c0763fbf9c 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -107,6 +107,14 @@
 // 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=SNLDTLTOGARANGE %s
+// RUN: %clang -### %s -g -flto=full -target x86_64-scei-ps4 2>&1 \
+// RUN:             | FileCheck -check-prefix=SNLDFLTOGARANGE %s
+// RUN: %clang -### %s -g -flto -target x86_64-scei-ps5 2>&1 \
+// RUN:             | FileCheck -check-prefix=LLDGARANGE %s
+// RUN: %clang -### %s -g -target x86_64-scei-ps5 2>&1 \
+// RUN:             | FileCheck -check-prefix=LDGARANGE %s
 
 // On the AIX, -g defaults to -gdbx and limited debug info.
 // RUN: %clang -### -c -g %s -target powerpc-ibm-aix-xcoff 2>&1 \
@@ -365,6 +373,13 @@
 // NOPUB-NOT: -ggnu-pubnames
 // NOPUB-NOT: -gpubnames
 //
+
+// LDGARANGE: {{".*ld.*"}} {{.*}}
+// LDGARANGE-NOT: "-generate-arange-section"
+// LLDGARANGE: {{".*lld.*"}} {{.*}} "-generate-arange-section"
+// SNLDTLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} "-lto-thin-debug-options=-generate-arange-section"
+// SNLDFLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} "-lto-debug-options=-generate-arange-section"
+
 // PUB: -gpubnames
 //
 // RNGBSE: -fdebug-ranges-base-address

diff  --git a/clang/test/Driver/ps4-ps5-linker-jmc.c b/clang/test/Driver/ps4-ps5-linker-jmc.c
index 3d308d13e64f..f5accd14291c 100644
--- a/clang/test/Driver/ps4-ps5-linker-jmc.c
+++ b/clang/test/Driver/ps4-ps5-linker-jmc.c
@@ -6,10 +6,10 @@
 // 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-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=-enable-jmc-instrument
+// CHECK-PS4-FULL-LTO: -lto-debug-options=-enable-jmc-instrument
 
 // CHECK-PS5-NOT: "-enable-jmc-instrument"
 


        


More information about the cfe-commits mailing list