Update dist-riscv64-linux to binutils 2.40 · rust-lang/rust@55256c5 (original) (raw)
``
1
`+
From 45116f342057b7facecd3d05c2091ce3a77eda59 Mon Sep 17 00:00:00 2001
`
``
2
`+
From: Nelson Chu nelson.chu@sifive.com
`
``
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)
`