[llvm-dev] Implementing stack probes

David Majnemer via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 30 09:59:47 PDT 2016


On Thu, Jun 30, 2016 at 8:29 AM, Martin J. O'Riordan via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> I am trying to implement stack probes for our SHAVE target, and I see that
> the compiler injects references to ‘__stack_chk_guard’ and
> ‘__stack_chk_fail’.  The code that gets generated is horribly wrong, but in
> order to understand how to fix it I was wondering if there is a clear
> statement of how the mechanism is supposed to work?
>

__stack_chk_guard is loaded and the resulting value is stored on the
stack.  The location on the stack contains the "canary".  Before the
function returns, the canary and __stack_chk_guard are compared again.  If
they compare unequal, __stack_chk_fail is called.  Typically, the
implementation of __stack_chk_fail is expected to abort the program.

I believe your libc is responsible for implementing these symbols.


>
>
> The variable ‘__stack_chk_guard’ appears to be a pointer to an unsigned
> integer.  Where is this supposed to reside, and what value should it
> contain?  And the function ‘__stack_chk_fail’ is called when the test fails
> - presumably this just aborts.
>
>
>
> We have done nothing to support these hooks, so the junk instructions that
> come out are unsurprising.  I am presuming that we need to handle their
> lowering in a target specific way, but before I can do that I am wondering
> if there is a clear definition of the semantics of how the probe is
> supposed to work?
>
>
>
> Thanks,
>
>
>
>             MartinO
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160630/0d077165/attachment.html>


More information about the llvm-dev mailing list