Skip to content

Commit ffb04a5

Browse files
jpochylapfalcon
authored andcommitted
unix: fix symbol references for x86 Mac
1 parent a6c9060 commit ffb04a5

3 files changed

Lines changed: 43 additions & 9 deletions

File tree

py/nlrx86.S

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,18 @@
3737

3838
#if defined(_WIN32) || defined(__CYGWIN__)
3939
#define NLR_OS_WINDOWS
40+
#endif
41+
42+
#if defined(__APPLE__) && defined(__MACH__)
43+
#define NLR_OS_MAC
44+
#endif
45+
46+
#if defined(NLR_OS_WINDOWS) || defined(NLR_OS_MAC)
4047
#define NLR_TOP (_mp_state_ctx + NLR_TOP_OFFSET)
48+
#define MP_THREAD_GET_STATE _mp_thread_get_state
4149
#else
4250
#define NLR_TOP (mp_state_ctx + NLR_TOP_OFFSET)
51+
#define MP_THREAD_GET_STATE mp_thread_get_state
4352
#endif
4453

4554
// offset of nlr_top within mp_state_thread_t structure
@@ -55,6 +64,9 @@
5564
.globl _nlr_push
5665
.def _nlr_push; .scl 2; .type 32; .endef
5766
_nlr_push:
67+
#elif defined(NLR_OS_MAC)
68+
.globl _nlr_push
69+
_nlr_push:
5870
#else
5971
.globl nlr_push
6072
.type nlr_push, @function
@@ -75,7 +87,7 @@ nlr_push:
7587
mov %edx, NLR_TOP # stor new nlr_buf (to make linked list)
7688
#else
7789
// to check: stack is aligned to 16-byte boundary before this call
78-
call mp_thread_get_state # get mp_state_thread ptr into eax
90+
call MP_THREAD_GET_STATE # get mp_state_thread ptr into eax
7991
mov 4(%esp), %edx # load nlr_buf argument into edx (edx clobbered by call)
8092
mov NLR_TOP_TH_OFF(%eax), %ecx # get thread.nlr_top (last nlr_buf)
8193
mov %ecx, (%edx) # store it
@@ -84,7 +96,7 @@ nlr_push:
8496

8597
xor %eax, %eax # return 0, normal return
8698
ret # return
87-
#if !defined(NLR_OS_WINDOWS)
99+
#if !defined(NLR_OS_WINDOWS) && !defined(NLR_OS_MAC)
88100
.size nlr_push, .-nlr_push
89101
#endif
90102

@@ -95,6 +107,9 @@ nlr_push:
95107
.globl _nlr_pop
96108
.def _nlr_pop; .scl 2; .type 32; .endef
97109
_nlr_pop:
110+
#elif defined(NLR_OS_MAC)
111+
.globl _nlr_pop
112+
_nlr_pop:
98113
#else
99114
.globl nlr_pop
100115
.type nlr_pop, @function
@@ -106,14 +121,14 @@ nlr_pop:
106121
mov (%eax), %eax # load prev nlr_buf
107122
mov %eax, NLR_TOP # store nlr_top (to unlink list)
108123
#else
109-
call mp_thread_get_state # get mp_state_thread ptr into eax
124+
call MP_THREAD_GET_STATE # get mp_state_thread ptr into eax
110125
mov NLR_TOP_TH_OFF(%eax), %ecx # get thread.nlr_top (last nlr_buf)
111126
mov (%ecx), %ecx # load prev nlr_buf
112127
mov %ecx, NLR_TOP_TH_OFF(%eax) # store prev nlr_buf (to unlink list)
113128
#endif
114129

115130
ret # return
116-
#if !defined(NLR_OS_WINDOWS)
131+
#if !defined(NLR_OS_WINDOWS) && !defined(NLR_OS_MAC)
117132
.size nlr_pop, .-nlr_pop
118133
#endif
119134

@@ -124,6 +139,9 @@ nlr_pop:
124139
.globl _nlr_jump
125140
.def _nlr_jump; .scl 2; .type 32; .endef
126141
_nlr_jump:
142+
#elif defined(NLR_OS_MAC)
143+
.globl _nlr_jump
144+
_nlr_jump:
127145
#else
128146
.globl nlr_jump
129147
.type nlr_jump, @function
@@ -133,7 +151,7 @@ nlr_jump:
133151
#if !MICROPY_PY_THREAD
134152
mov NLR_TOP, %edx # load nlr_top
135153
test %edx, %edx # check for nlr_top being NULL
136-
#if defined(NLR_OS_WINDOWS)
154+
#if defined(NLR_OS_WINDOWS) || defined(NLR_OS_MAC)
137155
je _nlr_jump_fail # fail if nlr_top is NULL
138156
#else
139157
je nlr_jump_fail # fail if nlr_top is NULL
@@ -143,10 +161,10 @@ nlr_jump:
143161
mov (%edx), %eax # load prev nlr_top
144162
mov %eax, NLR_TOP # store nlr_top (to unlink list)
145163
#else
146-
call mp_thread_get_state # get mp_state_thread ptr into eax
164+
call MP_THREAD_GET_STATE # get mp_state_thread ptr into eax
147165
mov NLR_TOP_TH_OFF(%eax), %edx # get thread.nlr_top (last nlr_buf)
148166
test %edx, %edx # check for nlr_top being NULL
149-
#if defined(NLR_OS_WINDOWS)
167+
#if defined(NLR_OS_WINDOWS) || defined(NLR_OS_MAC)
150168
je _nlr_jump_fail # fail if nlr_top is NULL
151169
#else
152170
je nlr_jump_fail # fail if nlr_top is NULL
@@ -167,7 +185,7 @@ nlr_jump:
167185
xor %eax, %eax # clear return register
168186
inc %al # increase to make 1, non-local return
169187
ret # return
170-
#if !defined(NLR_OS_WINDOWS)
188+
#if !defined(NLR_OS_WINDOWS) && !defined(NLR_OS_MAC)
171189
.size nlr_jump, .-nlr_jump
172190
#endif
173191

unix/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ endif
5858

5959
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
6060
# The unix port of micropython on OSX must be compiled with clang,
61-
# while cross-compile ports require gcc, so we test here for OSX and
61+
# while cross-compile ports require gcc, so we test here for OSX and
6262
# if necessary override the value of 'CC' set in py/mkenv.mk
6363
ifeq ($(UNAME_S),Darwin)
64+
ifeq ($(MICROPY_FORCE_32BIT),1)
65+
CC = clang -m32
66+
else
6467
CC = clang
68+
endif
6569
# Use clang syntax for map file
6670
LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip
6771
else

unix/gccollect.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ STATIC void gc_helper_get_regs(regs_t arr) {
8080
register long esi asm ("esi");
8181
register long edi asm ("edi");
8282
register long ebp asm ("ebp");
83+
#ifdef __clang__
84+
// TODO:
85+
// This is dirty workaround for Clang. It tries to get around
86+
// uncompliant (wrt to GCC) behavior of handling register variables.
87+
// Application of this patch here is random, and done only to unbreak
88+
// MacOS build. Better, cross-arch ways to deal with Clang issues should
89+
// be found.
90+
asm("" : "=r"(ebx));
91+
asm("" : "=r"(esi));
92+
asm("" : "=r"(edi));
93+
asm("" : "=r"(ebp));
94+
#endif
8395
arr[0] = ebx;
8496
arr[1] = esi;
8597
arr[2] = edi;

0 commit comments

Comments
 (0)