Skip to content

Commit f27ab2d

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 f27ab2d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

llvm/lib/CodeGen/StackProtector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,8 @@ 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);
729-
B.CreateCall(StackChkFail, Args);
728+
CallInst *Call = B.CreateCall(StackChkFail, Args);
729+
Call->addFnAttr(Attribute::NoReturn);
730730
B.CreateUnreachable();
731731
return FailBB;
732732
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
;; __stack_chk_fail should have the noreturn attr even if it is an alias
2+
; RUN: opt -mtriple=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+
; CHECK: CallStackCheckFailBlk:
12+
; CHECK-NEXT: call void @__stack_chk_fail() [[ATTRS:#.*]]
13+
define void @store_captures() sspstrong {
14+
entry:
15+
%a = alloca i32, align 4
16+
%j = alloca ptr, align 8
17+
store ptr %a, ptr %j, align 8
18+
ret void
19+
}
20+
21+
; CHECK: attributes [[ATTRS]] = { noreturn }

0 commit comments

Comments
 (0)