<div dir="ltr"><div dir="ltr">__chkstk_ms is used in x86_64-mingw <a href="https://godbolt.org/z/dajIju">https://godbolt.org/z/dajIju</a><br><br><br clear="all"><div><div dir="ltr" class="gmail_signature">~Craig</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Nov 30, 2018 at 1:17 PM Stefan Kanthak via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">"Friedman, Eli" <<a href="mailto:efriedma@codeaurora.org" target="_blank">efriedma@codeaurora.org</a>> wrote:<br>
<br>
> On 11/30/2018 8:31 AM, Stefan Kanthak via llvm-dev wrote:<br>
>> Hi @ll,<br>
>><br>
>> compiler-rt implements (for example) the MSVC (really Windows)<br>
>> specific routines compiler-rt/lib/builtins/i386/chkstk.S and<br>
>> compiler-rt/lib/builtins/x86_64/chkstk.S as __chkstk_ms()<br>
>> See <<a href="http://msdn.microsoft.com/en-us/library/ms648426.aspx" rel="noreferrer" target="_blank">http://msdn.microsoft.com/en-us/library/ms648426.aspx</a>><br>
>><br>
>> Is there any special reason why compiler-rt doesn't implement<br>
>> other MSVC specific functions (alias builtins or "compiler<br>
>> intrinsics") for which clang/LLVM but generates calls?<br>
> <br>
> There are two "Windows" targets supported by LLVM: one using the MinGW <br>
> runtime, and the other using the MSVC runtime. If you're targeting the <br>
> MSVC runtime, it provides _aulldiv and friends; if you're targeting <br>
> MinGW, LLVM won't refer to those routines. So I can't see a scenario <br>
> where we would need those routines in compiler-rt.<br>
<br>
What's the purpose of __chkstk_ms() then, implemented in compiler-rt?<br>
<br>
1. LLVM does NOT create calls to __chkstk_ms();<br>
<br>
2. both the MSVC and the MinGW runtime provide their own __chkstk()<br>
   as well as their own __alloca() routines.<br>
<br>
--- llvm.c ---<br>
int main(int argc) {<br>
    int stack[1111];<br>
    return _alloca(argc);<br>
}<br>
--- EOF ---<br>
<br>
Compiled with "-target i386-mingw" this generates the following code<br>
(see <<a href="https://godbolt.org/z/yPk4Jo" rel="noreferrer" target="_blank">https://godbolt.org/z/yPk4Jo</a>>):<br>
<br>
_main: # @main<br>
    push  ebp<br>
    mov   ebp, esp<br>
    mov   eax, 4456<br>
    call  __alloca<br>
    mov   eax, dword ptr [ebp + 8]<br>
    mov   dword ptr [ebp - 4452], eax # 4-byte Spill<br>
    call  ___main<br>
    mov   dword ptr [ebp - 4], 0<br>
    mov   eax, dword ptr [ebp + 8]<br>
    mov   dword ptr [esp], eax<br>
    call  __alloca<br>
    add   esp, 4456<br>
    pop   ebp<br>
    ret<br>
<br>
<br>
Compiled with "-target i386-win32" this generates the following code<br>
(see <<a href="https://godbolt.org/z/Hc8jaL" rel="noreferrer" target="_blank">https://godbolt.org/z/Hc8jaL</a>>):<br>
<br>
_main: # @main<br>
    push  ebp<br>
    mov   ebp, esp<br>
    push  esi<br>
    and   esp, -16<br>
    mov   eax, 4480<br>
    call  __chkstk<br>
    mov   esi, esp<br>
    mov   eax, dword ptr [ebp + 8]<br>
    mov   dword ptr [esi + 4464], 0<br>
    mov   ecx, dword ptr [ebp + 8]<br>
    add   ecx, 3<br>
    and   ecx, -4<br>
    mov   dword ptr [esi + 12], eax # 4-byte Spill<br>
    mov   eax, ecx<br>
    call  __chkstk<br>
    mov   ecx, esp<br>
    and   ecx, -16<br>
    mov   esp, ecx<br>
    mov   eax, ecx<br>
    lea   esp, [ebp - 4]<br>
    pop   esi<br>
    pop   ebp<br>
    ret<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">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>
</blockquote></div>