public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] RISC-V: Allow long jumps to __syscall_error
       [not found] <CGME20220916193237eucas1p2a0a82daf73a66f5e25b9fa5372268f61@eucas1p2.samsung.com>
@ 2022-09-16 19:31 ` Łukasz Stelmach
  2022-09-17  1:33   ` Andrew Waterman
  0 siblings, 1 reply; 4+ messages in thread
From: Łukasz Stelmach @ 2022-09-16 19:31 UTC (permalink / raw)
  To: libc-alpha, andrew
  Cc: Marek Szyprowski, Łukasz Stelmach, adhemerval.zanella,
	alistair.francis, aurelien, eggert, joseph, palmer, k.lewandowsk

__syscall_error may end up farther than 1MiB away from a caller,
especially when linking statically large binaries. tail allows for
4GiB jumps and is reduced to j when a linked symbol is within range.

Fixes: 36960f0c76 ("RISC-V: Linux Syscall Interface")
Fixes: 7f33b09c65 ("RISC-V: Linux ABI")
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
---
Changes in v2:
  - use tail instead of la+jr as advised by Andrew Waterman

 sysdeps/unix/sysv/linux/riscv/clone.S       | 2 +-
 sysdeps/unix/sysv/linux/riscv/getcontext.S  | 2 +-
 sysdeps/unix/sysv/linux/riscv/setcontext.S  | 2 +-
 sysdeps/unix/sysv/linux/riscv/swapcontext.S | 2 +-
 sysdeps/unix/sysv/linux/riscv/sysdep.h      | 2 +-
 sysdeps/unix/sysv/linux/riscv/vfork.S       | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/riscv/clone.S b/sysdeps/unix/sysv/linux/riscv/clone.S
index d7d2915e87..45ea8f184b 100644
--- a/sysdeps/unix/sysv/linux/riscv/clone.S
+++ b/sysdeps/unix/sysv/linux/riscv/clone.S
@@ -63,7 +63,7 @@ L (invalid):
 	li		a0, -EINVAL
 	/* Something bad happened -- no child created.  */
 L (error):
-	j		__syscall_error
+	tail		__syscall_error
 	END (__clone)
 
 /* Load up the arguments to the function.  Put this block of code in
diff --git a/sysdeps/unix/sysv/linux/riscv/getcontext.S b/sysdeps/unix/sysv/linux/riscv/getcontext.S
index 499f70b65d..f4f828805c 100644
--- a/sysdeps/unix/sysv/linux/riscv/getcontext.S
+++ b/sysdeps/unix/sysv/linux/riscv/getcontext.S
@@ -70,7 +70,7 @@ LEAF (__getcontext)
 
 	ret
 
-99:	j	__syscall_error
+99:	tail	__syscall_error
 
 PSEUDO_END (__getcontext)
 
diff --git a/sysdeps/unix/sysv/linux/riscv/setcontext.S b/sysdeps/unix/sysv/linux/riscv/setcontext.S
index e3bc84a2e6..1e529b900c 100644
--- a/sysdeps/unix/sysv/linux/riscv/setcontext.S
+++ b/sysdeps/unix/sysv/linux/riscv/setcontext.S
@@ -92,7 +92,7 @@ LEAF (__setcontext)
 
 	jr	t1
 
-99:	j	__syscall_error
+99:	tail	__syscall_error
 
 END (__setcontext)
 libc_hidden_def (__setcontext)
diff --git a/sysdeps/unix/sysv/linux/riscv/swapcontext.S b/sysdeps/unix/sysv/linux/riscv/swapcontext.S
index 4da615f6d4..287ba364cd 100644
--- a/sysdeps/unix/sysv/linux/riscv/swapcontext.S
+++ b/sysdeps/unix/sysv/linux/riscv/swapcontext.S
@@ -118,7 +118,7 @@ LEAF (__swapcontext)
 	jr	t1
 
 
-99:	j	__syscall_error
+99:	tail	__syscall_error
 
 PSEUDO_END (__swapcontext)
 
diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h
index 37ff07a0d7..aff8d857c9 100644
--- a/sysdeps/unix/sysv/linux/riscv/sysdep.h
+++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h
@@ -102,7 +102,7 @@
 # else
 #  define SYSCALL_ERROR_HANDLER(name)				\
 .Lsyscall_error ## name:					\
-        j       __syscall_error;
+        tail    __syscall_error;
 # endif
 
 /* Performs a system call, not setting errno.  */
