authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-08 19:08:33+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-09 16:56:23+02:00
log82b9ba071f33f7404db5d987232493dd122e991a
tree5cee608875b1f2e70e9638d1486ad7cedd0f04ea
parent19a0cef7e8adfff9dea6f9672cc022ad267939ef
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.pie: fix alpha, csky, and microblaze assembly

In hindsight, this approach was obviously not going to work since it's loading the unrelocated address of _DYNAMIC. Instead just use a PC-relative approach like other targets.

1 files changed, 27 insertions(+), 10 deletions(-)

lib/std/pie.zig+27-10
...@@ -83,7 +83,7 @@ inline fn getDynamicSymbol() [*]const elf.Dyn {...@@ -83,7 +83,7 @@ inline fn getDynamicSymbol() [*]const elf.Dyn {
83 \\ add %[ret], pc83 \\ add %[ret], pc
84 \\ b 2f84 \\ b 2f
85 \\1:85 \\1:
86 \\ .word _DYNAMIC-1b86 \\ .word _DYNAMIC - 1b
87 \\2:87 \\2:
88 : [ret] "=r" (-> [*]const elf.Dyn),88 : [ret] "=r" (-> [*]const elf.Dyn),
89 ),89 ),
...@@ -97,20 +97,29 @@ inline fn getDynamicSymbol() [*]const elf.Dyn {...@@ -97,20 +97,29 @@ inline fn getDynamicSymbol() [*]const elf.Dyn {
97 ),97 ),
98 // The compiler is not required to load the GP register, so do it ourselves.98 // The compiler is not required to load the GP register, so do it ourselves.
99 .alpha => asm volatile (99 .alpha => asm volatile (
100 \\ .weak _DYNAMIC
101 \\ .hidden _DYNAMIC
100 \\ br $29, 1f102 \\ br $29, 1f
101 \\1:103 \\1:
102 \\ ldgp $29, 0($29)104 \\ ldgp $29, 0($29)
103 \\ ldq %[ret], -0x8000($29)105 \\ ldah %[ret], _DYNAMIC($29) !gprelhigh
106 \\ lda %[ret], _DYNAMIC(%[ret]) !gprellow
104 : [ret] "=r" (-> [*]const elf.Dyn),107 : [ret] "=r" (-> [*]const elf.Dyn),
105 :108 :
106 : .{ .r26 = true, .r29 = true }),109 : .{ .r29 = true }),
107 // The CSKY ABI requires the gb register to point to the GOT. Additionally, the first
108 // entry in the GOT is defined to hold the address of _DYNAMIC.
109 .csky => asm volatile (110 .csky => asm volatile (
110 \\ mov %[ret], gb111 \\ .weak _DYNAMIC
111 \\ ldw %[ret], %[ret]112 \\ .hidden _DYNAMIC
113 \\ grs %[ret], 1f
114 \\ br 2f
115 \\1:
116 \\ .long _DYNAMIC - 1b
117 \\2:
118 \\ ldw r12, (%[ret], 0)
119 \\ addu %[ret], %[ret], r12
112 : [ret] "=r" (-> [*]const elf.Dyn),120 : [ret] "=r" (-> [*]const elf.Dyn),
113 ),121 :
122 : .{ .r12 = true }),
114 .hexagon => asm volatile (123 .hexagon => asm volatile (
115 \\ .weak _DYNAMIC124 \\ .weak _DYNAMIC
116 \\ .hidden _DYNAMIC125 \\ .hidden _DYNAMIC
...@@ -146,9 +155,17 @@ inline fn getDynamicSymbol() [*]const elf.Dyn {...@@ -146,9 +155,17 @@ inline fn getDynamicSymbol() [*]const elf.Dyn {
146 : [ret] "=r" (-> [*]const elf.Dyn),155 : [ret] "=r" (-> [*]const elf.Dyn),
147 ),156 ),
148 .microblaze, .microblazeel => asm volatile (157 .microblaze, .microblazeel => asm volatile (
149 \\ lwi %[ret], r20, 0158 \\ .weak _DYNAMIC
159 \\ .hidden _DYNAMIC
160 \\ mfs %[ret], rpc
161 \\ bri 1f
162 \\ .word _DYNAMIC - . + 8
163 \\1:
164 \\ lwi r18, %[ret], 8
165 \\ add %[ret], %[ret], r18
150 : [ret] "=r" (-> [*]const elf.Dyn),166 : [ret] "=r" (-> [*]const elf.Dyn),
151 ),167 :
168 : .{ .r18 = true }),
152 .mips, .mipsel => asm volatile (169 .mips, .mipsel => asm volatile (
153 \\ .weak _DYNAMIC170 \\ .weak _DYNAMIC
154 \\ .hidden _DYNAMIC171 \\ .hidden _DYNAMIC