Skip to content

Commit 704e60f

Browse files
committed
[llvm][StackProtector] Add noreturn to __stack_chk_fail aliassee
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.
1 parent 4e765b7 commit 704e60f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

llvm/lib/CodeGen/StackProtector.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,9 @@ BasicBlock *CreateFailBB(Function *F, const Triple &Trip) {
725725
StackChkFail =
726726
M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context));
727727
}
728-
cast<Function>(StackChkFail.getCallee())->addFnAttr(Attribute::NoReturn);
728+
cast<Function>(
729+
cast<GlobalValue>(StackChkFail.getCallee())->getAliaseeObject())
730+
->addFnAttr(Attribute::NoReturn);
729731
B.CreateCall(StackChkFail, Args);
730732
B.CreateUnreachable();
731733
return FailBB;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
;; __stack_chk_fail should have the noreturn attr even if it is an alias
2+
; RUN: opt -triple=x86_64-pc-linux-gnu %s -passes=stack-protector -S | FileCheck %s
3+
4+
define hidden void @__stack_chk_fail_impl() {
5+
unreachable
6+
}
7+
8+
@__stack_chk_fail = hidden alias void (), ptr @__stack_chk_fail_impl
9+
10+
; CHECK-LABEL: @store_captures(
11+
define void @store_captures() sspstrong {
12+
entry:
13+
%a = alloca i32, align 4
14+
%j = alloca ptr, align 8
15+
store ptr %a, ptr %j, align 8
16+
ret void
17+
}

0 commit comments

Comments
 (0)