[PATCH] D148034: [clang][driver] Disable GP relaxation with RISC-V ShadowCallStack

Paul Kirth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 11 11:11:46 PDT 2023


paulkirth created this revision.
paulkirth added reviewers: phosek, mcgrathr, jrtc27, craig.topper, aaron.ballman.
Herald added subscribers: VincentWu, vkmr, luismarques, sameer.abuasal, s.egerton, Jim, PkmX, rogfer01, shiva0217, kito-cheng, simoncook, asb, arichardson.
Herald added a project: All.
paulkirth requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay.
Herald added a project: clang.

GP linker relaxation conflicts with the use of `x3` (`gp`) register as
the SCS register on RISC-V. To avoid incompatibility, we pass the
`--no-relax-gp` to the linker.

Depends on D147983 <https://reviews.llvm.org/D147983>, D148031 <https://reviews.llvm.org/D148031>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148034

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/sanitizer-ld.c


Index: clang/test/Driver/sanitizer-ld.c
===================================================================
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -738,18 +738,32 @@
 // RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-ELF-RISCV32 %s
 // CHECK-SHADOWCALLSTACK-ELF-RISCV32: '-fsanitize=shadow-call-stack' only allowed with '-ffixed-x18'
 
+// RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
+// RUN:     --target=riscv32-unknown-linux -fuse-ld=ld -ffixed-x18 \
+// RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-ELF-RISCV32-FIXED-X18 %s
+// CHECK-SHADOWCALLSTACK-ELF-RISCV32-FIXED-X18: --no-relax-gp
+// CHECK-SHADOWCALLSTACK-ELF-RISCV32-FIXED-X18-NOT: error:
+
 // RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
 // RUN:     --target=riscv64-unknown-linux -fuse-ld=ld \
 // RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-LINUX-RISCV64 %s
 // CHECK-SHADOWCALLSTACK-LINUX-RISCV64: '-fsanitize=shadow-call-stack' only allowed with '-ffixed-x18'
 
+// RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
+// RUN:     --target=riscv64-unknown-linux -fuse-ld=ld -ffixed-x18 \
+// RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-LINUX-RISCV64-FIXED-X18 %s
+// CHECK-SHADOWCALLSTACK-LINUX-RISCV64-FIXED-X18: --no-relax-gp
+// CHECK-SHADOWCALLSTACK-LINUX-RISCV64-FIXED-X18-NOT: error:
+
 // RUN: %clang -target riscv64-linux-android -fsanitize=shadow-call-stack %s -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-SHADOWCALLSTACK-ANDROID-RISCV64
+// CHECK-SHADOWCALLSTACK-ANDROID-RISCV64: --no-relax-gp
 // CHECK-SHADOWCALLSTACK-ANDROID-RISCV64-NOT: error:
 
 // RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
 // RUN:     --target=riscv64-unknown-fuchsia -fuse-ld=ld \
 // RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-FUCHSIA-RISCV64 %s
+// CHECK-SHADOWCALLSTACK-FUCHSIA-RISCV64: --no-relax-gp
 // CHECK-SHADOWCALLSTACK-FUCHSIA-RISCV64-NOT: error:
 
 // RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1183,6 +1183,9 @@
       CmdArgs.push_back("--android-memtag-stack");
   }
 
+  if (SanArgs.hasShadowCallStack() && TC.getTriple().isRISCV())
+    CmdArgs.push_back("--no-relax-gp");
+
   return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148034.512530.patch
Type: text/x-patch
Size: 2500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230411/36e90645/attachment.bin>


More information about the cfe-commits mailing list