Index: lib/builtins/CMakeLists.txt =================================================================== --- lib/builtins/CMakeLists.txt +++ lib/builtins/CMakeLists.txt @@ -234,6 +234,7 @@ set(x86_64_SOURCES x86_64/chkstk.S x86_64/chkstk2.S + x86_64/chkstk_darwin.S x86_64/floatdidf.c x86_64/floatdisf.c x86_64/floatdixf.c Index: lib/builtins/x86_64/chkstk_darwin.S =================================================================== --- /dev/null +++ lib/builtins/x86_64/chkstk_darwin.S @@ -0,0 +1,32 @@ +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. + +#include "../assembly.h" + +#ifdef __x86_64__ + +#define PAGE_SZ 4096 + +// ___chkstk_darwin is at the moment implemented the same way as ms version. +DEFINE_COMPILERRT_FUNCTION(___chkstk_darwin) +.weak_definition ___chkstk_darwin + push %rcx + push %rax + cmp $PAGE_SZ,%rax + lea 24(%rsp),%rcx + jb 1f +2: + sub $PAGE_SZ,%rcx + test %rcx,(%rcx) + sub $PAGE_SZ,%rax + cmp $PAGE_SZ,%rax + ja 2b +1: + sub %rax,%rcx + test %rcx,(%rcx) + pop %rax + pop %rcx + ret +END_COMPILERRT_FUNCTION(___chkstk_darwin) + +#endif // __x86_64__