qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] common-user/host/riscv: use tail pseudoinstruction for calling tail
@ 2025-04-17  7:22 Icenowy Zheng
  2025-04-18 22:04 ` Richard Henderson
  2025-04-22  2:48 ` Alistair Francis
  0 siblings, 2 replies; 3+ messages in thread
From: Icenowy Zheng @ 2025-04-17  7:22 UTC (permalink / raw)
  To: Riku Voipio, Palmer Dabbelt, Alistair Francis, Weiwei Li,
	Daniel Henrique Barboza, Liu Zhiwei
  Cc: qemu-devel, qemu-riscv, Icenowy Zheng

The j pseudoinstruction maps to a JAL instruction, which can only handle
a jump to somewhere with a signed 20-bit destination. In case of static
linking and LTO'ing this easily leads to "relocation truncated to fit"
error.

Switch to use tail pseudoinstruction, which is the standard way to
tail-call a function in medium code model (emits AUIPC+JALR).

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
---
P.S.
It seems that moving it to common-user/ makes the file out of the
MAINTAINERS section of "RISC-V TCG CPUS". I Manually added the
maintainers there, but the MAINTAINERS file seems to need a change on
this.

 common-user/host/riscv/safe-syscall.inc.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common-user/host/riscv/safe-syscall.inc.S b/common-user/host/riscv/safe-syscall.inc.S
index dfe83c300e..c8b81e33d0 100644
--- a/common-user/host/riscv/safe-syscall.inc.S
+++ b/common-user/host/riscv/safe-syscall.inc.S
@@ -69,11 +69,11 @@ safe_syscall_end:
 
         /* code path setting errno */
 0:      neg     a0, a0
-        j       safe_syscall_set_errno_tail
+        tail    safe_syscall_set_errno_tail
 
         /* code path when we didn't execute the syscall */
 2:      li      a0, QEMU_ERESTARTSYS
-        j       safe_syscall_set_errno_tail
+        tail    safe_syscall_set_errno_tail
 
         .cfi_endproc
         .size   safe_syscall_base, .-safe_syscall_base
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] common-user/host/riscv: use tail pseudoinstruction for calling tail
  2025-04-17  7:22 [PATCH] common-user/host/riscv: use tail pseudoinstruction for calling tail Icenowy Zheng
@ 2025-04-18 22:04 ` Richard Henderson
  2025-04-22  2:48 ` Alistair Francis
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2025-04-18 22:04 UTC (permalink / raw)
  To: Icenowy Zheng, Riku Voipio, Palmer Dabbelt, Alistair Francis,
	Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei
  Cc: qemu-devel, qemu-riscv

On 4/17/25 00:22, Icenowy Zheng wrote:
> The j pseudoinstruction maps to a JAL instruction, which can only handle
> a jump to somewhere with a signed 20-bit destination. In case of static
> linking and LTO'ing this easily leads to "relocation truncated to fit"
> error.
> 
> Switch to use tail pseudoinstruction, which is the standard way to
> tail-call a function in medium code model (emits AUIPC+JALR).
> 
> Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
> ---
> P.S.
> It seems that moving it to common-user/ makes the file out of the
> MAINTAINERS section of "RISC-V TCG CPUS". I Manually added the
> maintainers there, but the MAINTAINERS file seems to need a change on
> this.
> 
>   common-user/host/riscv/safe-syscall.inc.S | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

> 
> diff --git a/common-user/host/riscv/safe-syscall.inc.S b/common-user/host/riscv/safe-syscall.inc.S
> index dfe83c300e..c8b81e33d0 100644
> --- a/common-user/host/riscv/safe-syscall.inc.S
> +++ b/common-user/host/riscv/safe-syscall.inc.S
> @@ -69,11 +69,11 @@ safe_syscall_end:
>   
>           /* code path setting errno */
>   0:      neg     a0, a0
> -        j       safe_syscall_set_errno_tail
> +        tail    safe_syscall_set_errno_tail
>   
>           /* code path when we didn't execute the syscall */
>   2:      li      a0, QEMU_ERESTARTSYS
> -        j       safe_syscall_set_errno_tail
> +        tail    safe_syscall_set_errno_tail
>   
>           .cfi_endproc
>           .size   safe_syscall_base, .-safe_syscall_base



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] common-user/host/riscv: use tail pseudoinstruction for calling tail
  2025-04-17  7:22 [PATCH] common-user/host/riscv: use tail pseudoinstruction for calling tail Icenowy Zheng
  2025-04-18 22:04 ` Richard Henderson
@ 2025-04-22  2:48 ` Alistair Francis
  1 sibling, 0 replies; 3+ messages in thread
From: Alistair Francis @ 2025-04-22  2:48 UTC (permalink / raw)
  To: Icenowy Zheng
  Cc: Riku Voipio, Palmer Dabbelt, Alistair Francis, Weiwei Li,
	Daniel Henrique Barboza, Liu Zhiwei, qemu-devel, qemu-riscv

On Thu, Apr 17, 2025 at 5:24 PM Icenowy Zheng <uwu@icenowy.me> wrote:
>
> The j pseudoinstruction maps to a JAL instruction, which can only handle
> a jump to somewhere with a signed 20-bit destination. In case of static
> linking and LTO'ing this easily leads to "relocation truncated to fit"
> error.
>
> Switch to use tail pseudoinstruction, which is the standard way to
> tail-call a function in medium code model (emits AUIPC+JALR).
>
> Signed-off-by: Icenowy Zheng <uwu@icenowy.me>

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
> P.S.
> It seems that moving it to common-user/ makes the file out of the
> MAINTAINERS section of "RISC-V TCG CPUS". I Manually added the
> maintainers there, but the MAINTAINERS file seems to need a change on
> this.
>
>  common-user/host/riscv/safe-syscall.inc.S | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/common-user/host/riscv/safe-syscall.inc.S b/common-user/host/riscv/safe-syscall.inc.S
> index dfe83c300e..c8b81e33d0 100644
> --- a/common-user/host/riscv/safe-syscall.inc.S
> +++ b/common-user/host/riscv/safe-syscall.inc.S
> @@ -69,11 +69,11 @@ safe_syscall_end:
>
>          /* code path setting errno */
>  0:      neg     a0, a0
> -        j       safe_syscall_set_errno_tail
> +        tail    safe_syscall_set_errno_tail
>
>          /* code path when we didn't execute the syscall */
>  2:      li      a0, QEMU_ERESTARTSYS
> -        j       safe_syscall_set_errno_tail
> +        tail    safe_syscall_set_errno_tail
>
>          .cfi_endproc
>          .size   safe_syscall_base, .-safe_syscall_base
> --
> 2.49.0
>
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-22  2:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-17  7:22 [PATCH] common-user/host/riscv: use tail pseudoinstruction for calling tail Icenowy Zheng
2025-04-18 22:04 ` Richard Henderson
2025-04-22  2:48 ` Alistair Francis

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).