[stackprotector] Add the llvm.stackprotectorcheck intrinsic

Eli Friedman eli.friedman at gmail.com
Fri Aug 9 13:36:59 PDT 2013


On Fri, Aug 9, 2013 at 1:21 PM, Michael Gottesman <mgottesman at apple.com> wrote:
> Hey Eli! Sorry for the delay.
>
> On Jul 23, 2013, at 4:14 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>
> What happens if the call satisfies all the platform-independent
> requirements, but fails some platform-specific requirement?  Does it
> just not matter because the buffers the stack protector is protecting
> can't be referenced?
>
>
> The key thing about the patch is that something magical is happening. No
> matter where the stack protector intrinsic is in the actual basic block, the
> stack protector code will be inserted right before the terminator whether or
> not it is a return or a tail return. If the call fails the platform specific
> requirements, then there will be a call and then the terminator. The stack
> protector code will be inserted right before the terminator and thus right
> before the call.
>
>
> Also, I don't understand why we need to introduce an intrinsic: if
> steps 1 and 2 are both in the same pass, can't you just insert the
> compare+branch before the tail call?
>
>
> I can’t actually insert the compare + branch before the tail call at the IR
> level since the branch will be a terminator implying that I would need to
> split the basic block at the IR level. Splitting the basic block at the IR
> level is exactly what we do not want to do since then we would be required
> to move a failed tail call at the MI level from the success basic block to
> the parent basic block before the actual stack protector compare happens.
> This would require doing platform dependent pattern matching, something that
> I am trying to avoid.
>
> What the intrinsic is really being used for is delaying the code-gen of the
> stack protector check until we know the exact position where we wish to
> insert it (which due to the way we represent tail calls at the MI level is
> always right before the terminator of the basic block no matter whether we
> have a tail call, failed tail call, or normal call). Thus we can stay
> platform independent and clean.

That makes sense; thanks.

-Eli




More information about the llvm-commits mailing list