diff --git a/sysdeps/unix/sysv/linux/riscv/vfork.S b/sysdeps/unix/sysv/linux/riscv/vfork.S
index 0970543619..1482406e2d 100644
--- a/sysdeps/unix/sysv/linux/riscv/vfork.S
+++ b/sysdeps/unix/sysv/linux/riscv/vfork.S
@@ -39,7 +39,7 @@ LEAF (__libc_vfork)
 	bltz	a0, 1f
 	ret
 
-1:	j		__syscall_error
+1:	tail	__syscall_error
 END (__libc_vfork)
 
 weak_alias (__libc_vfork, vfork)
-- 
2.30.2


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

* Re: [PATCH v2] RISC-V: Allow long jumps to __syscall_error
  2022-09-16 19:31 ` [PATCH v2] RISC-V: Allow long jumps to __syscall_error Łukasz Stelmach
@ 2022-09-17  1:33   ` Andrew Waterman
  2022-09-17  3:29     ` DJ Delorie
  2022-09-17  7:59     ` Palmer Dabbelt
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Waterman @ 2022-09-17  1:33 UTC (permalink / raw)
  To: Łukasz Stelmach
  Cc: libc-alpha, Marek Szyprowski, adhemerval.zanella,
	alistair.francis, aurelien, eggert, joseph, palmer, k.lewandowsk

Thank you for making my suggested change.  LGTM.  (I don't have commit
access, though.)

On Fri, Sep 16, 2022 at 12:32 PM Łukasz Stelmach <l.stelmach@samsung.com> wrote:
>
> __syscall_error may end up farther than 1MiB away from a caller,
> especially when linking statically large binaries. tail allows for
> 4GiB jumps and is reduced to j when a linked symbol is within range.
>
> Fixes: 36960f0c76 ("RISC-V: Linux Syscall Interface")
> Fixes: 7f33b09c65 ("RISC-V: Linux ABI")
> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
> ---
> Changes in v2:
>   - use tail instead of la+jr as advised by Andrew Waterman
>
>  sysdeps/unix/sysv/linux/riscv/clone.S       | 2 +-
>  sysdeps/unix/sysv/linux/riscv/getcontext.S  | 2 +-
>  sysdeps/unix/sysv/linux/riscv/setcontext.S  | 2 +-
>  sysdeps/unix/sysv/linux/riscv/swapcontext.S | 2 +-
>  sysdeps/unix/sysv/linux/riscv/sysdep.h      | 2 +-
>  sysdeps/unix/sysv/linux/riscv/vfork.S       | 2 +-
>  6 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/riscv/clone.S b/sysdeps/unix/sysv/linux/riscv/clone.S
> index d7d2915e87..45ea8f184b 100644
> --- a/sysdeps/unix/sysv/linux/riscv/clone.S
> +++ b/sysdeps/unix/sysv/linux/riscv/clone.S
> @@ -63,7 +63,7 @@ L (invalid):
>         li              a0, -EINVAL
>         /* Something bad happened -- no child created.  */
>  L (error):
> -       j               __syscall_error
> +       tail            __syscall_error
>         END (__clone)
>
>  /* Load up the arguments to the function.  Put this block of code in
> diff --git a/sysdeps/unix/sysv/linux/riscv/getcontext.S b/sysdeps/unix/sysv/linux/riscv/getcontext.S
> index 499f70b65d..f4f828805c 100644
> --- a/sysdeps/unix/sysv/linux/riscv/getcontext.S
> +++ b/sysdeps/unix/sysv/linux/riscv/getcontext.S
> @@ -70,7 +70,7 @@ LEAF (__getcontext)
>
>         ret
>
> -99:    j       __syscall_error
> +99:    tail    __syscall_error
>
>  PSEUDO_END (__getcontext)
>
> diff --git a/sysdeps/unix/sysv/linux/riscv/setcontext.S b/sysdeps/unix/sysv/linux/riscv/setcontext.S
> index e3bc84a2e6..1e529b900c 100644
> --- a/sysdeps/unix/sysv/linux/riscv/setcontext.S
> +++ b/sysdeps/unix/sysv/linux/riscv/setcontext.S
> @@ -92,7 +92,7 @@ LEAF (__setcontext)
>
>         jr      t1
>
> -99:    j       __syscall_error
> +99:    tail    __syscall_error
>
>  END (__setcontext)
>  libc_hidden_def (__setcontext)
> diff --git a/sysdeps/unix/sysv/linux/riscv/swapcontext.S b/sysdeps/unix/sysv/linux/riscv/swapcontext.S
> index 4da615f6d4..287ba364cd 100644
> --- a/sysdeps/unix/sysv/linux/riscv/swapcontext.S
> +++ b/sysdeps/unix/sysv/linux/riscv/swapcontext.S
> @@ -118,7 +118,7 @@ LEAF (__swapcontext)
>         jr      t1
>
>
> -99:    j       __syscall_error
> +99:    tail    __syscall_error
>
>  PSEUDO_END (__swapcontext)
>
> diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h
> index 37ff07a0d7..aff8d857c9 100644
> --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h
> @@ -102,7 +102,7 @@
>  # else
>  #  define SYSCALL_ERROR_HANDLER(name)                          \
>  .Lsyscall_error ## name:                                       \
> -        j       __syscall_error;
> +        tail    __syscall_error;
>  # endif
>
>  /* Performs a system call, not setting errno.  */
> diff --git a/sysdeps/unix/sysv/linux/riscv/vfork.S b/sysdeps/unix/sysv/linux/riscv/vfork.S
> index 0970543619..1482406e2d 100644
> --- a/sysdeps/unix/sysv/linux/riscv/vfork.S
> +++ b/sysdeps/unix/sysv/linux/riscv/vfork.S
> @@ -39,7 +39,7 @@ LEAF (__libc_vfork)
>         bltz    a0, 1f
>         ret
>
> -1:     j               __syscall_error
> +1:     tail    __syscall_error
>  END (__libc_vfork)
>
>  weak_alias (__libc_vfork, vfork)
> --
> 2.30.2
>

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

