* [musl] [PATCH] clone: align the given stack pointer on or1k and riscv
@ 2025-02-08 4:39 Alex Rønne Petersen
2025-04-14 14:59 ` Szabolcs Nagy
0 siblings, 1 reply; 2+ messages in thread
From: Alex Rønne Petersen @ 2025-02-08 4:39 UTC (permalink / raw)
To: musl; +Cc: Alex Rønne Petersen
This is done for all(?) other musl ports, and is also done by glibc, and thus
looks like an oversight for these ports. We ran into stack alignment issues for
non-main threads in Zig as a result.
---
src/thread/or1k/clone.s | 2 ++
src/thread/riscv32/clone.s | 1 +
src/thread/riscv64/clone.s | 1 +
3 files changed, 4 insertions(+)
diff --git a/src/thread/or1k/clone.s b/src/thread/or1k/clone.s
index 2473ac20..9a84aeba 100644
--- a/src/thread/or1k/clone.s
+++ b/src/thread/or1k/clone.s
@@ -6,6 +6,8 @@
.hidden __clone
.type __clone,@function
__clone:
+ l.xori r11, r0, -4
+ l.and r4, r4, r11
l.addi r4, r4, -8
l.sw 0(r4), r3
l.sw 4(r4), r6
diff --git a/src/thread/riscv32/clone.s b/src/thread/riscv32/clone.s
index 3102239d..e2116e33 100644
--- a/src/thread/riscv32/clone.s
+++ b/src/thread/riscv32/clone.s
@@ -8,6 +8,7 @@
.type __clone, %function
__clone:
# Save func and arg to stack
+ andi a1, a1, -16
addi a1, a1, -16
sw a0, 0(a1)
sw a3, 4(a1)
diff --git a/src/thread/riscv64/clone.s b/src/thread/riscv64/clone.s
index db908248..0e6f41a8 100644
--- a/src/thread/riscv64/clone.s
+++ b/src/thread/riscv64/clone.s
@@ -8,6 +8,7 @@
.type __clone, %function
__clone:
# Save func and arg to stack
+ andi a1, a1, -16
addi a1, a1, -16
sd a0, 0(a1)
sd a3, 8(a1)
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [musl] [PATCH] clone: align the given stack pointer on or1k and riscv
2025-02-08 4:39 [musl] [PATCH] clone: align the given stack pointer on or1k and riscv Alex Rønne Petersen
@ 2025-04-14 14:59 ` Szabolcs Nagy
0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2025-04-14 14:59 UTC (permalink / raw)
To: Alex Rønne Petersen; +Cc: musl
* Alex Rønne Petersen <alex@alexrp.com> [2025-02-08 05:39:59 +0100]:
> This is done for all(?) other musl ports, and is also done by glibc, and thus
> looks like an oversight for these ports. We ran into stack alignment issues for
> non-main threads in Zig as a result.
fwiw this patch looks good.
> ---
> src/thread/or1k/clone.s | 2 ++
> src/thread/riscv32/clone.s | 1 +
> src/thread/riscv64/clone.s | 1 +
> 3 files changed, 4 insertions(+)
>
> diff --git a/src/thread/or1k/clone.s b/src/thread/or1k/clone.s
> index 2473ac20..9a84aeba 100644
> --- a/src/thread/or1k/clone.s
> +++ b/src/thread/or1k/clone.s
> @@ -6,6 +6,8 @@
> .hidden __clone
> .type __clone,@function
> __clone:
> + l.xori r11, r0, -4
> + l.and r4, r4, r11
> l.addi r4, r4, -8
> l.sw 0(r4), r3
> l.sw 4(r4), r6
> diff --git a/src/thread/riscv32/clone.s b/src/thread/riscv32/clone.s
> index 3102239d..e2116e33 100644
> --- a/src/thread/riscv32/clone.s
> +++ b/src/thread/riscv32/clone.s
> @@ -8,6 +8,7 @@
> .type __clone, %function
> __clone:
> # Save func and arg to stack
> + andi a1, a1, -16
> addi a1, a1, -16
> sw a0, 0(a1)
> sw a3, 4(a1)
> diff --git a/src/thread/riscv64/clone.s b/src/thread/riscv64/clone.s
> index db908248..0e6f41a8 100644
> --- a/src/thread/riscv64/clone.s
> +++ b/src/thread/riscv64/clone.s
> @@ -8,6 +8,7 @@
> .type __clone, %function
> __clone:
> # Save func and arg to stack
> + andi a1, a1, -16
> addi a1, a1, -16
> sd a0, 0(a1)
> sd a3, 8(a1)
> --
> 2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-14 15:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-08 4:39 [musl] [PATCH] clone: align the given stack pointer on or1k and riscv Alex Rønne Petersen
2025-04-14 14:59 ` Szabolcs Nagy
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).