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(); }
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(); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits