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

Martin Storsjö via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 30 14:43:53 PST 2018


On Fri, 30 Nov 2018, Stefan Kanthak via llvm-dev wrote:

>> __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

Yes, this one is potentially superfluous (although I haven't tested 
building without it to see if it's needed by some weirdness somewhere)

> compiler-rt/lib/builtins/i386/chkstk2.S

Not superfluous, this contains the __alloca function that llvm produces 
calls to. The mingw runtime doesn't provide __alloca; libgcc or 
compiler-rt does.

> compiler-rt/lib/builtins/x86_64/chkstk2.S

Yes, potentially superfluous

> compiler-rt/lib/builtins/arm/chkstk.S
> compiler-rt/lib/builtins/aarch64/chkstk.S

No, these contains the __chkstk function that llvm produces calls to when 
targeting armv7-mingw or aarch64-mingw. Contrary to x86, it's the same 
function name for both mingw and msvc targets, and either the msvc runtime 
or compiler-rt provides it.

// Martin



> {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
>>>
>>
> _______________________________________________
> 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