[clang] [clang][Driver] Prevent Safe Stack runtime from linking if enabled then disabled (PR #228537)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux-bootstrap-asan` running on `sanitizer-buildbot1` while building `clang` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/52/builds/20587 Here is the relevant piece of the build log for the reference ``` Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) ... llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using ld.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using lld-link: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using ld.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using lld-link: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld -- Testing: 105772 tests, 64 workers -- Testing: 0.. 10.. 20.. 30.. 40.. 50.. FAIL: LLVM :: ExecutionEngine/JITLink/x86-64/MachO_weak_references.s (64900 of 105772) TEST 'LLVM :: ExecutionEngine/JITLink/x86-64/MachO_weak_references.s' FAILED Exit Code: 1 Command Output (stdout): -- # RUN: at line 1 rm -rf /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp && mkdir -p /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp # executed command: rm -rf /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp # note: command had no output on stdout or stderr # executed command: mkdir -p /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp # note: command had no output on stdout or stderr # RUN: at line 2 /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s # executed command: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s # note: command had no output on stdout or stderr # RUN: at line 3 /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-jitlink -noexec -check-name=jitlink-check-bar-present -abs bar=0x1 -check=/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o # executed command: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-jitlink -noexec -check-name=jitlink-check-bar-present -abs bar=0x1
[clang] [clang][Driver] Prevent Safe Stack runtime from linking if enabled then disabled (PR #228537)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `lldb-arm-ubuntu` running on `linaro-lldb-arm-ubuntu` while building `clang` at step 6 "test". Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/27317 Here is the relevant piece of the build log for the reference ``` Step 6 (test) failure: build (failure) ... PASS: lldb-api :: functionalities/thread/ignore_suspended/TestIgnoreSuspendedThread.py (784 of 3012) XFAIL: lldb-api :: functionalities/thread/create_during_step/TestCreateDuringStep.py (785 of 3012) PASS: lldb-api :: functionalities/thread/exit_during_break/TestExitDuringBreak.py (786 of 3012) PASS: lldb-api :: functionalities/thread/multi_break/TestMultipleBreakpoints.py (787 of 3012) PASS: lldb-api :: functionalities/thread/num_threads/TestNumThreads.py (788 of 3012) PASS: lldb-api :: functionalities/thread/jump/TestThreadJump.py (789 of 3012) PASS: lldb-api :: functionalities/thread/main_thread_exit/TestMainThreadExit.py (790 of 3012) PASS: lldb-api :: functionalities/thread/step_out/TestThreadStepOut.py (791 of 3012) PASS: lldb-api :: functionalities/thread/step_out_inline/TestThreadStepOutInline.py (792 of 3012) PASS: lldb-api :: functionalities/thread/exit_during_expression/TestExitDuringExpression.py (793 of 3012) FAIL: lldb-api :: functionalities/thread/exit_during_step/TestExitDuringStep.py (794 of 3012) TEST 'lldb-api :: functionalities/thread/exit_during_step/TestExitDuringStep.py' FAILED Script: -- /usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --triple armv8l-unknown-linux-gnueabihf --build-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb --lldb-python-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/local/lib/python3.10/dist-packages --compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --cmake-build-type Release /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/functionalities/thread/exit_during_step -p TestExitDuringStep.py --timeout 600 -- Exit Code: 1 Command Output (stdout): -- Skipping the following test categories: libc++, msvcstl, dsym, pdb, gmodules, debugserver, objc -- Command Output (stderr): -- UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_dsym (TestExitDuringStep.ExitDuringStepTestCase) (test case does not fall in any category of interest for this run) PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_dwarf (TestExitDuringStep.ExitDuringStepTestCase) PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_dwo (TestExitDuringStep.ExitDuringStepTestCase) UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_step_in_dsym (TestExitDuringStep.ExitDuringStepTestCase) (test case does not fall in any category of interest for this run) PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_step_in_dwarf (TestExitDuringStep.ExitDuringStepTestCase) PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_step_in_dwo (TestExitDuringStep.ExitDuringStepTestCase) UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_step_over_dsym (TestExitDuringStep.ExitDuringStepTestCase) (test case does not fall in any category of interest for this run) PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_step_over_dwarf (TestExitDuringStep.ExitDuringStepTestCase) FAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_step_over_dwo (TestExitDuringStep.ExitDuringStepTestCase) Log Files: - /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build/functionalities/thread/exit_during_step/TestExitDuringStep.dwo/Failure_test_step_over_dwo.log == FAIL: test_step_over_dwo (TestExitDuringStep.ExitDuringStepTestCase)
[clang] [clang][Driver] Prevent Safe Stack runtime from linking if enabled then disabled (PR #228537)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux-fast` running on `sanitizer-buildbot3` while building `clang` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/169/builds/27175 Here is the relevant piece of the build log for the reference ``` Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) ... llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using ld.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using ld.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:572: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld -- Testing: 105772 tests, 64 workers -- Testing: 0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90 FAIL: LLVM :: ExecutionEngine/JITLink/x86-64/MachO_test_harness_harness.s (64613 of 105772) TEST 'LLVM :: ExecutionEngine/JITLink/x86-64/MachO_test_harness_harness.s' FAILED Exit Code: 1 Command Output (stdout): -- # RUN: at line 1 rm -rf /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_test_harness_harness.s.tmp && mkdir -p /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_test_harness_harness.s.tmp # executed command: rm -rf /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_test_harness_harness.s.tmp # note: command had no output on stdout or stderr # executed command: mkdir -p /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_test_harness_harness.s.tmp # note: command had no output on stdout or stderr # RUN: at line 2 /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj-o /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_test_harness_harness.s.tmp/file_to_test.o /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/Inputs/MachO_test_harness_test.s # executed command: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_test_harness_harness.s.tmp/file_to_test.o /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/Inputs/MachO_test_harness_test.s # note: command had no output on stdout or stderr # RUN: at line 4 /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj-o /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_test_harness_harness.s.tmp/test_harness.o /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_test_harness_harness.s # executed command: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_test_harness_harness.s.tmp/test_harness.o
[clang] [clang][Driver] Prevent Safe Stack runtime from linking if enabled then disabled (PR #228537)
https://github.com/vitalybuka closed https://github.com/llvm/llvm-project/pull/228537 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Prevent Safe Stack runtime from linking if enabled then disabled (PR #228537)
https://github.com/vitalybuka auto_merge_enabled https://github.com/llvm/llvm-project/pull/228537 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Prevent Safe Stack runtime from linking if enabled then disabled (PR #228537)
https://github.com/vitalybuka updated
https://github.com/llvm/llvm-project/pull/228537
>From e9f359c27619f5adf58d4cbf7dfac4a04a8bb575 Mon Sep 17 00:00:00 2001
From: Douglas Gliner
Date: Fri, 2 Oct 2026 10:29:58 -0700
Subject: [PATCH] [clang][Driver] Prevent Safe Stack runtime from linking if
enabled then disabled
Currently:
```
$ ./clang -fsanitize=safe-stack -fno-sanitize=safe-stack -Wl,--trace -x c++ -o-
- < /dev/null
...
.../libclang_rt.safestack.a
...
```
See https://godbolt.org/z/e63za9sjn
With this change, `libclang_rt.safestack.a` is not included when Safe Stack is
disabled as the last option. This is because `Kinds` is the final resolved set
of sanitizers after removals via `-fno-sanitize`. `AllAddedKinds` is the set
of all sanitizers which were seen at least once even if they were removed.
This change makes it so we check against `Kinds` instead of `AllAddedKinds`.
Besides Safe Stack, there are quite a few options resolved and passed to the
driver unintentionally when using particular combinations of `-fsanitize` and
`-fno-sanitize`. This is filed as
https://github.com/llvm/llvm-project/issues/228529.
Should fix https://github.com/llvm/llvm-project/issues/107763.
---
clang/lib/Driver/SanitizerArgs.cpp | 2 +-
clang/test/Driver/sanitizer-ld.c | 25 +
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/clang/lib/Driver/SanitizerArgs.cpp
b/clang/lib/Driver/SanitizerArgs.cpp
index 438283c60c0ba2f..a1bfa90e5dceb28 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -1309,7 +1309,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
HwasanUseAliases);
}
- if (AllAddedKinds & SanitizerKind::SafeStack) {
+ if (Kinds & SanitizerKind::SafeStack) {
// SafeStack runtime is built into the system on Android and Fuchsia.
SafeStackRuntime =
!TC.getTriple().isAndroid() && !TC.getTriple().isOSFuchsia();
diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
index f55c2917408a28b..d54232e2650b276 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -1017,16 +1017,25 @@
// RUN: --target=x86_64-unknown-linux -fuse-ld=ld -fsanitize=safe-stack \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
-// RUN: | %{filecheck} --check-prefix=CHECK-SAFESTACK-LINUX
+// RUN: | %{filecheck}
--check-prefixes=CHECK-SAFESTACK-LINUX,CHECK-SAFESTACK-LINUX-ENABLED
+//
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
+// RUN: -fsanitize=safe-stack -fno-sanitize=safe-stack \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: | %{filecheck}
--check-prefixes=CHECK-SAFESTACK-LINUX,CHECK-SAFESTACK-LINUX-DISABLED
//
// CHECK-SAFESTACK-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-SAFESTACK-LINUX-NOT: "-lc"
-// CHECK-SAFESTACK-LINUX-NOT: whole-archive
-// CHECK-SAFESTACK-LINUX: "-u" "__safestack_init"
-// CHECK-SAFESTACK-LINUX: libclang_rt.safestack.a"
-// CHECK-SAFESTACK-LINUX: "-lpthread"
-// CHECK-SAFESTACK-LINUX: "-ldl"
-// CHECK-SAFESTACK-LINUX: "-lresolv"
+// CHECK-SAFESTACK-LINUX-ENABLED-NOT: "-lc"
+// CHECK-SAFESTACK-LINUX-ENABLED-NOT: whole-archive
+// CHECK-SAFESTACK-LINUX-ENABLED: "-u" "__safestack_init"
+// CHECK-SAFESTACK-LINUX-ENABLED: libclang_rt.safestack.a"
+// CHECK-SAFESTACK-LINUX-ENABLED: "-lpthread"
+// CHECK-SAFESTACK-LINUX-ENABLED: "-ldl"
+// CHECK-SAFESTACK-LINUX-ENABLED: "-lresolv"
+// CHECK-SAFESTACK-LINUX-DISABLED-NOT: "-u" "__safestack_init"
+// CHECK-SAFESTACK-LINUX-DISABLED-NOT: libclang_rt.safestack.a"
// RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
// RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Prevent Safe Stack runtime from linking if enabled then disabled (PR #228537)
https://github.com/vitalybuka approved this pull request. https://github.com/llvm/llvm-project/pull/228537 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Prevent Safe Stack runtime from linking if enabled then disabled (PR #228537)
llvmorg-github-actions[bot] wrote:
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-driver
Author: Douglas (dgg5503)
Changes
Currently:
```
$ ./clang -fsanitize=safe-stack -fno-sanitize=safe-stack -Wl,--trace -x c++ -o-
- < /dev/null
...
.../libclang_rt.safestack.a
...
```
See https://godbolt.org/z/e63za9sjn
With this change, `libclang_rt.safestack.a` is not included when Safe Stack is
disabled as the last option. This is because `Kinds` is the final resolved set
of sanitizers after removals via `-fno-sanitize`. `AllAddedKinds` is the set of
all sanitizers which were seen at least once even if they were removed. This
change makes it so we check against `Kinds` instead of `AllAddedKinds`.
Besides Safe Stack, there are quite a few options resolved and passed to the
driver unintentionally when using particular combinations of `-fsanitize` and
`-fno-sanitize`. This is filed as
https://github.com/llvm/llvm-project/issues/228529.
Should fix https://github.com/llvm/llvm-project/issues/107763.
---
Full diff: https://github.com/llvm/llvm-project/pull/228537.diff
2 Files Affected:
- (modified) clang/lib/Driver/SanitizerArgs.cpp (+1-1)
- (modified) clang/test/Driver/sanitizer-ld.c (+17-8)
``diff
diff --git a/clang/lib/Driver/SanitizerArgs.cpp
b/clang/lib/Driver/SanitizerArgs.cpp
index 438283c60c0ba2..a1bfa90e5dceb2 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -1309,7 +1309,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
HwasanUseAliases);
}
- if (AllAddedKinds & SanitizerKind::SafeStack) {
+ if (Kinds & SanitizerKind::SafeStack) {
// SafeStack runtime is built into the system on Android and Fuchsia.
SafeStackRuntime =
!TC.getTriple().isAndroid() && !TC.getTriple().isOSFuchsia();
diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
index f55c2917408a28..d54232e2650b27 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -1017,16 +1017,25 @@
// RUN: --target=x86_64-unknown-linux -fuse-ld=ld -fsanitize=safe-stack \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
-// RUN: | %{filecheck} --check-prefix=CHECK-SAFESTACK-LINUX
+// RUN: | %{filecheck}
--check-prefixes=CHECK-SAFESTACK-LINUX,CHECK-SAFESTACK-LINUX-ENABLED
+//
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
+// RUN: -fsanitize=safe-stack -fno-sanitize=safe-stack \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: | %{filecheck}
--check-prefixes=CHECK-SAFESTACK-LINUX,CHECK-SAFESTACK-LINUX-DISABLED
//
// CHECK-SAFESTACK-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-SAFESTACK-LINUX-NOT: "-lc"
-// CHECK-SAFESTACK-LINUX-NOT: whole-archive
-// CHECK-SAFESTACK-LINUX: "-u" "__safestack_init"
-// CHECK-SAFESTACK-LINUX: libclang_rt.safestack.a"
-// CHECK-SAFESTACK-LINUX: "-lpthread"
-// CHECK-SAFESTACK-LINUX: "-ldl"
-// CHECK-SAFESTACK-LINUX: "-lresolv"
+// CHECK-SAFESTACK-LINUX-ENABLED-NOT: "-lc"
+// CHECK-SAFESTACK-LINUX-ENABLED-NOT: whole-archive
+// CHECK-SAFESTACK-LINUX-ENABLED: "-u" "__safestack_init"
+// CHECK-SAFESTACK-LINUX-ENABLED: libclang_rt.safestack.a"
+// CHECK-SAFESTACK-LINUX-ENABLED: "-lpthread"
+// CHECK-SAFESTACK-LINUX-ENABLED: "-ldl"
+// CHECK-SAFESTACK-LINUX-ENABLED: "-lresolv"
+// CHECK-SAFESTACK-LINUX-DISABLED-NOT: "-u" "__safestack_init"
+// CHECK-SAFESTACK-LINUX-DISABLED-NOT: libclang_rt.safestack.a"
// RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
// RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
``
https://github.com/llvm/llvm-project/pull/228537
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Prevent Safe Stack runtime from linking if enabled then disabled (PR #228537)
https://github.com/dgg5503 created
https://github.com/llvm/llvm-project/pull/228537
Currently:
```
$ ./clang -fsanitize=safe-stack -fno-sanitize=safe-stack -Wl,--trace -x c++ -o-
- < /dev/null
...
.../libclang_rt.safestack.a
...
```
See https://godbolt.org/z/e63za9sjn
With this change, `libclang_rt.safestack.a` is not included when Safe Stack is
disabled as the last option. This is because `Kinds` is the final resolved set
of sanitizers after removals via `-fno-sanitize`. `AllAddedKinds` is the set of
all sanitizers which were seen at least once even if they were removed. This
change makes it so we check against `Kinds` instead of `AllAddedKinds`.
Besides Safe Stack, there are quite a few options resolved and passed to the
driver unintentionally when using particular combinations of `-fsanitize` and
`-fno-sanitize`. This is filed as
https://github.com/llvm/llvm-project/issues/228529.
Should fix https://github.com/llvm/llvm-project/issues/107763.
>From e9f359c27619f5adf58d4cbf7dfac4a04a8bb575 Mon Sep 17 00:00:00 2001
From: Douglas Gliner
Date: Fri, 2 Oct 2026 10:29:58 -0700
Subject: [PATCH] [clang][Driver] Prevent Safe Stack runtime from linking if
enabled then disabled
Currently:
```
$ ./clang -fsanitize=safe-stack -fno-sanitize=safe-stack -Wl,--trace -x c++ -o-
- < /dev/null
...
.../libclang_rt.safestack.a
...
```
See https://godbolt.org/z/e63za9sjn
With this change, `libclang_rt.safestack.a` is not included when Safe Stack is
disabled as the last option. This is because `Kinds` is the final resolved set
of sanitizers after removals via `-fno-sanitize`. `AllAddedKinds` is the set
of all sanitizers which were seen at least once even if they were removed.
This change makes it so we check against `Kinds` instead of `AllAddedKinds`.
Besides Safe Stack, there are quite a few options resolved and passed to the
driver unintentionally when using particular combinations of `-fsanitize` and
`-fno-sanitize`. This is filed as
https://github.com/llvm/llvm-project/issues/228529.
Should fix https://github.com/llvm/llvm-project/issues/107763.
---
clang/lib/Driver/SanitizerArgs.cpp | 2 +-
clang/test/Driver/sanitizer-ld.c | 25 +
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/clang/lib/Driver/SanitizerArgs.cpp
b/clang/lib/Driver/SanitizerArgs.cpp
index 438283c60c0ba2..a1bfa90e5dceb2 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -1309,7 +1309,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
HwasanUseAliases);
}
- if (AllAddedKinds & SanitizerKind::SafeStack) {
+ if (Kinds & SanitizerKind::SafeStack) {
// SafeStack runtime is built into the system on Android and Fuchsia.
SafeStackRuntime =
!TC.getTriple().isAndroid() && !TC.getTriple().isOSFuchsia();
diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
index f55c2917408a28..d54232e2650b27 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -1017,16 +1017,25 @@
// RUN: --target=x86_64-unknown-linux -fuse-ld=ld -fsanitize=safe-stack \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
-// RUN: | %{filecheck} --check-prefix=CHECK-SAFESTACK-LINUX
+// RUN: | %{filecheck}
--check-prefixes=CHECK-SAFESTACK-LINUX,CHECK-SAFESTACK-LINUX-ENABLED
+//
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
+// RUN: -fsanitize=safe-stack -fno-sanitize=safe-stack \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: | %{filecheck}
--check-prefixes=CHECK-SAFESTACK-LINUX,CHECK-SAFESTACK-LINUX-DISABLED
//
// CHECK-SAFESTACK-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-SAFESTACK-LINUX-NOT: "-lc"
-// CHECK-SAFESTACK-LINUX-NOT: whole-archive
-// CHECK-SAFESTACK-LINUX: "-u" "__safestack_init"
-// CHECK-SAFESTACK-LINUX: libclang_rt.safestack.a"
-// CHECK-SAFESTACK-LINUX: "-lpthread"
-// CHECK-SAFESTACK-LINUX: "-ldl"
-// CHECK-SAFESTACK-LINUX: "-lresolv"
+// CHECK-SAFESTACK-LINUX-ENABLED-NOT: "-lc"
+// CHECK-SAFESTACK-LINUX-ENABLED-NOT: whole-archive
+// CHECK-SAFESTACK-LINUX-ENABLED: "-u" "__safestack_init"
+// CHECK-SAFESTACK-LINUX-ENABLED: libclang_rt.safestack.a"
+// CHECK-SAFESTACK-LINUX-ENABLED: "-lpthread"
+// CHECK-SAFESTACK-LINUX-ENABLED: "-ldl"
+// CHECK-SAFESTACK-LINUX-ENABLED: "-lresolv"
+// CHECK-SAFESTACK-LINUX-DISABLED-NOT: "-u" "__safestack_init"
+// CHECK-SAFESTACK-LINUX-DISABLED-NOT: libclang_rt.safestack.a"
// RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
// RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
