-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path01-toolchains.sh
executable file
·334 lines (280 loc) · 8.87 KB
/
01-toolchains.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#!/bin/sh
# This script needs to be run from the directory where you've just build musl cross make
: ${PREFIX:=/opt/toolchains}
export PREFIX
echo clone musl-cross-make
git clone https://github.com/richfelker/musl-cross-make.git &&
cd musl-cross-make &&
echo patch for musl 1.2.4 &&
patch -p1 << 'EOF' &&
--- a/Makefile
+++ b/Makefile
@@ -4,13 +4,13 @@ SOURCES = sources
CONFIG_SUB_REV = 3d5db9ebe860
BINUTILS_VER = 2.33.1
GCC_VER = 9.4.0
-MUSL_VER = 1.2.3
+MUSL_VER = 1.2.4
GMP_VER = 6.1.2
MPC_VER = 1.1.0
MPFR_VER = 4.0.2
LINUX_VER = headers-4.19.88-1
-GNU_SITE = https://ftpmirror.gnu.org/gnu
+GNU_SITE = https://ftp.gnu.org/gnu
GCC_SITE = $(GNU_SITE)/gcc
BINUTILS_SITE = $(GNU_SITE)/binutils
GMP_SITE = $(GNU_SITE)/gmp
diff --git a/hashes/musl-1.2.4.tar.gz.sha1 b/hashes/musl-1.2.4.tar.gz.sha1
new file mode 100644
index 0000000..0f94407
--- /dev/null
+++ b/hashes/musl-1.2.4.tar.gz.sha1
@@ -0,0 +1 @@
+78eb982244b857dbacb2ead25cc0f631ce44204d musl-1.2.4.tar.gz
EOF
echo config &&
echo "OUTPUT = $PREFIX" > config.mak &&
cat presets/j2-fdpic >> config.mak &&
echo patch for specs &&
cat >> patches/gcc-9.4.0/0020-gcc-specs.patch << 'EOF' &&
--- gcc-9.4.0.orig/gcc/gcc.c 2021-06-01 02:53:04.800475820 -0500
+++ gcc-9.4.0/gcc/gcc.c 2023-05-12 22:49:06.476185322 -0500
@@ -2178,7 +2179,7 @@
/* Is this a special command that starts with '%'? */
/* Don't allow this for the main specs file, since it would
encourage people to overwrite it. */
- if (*p == '%' && !main_p)
+ if (*p == '%')
{
p1 = p;
while (*p && *p != '\n')
EOF
echo patch for vfork &&
mkdir patches/musl-1.2.4 && cat >> patches/musl-1.2.4/0001-nommu.patch << 'EOF' &&
--- a/src/legacy/daemon.c
+++ b/src/legacy/daemon.c
@@ -17,3 +17,3 @@
- switch(fork()) {
+ switch(vfork()) {
case 0: break;
@@ -25,3 +25,3 @@
- switch(fork()) {
+ switch(vfork()) {
case 0: break;
--- a/src/misc/forkpty.c
+++ b/src/misc/forkpty.c
@@ -8,2 +8,3 @@
+#ifndef __SH_FDPIC__
int forkpty(int *pm, char *name, const struct termios *tio, const struct winsize *ws)
@@ -57,1 +58,2 @@
}
+#endif
--- a/src/misc/wordexp.c
+++ b/src/misc/wordexp.c
@@ -25,2 +25,3 @@
+#ifndef __SH_FDPIC__
static int do_wordexp(const char *s, wordexp_t *we, int flags)
@@ -177,2 +178,3 @@
}
+#endif
--- a/src/process/fork.c
+++ b/src/process/fork.c
@@ -7,2 +7,3 @@
+#ifndef __SH_FDPIC__
static void dummy(int x)
@@ -37,1 +38,2 @@
}
+#endif
--- a/Makefile
+++ b/Makefile
@@ -100,3 +100,3 @@
cp $< $@
- sed -n -e s/__NR_/SYS_/p < $< >> $@
+ sed -e s/__NR_/SYS_/ < $< >> $@
--- a/arch/sh/bits/syscall.h.in
+++ b/arch/sh/bits/syscall.h.in
@@ -2,3 +2,5 @@
#define __NR_exit 1
+#ifndef __SH_FDPIC__
#define __NR_fork 2
+#endif
#define __NR_read 3
EOF
echo building sh2-fdpic linux toolchain &&
make -j$(nproc) &&
echo install linux toolchain &&
make install &&
cd .. || exit 1
echo clone target side libraries
git clone https://github.com/sabotage-linux/netbsd-curses.git &&
echo patching curses for J-Core &&
cd netbsd-curses &&
rm infocmp/Makefile \
libcurses/EXAMPLES/Makefile \
libcurses/PSD.doc/Makefile \
nbperf/Makefile \
tabs/Makefile \
tic/Makefile \
tput/Makefile \
tset/Makefile &&
patch -p1 << EOF &&
diff --git a/GNUmakefile b/GNUmakefile
index d302ce1..4623ffb 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -1,7 +1,9 @@
-HOSTCC ?= \$(CC)
+CROSS = sh2eb-linux-muslfdpic-
+HOSTCC = gcc
+CC = \$(CROSS)gcc
AWK ?= awk
-AR ?= ar
-RANLIB ?= ranlib
+AR = \$(CROSS)ar
+RANLIB = \$(CROSS)ranlib
HOST_SH ?= /bin/sh
LN ?= ln
INSTALL ?= ./install.sh
@@ -11,7 +13,7 @@ SO_SUFFIX ?= .so
PIC = -fPIC
-PREFIX=/usr/local
+PREFIX=$PREFIX/sh2eb-linux-muslfdpic
BINDIR=\$(PREFIX)/bin
LIBDIR=\$(PREFIX)/lib
INCDIR=\$(PREFIX)/include
@@ -43,7 +45,7 @@ STATIC_BINS=0
endif
CFLAGS+=-Werror-implicit-function-declaration
-CPPFLAGS+= -I. -I./libterminfo
+CPPFLAGS+= -I. -I./libterminfo -I./libcurses
TOOL_NBPERF= nbperf/nbperf
NBPERF_SRCS= nbperf/nbperf.c
diff --git a/libterminfo/GNUmakefile b/libterminfo/GNUmakefile
index ce0dc06..80b7992 100644
--- a/libterminfo/GNUmakefile
+++ b/libterminfo/GNUmakefile
@@ -5,8 +5,8 @@ USE_SHLIBDIR= yes
LIB= terminfo
WARNS?= 5
-CPPFLAGS+= -I.
-CPPFLAGS+= -I..
+CPPFLAGS+= -I. -I../libcurses
+CPPFLAGS+= -I.. -I../libcurses
SRCS= term.c ti.c setupterm.c curterm.c tparm.c tputs.c
SRCS+= compile.c hash.c
EOF
PATH=$PATH:$PREFIX/bin make CFLAGS=-Os LDFLAGS=-static all-static &&
make CFLAGS=-Os LDFLAGS=-static install-headers install-stalibs &&
cd .. || exit 1
echo building a bare sh2-elf binutils
mkdir bare-binutils &&
cd bare-binutils &&
../musl-cross-make/build/local/sh2eb-linux-muslfdpic/src_binutils/configure --prefix=$PREFIX --enable-deterministic-archives --target=sh2-elf --disable-separate-code --disable-werror &&
make -j$(nproc) &&
echo install bare metal binutils &&
make install &&
cd .. || exit 1
echo patching gcc for __attribute__ naked functions
(cd musl-cross-make/build/local/sh2eb-linux-muslfdpic/src_gcc/gcc/config/sh ; patch -p4 ) << EOF &&
--- src_gcc/gcc/config/sh/sh.c.cas 2022-06-11 15:59:46.746762896 +0900
+++ src_gcc/gcc/config/sh/sh.c 2022-06-11 16:32:06.714818662 +0900
@@ -210,6 +210,7 @@
tree, int, bool *);
static tree sh_handle_sp_switch_attribute (tree *, tree, tree, int, bool *);
static tree sh_handle_trap_exit_attribute (tree *, tree, tree, int, bool *);
+static tree sh_handle_naked_attribute (tree *, tree, tree, int, bool *);
static tree sh_handle_renesas_attribute (tree *, tree, tree, int, bool *);
static void sh_print_operand (FILE *, rtx, int);
static void sh_print_operand_address (FILE *, machine_mode, rtx);
@@ -341,6 +342,8 @@
sh_handle_sp_switch_attribute, NULL },
{ "trap_exit", 1, 1, true, false, false, false,
sh_handle_trap_exit_attribute, NULL },
+ { "naked", 0, 0, true, false, false, false,
+ sh_handle_naked_attribute, NULL },
{ "renesas", 0, 0, false, true, false, false,
sh_handle_renesas_attribute, NULL },
{ "trapa_handler", 0, 0, true, false, false, false,
@@ -7138,6 +7141,8 @@
tree sp_switch_attr
= lookup_attribute ("sp_switch", DECL_ATTRIBUTES (current_function_decl));
+ if (lookup_attribute ("naked", DECL_ATTRIBUTES (current_function_decl)) != NULL_TREE) return;
+
current_function_interrupt = sh_cfun_interrupt_handler_p ();
/* We have pretend args if we had an object sent partially in registers
@@ -7238,6 +7243,8 @@
int save_size = d;
int frame_size = rounded_frame_size (d);
+ if (lookup_attribute ("naked", DECL_ATTRIBUTES (current_function_decl)) != NULL_TREE) return;
+
if (frame_pointer_needed)
{
/* We must avoid scheduling the epilogue with previous basic blocks.
@@ -8416,6 +8423,9 @@
* trap_exit
Use a trapa to exit an interrupt function instead of rte.
+ * naked
+ Do not emit a function prolog or epilog.
+
* nosave_low_regs
Don't save r0..r7 in an interrupt handler function.
This is useful on SH3* and SH4*, which have a separate set of low
@@ -8606,6 +8616,24 @@
return NULL_TREE;
}
+/* Handle an "naked" attribute; arguments as in
+ struct attribute_spec.handler. */
+static tree
+sh_handle_naked_attribute (tree *node, tree name,
+ tree args ATTRIBUTE_UNUSED,
+ int flags ATTRIBUTE_UNUSED,
+ bool *no_add_attrs)
+{
+ if (TREE_CODE (*node) != FUNCTION_DECL)
+ {
+ warning (OPT_Wattributes, "%qE attribute only applies to functions",
+ name);
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+}
+
static tree
sh_handle_renesas_attribute (tree *node ATTRIBUTE_UNUSED,
tree name ATTRIBUTE_UNUSED,
@@ -8684,6 +8712,14 @@
!= NULL_TREE;
}
+/* Returns true if the current function has a "naked" attribute set. */
+bool
+sh_cfun_naked_p (void)
+{
+ return lookup_attribute ("naked", DECL_ATTRIBUTES (current_function_decl))
+ != NULL_TREE;
+}
+
/* Implement TARGET_CHECK_PCH_TARGET_FLAGS. */
static const char *
sh_check_pch_target_flags (int old_flags)
EOF
echo building a bare sh2-elf gcc for C language &&
mkdir bare-gcc &&
cd bare-gcc &&
../musl-cross-make/build/local/sh2eb-linux-muslfdpic/src_gcc/configure --prefix=$PREFIX --target=sh2-elf --disable-bootstrap --disable-assembly --disable-werror --disable-libmudflap --disable-libsanitizer --disable-gnu-indirect-function --disable-libmpx --disable-libmudflap --disable-libstdcxx-pch --disable-ssp --disable-libssp --enable-languages=c,c++ --with-newlib --without-headers --disable-hosted-libstdcxx &&
make -j$(nproc) all-gcc &&
make -j$(nproc) all-target-libgcc &&
echo install bare metal compiler &&
make install-strip-gcc &&
make install-strip-target-libgcc &&
ln -s sh2-elf-gcc "$PREFIX"/bin/sh2-elf-cc &&
cd .. || exit 1
if [ $(id -u) -eq 0 ]
then
echo install mercurial
wget https://www.mercurial-scm.org/release/mercurial-6.4.2.tar.gz &&
tar -zxvf mercurial-6.4.2.tar.gz &&
cd mercurial-6.4.2 &&
make install &&
cd .. || exit 1
fi