Skip to content

Commit 3300fa5

Browse files
committed
Fix musl-cross-make nommu build (at least for sh2eb).
1 parent f40ea28 commit 3300fa5

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

scripts/mcm-buildall.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,94 @@ make_tuple()
127127
done
128128
}
129129

130+
# Packages detect nommu via the absence of fork(). Musl provides a broken fork()
131+
# on nommu builds that always returns -ENOSYS at runtime. Rip it out.
132+
# (Currently only for superh/jcore.)
133+
fix_nommu()
134+
{
135+
# Rich won't merge this
136+
sed -i 's/--enable-fdpic$/& --enable-twoprocess/' litecross/Makefile
137+
138+
PP=patches/musl-"$(sed -n 's/MUSL_VER[ \t]*=[ \t]*//p' Makefile)"
139+
mkdir -p "$PP" &&
140+
cat > "$PP"/0001-nommu.patch << 'EOF'
141+
--- a/include/features.h
142+
+++ b/include/features.h
143+
@@ -3,2 +3,4 @@
144+
145+
+#define __MUSL__ 1
146+
+
147+
#if defined(_ALL_SOURCE) && !defined(_GNU_SOURCE)
148+
--- a/src/legacy/daemon.c
149+
+++ b/src/legacy/daemon.c
150+
@@ -17,3 +17,3 @@
151+
152+
- switch(fork()) {
153+
+ switch(vfork()) {
154+
case 0: break;
155+
@@ -25,3 +25,3 @@
156+
157+
- switch(fork()) {
158+
+ switch(vfork()) {
159+
case 0: break;
160+
--- a/src/misc/forkpty.c
161+
+++ b/src/misc/forkpty.c
162+
@@ -8,2 +8,3 @@
163+
164+
+#ifndef __SH_FDPIC__
165+
int forkpty(int *pm, char *name, const struct termios *tio, const struct winsize *ws)
166+
@@ -57,1 +58,2 @@
167+
}
168+
+#endif
169+
--- a/src/misc/wordexp.c
170+
+++ b/src/misc/wordexp.c
171+
@@ -25,2 +25,3 @@
172+
173+
+#ifndef __SH_FDPIC__
174+
static int do_wordexp(const char *s, wordexp_t *we, int flags)
175+
@@ -177,2 +178,3 @@
176+
}
177+
+#endif
178+
179+
--- a/src/process/fork.c
180+
+++ b/src/process/fork.c
181+
@@ -7,2 +7,3 @@
182+
183+
+#ifndef __SH_FDPIC__
184+
static void dummy(int x)
185+
@@ -37,1 +38,2 @@
186+
}
187+
+#endif
188+
--- a/Makefile
189+
+++ b/Makefile
190+
@@ -100,3 +100,3 @@
191+
cp $< $@
192+
- sed -n -e s/__NR_/SYS_/p < $< >> $@
193+
+ sed -e s/__NR_/SYS_/ < $< >> $@
194+
195+
--- a/arch/sh/bits/syscall.h.in
196+
+++ b/arch/sh/bits/syscall.h.in
197+
@@ -2,3 +2,5 @@
198+
#define __NR_exit 1
199+
+#ifndef __SH_FDPIC__
200+
#define __NR_fork 2
201+
+#endif
202+
#define __NR_read 3
203+
EOF
204+
205+
# I won't sign the FSF's copyright assignment
206+
tee $(for i in patches/gcc-*; do echo $i/099-vfork.patch; done) > /dev/null << 'EOF'
207+
--- gcc-8.3.0/fixincludes/procopen.c 2005-08-14 19:50:43.000000000 -0500
208+
+++ gcc-bak/fixincludes/procopen.c 2020-02-06 23:27:15.408071708 -0600
209+
@@ -116,3 +116,3 @@
210+
*/
211+
- ch_id = fork ();
212+
+ ch_id = vfork ();
213+
switch (ch_id)
214+
EOF
215+
}
216+
217+
fix_nommu || exit 1
130218
mkdir -p "$OUTPUT"/log
131219

132220
# Make bootstrap compiler (no $TYPE, dynamically linked against host libc)

0 commit comments

Comments
 (0)