Files
clang-p2996/llvm/test/Transforms/SafeStack/X86/ssp.ll
Pengxuan Zheng 056733d019 [SafeStack] Use proper API to get stack guard
Using the proper API automatically sets `__stack_chk_guard` to `dso_local` if
`Reloc::Static`. This wasn't strictly necessary until recently when dso_local was
no longer implied by `TargetMachine::shouldAssumeDSOLocal` for
`__stack_chk_guard`. By using the proper API, we can avoid generating unnecessary
GOT relocations.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102646
2021-05-30 00:52:48 -07:00

31 lines
1004 B
LLVM

; RUN: opt -safe-stack -S -mtriple=x86_64-unknown < %s -o - | FileCheck %s
define void @foo() safestack sspreq {
entry:
; CHECK: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr
; CHECK: %[[USST:.*]] = getelementptr i8, i8* %[[USP]], i32 -16
; CHECK: store i8* %[[USST]], i8** @__safestack_unsafe_stack_ptr
; CHECK: %[[A:.*]] = getelementptr i8, i8* %[[USP]], i32 -8
; CHECK: %[[StackGuardSlot:.*]] = bitcast i8* %[[A]] to i8**
; CHECK: %[[StackGuard:.*]] = call i8* @llvm.stackguard()
; CHECK: store i8* %[[StackGuard]], i8** %[[StackGuardSlot]]
%a = alloca i8, align 1
; CHECK: call void @Capture
call void @Capture(i8* %a)
; CHECK: %[[B:.*]] = load i8*, i8** %[[StackGuardSlot]]
; CHECK: %[[COND:.*]] = icmp ne i8* %[[StackGuard]], %[[B]]
; CHECK: br i1 %[[COND]], {{.*}} !prof
; CHECK: call void @__stack_chk_fail()
; CHECK-NEXT: unreachable
; CHECK: store i8* %[[USP]], i8** @__safestack_unsafe_stack_ptr
; CHECK-NEXT: ret void
ret void
}
declare void @Capture(i8*)