Skip to content

Commit 946a81f

Browse files
committed
[builtins] Implement the __chkstk function for ARM for MinGW
This function is available for linking in from kernel32.dll, but it's not allowed to link that function from there in Windows Store apps. Differential Revision: https://reviews.llvm.org/D49055 llvm-svn: 337313
1 parent d0166a0 commit 946a81f

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

compiler-rt/lib/builtins/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ if(MINGW)
406406
arm/aeabi_ldivmod.S
407407
arm/aeabi_uidivmod.S
408408
arm/aeabi_uldivmod.S
409+
arm/chkstk.S
409410
divmoddi4.c
410411
divmodsi4.c
411412
divdi3.c

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

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This file is dual licensed under the MIT and the University of Illinois Open
2+
// Source Licenses. See LICENSE.TXT for details.
3+
4+
#include "../assembly.h"
5+
6+
// __chkstk routine
7+
// This routine is windows specific.
8+
// http://msdn.microsoft.com/en-us/library/ms648426.aspx
9+
10+
// This clobbers the register r12, and the condition codes, and uses r5 and r6
11+
// as temporaries by backing them up and restoring them afterwards.
12+
// Does not modify any memory or the stack pointer.
13+
14+
// movw r4, #256 // Number of bytes of stack, in units of 4 byte
15+
// bl __chkstk
16+
// sub.w sp, sp, r4
17+
18+
#define PAGE_SIZE 4096
19+
20+
.p2align 2
21+
DEFINE_COMPILERRT_FUNCTION(__chkstk)
22+
lsl r4, r4, #2
23+
mov r12, sp
24+
push {r5, r6}
25+
mov r5, r4
26+
1:
27+
sub r12, r12, #PAGE_SIZE
28+
subs r5, r5, #PAGE_SIZE
29+
ldr r6, [r12]
30+
bgt 1b
31+
32+
pop {r5, r6}
33+
bx lr
34+
END_COMPILERRT_FUNCTION(__chkstk)

0 commit comments

Comments
 (0)