It's currently ambiguous in IR whether the source language explicitly did not want a stack a stack protector (in C, via function attribute no_stack_protector) or doesn't care for any given function. It's common for code that manipulates the stack via inline assembly or that has to set up its own stack canary (such as the Linux kernel) would like to avoid stack protectors in certain functions. In this case, we've been bitten by numerous bugs where a callee with a stack protector is inlined into an __attribute__((__no_stack_protector__)) caller, which generally breaks the caller's assumptions about not having a stack protector. LTO exacerbates the issue. While developers can avoid this by putting all no_stack_protector functions in one translation unit together and compiling those with -fno-stack-protector, it's generally not very ergonomic or as ergonomic as a function attribute, and still doesn't work for LTO. See also: https://lore.kernel.org/linux-pm/20200915172658.1432732-1-rkir@google.com/ https://lore.kernel.org/lkml/20200918201436.2932360-30-samitolvanen@google.com/T/#u Typically, when inlining a callee into a caller, the caller will be upgraded in its level of stack protection (see adjustCallerSSPLevel()). By adding an explicit attribute in the IR when the function attribute is used in the source language, we can now identify such cases and prevent inlining. Block inlining when the callee and caller differ in the case that one contains `nossp` when the other has `ssp`, `sspstrong`, or `sspreq`. Fixes pr/47479. Reviewed By: void Differential Revision: https://reviews.llvm.org/D87956
65 lines
1.7 KiB
LLVM
65 lines
1.7 KiB
LLVM
; RUN: opt -inline -o - -S %s | FileCheck %s
|
|
; RUN: opt -passes='cgscc(inline)' %s -S | FileCheck %s
|
|
; RUN: opt -always-inline -o - -S %s | FileCheck %s
|
|
|
|
declare dso_local void @foo(i8*)
|
|
|
|
define dso_local void @ssp(i64 %0) #0 {
|
|
%2 = alloca i64, align 8
|
|
store i64 %0, i64* %2, align 8
|
|
%3 = load i64, i64* %2, align 8
|
|
%4 = alloca i8, i64 %3, align 16
|
|
call void @foo(i8* %4)
|
|
ret void
|
|
}
|
|
|
|
define dso_local void @ssp_alwaysinline(i64 %0) #1 {
|
|
%2 = alloca i64, align 8
|
|
store i64 %0, i64* %2, align 8
|
|
%3 = load i64, i64* %2, align 8
|
|
%4 = alloca i8, i64 %3, align 16
|
|
call void @foo(i8* %4)
|
|
ret void
|
|
}
|
|
|
|
define dso_local void @nossp() #2 {
|
|
; Check that the calls to @ssp and @ssp_alwaysinline are not inlined into
|
|
; @nossp, since @nossp does not want a stack protector.
|
|
; CHECK-LABEL: @nossp
|
|
; CHECK-NEXT: call void @ssp
|
|
; CHECK-NEXT: call void @ssp_alwaysinline
|
|
call void @ssp(i64 1024)
|
|
call void @ssp_alwaysinline(i64 1024)
|
|
ret void
|
|
}
|
|
|
|
define dso_local void @nossp_alwaysinline() #3 {
|
|
call void @ssp(i64 1024)
|
|
call void @ssp_alwaysinline(i64 1024)
|
|
ret void
|
|
}
|
|
|
|
define dso_local void @nossp_caller() #2 {
|
|
; Permit nossp callee to be inlined into nossp caller.
|
|
; CHECK-LABEL: @nossp_caller
|
|
; CHECK-NEXT: call void @ssp
|
|
; CHECK-NEXT: call void @ssp_alwaysinline
|
|
; CHECK-NOT: call void @nossp_alwaysinline
|
|
call void @nossp_alwaysinline()
|
|
ret void
|
|
}
|
|
|
|
define dso_local void @ssp2() #0 {
|
|
; Check the call to @nossp is not inlined, since @nossp should not have a stack
|
|
; protector.
|
|
; CHECK-LABEL: @ssp2
|
|
; CHECK-NEXT: call void @nossp
|
|
call void @nossp()
|
|
ret void
|
|
}
|
|
|
|
attributes #0 = { sspstrong }
|
|
attributes #1 = { sspstrong alwaysinline }
|
|
attributes #2 = { nossp }
|
|
attributes #3 = { nossp alwaysinline}
|