Skip to content

Commit d1a2d49

Browse files
andypostclaude
andcommitted
Fix ARMv6 fiber asm: gate Cortex-M0 branch on __ARM_ARCH_6M__
The Boost.Context 1.91.0 sync (GH-22584) pulled in boostorg/context#325, "fix cortex-m0 support to aapcs_elf_gas target", which adds a fallback branch to make_fcontext/jump_fcontext for the Thumb-1 encoding limits of ARMv6-M. The branch is correct for Cortex-M0 but is gated on __ARM_ARCH >= 7, which is also false for classic ARMv6 in ARM state (Alpine armhf, Raspberry Pi 1/Zero) -- targets that can encode every instruction in the >= 7 branch and need none of the workaround. Two consequences. make_fcontext took `ldr a2, =finish', materialising the absolute address of finish through a literal pool in .text and emitting R_ARM_ABS32 against .text. In a PIE link that becomes an R_ARM_RELATIVE dynamic relocation inside the read-only text segment, tagging the binary DT_TEXTREL. musl supports DT_TEXTREL only for DSOs it maps itself; the main executable is kernel-mapped and handled by kernel_mapped_dso(), which never inspects it, so ldso writes to a read-only page and dies with SIGSEGV in do_relocs() before main(). Every SAPI, every invocation, no output. glibc masks this by mprotecting the segment writable, which is why only musl builds noticed. Separately, jump_fcontext -- the hot path on every fiber switch -- grew from 13 to 43 instructions on all ARMv6 builds, glibc included. Gate on __ARM_ARCH_6M__ instead, exactly the target #325 names. The result emits byte-identical .text to 8.6.0alpha1 on every ARM target except Cortex-M0, where it emits byte-identical .text to current master: each target gets back the code it had before the regression, and M0 keeps what #325 added. armv7 and arm64 are unaffected either way. Zend/asm is vendored and verified by the Verify Bundled Files workflow, so carry the same diff in .github/scripts/download-bundled and re-apply it from the sync script, as uriparser already does. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 1986088 commit d1a2d49

4 files changed

