Skip to content

Commit 9b4dd2e

Browse files
committed
Change ARM code to use position independent code
This is all arising from issue #68 and PR #76. It seems that MacOS Arm64 does not like the use of relocation in the original switch-arm64.c code. This arises from a single instruction ldr lr, =action_entry As action_entry is extremely close to this code this can simply be replaced with adr lr, action_entry for both ARM32 and ARM64.
1 parent da8b793 commit 9b4dd2e

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

context/switch-arm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ FSIZE(switch_frame)
6868
FNAME(create_frame)
6969
" stmfd r0!, {r1, r2}\n" // Save arguments for new coroutine
7070
" mov ip, lr\n" // Save LR so can use same STM slot
71-
" ldr lr, =action_entry\n"
71+
" adr lr, action_entry\n"
7272
" stmfd r0!, {r4, r5, r6, r7, r8, r9, sl, fp, lr}\n"
7373
IF_VFP_FP(
7474
" fstmfdd r0!, {d8-d15}\n")

context/switch-arm64.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ FSIZE(switch_frame)
105105
FNAME(create_frame)
106106
" stp x1, x2, [x0, #-16]!\n"
107107
" mov x16, lr\n" // Save LR so can use same STP slot
108-
" ldr lr, =action_entry\n"
108+
// This should be simply
109+
// adr lr,action_entry
110+
// but it would appear that on Apple the target for adr needs to be both
111+
// local AND known at the instant it is seen by the assembler. The
112+
// reference .1f is an alias for action_entry below to work around this
113+
" adr lr, .1f\n"
109114
" stp x19, x20, [x0, #-16]!\n"
110115
" stp x21, x22, [x0, #-16]!\n"
111116
" stp x23, x24, [x0, #-16]!\n"
@@ -118,6 +123,7 @@ FNAME(create_frame)
118123
" stp d14, d15, [x0, #-16]!\n"
119124
" br x16\n"
120125

126+
"1:\n"
121127
"action_entry:\n"
122128
// Receive control after first switch to new frame. Top of stack has
123129
// the saved context and routine to call, switch argument is in r0.

0 commit comments

Comments
 (0)