Skip to content

Commit 3ad5ec8

Browse files
committed
Auto merge of #127811 - weihanglo:update-beta-cargo, r=weihanglo
[beta-1.80] Update cargo 1 commits in 34a6a87d8a2330d8c9d578f927489689328a652d..37629051518c3df9ac2c1744589362a02ecafa99 2024-06-04 15:31:01 +0000 to 2024-07-16 01:31:28 +0000 - [beta-1.80.0] chore: downgrade to [email protected] (rust-lang/cargo#14255) try-job: dist-riscv64-linux
2 parents b8b9158 + e710f0d commit 3ad5ec8

File tree

6 files changed

+217
-2
lines changed

6 files changed

+217
-2
lines changed

src/ci/docker/host-x86_64/dist-riscv64-linux/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ RUN sh /scripts/rustbuild-setup.sh
1111
WORKDIR /tmp
1212

1313
COPY scripts/crosstool-ng-build.sh /scripts/
14+
COPY host-x86_64/dist-riscv64-linux/patches/ /tmp/patches/
1415
COPY host-x86_64/dist-riscv64-linux/riscv64-unknown-linux-gnu.defconfig /tmp/crosstool.defconfig
1516
RUN /scripts/crosstool-ng-build.sh
1617

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
From 4013baf99c38f7bca06a51f8301e8fb195ccfa33 Mon Sep 17 00:00:00 2001
2+
From: Jim Wilson <[email protected]>
3+
Date: Tue, 2 Jun 2020 11:19:39 -0700
4+
Subject: [PATCH] RISC-V: Make __divdi3 handle div by zero same as hardware.
5+
6+
The ISA manual specifies that divide by zero always returns -1 as the result.
7+
We were failing to do that when the dividend was negative.
8+
9+
Original patch from Virginie Moser.
10+
11+
libgcc/
12+
* config/riscv/div.S (__divdi3): For negative arguments, change bgez
13+
to bgtz.
14+
---
15+
libgcc/config/riscv/div.S | 8 +++++---
16+
1 file changed, 5 insertions(+), 3 deletions(-)
17+
18+
diff --git a/libgcc/config/riscv/div.S b/libgcc/config/riscv/div.S
19+
index 151f8e273ac77..17234324c1e41 100644
20+
--- a/libgcc/config/riscv/div.S
21+
+++ b/libgcc/config/riscv/div.S
22+
@@ -107,10 +107,12 @@ FUNC_END (__umoddi3)
23+
/* Handle negative arguments to __divdi3. */
24+
.L10:
25+
neg a0, a0
26+
- bgez a1, .L12 /* Compute __udivdi3(-a0, a1), then negate the result. */
27+
+ /* Zero is handled as a negative so that the result will not be inverted. */
28+
+ bgtz a1, .L12 /* Compute __udivdi3(-a0, a1), then negate the result. */
29+
+
30+
neg a1, a1
31+
- j __udivdi3 /* Compute __udivdi3(-a0, -a1). */
32+
-.L11: /* Compute __udivdi3(a0, -a1), then negate the result. */
33+
+ j __udivdi3 /* Compute __udivdi3(-a0, -a1). */
34+
+.L11: /* Compute __udivdi3(a0, -a1), then negate the result. */
35+
neg a1, a1
36+
.L12:
37+
move t0, ra
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
From 45116f342057b7facecd3d05c2091ce3a77eda59 Mon Sep 17 00:00:00 2001
2+
From: Nelson Chu <[email protected]>
3+
Date: Mon, 29 Nov 2021 04:48:20 -0800
4+
Subject: [PATCH] RISC-V: jal cannot refer to a default visibility symbol for
5+
shared object.
6+
7+
This is the original binutils bugzilla report,
8+
https://sourceware.org/bugzilla/show_bug.cgi?id=28509
9+
10+
And this is the first version of the proposed binutils patch,
11+
https://sourceware.org/pipermail/binutils/2021-November/118398.html
12+
13+
After applying the binutils patch, I get the the unexpected error when
14+
building libgcc,
15+
16+
/scratch/nelsonc/riscv-gnu-toolchain/riscv-gcc/libgcc/config/riscv/div.S:42:
17+
/scratch/nelsonc/build-upstream/rv64gc-linux/build-install/riscv64-unknown-linux-gnu/bin/ld: relocation R_RISCV_JAL against `__udivdi3' which may bind externally can not be used when making a shared object; recompile with -fPIC
18+
19+
Therefore, this patch add an extra hidden alias symbol for __udivdi3, and
20+
then use HIDDEN_JUMPTARGET to target a non-preemptible symbol instead.
21+
The solution is similar to glibc as follows,
22+
https://sourceware.org/git/?p=glibc.git;a=commit;h=68389203832ab39dd0dbaabbc4059e7fff51c29b
23+
24+
libgcc/ChangeLog:
25+
26+
* config/riscv/div.S: Add the hidden alias symbol for __udivdi3, and
27+
then use HIDDEN_JUMPTARGET to target it since it is non-preemptible.
28+
* config/riscv/riscv-asm.h: Added new macros HIDDEN_JUMPTARGET and
29+
HIDDEN_DEF.
30+
---
31+
libgcc/config/riscv/div.S | 15 ++++++++-------
32+
libgcc/config/riscv/riscv-asm.h | 6 ++++++
33+
2 files changed, 14 insertions(+), 7 deletions(-)
34+
35+
diff --git a/libgcc/config/riscv/div.S b/libgcc/config/riscv/div.S
36+
index c9bd7879c1e36..723c3b82e48c6 100644
37+
--- a/libgcc/config/riscv/div.S
38+
+++ b/libgcc/config/riscv/div.S
39+
@@ -40,7 +40,7 @@ FUNC_BEGIN (__udivsi3)
40+
sll a0, a0, 32
41+
sll a1, a1, 32
42+
move t0, ra
43+
- jal __udivdi3
44+
+ jal HIDDEN_JUMPTARGET(__udivdi3)
45+
sext.w a0, a0
46+
jr t0
47+
FUNC_END (__udivsi3)
48+
@@ -52,7 +52,7 @@ FUNC_BEGIN (__umodsi3)
49+
srl a0, a0, 32
50+
srl a1, a1, 32
51+
move t0, ra
52+
- jal __udivdi3
53+
+ jal HIDDEN_JUMPTARGET(__udivdi3)
54+
sext.w a0, a1
55+
jr t0
56+
FUNC_END (__umodsi3)
57+
@@ -95,11 +95,12 @@ FUNC_BEGIN (__udivdi3)
58+
.L5:
59+
ret
60+
FUNC_END (__udivdi3)
61+
+HIDDEN_DEF (__udivdi3)
62+
63+
FUNC_BEGIN (__umoddi3)
64+
/* Call __udivdi3(a0, a1), then return the remainder, which is in a1. */
65+
move t0, ra
66+
- jal __udivdi3
67+
+ jal HIDDEN_JUMPTARGET(__udivdi3)
68+
move a0, a1
69+
jr t0
70+
FUNC_END (__umoddi3)
71+
@@ -111,12 +112,12 @@ FUNC_END (__umoddi3)
72+
bgtz a1, .L12 /* Compute __udivdi3(-a0, a1), then negate the result. */
73+
74+
neg a1, a1
75+
- j __udivdi3 /* Compute __udivdi3(-a0, -a1). */
76+
+ j HIDDEN_JUMPTARGET(__udivdi3) /* Compute __udivdi3(-a0, -a1). */
77+
.L11: /* Compute __udivdi3(a0, -a1), then negate the result. */
78+
neg a1, a1
79+
.L12:
80+
move t0, ra
81+
- jal __udivdi3
82+
+ jal HIDDEN_JUMPTARGET(__udivdi3)
83+
neg a0, a0
84+
jr t0
85+
FUNC_END (__divdi3)
86+
@@ -126,7 +127,7 @@ FUNC_BEGIN (__moddi3)
87+
bltz a1, .L31
88+
bltz a0, .L32
89+
.L30:
90+
- jal __udivdi3 /* The dividend is not negative. */
91+
+ jal HIDDEN_JUMPTARGET(__udivdi3) /* The dividend is not negative. */
92+
move a0, a1
93+
jr t0
94+
.L31:
95+
@@ -134,7 +135,7 @@ FUNC_BEGIN (__moddi3)
96+
bgez a0, .L30
97+
.L32:
98+
neg a0, a0
99+
- jal __udivdi3 /* The dividend is hella negative. */
100+
+ jal HIDDEN_JUMPTARGET(__udivdi3) /* The dividend is hella negative. */
101+
neg a0, a1
102+
jr t0
103+
FUNC_END (__moddi3)
104+
diff --git a/libgcc/config/riscv/riscv-asm.h b/libgcc/config/riscv/riscv-asm.h
105+
index 8550707a4a26a..96dd85b0df2e5 100644
106+
--- a/libgcc/config/riscv/riscv-asm.h
107+
+++ b/libgcc/config/riscv/riscv-asm.h
108+
@@ -33,3 +33,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
109+
#define FUNC_ALIAS(X,Y) \
110+
.globl X; \
111+
X = Y
112+
+
113+
+#define CONCAT1(a, b) CONCAT2(a, b)
114+
+#define CONCAT2(a, b) a ## b
115+
+#define HIDDEN_JUMPTARGET(X) CONCAT1(__hidden_, X)
116+
+#define HIDDEN_DEF(X) FUNC_ALIAS(HIDDEN_JUMPTARGET(X), X); \
117+
+ .hidden HIDDEN_JUMPTARGET(X)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
From 68389203832ab39dd0dbaabbc4059e7fff51c29b Mon Sep 17 00:00:00 2001
2+
From: Fangrui Song <[email protected]>
3+
Date: Thu, 28 Oct 2021 11:39:49 -0700
4+
Subject: [PATCH] riscv: Fix incorrect jal with HIDDEN_JUMPTARGET
5+
6+
A non-local STV_DEFAULT defined symbol is by default preemptible in a
7+
shared object. j/jal cannot target a preemptible symbol. On other
8+
architectures, such a jump instruction either causes PLT [BZ #18822], or
9+
if short-ranged, sometimes rejected by the linker (but not by GNU ld's
10+
riscv port [ld PR/28509]).
11+
12+
Use HIDDEN_JUMPTARGET to target a non-preemptible symbol instead.
13+
14+
With this patch, ld.so and libc.so can be linked with LLD if source
15+
files are compiled/assembled with -mno-relax/-Wa,-mno-relax.
16+
17+
Acked-by: Palmer Dabbelt <[email protected]>
18+
Reviewed-by: Adhemerval Zanella <[email protected]>
19+
---
20+
sysdeps/riscv/setjmp.S | 2 +-
21+
sysdeps/unix/sysv/linux/riscv/setcontext.S | 5 +++--
22+
2 files changed, 4 insertions(+), 3 deletions(-)
23+
24+
diff --git a/sysdeps/riscv/setjmp.S b/sysdeps/riscv/setjmp.S
25+
index 0b92016b311..bec7ff80f49 100644
26+
--- a/sysdeps/riscv/setjmp.S
27+
+++ b/sysdeps/riscv/setjmp.S
28+
@@ -21,7 +21,7 @@
29+
30+
ENTRY (_setjmp)
31+
li a1, 0
32+
- j __sigsetjmp
33+
+ j HIDDEN_JUMPTARGET (__sigsetjmp)
34+
END (_setjmp)
35+
ENTRY (setjmp)
36+
li a1, 1
37+
diff --git a/sysdeps/unix/sysv/linux/riscv/setcontext.S b/sysdeps/unix/sysv/linux/riscv/setcontext.S
38+
index 9510518750a..e44a68aad47 100644
39+
--- a/sysdeps/unix/sysv/linux/riscv/setcontext.S
40+
+++ b/sysdeps/unix/sysv/linux/riscv/setcontext.S
41+
@@ -95,6 +95,7 @@ LEAF (__setcontext)
42+
99: j __syscall_error
43+
44+
END (__setcontext)
45+
+libc_hidden_def (__setcontext)
46+
weak_alias (__setcontext, setcontext)
47+
48+
LEAF (__start_context)
49+
@@ -108,7 +109,7 @@ LEAF (__start_context)
50+
/* Invoke subsequent context if present, else exit(0). */
51+
mv a0, s2
52+
beqz s2, 1f
53+
- jal __setcontext
54+
-1: j exit
55+
+ jal HIDDEN_JUMPTARGET (__setcontext)
56+
+1: j HIDDEN_JUMPTARGET (exit)
57+
58+
END (__start_context)

src/ci/docker/host-x86_64/dist-riscv64-linux/riscv64-unknown-linux-gnu.defconfig

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ CT_EXPERIMENTAL=y
33
CT_PREFIX_DIR="/x-tools/${CT_TARGET}"
44
CT_USE_MIRROR=y
55
CT_MIRROR_BASE_URL="https://ci-mirrors.rust-lang.org/rustc"
6+
CT_PATCH_BUNDLED_LOCAL=y
7+
CT_LOCAL_PATCH_DIR="/tmp/patches"
68
CT_ARCH_RISCV=y
79
# CT_DEMULTILIB is not set
810
CT_ARCH_USE_MMU=y
911
CT_ARCH_64=y
1012
CT_ARCH_ARCH="rv64gc"
1113
CT_KERNEL_LINUX=y
1214
CT_LINUX_V_4_20=y
13-
CT_BINUTILS_V_2_36=y
15+
CT_BINUTILS_V_2_40=y
1416
CT_GLIBC_V_2_29=y
1517
CT_GCC_V_8=y
1618
CT_CC_LANG_CXX=y

0 commit comments

Comments
 (0)