glibc-riscv-jumptarget.patch raw
1 commit 68389203832ab39dd0dbaabbc4059e7fff51c29b
2 Author: Fangrui Song <maskray@google.com>
3 Date: Thu Oct 28 11:39:49 2021 -0700
4
5 riscv: Fix incorrect jal with HIDDEN_JUMPTARGET
6
7 A non-local STV_DEFAULT defined symbol is by default preemptible in a
8 shared object. j/jal cannot target a preemptible symbol. On other
9 architectures, such a jump instruction either causes PLT [BZ #18822], or
10 if short-ranged, sometimes rejected by the linker (but not by GNU ld's
11 riscv port [ld PR/28509]).
12
13 Use HIDDEN_JUMPTARGET to target a non-preemptible symbol instead.
14
15 With this patch, ld.so and libc.so can be linked with LLD if source
16 files are compiled/assembled with -mno-relax/-Wa,-mno-relax.
17
18 Acked-by: Palmer Dabbelt <palmer@dabbelt.com>
19 Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
20
21 Can be dropped when we are using glibc 2.35 or later.
22
23 diff --git a/sysdeps/riscv/setjmp.S b/sysdeps/riscv/setjmp.S
24 index 0b92016b31..bec7ff80f4 100644
25 --- a/sysdeps/riscv/setjmp.S
26 +++ b/sysdeps/riscv/setjmp.S
27 @@ -21,7 +21,7 @@
28
29 ENTRY (_setjmp)
30 li a1, 0
31 - j __sigsetjmp
32 + j HIDDEN_JUMPTARGET (__sigsetjmp)
33 END (_setjmp)
34 ENTRY (setjmp)
35 li a1, 1
36 diff --git a/sysdeps/unix/sysv/linux/riscv/setcontext.S b/sysdeps/unix/sysv/linux/riscv/setcontext.S
37 index 9510518750..e44a68aad4 100644
38 --- a/sysdeps/unix/sysv/linux/riscv/setcontext.S
39 +++ b/sysdeps/unix/sysv/linux/riscv/setcontext.S
40 @@ -95,6 +95,7 @@ LEAF (__setcontext)
41 99: j __syscall_error
42
43 END (__setcontext)
44 +libc_hidden_def (__setcontext)
45 weak_alias (__setcontext, setcontext)
46
47 LEAF (__start_context)
48 @@ -108,7 +109,7 @@ LEAF (__start_context)
49 /* Invoke subsequent context if present, else exit(0). */
50 mv a0, s2
51 beqz s2, 1f
52 - jal __setcontext
53 -1: j exit
54 + jal HIDDEN_JUMPTARGET (__setcontext)
55 +1: j HIDDEN_JUMPTARGET (exit)
56
57 END (__start_context)
58