-
Notifications
You must be signed in to change notification settings - Fork 14k
[llvm][StackProtector] Add noreturn to __stack_chk_fail call #143976
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
Conversation
@llvm/pr-subscribers-llvm-transforms Author: None (PiJoules) ChangesIt's possible for __stack_chk_fail to be an alias when using CrossDSOCFI since it will make a jump table entry for this function and replace it with an alias. StackProtector can crash since it always expects this to be a regular function. I think it should be safe to continue treating this as an alias since we only call into it, and we can apply the noreturn attr to the underlying function if it is an alias. Full diff: https://github.com/llvm/llvm-project/pull/143976.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp
index 5f866eea7d4e7..0e5c421d2fa5e 100644
--- a/llvm/lib/CodeGen/StackProtector.cpp
+++ b/llvm/lib/CodeGen/StackProtector.cpp
@@ -725,7 +725,9 @@ BasicBlock *CreateFailBB(Function *F, const Triple &Trip) {
StackChkFail =
M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context));
}
- cast<Function>(StackChkFail.getCallee())->addFnAttr(Attribute::NoReturn);
+ cast<Function>(
+ cast<GlobalValue>(StackChkFail.getCallee())->getAliaseeObject())
+ ->addFnAttr(Attribute::NoReturn);
B.CreateCall(StackChkFail, Args);
B.CreateUnreachable();
return FailBB;
diff --git a/llvm/test/Transforms/StackProtector/stack-chk-fail-alias.ll b/llvm/test/Transforms/StackProtector/stack-chk-fail-alias.ll
new file mode 100644
index 0000000000000..9314800cf0441
--- /dev/null
+++ b/llvm/test/Transforms/StackProtector/stack-chk-fail-alias.ll
@@ -0,0 +1,17 @@
+;; __stack_chk_fail should have the noreturn attr even if it is an alias
+; RUN: opt -triple=x86_64-pc-linux-gnu %s -passes=stack-protector -S | FileCheck %s
+
+define hidden void @__stack_chk_fail_impl() {
+ unreachable
+}
+
+@__stack_chk_fail = hidden alias void (), ptr @__stack_chk_fail_impl
+
+; CHECK-LABEL: @store_captures(
+define void @store_captures() sspstrong {
+entry:
+ %a = alloca i32, align 4
+ %j = alloca ptr, align 8
+ store ptr %a, ptr %j, align 8
+ ret void
+}
|
704e60f
to
f27ab2d
Compare
Shouldn’t we have a test for crossdsocfi if that’s the bug you’re fixing gets exercised? Certainly the simple test you’ve added is good, but I’d think we want to test the actual failure case as well. |
f27ab2d
to
11b9450
Compare
Done |
It's possible for __stack_chk_fail to be an alias when using CrossDSOCFI since it will make a jump table entry for this function and replace it with an alias. StackProtector can crash since it always expects this to be a regular function. I think it should be safe to continue treating this as an alias since we only call into it, and we can apply the noreturn attr to the underlying function if it is an alias.
11b9450
to
8907144
Compare
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
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. Thanks for adding the regression test.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/21563 Here is the relevant piece of the build log for the reference
|
…#144452) Reverts #143976 Reverting since this broke a builder: https://lab.llvm.org/buildbot/#/builders/190/builds/21563
…_fail call" (#144452) Reverts llvm/llvm-project#143976 Reverting since this broke a builder: https://lab.llvm.org/buildbot/#/builders/190/builds/21563
It's possible for __stack_chk_fail to be an alias when using CrossDSOCFI since it will make a jump table entry for this function and replace it with an alias. StackProtector can crash since it always expects this to be a regular function. Instead add the noreturn attribute to the call.