Skip to content

Commit

Permalink
Add a "probe-stack" attribute
Browse files Browse the repository at this point in the history
This attribute is used to ensure the guard page is triggered on stack
overflow. Stack frames larger than the guard page size will generate
a call to __probestack to touch each page so the guard page won't
be skipped.

Reviewed By: majnemer

Differential Revision: https://reviews.llvm.org/D34386

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305939 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
whitequark authored and arielb1 committed Jun 27, 2017
1 parent 4a6869c commit d00e96a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,19 @@ example:
This attribute by itself does not imply restrictions on
inter-procedural optimizations. All of the semantic effects the
patching may have to be separately conveyed via the linkage type.
``"probe-stack"``
This attribute indicates that the function will trigger a guard region
in the end of the stack. It ensures that accesses to the stack must be
no further apart than the size of the guard region to a previous
access of the stack. It takes one required string value, the name of
the stack probing function that will be called.

If a function that has a ``"probe-stack"`` attribute is inlined into
a function with another ``"probe-stack"`` attribute, the resulting
function has the ``"probe-stack"`` attribute of the caller. If a
function that has a ``"probe-stack"`` attribute is inlined into a
function that has no ``"probe-stack"`` attribute at all, the resulting
function has the ``"probe-stack"`` attribute of the callee.
``readnone``
On a function, this attribute indicates that the function computes its
result (or decides to unwind an exception) based strictly on its arguments,
Expand Down
1 change: 1 addition & 0 deletions include/llvm/IR/Attributes.td
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,4 @@ def : MergeRule<"setAND<UnsafeFPMathAttr>">;
def : MergeRule<"setOR<NoImplicitFloatAttr>">;
def : MergeRule<"setOR<NoJumpTablesAttr>">;
def : MergeRule<"adjustCallerSSPLevel">;
def : MergeRule<"adjustCallerStackProbes">;
7 changes: 7 additions & 0 deletions lib/IR/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,13 @@ static void adjustCallerSSPLevel(Function &Caller, const Function &Callee) {
Caller.addFnAttr(Attribute::StackProtect);
}

/// \brief If the inlined function required stack probes, then ensure that
/// the calling function has those too.
static void adjustCallerStackProbes(Function &Caller, const Function &Callee) {
if (!Caller.hasFnAttribute("probe-stack") && Callee.hasFnAttribute("probe-stack"))
Caller.addFnAttr("probe-stack", Callee.getFnAttribute("probe-stack").getValueAsString());
}

#define GET_ATTR_COMPAT_FUNC
#include "AttributesCompatFunc.inc"

Expand Down
20 changes: 20 additions & 0 deletions test/Transforms/Inline/inline-probe-stack.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; RUN: opt %s -inline -S | FileCheck %s

define internal void @inner() "probe-stack"="__probestackinner" {
ret void
}

define void @outerNoAttribute() {
call void @inner()
ret void
}

define void @outerConflictingAttribute() "probe-stack"="__probestackouter" {
call void @inner()
ret void
}

; CHECK: define void @outerNoAttribute() #0
; CHECK: define void @outerConflictingAttribute() #1
; CHECK: attributes #0 = { "probe-stack"="__probestackinner" }
; CHECK: attributes #1 = { "probe-stack"="__probestackouter" }

0 comments on commit d00e96a

Please sign in to comment.