-
Notifications
You must be signed in to change notification settings - Fork 14.5k
SafeStack: Emit call to __stack_chk_fail through RuntimeLibcalls #147915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arsenm
merged 1 commit into
main
from
users/arsenm/safestack/use-runtime-libcalls-__stack_chk_fail
Jul 15, 2025
Merged
SafeStack: Emit call to __stack_chk_fail through RuntimeLibcalls #147915
arsenm
merged 1 commit into
main
from
users/arsenm/safestack/use-runtime-libcalls-__stack_chk_fail
Jul 15, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Jul 10, 2025
This was referenced Jul 10, 2025
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-backend-nvptx Author: Matt Arsenault (arsenm) ChangesAvoid hardcoding the function name, and query if it's really Full diff: https://github.com/llvm/llvm-project/pull/147915.diff 3 Files Affected:
diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp
index da229f86f24ce..a6c1a76f53f39 100644
--- a/llvm/lib/CodeGen/SafeStack.cpp
+++ b/llvm/lib/CodeGen/SafeStack.cpp
@@ -475,8 +475,16 @@ void SafeStack::checkStackGuard(IRBuilder<> &IRB, Function &F, Instruction &RI,
SplitBlockAndInsertIfThen(Cmp, &RI, /* Unreachable */ true, Weights, DTU);
IRBuilder<> IRBFail(CheckTerm);
// FIXME: respect -fsanitize-trap / -ftrap-function here?
+ const char *StackChkFailName =
+ TL.getLibcallName(RTLIB::STACKPROTECTOR_CHECK_FAIL);
+ if (!StackChkFailName) {
+ F.getContext().emitError(
+ "no libcall available for stackprotector check fail");
+ return;
+ }
+
FunctionCallee StackChkFail =
- F.getParent()->getOrInsertFunction("__stack_chk_fail", IRB.getVoidTy());
+ F.getParent()->getOrInsertFunction(StackChkFailName, IRB.getVoidTy());
IRBFail.CreateCall(StackChkFail, {});
}
diff --git a/llvm/test/Transforms/SafeStack/NVPTX/lit.local.cfg b/llvm/test/Transforms/SafeStack/NVPTX/lit.local.cfg
new file mode 100644
index 0000000000000..0d37b86e1c8e6
--- /dev/null
+++ b/llvm/test/Transforms/SafeStack/NVPTX/lit.local.cfg
@@ -0,0 +1,2 @@
+if not "NVPTX" in config.root.targets:
+ config.unsupported = True
diff --git a/llvm/test/Transforms/SafeStack/NVPTX/safestack-libcall-error.ll b/llvm/test/Transforms/SafeStack/NVPTX/safestack-libcall-error.ll
new file mode 100644
index 0000000000000..a17a9dd867e3a
--- /dev/null
+++ b/llvm/test/Transforms/SafeStack/NVPTX/safestack-libcall-error.ll
@@ -0,0 +1,12 @@
+; RUN: not opt -disable-output -mtriple=nvptx64-- -mcpu=sm_90 -passes=safe-stack %s 2>&1 | FileCheck %s
+
+; CHECK: error: no libcall available for stackprotector check fail
+define void @foo(i32 %t) #0 {
+ %vla = alloca i32, i32 %t, align 4
+ call void @baz(ptr %vla)
+ ret void
+}
+
+declare void @baz(ptr)
+
+attributes #0 = { nounwind safestack sspstrong }
|
MaskRay
approved these changes
Jul 15, 2025
cb3cf0b
to
a74db10
Compare
ed4c2aa
to
562bee8
Compare
RKSimon
approved these changes
Jul 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
562bee8
to
f467d13
Compare
Base automatically changed from
users/arsenm/runtime-libcalls/add-exception-libcall-entries
to
main
July 15, 2025 09:40
Avoid hardcoding the function name, and query if it's really supported or not.
a74db10
to
3c4dcd4
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Avoid hardcoding the function name, and query if it's really
supported or not.