Lines changed: 81 additions & 7 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
diff --git a/Zend/asm/jump_arm_aapcs_elf_gas.S b/Zend/asm/jump_arm_aapcs_elf_gas.S
2+
index 4415a541fd3..647ae9f45ad 100644
3+
--- a/Zend/asm/jump_arm_aapcs_elf_gas.S
4+
+++ b/Zend/asm/jump_arm_aapcs_elf_gas.S
5+
@@ -50,7 +50,7 @@ jump_fcontext:
6+
push {lr}
7+
@ save hidden,V1-V8,LR
8+
9+
- #if __ARM_ARCH >= 7
10+
+ #if !defined(__ARM_ARCH_6M__)
11+
12+
push {a1,v1-v8,lr}
13+
14+
@@ -102,7 +102,7 @@ jump_fcontext:
15+
add sp, sp, #64
16+
17+
@ restore hidden,V1-V8,LR
18+
- #if __ARM_ARCH >= 7
19+
+ #if !defined(__ARM_ARCH_6M__)
20+
pop {a4,v1-v8,lr}
21+
#else
22+
23+
diff --git a/Zend/asm/make_arm_aapcs_elf_gas.S b/Zend/asm/make_arm_aapcs_elf_gas.S
24+
index 2367c75a6a7..b5cf0c8fa09 100644
25+
--- a/Zend/asm/make_arm_aapcs_elf_gas.S
26+
+++ b/Zend/asm/make_arm_aapcs_elf_gas.S
27+
@@ -48,7 +48,7 @@
28+
make_fcontext:
29+
@ shift address in A1 to lower 16 byte boundary
30+
31+
- #if __ARM_ARCH >= 7
32+
+ #if !defined(__ARM_ARCH_6M__)
33+
bic a1, a1, #15
34+
#else
35+
lsrs a1, a1, #4
36+
@@ -56,7 +56,7 @@ make_fcontext:
37+
#endif
38+
39+
@ reserve space for context-data on context-stack
40+
- #if __ARM_ARCH >= 7
41+
+ #if !defined(__ARM_ARCH_6M__)
42+
sub a1, a1, #124
43+
#else
44+
subs a1, #124
45+
@@ -66,7 +66,7 @@ make_fcontext:
46+
str a3, [a1, #104]
47+
48+
@ compute address of returned transfer_t
49+
- #if __ARM_ARCH >= 7
50+
+ #if !defined(__ARM_ARCH_6M__)
51+
add a2, a1, #108
52+
#else
53+
mov a2, a1
54+
@@ -77,7 +77,7 @@ make_fcontext:
55+
56+
57+
@ compute abs address of label finish
58+
- #if __ARM_ARCH >= 7
59+
+ #if !defined(__ARM_ARCH_6M__)
60+
adr a2, finish
61+
#else
62+
ldr a2, =finish
63+
@@ -93,7 +93,7 @@ make_fcontext:
64+
65+
finish:
66+
@ exit code is zero
67+
- #if __ARM_ARCH >=7
68+
+ #if !defined(__ARM_ARCH_6M__)
69+
mov a1, #0
70+
#else
71+
movs r3, #0

.github/scripts/download-bundled/boost-context.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ mv make_x86_64_ms_pe_gas.asm make_x86_64_ms_pe_gas.S
4141
# add extra files
4242
git restore LICENSE
4343
git restore save_xmm_x86_64_ms_masm.asm # added in GH-18352, not an upstream boost.context file
44+
45+
# patch customized files
46+
git apply -v ../../.github/scripts/download-bundled/boost-context.patch

Zend/asm/jump_arm_aapcs_elf_gas.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jump_fcontext:
5050
push {lr}
5151
@ save hidden,V1-V8,LR
5252

53-
#if __ARM_ARCH >= 7
53+
#if !defined(__ARM_ARCH_6M__)
5454

5555
push {a1,v1-v8,lr}
5656

@@ -102,7 +102,7 @@ jump_fcontext:
102102
add sp, sp, #64
103103

104104
@ restore hidden,V1-V8,LR
105-
#if __ARM_ARCH >= 7
105+
#if !defined(__ARM_ARCH_6M__)
106106
pop {a4,v1-v8,lr}
107107
#else
108108

Zend/asm/make_arm_aapcs_elf_gas.S

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@
4848
make_fcontext:
4949
@ shift address in A1 to lower 16 byte boundary
5050

51-
#if __ARM_ARCH >= 7
51+
#if !defined(__ARM_ARCH_6M__)
5252
bic a1, a1, #15
5353
#else
5454
lsrs a1, a1, #4
5555
lsls a1, a1, #4
5656
#endif
5757

5858
@ reserve space for context-data on context-stack
59-
#if __ARM_ARCH >= 7
59+
#if !defined(__ARM_ARCH_6M__)
6060
sub a1, a1, #124
6161
#else
6262
subs a1, #124
@@ -66,7 +66,7 @@ make_fcontext:
6666
str a3, [a1, #104]
6767

6868
@ compute address of returned transfer_t
69-
#if __ARM_ARCH >= 7
69+
#if !defined(__ARM_ARCH_6M__)
7070
add a2, a1, #108
7171
#else
7272
mov a2, a1
@@ -77,7 +77,7 @@ make_fcontext:
7777

7878

7979
@ compute abs address of label finish
80-
#if __ARM_ARCH >= 7
80+
#if !defined(__ARM_ARCH_6M__)
8181
adr a2, finish
8282
#else
8383
ldr a2, =finish
@@ -93,7 +93,7 @@ make_fcontext:
9393

9494
finish:
9595
@ exit code is zero
96-
#if __ARM_ARCH >=7
96+
#if !defined(__ARM_ARCH_6M__)
9797
mov a1, #0
9898
#else
9999
movs r3, #0

0 commit comments

Comments
 (0)