<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 30, 2016 at 8:29 AM, Martin J. O'Riordan via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div lang="EN-IE" link="#0563C1" vlink="#954F72"><div><p class="MsoNormal"><span style="font-size:12pt;font-family:"Book Antiqua",serif">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?</span></p></div></div></blockquote><div><br></div><div>__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.<br></div><div><br></div><div>I believe your libc is responsible for implementing these symbols. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div lang="EN-IE" link="#0563C1" vlink="#954F72"><div><p class="MsoNormal"><span style="font-size:12pt;font-family:"Book Antiqua",serif"><u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:12pt;font-family:"Book Antiqua",serif"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:12pt;font-family:"Book Antiqua",serif">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.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:12pt;font-family:"Book Antiqua",serif"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:12pt;font-family:"Book Antiqua",serif">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?<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:12pt;font-family:"Book Antiqua",serif"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:12pt;font-family:"Book Antiqua",serif">Thanks,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:12pt;font-family:"Book Antiqua",serif"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:12pt;font-family:"Book Antiqua",serif">            MartinO<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:12pt;font-family:"Book Antiqua",serif"><u></u> <u></u></span></p></div></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>