* Re: [PATCH v2] RISC-V: Allow long jumps to __syscall_error
  2022-09-17  1:33   ` Andrew Waterman
@ 2022-09-17  3:29     ` DJ Delorie
  2022-09-17  7:59     ` Palmer Dabbelt
  1 sibling, 0 replies; 4+ messages in thread
From: DJ Delorie @ 2022-09-17  3:29 UTC (permalink / raw)
  To: Andrew Waterman; +Cc: l.stelmach, libc-alpha

Andrew Waterman <andrew@sifive.com> writes:
> Thank you for making my suggested change.  LGTM.  (I don't have commit
> access, though.)

I committed it.


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

* Re: [PATCH v2] RISC-V: Allow long jumps to __syscall_error
  2022-09-17  1:33   ` Andrew Waterman
  2022-09-17  3:29     ` DJ Delorie
@ 2022-09-17  7:59     ` Palmer Dabbelt
  1 sibling, 0 replies; 4+ messages in thread
From: Palmer Dabbelt @ 2022-09-17  7:59 UTC (permalink / raw)
  To: Andrew Waterman
  Cc: l.stelmach, libc-alpha, m.szyprowski, adhemerval.zanella,
	Alistair Francis, aurelien, eggert, joseph, k.lewandowsk

On Fri, 16 Sep 2022 18:33:17 PDT (-0700), Andrew Waterman wrote:
> Thank you for making my suggested change.  LGTM.  (I don't have commit
> access, though.)

I do have commit access, but I have spotty internet here and it looks 
like only the review has shown up in my local inbox so far.  I'll commit 
it if this sorts itself out, but in case anyone else is faster

Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>

Thanks!

