-
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
base: users/arsenm/runtime-libcalls/add-exception-libcall-entries
Are you sure you want to change the base?
Conversation
Avoid hardcoding the function name, and query if it's really supported or not.
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@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 }
|
Avoid hardcoding the function name, and query if it's really
supported or not.