[llvm-dev] (Question regarding the) incomplete "builtins library" of "Compiler-RT"

Stefan Kanthak via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 30 13:45:58 PST 2018


> __chkstk_ms is used in x86_64-mingw https://godbolt.org/z/dajIju

OK.
Which leaves the following (apparently) superfluous files:

compiler-rt/lib/builtins/i386/chkstk.S
compiler-rt/lib/builtins/i386/chkstk2.S
compiler-rt/lib/builtins/x86_64/chkstk2.S
compiler-rt/lib/builtins/arm/chkstk.S
compiler-rt/lib/builtins/aarch64/chkstk.S

{Sh,C}ouldn't these be removed then?

Stefan

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


More information about the llvm-dev mailing list