>
> On Fri, Sep 16, 2022 at 12:32 PM Łukasz Stelmach <l.stelmach@samsung.com> wrote:
>>
>> __syscall_error may end up farther than 1MiB away from a caller,
>> especially when linking statically large binaries. tail allows for
>> 4GiB jumps and is reduced to j when a linked symbol is within range.
>>
>> Fixes: 36960f0c76 ("RISC-V: Linux Syscall Interface")
>> Fixes: 7f33b09c65 ("RISC-V: Linux ABI")
>> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
>> ---
>> Changes in v2:
>>   - use tail instead of la+jr as advised by Andrew Waterman
>>
>>  sysdeps/unix/sysv/linux/riscv/clone.S       | 2 +-
>>  sysdeps/unix/sysv/linux/riscv/getcontext.S  | 2 +-
>>  sysdeps/unix/sysv/linux/riscv/setcontext.S  | 2 +-
>>  sysdeps/unix/sysv/linux/riscv/swapcontext.S | 2 +-
>>  sysdeps/unix/sysv/linux/riscv/sysdep.h      | 2 +-
>>  sysdeps/unix/sysv/linux/riscv/vfork.S       | 2 +-
>>  6 files changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/sysdeps/unix/sysv/linux/riscv/clone.S b/sysdeps/unix/sysv/linux/riscv/clone.S
>> index d7d2915e87..45ea8f184b 100644
>> --- a/sysdeps/unix/sysv/linux/riscv/clone.S
>> +++ b/sysdeps/unix/sysv/linux/riscv/clone.S
>> @@ -63,7 +63,7 @@ L (invalid):
>>         li              a0, -EINVAL
>>         /* Something bad happened -- no child created.  */
>>  L (error):
>> -       j               __syscall_error
>> +       tail            __syscall_error
>>         END (__clone)
>>
>>  /* Load up the arguments to the function.  Put this block of code in
>> diff --git a/sysdeps/unix/sysv/linux/riscv/getcontext.S b/sysdeps/unix/sysv/linux/riscv/getcontext.S
>> index 499f70b65d..f4f828805c 100644
>> --- a/sysdeps/unix/sysv/linux/riscv/getcontext.S
>> +++ b/sysdeps/unix/sysv/linux/riscv/getcontext.S
>> @@ -70,7 +70,7 @@ LEAF (__getcontext)
>>
>>         ret
>>
>> -99:    j       __syscall_error
>> +99:    tail    __syscall_error
>>
>>  PSEUDO_END (__getcontext)
>>
>> diff --git a/sysdeps/unix/sysv/linux/riscv/setcontext.S b/sysdeps/unix/sysv/linux/riscv/setcontext.S
>> index e3bc84a2e6..1e529b900c 100644
>> --- a/sysdeps/unix/sysv/linux/riscv/setcontext.S
>> +++ b/sysdeps/unix/sysv/linux/riscv/setcontext.S
>> @@ -92,7 +92,7 @@ LEAF (__setcontext)
>>
>>         jr      t1
>>
>> -99:    j       __syscall_error
>> +99:    tail    __syscall_error
>>
>>  END (__setcontext)
>>  libc_hidden_def (__setcontext)
>> diff --git a/sysdeps/unix/sysv/linux/riscv/swapcontext.S b/sysdeps/unix/sysv/linux/riscv/swapcontext.S
>> index 4da615f6d4..287ba364cd 100644
>> --- a/sysdeps/unix/sysv/linux/riscv/swapcontext.S
>> +++ b/sysdeps/unix/sysv/linux/riscv/swapcontext.S
>> @@ -118,7 +118,7 @@ LEAF (__swapcontext)
>>         jr      t1
>>
>>
>> -99:    j       __syscall_error
>> +99:    tail    __syscall_error
>>
>>  PSEUDO_END (__swapcontext)
>>
>> diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h
>> index 37ff07a0d7..aff8d857c9 100644
>> --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h
>> +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h
>> @@ -102,7 +102,7 @@
>>  # else
>>  #  define SYSCALL_ERROR_HANDLER(name)                          \
>>  .Lsyscall_error ## name:                                       \
>> -        j       __syscall_error;
>> +        tail    __syscall_error;
>>  # endif
>>
>>  /* Performs a system call, not setting errno.  */
>> diff --git a/sysdeps/unix/sysv/linux/riscv/vfork.S b/sysdeps/unix/sysv/linux/riscv/vfork.S
>> index 0970543619..1482406e2d 100644
>> --- a/sysdeps/unix/sysv/linux/riscv/vfork.S
>> +++ b/sysdeps/unix/sysv/linux/riscv/vfork.S
>> @@ -39,7 +39,7 @@ LEAF (__libc_vfork)
>>         bltz    a0, 1f
>>         ret
>>
>> -1:     j               __syscall_error
>> +1:     tail    __syscall_error
>>  END (__libc_vfork)
>>
>>  weak_alias (__libc_vfork, vfork)
>> --
>> 2.30.2
>>

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

end of thread, other threads:[~2022-09-17  7:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20220916193237eucas1p2a0a82daf73a66f5e25b9fa5372268f61@eucas1p2.samsung.com>
2022-09-16 19:31 ` [PATCH v2] RISC-V: Allow long jumps to __syscall_error Łukasz Stelmach
2022-09-17  1:33   ` Andrew Waterman
2022-09-17  3:29     ` DJ Delorie
2022-09-17  7:59     ` Palmer Dabbelt

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 read-only IMAP folder(s) and NNTP newsgroup(s).