Feat: init

This commit is contained in:
zijiren233 2024-01-10 03:39:51 +08:00
parent fe915821b6
commit 1eb8520be4
54 changed files with 3429 additions and 12 deletions

View File

@ -10,13 +10,14 @@ 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
MPC_SITE = $(GNU_SITE)/mpc
MPFR_SITE = $(GNU_SITE)/mpfr
ISL_SITE = http://isl.gforge.inria.fr/
ISL_SITE = https://downloads.sourceforge.net/project/libisl/
GCC_SNAP = https://sourceware.org/pub/gcc/snapshots
MUSL_SITE = https://musl.libc.org/releases
MUSL_REPO = git://git.musl-libc.org/musl
@ -24,7 +25,7 @@ MUSL_REPO = git://git.musl-libc.org/musl
LINUX_SITE = https://cdn.kernel.org/pub/linux/kernel
LINUX_HEADERS_SITE = http://ftp.barfooze.de/pub/sabotage/tarballs/
DL_CMD = wget -c -O
DL_CMD = curl -sLo
SHA1_CMD = sha1sum -c
COWPATCH = $(CURDIR)/cowpatch.sh
@ -63,8 +64,10 @@ $(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/mpc*)): SITE = $(MPC_SIT
$(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/mpfr*)): SITE = $(MPFR_SITE)
$(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/isl*)): SITE = $(ISL_SITE)
$(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/binutils*)): SITE = $(BINUTILS_SITE)
$(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/gcc*)): SITE = $(GCC_SITE)/$(basename $(basename $(notdir $@)))
$(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/gcc-*)): SITE = $(GCC_SITE)/$(basename $(basename $(notdir $@)))
$(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/gcc-*-*)): SITE = $(GCC_SNAP)/$(subst gcc-,,$(basename $(basename $(notdir $@))))
$(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/musl*)): SITE = $(MUSL_SITE)
$(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/linux-6*)): SITE = $(LINUX_SITE)/v6.x
$(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/linux-5*)): SITE = $(LINUX_SITE)/v5.x
$(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/linux-4*)): SITE = $(LINUX_SITE)/v4.x
$(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/linux-3*)): SITE = $(LINUX_SITE)/v3.x
@ -76,7 +79,7 @@ $(SOURCES):
$(SOURCES)/config.sub: | $(SOURCES)
mkdir -p $@.tmp
cd $@.tmp && $(DL_CMD) $(notdir $@) "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=$(CONFIG_SUB_REV)"
cd $@.tmp && $(DL_CMD) $(notdir $@) "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=$(CONFIG_SUB_REV)"
cd $@.tmp && touch $(notdir $@)
cd $@.tmp && $(SHA1_CMD) $(CURDIR)/hashes/$(notdir $@).$(CONFIG_SUB_REV).sha1
mv $@.tmp/$(notdir $@) $@
@ -97,8 +100,9 @@ endif
musl-git-%:
rm -rf $@.tmp
git clone -b $(patsubst musl-git-%,%,$@) $(MUSL_REPO) $@.tmp
cd $@.tmp && git fsck
git clone $(MUSL_REPO) $@.tmp
cd $@.tmp && git reset --hard $(patsubst musl-git-%,%,$@) && git fsck
test ! -d patches/$@ || cat patches/$@/* | ( cd $@.tmp && patch -p1 )
mv $@.tmp $@
%.orig: $(SOURCES)/%.tar.gz
@ -140,6 +144,7 @@ musl-git-%:
if test -f $</configfsf.sub ; then cs=configfsf.sub ; elif test -f $</config.sub ; then cs=config.sub ; else exit 0 ; fi ; rm -f $@.tmp/$$cs && cp -f $(SOURCES)/config.sub $@.tmp/$$cs && chmod +x $@.tmp/$$cs
rm -rf $@
mv $@.tmp $@
$(COWPATCH) -S gcc-$(GCC_VER)/libstdc++-v3
# Add deps for all patched source dirs on their patchsets

View File

@ -0,0 +1 @@
78f7ba4c0775ae75f5b906dc9af03d70b39b0785 binutils-2.34.tar.xz

View File

@ -0,0 +1 @@
45f7a96a2580a422f44b78317f0abf13935fecb6 binutils-2.35.1.tar.xz

View File

@ -0,0 +1 @@
2dd8d1ce34dc7b1cb2073123e30c4901221835b0 binutils-2.35.2.tar.xz

View File

@ -0,0 +1 @@
6bdd090ce268b6d6c3442516021c4e4b5019e303 binutils-2.35.tar.xz

View File

@ -0,0 +1 @@
021c97cc0e751e989afb8db025fbd2ae48391831 binutils-2.36.1.tar.xz

View File

@ -0,0 +1 @@
3767185ed0bd82c0682ed026f202cc7872b4c55b binutils-2.36.tar.xz

View File

@ -0,0 +1 @@
e9cf391b000010d6c752771974b394c9c743c928 binutils-2.37.tar.xz

View File

@ -0,0 +1 @@
15d42de8f15404a4a43a912440cf367f994779d7 binutils-2.38.tar.xz

View File

@ -0,0 +1 @@
f17653e7b1d1fa5242a408919845da23e8cc5141 binutils-2.39.tar.xz

View File

@ -0,0 +1 @@
fee4fbef9d632afc1988dd631d7f75d4394b7f8d binutils-2.40.tar.xz

View File

@ -0,0 +1 @@
71d4a097984191a1d6fc53dd247ecdd187ad7201 config.sub

View File

@ -0,0 +1 @@
675e70687f262748fcd2468768147ae8a0e50ddf config.sub

View File

@ -0,0 +1 @@
03f21dce9edf9092e38b4e23dd27b29f6ab56f63 gcc-11.4.0.tar.xz

View File

@ -0,0 +1 @@
5e9341d3807bc7505376f9ed9f5c1c6c57050aa6 gmp-6.2.0.tar.bz2

View File

@ -0,0 +1 @@
2dcf34d4a432dbe6cce1475a835d20fe44f75822 gmp-6.2.1.tar.bz2

View File

@ -0,0 +1 @@
32d21c4fae046de45e8fce37bf4002236d283b71 gmp-6.3.0.tar.bz2

View File

@ -0,0 +1 @@
afa6c0129d08bd9476a642095112b7c49c9455e4 linux-6.1.36.tar.xz

View File

@ -0,0 +1 @@
0abdc94acab0c9bfdaa391347cdfd7bbdb1cf017 mpc-1.2.0.tar.gz

View File

@ -0,0 +1 @@
2a4919abf445c6eda4e120cd669b8733ce337227 mpc-1.2.1.tar.gz

View File

@ -0,0 +1 @@
bac1c1fa79f5602df1e29e4684e103ad55714e02 mpc-1.3.1.tar.gz

View File

@ -0,0 +1 @@
874e84bb5959fd5a19c032cfb5d673dded4b5cff mpfr-3.1.5.tar.bz2

View File

@ -0,0 +1 @@
c207aada1c0af969d800c16f25e0a78e15b9c9cc mpfr-3.1.6.tar.bz2

View File

@ -0,0 +1 @@
fcbbafb37c683898e585b926608d540ed037609e mpfr-4.0.1.tar.bz2

View File

@ -0,0 +1 @@
ae555c56a6fccd21a0ffe3dd3bdc5eb5cc1a5fce mpfr-4.0.1.tar.xz

View File

@ -0,0 +1 @@
52c1f2a4c9a202f46cf3275a8d46b562aa584208 mpfr-4.0.2.tar.xz

View File

@ -0,0 +1 @@
877d35a8a81a4d2d9446252e9b4ae944754d8ceb mpfr-4.1.0.tar.bz2

View File

@ -0,0 +1 @@
159c3a58705662bfde4dc93f2617f3660855ead6 mpfr-4.1.0.tar.xz

View File

@ -0,0 +1 @@
08390d482ffcb198329632c0bf76dace53016dd8 mpfr-4.2.0.tar.bz2

View File

@ -0,0 +1 @@
4f734ca3ebceac28e2f944b131a47133b19e2c5e mpfr-4.2.0.tar.xz

View File

@ -0,0 +1 @@
f9dbe49b092e4c8e0a039e6d46c059696cc2f51c mpfr-4.2.1.tar.bz2

View File

@ -0,0 +1 @@
78eb982244b857dbacb2ead25cc0f631ce44204d musl-1.2.4.tar.gz

View File

@ -15,6 +15,12 @@ XGCC = $(XGCC_DIR)/xgcc -B $(XGCC_DIR)
-include config.mak
ifeq ($(CPUS),)
CPUS = $(shell if command -v nproc >/dev/null 2>&1; then nproc; else echo 1; fi)
endif
MAKE += -j$(CPUS)
ifneq ($(findstring fdpic,$(TARGET)),)
GCC_CONFIG_FOR_TARGET += --enable-fdpic
endif
@ -23,8 +29,14 @@ ifneq ($(filter x86_64%x32,$(TARGET)),)
GCC_CONFIG_FOR_TARGET += --with-abi=x32
endif
ifneq ($(findstring microblaze,$(TARGET)),)
# ICE in GCC; temporarily disable gfortran support.
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87438
GCC_CONFIG_FOR_TARGET += --enable-languages=c,c++
endif
ifneq ($(findstring powerpc64,$(TARGET)),)
GCC_CONFIG_FOR_TARGET += --with-abi=elfv2
GCC_CONFIG_FOR_TARGET += --with-abi=elfv2 --with-cpu=970
endif
ifneq ($(findstring mips64,$(TARGET))$(findstring mipsisa64,$(TARGET)),)
@ -65,7 +77,7 @@ FULL_BINUTILS_CONFIG = \
--with-sysroot=$(SYSROOT) \
--enable-deterministic-archives
FULL_GCC_CONFIG = --enable-languages=c,c++ \
FULL_GCC_CONFIG = --enable-languages=c,c++,fortran \
$(GCC_CONFIG_FOR_TARGET) \
$(COMMON_CONFIG) $(GCC_CONFIG) $(TOOLCHAIN_CONFIG) \
--disable-bootstrap \
@ -79,7 +91,12 @@ FULL_GCC_CONFIG = --enable-languages=c,c++ \
--disable-gnu-indirect-function \
--disable-libmpx \
--enable-initfini-array \
--enable-libstdcxx-time=rt
--enable-libstdcxx-time=rt \
--enable-deterministic-archives \
--enable-libstdcxx-time \
--enable-libquadmath --enable-libquadmath-support \
--disable-decimal-float \
$(OVERRIDE)
FULL_MUSL_CONFIG = $(MUSL_CONFIG) \
--prefix= --host=$(TARGET)
@ -258,7 +275,7 @@ install-gcc: | obj_gcc/.lc_built
ifneq ($(LINUX_SRCDIR),)
TARGET_ARCH = $(firstword $(subst -, ,$(TARGET)))
TARGET_ARCH_MANGLED = $(patsubst i%86,x86,$(patsubst aarch64%,arm64%,$(TARGET_ARCH)))
TARGET_ARCH_MANGLED = $(patsubst i%86,x86,$(patsubst aarch64%,arm64%,$(patsubst or1k%,openrisc%,$(TARGET_ARCH))))
LINUX_ARCH_LIST = $(sort $(notdir $(wildcard $(LINUX_SRCDIR)/arch/*)))
LINUX_ARCH = $(lastword $(foreach a,$(LINUX_ARCH_LIST),$(if $(filter $(a)%,$(TARGET_ARCH_MANGLED)),$(a))))
ifneq ($(LINUX_ARCH),)
@ -269,7 +286,7 @@ src_kernel_headers: | $(LINUX_SRCDIR)
ln -sf "$(LINUX_SRCDIR)" $@
obj_kernel_headers/.lc_built: | src_kernel_headers
mkdir -p $(CURDIR)/obj_kernel_headers/staged
cd src_kernel_headers && $(MAKE) ARCH=$(LINUX_ARCH) O=$(CURDIR)/obj_kernel_headers INSTALL_HDR_PATH=$(CURDIR)/obj_kernel_headers/staged headers_install
cd src_kernel_headers && $(MAKE) ARCH=$(LINUX_ARCH) O=$(CURDIR)/obj_kernel_headers INSTALL_HDR_PATH=$(CURDIR)/obj_kernel_headers/staged headers_install HOSTCC="$(CC) $(STAT)"
find obj_kernel_headers/staged/include '(' -name .install -o -name ..install.cmd ')' -exec rm {} +
touch $@
install-kernel-headers: | obj_kernel_headers/.lc_built

View File

@ -0,0 +1,26 @@
diff --git a/configure b/configure
index 6157a8c87fb..2a4a05b4edf 100755
--- a/configure
+++ b/configure
@@ -16653,7 +16653,7 @@ else
fi
-RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET"
+RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET -nostdinc++"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking where to find the target ar" >&5
$as_echo_n "checking where to find the target ar... " >&6; }
diff --git a/configure.ac b/configure.ac
index 2ff48941754..01ecc8c42d9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3515,7 +3515,7 @@ ACX_CHECK_INSTALLED_TARGET_TOOL(STRIP_FOR_TARGET, strip)
ACX_CHECK_INSTALLED_TARGET_TOOL(WINDRES_FOR_TARGET, windres)
ACX_CHECK_INSTALLED_TARGET_TOOL(WINDMC_FOR_TARGET, windmc)
-RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET"
+RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET -nostdinc++"
GCC_TARGET_TOOL(ar, AR_FOR_TARGET, AR, [binutils/ar])
GCC_TARGET_TOOL(as, AS_FOR_TARGET, AS, [gas/as-new])

View File

@ -0,0 +1,14 @@
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 7837553958b..3c81c5798d8 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -980,7 +980,8 @@ proper position among the other output files. */
#ifndef LINK_SSP_SPEC
#ifdef TARGET_LIBC_PROVIDES_SSP
#define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
- "|fstack-protector-strong|fstack-protector-explicit:}"
+ "|fstack-protector-strong|fstack-protector-explicit" \
+ ":-lssp_nonshared}"
#else
#define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
"|fstack-protector-strong|fstack-protector-explicit" \

View File

@ -0,0 +1,30 @@
diff --git a/gcc/config/i386/pmm_malloc.h b/gcc/config/i386/pmm_malloc.h
index 1b0bfe37852..d7b2b19bb3c 100644
--- a/gcc/config/i386/pmm_malloc.h
+++ b/gcc/config/i386/pmm_malloc.h
@@ -27,12 +27,13 @@
#include <stdlib.h>
/* We can't depend on <stdlib.h> since the prototype of posix_memalign
- may not be visible. */
+ may not be visible and we can't pollute the namespace either. */
#ifndef __cplusplus
-extern int posix_memalign (void **, size_t, size_t);
+extern int _mm_posix_memalign (void **, size_t, size_t)
#else
-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
+extern "C" int _mm_posix_memalign (void **, size_t, size_t) throw ()
#endif
+__asm__("posix_memalign");
static __inline void *
_mm_malloc (size_t __size, size_t __alignment)
@@ -42,7 +43,7 @@ _mm_malloc (size_t __size, size_t __alignment)
return malloc (__size);
if (__alignment == 2 || (sizeof (void *) == 8 && __alignment == 4))
__alignment = sizeof (void *);
- if (posix_memalign (&__ptr, __alignment, __size) == 0)
+ if (_mm_posix_memalign (&__ptr, __alignment, __size) == 0)
return __ptr;
else
return NULL;

View File

@ -0,0 +1,346 @@
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 357b0bed067..528add999f2 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -556,7 +556,7 @@ s390*-*-*)
extra_headers="s390intrin.h htmintrin.h htmxlintrin.h vecintrin.h"
;;
# Note the 'l'; we need to be able to match e.g. "shle" or "shl".
-sh[123456789lbe]*-*-* | sh-*-*)
+sh[123456789lbej]*-*-* | sh-*-*)
cpu_type=sh
extra_options="${extra_options} fused-madd.opt"
extra_objs="${extra_objs} sh_treg_combine.o sh-mem.o sh_optimize_sett_clrt.o"
@@ -3202,18 +3202,18 @@ s390x-ibm-tpf*)
extra_options="${extra_options} s390/tpf.opt"
tmake_file="${tmake_file} s390/t-s390"
;;
-sh-*-elf* | sh[12346l]*-*-elf* | \
- sh-*-linux* | sh[2346lbe]*-*-linux* | \
+sh-*-elf* | sh[12346lj]*-*-elf* | \
+ sh-*-linux* | sh[2346lbej]*-*-linux* | \
sh-*-netbsdelf* | shl*-*-netbsdelf*)
tmake_file="${tmake_file} sh/t-sh sh/t-elf"
if test x${with_endian} = x; then
case ${target} in
- sh[1234]*be-*-* | sh[1234]*eb-*-*) with_endian=big ;;
+ sh[j1234]*be-*-* | sh[j1234]*eb-*-*) with_endian=big ;;
shbe-*-* | sheb-*-*) with_endian=big,little ;;
sh[1234]l* | sh[34]*-*-linux*) with_endian=little ;;
shl* | sh*-*-linux* | \
sh-superh-elf) with_endian=little,big ;;
- sh[1234]*-*-*) with_endian=big ;;
+ sh[j1234]*-*-*) with_endian=big ;;
*) with_endian=big,little ;;
esac
fi
@@ -3280,6 +3280,7 @@ sh-*-elf* | sh[12346l]*-*-elf* | \
sh2a_nofpu*) sh_cpu_target=sh2a-nofpu ;;
sh2a*) sh_cpu_target=sh2a ;;
sh2e*) sh_cpu_target=sh2e ;;
+ shj2*) sh_cpu_target=shj2;;
sh2*) sh_cpu_target=sh2 ;;
*) sh_cpu_target=sh1 ;;
esac
@@ -3301,7 +3302,7 @@ sh-*-elf* | sh[12346l]*-*-elf* | \
sh2a-single-only | sh2a-single | sh2a-nofpu | sh2a | \
sh4a-single-only | sh4a-single | sh4a-nofpu | sh4a | sh4al | \
sh4-single-only | sh4-single | sh4-nofpu | sh4 | sh4-300 | \
- sh3e | sh3 | sh2e | sh2 | sh1) ;;
+ sh3e | sh3 | sh2e | sh2 | sh1 | shj2) ;;
"") sh_cpu_default=${sh_cpu_target} ;;
*) echo "with_cpu=$with_cpu not supported"; exit 1 ;;
esac
@@ -3310,9 +3311,9 @@ sh-*-elf* | sh[12346l]*-*-elf* | \
case ${target} in
sh[1234]*) sh_multilibs=${sh_cpu_target} ;;
sh-superh-*) sh_multilibs=m4,m4-single,m4-single-only,m4-nofpu ;;
- sh*-*-linux*) sh_multilibs=m1,m2,m2a,m3e,m4 ;;
+ sh*-*-linux*) sh_multilibs=m1,m2,m2a,m3e,m4,mj2 ;;
sh*-*-netbsd*) sh_multilibs=m3,m3e,m4 ;;
- *) sh_multilibs=m1,m2,m2e,m4,m4-single,m4-single-only,m2a,m2a-single ;;
+ *) sh_multilibs=m1,m2,m2e,m4,m4-single,m4-single-only,m2a,m2a-single,mj2 ;;
esac
if test x$with_fp = xno; then
sh_multilibs="`echo $sh_multilibs|sed -e s/m4/sh4-nofpu/ -e s/,m4-[^,]*//g -e s/,m[23]e// -e s/m2a,m2a-single/m2a-nofpu/ -e s/m5-..m....,//g`"
@@ -3327,7 +3328,8 @@ sh-*-elf* | sh[12346l]*-*-elf* | \
m1 | m2 | m2e | m3 | m3e | \
m4 | m4-single | m4-single-only | m4-nofpu | m4-300 |\
m4a | m4a-single | m4a-single-only | m4a-nofpu | m4al | \
- m2a | m2a-single | m2a-single-only | m2a-nofpu)
+ m2a | m2a-single | m2a-single-only | m2a-nofpu | \
+ mj2)
# TM_MULTILIB_CONFIG is used by t-sh for the non-endian multilib definition
# It is passed to MULTIILIB_OPTIONS verbatim.
TM_MULTILIB_CONFIG="${TM_MULTILIB_CONFIG}/${sh_multilib}"
@@ -3344,7 +3346,7 @@ sh-*-elf* | sh[12346l]*-*-elf* | \
done
TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's:^/::'`
if test x${enable_incomplete_targets} = xyes ; then
- tm_defines="$tm_defines SUPPORT_SH1=1 SUPPORT_SH2E=1 SUPPORT_SH4=1 SUPPORT_SH4_SINGLE=1 SUPPORT_SH2A=1 SUPPORT_SH2A_SINGLE=1"
+ tm_defines="$tm_defines SUPPORT_SH1=1 SUPPORT_SH2E=1 SUPPORT_SH4=1 SUPPORT_SH4_SINGLE=1 SUPPORT_SH2A=1 SUPPORT_SH2A_SINGLE=1 SUPPORT_SHJ2=1"
fi
tm_file="$tm_file ./sysroot-suffix.h"
tmake_file="$tmake_file t-sysroot-suffix"
@@ -5175,6 +5177,8 @@ case "${target}" in
;;
m4a | m4a-single | m4a-single-only | m4a-nofpu | m4al)
;;
+ mj2)
+ ;;
*)
echo "Unknown CPU used in --with-cpu=$with_cpu, known values:" 1>&2
echo "m1 m2 m2e m3 m3e m4 m4-single m4-single-only m4-nofpu" 1>&2
@@ -5385,7 +5389,7 @@ case ${target} in
tmake_file="${cpu_type}/t-${cpu_type} ${tmake_file}"
;;
- sh[123456ble]*-*-* | sh-*-*)
+ sh[123456blej]*-*-* | sh-*-*)
c_target_objs="${c_target_objs} sh-c.o"
cxx_target_objs="${cxx_target_objs} sh-c.o"
;;
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index 1564109c942..798c1c1c1a3 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -686,6 +686,7 @@ parse_validate_atomic_model_option (const char* str)
model_names[sh_atomic_model::hard_llcs] = "hard-llcs";
model_names[sh_atomic_model::soft_tcb] = "soft-tcb";
model_names[sh_atomic_model::soft_imask] = "soft-imask";
+ model_names[sh_atomic_model::hard_cas] = "hard-cas";
const char* model_cdef_names[sh_atomic_model::num_models];
model_cdef_names[sh_atomic_model::none] = "NONE";
@@ -693,6 +694,7 @@ parse_validate_atomic_model_option (const char* str)
model_cdef_names[sh_atomic_model::hard_llcs] = "HARD_LLCS";
model_cdef_names[sh_atomic_model::soft_tcb] = "SOFT_TCB";
model_cdef_names[sh_atomic_model::soft_imask] = "SOFT_IMASK";
+ model_cdef_names[sh_atomic_model::hard_cas] = "HARD_CAS";
sh_atomic_model ret;
ret.type = sh_atomic_model::none;
@@ -771,6 +773,9 @@ got_mode_name:;
if (ret.type == sh_atomic_model::soft_imask && TARGET_USERMODE)
err_ret ("cannot use atomic model %s in user mode", ret.name);
+ if (ret.type == sh_atomic_model::hard_cas && !TARGET_SHJ2)
+ err_ret ("atomic model %s is only available J2 targets", ret.name);
+
return ret;
#undef err_ret
@@ -827,6 +832,8 @@ sh_option_override (void)
sh_cpu = PROCESSOR_SH2E;
if (TARGET_SH2A)
sh_cpu = PROCESSOR_SH2A;
+ if (TARGET_SHJ2)
+ sh_cpu = PROCESSOR_SHJ2;
if (TARGET_SH3)
sh_cpu = PROCESSOR_SH3;
if (TARGET_SH3E)
diff --git a/gcc/config/sh/sh.h b/gcc/config/sh/sh.h
index d2280e2ffe6..3a54a896721 100644
--- a/gcc/config/sh/sh.h
+++ b/gcc/config/sh/sh.h
@@ -85,6 +85,7 @@ extern int code_for_indirect_jump_scratch;
#define SUPPORT_SH4_SINGLE 1
#define SUPPORT_SH2A 1
#define SUPPORT_SH2A_SINGLE 1
+#define SUPPORT_SHJ2 1
#endif
#define TARGET_DIVIDE_CALL_DIV1 (sh_div_strategy == SH_DIV_CALL_DIV1)
@@ -117,6 +118,7 @@ extern int code_for_indirect_jump_scratch;
#define SELECT_SH4A_SINGLE_ONLY (MASK_SH4A | SELECT_SH4_SINGLE_ONLY)
#define SELECT_SH4A (MASK_SH4A | SELECT_SH4)
#define SELECT_SH4A_SINGLE (MASK_SH4A | SELECT_SH4_SINGLE)
+#define SELECT_SHJ2 (MASK_SHJ2 | SELECT_SH2)
#if SUPPORT_SH1
#define SUPPORT_SH2 1
@@ -124,6 +126,7 @@ extern int code_for_indirect_jump_scratch;
#if SUPPORT_SH2
#define SUPPORT_SH3 1
#define SUPPORT_SH2A_NOFPU 1
+#define SUPPORT_SHJ2 1
#endif
#if SUPPORT_SH3
#define SUPPORT_SH4_NOFPU 1
@@ -156,7 +159,7 @@ extern int code_for_indirect_jump_scratch;
#define MASK_ARCH (MASK_SH1 | MASK_SH2 | MASK_SH3 | MASK_SH_E | MASK_SH4 \
| MASK_HARD_SH2A | MASK_HARD_SH2A_DOUBLE | MASK_SH4A \
| MASK_HARD_SH4 | MASK_FPU_SINGLE \
- | MASK_FPU_SINGLE_ONLY)
+ | MASK_FPU_SINGLE_ONLY | MASK_SHJ2)
/* This defaults us to big-endian. */
#ifndef TARGET_ENDIAN_DEFAULT
@@ -231,7 +234,8 @@ extern int code_for_indirect_jump_scratch;
%{m2a-single:--isa=sh2a} \
%{m2a-single-only:--isa=sh2a} \
%{m2a-nofpu:--isa=sh2a-nofpu} \
-%{m4al:-dsp}"
+%{m4al:-dsp} \
+%{mj2:-isa=j2}"
#define ASM_SPEC SH_ASM_SPEC
@@ -347,6 +351,7 @@ struct sh_atomic_model
hard_llcs,
soft_tcb,
soft_imask,
+ hard_cas,
num_models
};
@@ -390,6 +395,9 @@ extern const sh_atomic_model& selected_atomic_model (void);
#define TARGET_ATOMIC_SOFT_IMASK \
(selected_atomic_model ().type == sh_atomic_model::soft_imask)
+#define TARGET_ATOMIC_HARD_CAS \
+ (selected_atomic_model ().type == sh_atomic_model::hard_cas)
+
#endif // __cplusplus
#define SUBTARGET_OVERRIDE_OPTIONS (void) 0
@@ -1484,7 +1492,7 @@ extern bool current_function_interrupt;
/* Nonzero if the target supports dynamic shift instructions
like shad and shld. */
-#define TARGET_DYNSHIFT (TARGET_SH3 || TARGET_SH2A)
+#define TARGET_DYNSHIFT (TARGET_SH3 || TARGET_SH2A || TARGET_SHJ2)
/* The cost of using the dynamic shift insns (shad, shld) are the same
if they are available. If they are not available a library function will
@@ -1747,6 +1755,7 @@ enum processor_type {
PROCESSOR_SH2,
PROCESSOR_SH2E,
PROCESSOR_SH2A,
+ PROCESSOR_SHJ2,
PROCESSOR_SH3,
PROCESSOR_SH3E,
PROCESSOR_SH4,
diff --git a/gcc/config/sh/sh.opt b/gcc/config/sh/sh.opt
index b4755a812f3..0989a1c18da 100644
--- a/gcc/config/sh/sh.opt
+++ b/gcc/config/sh/sh.opt
@@ -65,6 +65,10 @@ m2e
Target RejectNegative Condition(SUPPORT_SH2E)
Generate SH2e code.
+mj2
+Target RejectNegative Mask(SHJ2) Condition(SUPPORT_SHJ2)
+Generate J2 code.
+
m3
Target RejectNegative Mask(SH3) Condition(SUPPORT_SH3)
Generate SH3 code.
diff --git a/gcc/config/sh/sync.md b/gcc/config/sh/sync.md
index 2b43f8edb86..118fc5d06db 100644
--- a/gcc/config/sh/sync.md
+++ b/gcc/config/sh/sync.md
@@ -240,6 +240,9 @@
|| (TARGET_SH4A && <MODE>mode == SImode && !TARGET_ATOMIC_STRICT))
atomic_insn = gen_atomic_compare_and_swap<mode>_hard (old_val, mem,
exp_val, new_val);
+ else if (TARGET_ATOMIC_HARD_CAS && <MODE>mode == SImode)
+ atomic_insn = gen_atomic_compare_and_swap<mode>_cas (old_val, mem,
+ exp_val, new_val);
else if (TARGET_ATOMIC_SOFT_GUSA)
atomic_insn = gen_atomic_compare_and_swap<mode>_soft_gusa (old_val, mem,
exp_val, new_val);
@@ -306,6 +309,57 @@
}
[(set_attr "length" "14")])
+(define_expand "atomic_compare_and_swapsi_cas"
+ [(set (match_operand:SI 0 "register_operand" "=r")
+ (unspec_volatile:SI
+ [(match_operand:SI 1 "atomic_mem_operand_0" "=Sra")
+ (match_operand:SI 2 "register_operand" "r")
+ (match_operand:SI 3 "register_operand" "r")]
+ UNSPECV_CMPXCHG_1))]
+ "TARGET_ATOMIC_HARD_CAS"
+{
+ rtx mem = gen_rtx_REG (SImode, 0);
+ emit_move_insn (mem, force_reg (SImode, XEXP (operands[1], 0)));
+ emit_insn (gen_shj2_cas (operands[0], mem, operands[2], operands[3]));
+ DONE;
+})
+
+(define_insn "shj2_cas"
+ [(set (match_operand:SI 0 "register_operand" "=&r")
+ (unspec_volatile:SI
+ [(match_operand:SI 1 "register_operand" "=r")
+ (match_operand:SI 2 "register_operand" "r")
+ (match_operand:SI 3 "register_operand" "0")]
+ UNSPECV_CMPXCHG_1))
+ (set (reg:SI T_REG)
+ (unspec_volatile:SI [(const_int 0)] UNSPECV_CMPXCHG_3))]
+ "TARGET_ATOMIC_HARD_CAS"
+ "cas.l %2,%0,@%1"
+ [(set_attr "length" "2")]
+)
+
+(define_expand "atomic_compare_and_swapqi_cas"
+ [(set (match_operand:SI 0 "arith_reg_dest" "=&r")
+ (unspec_volatile:SI
+ [(match_operand:SI 1 "atomic_mem_operand_0" "=Sra")
+ (match_operand:SI 2 "arith_operand" "rI08")
+ (match_operand:SI 3 "arith_operand" "rI08")]
+ UNSPECV_CMPXCHG_1))]
+ "TARGET_ATOMIC_HARD_CAS"
+{FAIL;}
+)
+
+(define_expand "atomic_compare_and_swaphi_cas"
+ [(set (match_operand:SI 0 "arith_reg_dest" "=&r")
+ (unspec_volatile:SI
+ [(match_operand:SI 1 "atomic_mem_operand_0" "=Sra")
+ (match_operand:SI 2 "arith_operand" "rI08")
+ (match_operand:SI 3 "arith_operand" "rI08")]
+ UNSPECV_CMPXCHG_1))]
+ "TARGET_ATOMIC_HARD_CAS"
+{FAIL;}
+)
+
;; The QIHImode llcs patterns modify the address register of the memory
;; operand. In order to express that, we have to open code the memory
;; operand. Initially the insn is expanded like every other atomic insn
diff --git a/gcc/config/sh/t-sh b/gcc/config/sh/t-sh
index 888f8ff7f25..29fd6ae45fd 100644
--- a/gcc/config/sh/t-sh
+++ b/gcc/config/sh/t-sh
@@ -50,7 +50,8 @@ MULTILIB_MATCHES = $(shell \
m2e,m3e,m4-single-only,m4-100-single-only,m4-200-single-only,m4-300-single-only,m4a-single-only \
m2a-single,m2a-single-only \
m4-single,m4-100-single,m4-200-single,m4-300-single,m4a-single \
- m4,m4-100,m4-200,m4-300,m4a; do \
+ m4,m4-100,m4-200,m4-300,m4a \
+ mj2; do \
subst= ; \
for lib in `echo $$abi|tr , ' '` ; do \
if test "`echo $$multilibs|sed s/$$lib//`" != "$$multilibs"; then \
@@ -63,9 +64,9 @@ MULTILIB_MATCHES = $(shell \
# SH1 and SH2A support big endian only.
ifeq ($(DEFAULT_ENDIAN),ml)
-MULTILIB_EXCEPTIONS = m1 ml/m1 m2a* ml/m2a* $(TM_MULTILIB_EXCEPTIONS_CONFIG)
+MULTILIB_EXCEPTIONS = m1 ml/m1 m2a* ml/m2a* ml/mj2 $(TM_MULTILIB_EXCEPTIONS_CONFIG)
else
-MULTILIB_EXCEPTIONS = ml/m1 ml/m2a* $(TM_MULTILIB_EXCEPTIONS_CONFIG)
+MULTILIB_EXCEPTIONS = ml/m1 ml/m2a* ml/mj2 $(TM_MULTILIB_EXCEPTIONS_CONFIG)
endif
MULTILIB_OSDIRNAMES = \
@@ -87,7 +88,8 @@ MULTILIB_OSDIRNAMES = \
m4a-single-only=!m4a-single-only $(OTHER_ENDIAN)/m4a-single-only=!$(OTHER_ENDIAN)/m4a-single-only \
m4a-single=!m4a-single $(OTHER_ENDIAN)/m4a-single=!$(OTHER_ENDIAN)/m4a-single \
m4a=!m4a $(OTHER_ENDIAN)/m4a=!$(OTHER_ENDIAN)/m4a \
- m4al=!m4al $(OTHER_ENDIAN)/m4al=!$(OTHER_ENDIAN)/m4al
+ m4al=!m4al $(OTHER_ENDIAN)/m4al=!$(OTHER_ENDIAN)/m4al \
+ mj2=!j2
$(out_object_file): gt-sh.h
gt-sh.h : s-gtype ; @true

View File

@ -0,0 +1,92 @@
diff --git a/gcc/common.opt b/gcc/common.opt
index a75b44ee47e..7c564818b49 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3473,11 +3473,11 @@ Driver
no-pie
Driver RejectNegative Negative(shared)
-Don't create a dynamically linked position independent executable.
+Don't create a position independent executable.
pie
Driver RejectNegative Negative(no-pie)
-Create a dynamically linked position independent executable.
+Create a position independent executable.
static-pie
Driver RejectNegative Negative(pie)
diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
index 5ebbf42a13d..bb907d8e89a 100644
--- a/gcc/config/gnu-user.h
+++ b/gcc/config/gnu-user.h
@@ -51,13 +51,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#define GNU_USER_TARGET_STARTFILE_SPEC \
"%{shared:; \
pg|p|profile:%{static-pie:grcrt1.o%s;:gcrt1.o%s}; \
- static:crt1.o%s; \
- static-pie:rcrt1.o%s; \
+ static|static-pie:%{" PIE_SPEC ":rcrt1.o%s;:crt1.o%s}; \
" PIE_SPEC ":Scrt1.o%s; \
:crt1.o%s} " \
GNU_USER_TARGET_CRTI " \
- %{static:crtbeginT.o%s; \
- shared|static-pie|" PIE_SPEC ":crtbeginS.o%s; \
+ %{shared|" PIE_SPEC ":crtbeginS.o%s; \
+ static:crtbeginT.o%s; \
:crtbegin.o%s} \
%{fvtable-verify=none:%s; \
fvtable-verify=preinit:vtv_start_preinit.o%s; \
@@ -73,11 +72,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
GNU userspace "finalizer" file, `crtn.o'. */
#define GNU_USER_TARGET_ENDFILE_SPEC \
- "%{!static:%{fvtable-verify=none:%s; \
+ "%{static|static-pie:; \
+ fvtable-verify=none:%s; \
fvtable-verify=preinit:vtv_end_preinit.o%s; \
- fvtable-verify=std:vtv_end.o%s}} \
- %{static:crtend.o%s; \
- shared|static-pie|" PIE_SPEC ":crtendS.o%s; \
+ fvtable-verify=std:vtv_end.o%s} \
+ %{shared|" PIE_SPEC ":crtendS.o%s; \
:crtend.o%s} " \
GNU_USER_TARGET_CRTN " " \
CRTOFFLOADEND
@@ -106,7 +105,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
#if defined(HAVE_LD_EH_FRAME_HDR)
-#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
+#define LINK_EH_SPEC "%{!static|" PIE_SPEC ":--eh-frame-hdr} "
#endif
#define GNU_USER_TARGET_LINK_GCC_C_SEQUENCE_SPEC \
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 3c81c5798d8..cd96eac5d12 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1010,7 +1010,7 @@ proper position among the other output files. */
#define NO_FPIE_AND_FPIC_SPEC NO_FPIE_SPEC "|" NO_FPIC_SPEC
#define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;"
#else
-#define PIE_SPEC "pie"
+#define PIE_SPEC "pie|static-pie"
#define FPIE1_SPEC "fpie"
#define NO_FPIE1_SPEC FPIE1_SPEC ":;"
#define FPIE2_SPEC "fPIE"
@@ -1034,12 +1034,12 @@ proper position among the other output files. */
#ifndef LINK_PIE_SPEC
#ifdef HAVE_LD_PIE
#ifndef LD_PIE_SPEC
-#define LD_PIE_SPEC "-pie"
+#define LD_PIE_SPEC "-pie %{static|static-pie:--no-dynamic-linker -z text -Bsymbolic}"
#endif
#else
#define LD_PIE_SPEC ""
#endif
-#define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
+#define LINK_PIE_SPEC "%{shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
#endif
#ifndef LINK_BUILDID_SPEC

View File

@ -0,0 +1,20 @@
diff --git a/gcc/config/m68k/m68k.md b/gcc/config/m68k/m68k.md
index 59a456cd496..dbfddea41bd 100644
--- a/gcc/config/m68k/m68k.md
+++ b/gcc/config/m68k/m68k.md
@@ -4174,13 +4174,13 @@
(define_expand "sqrt<mode>2"
[(set (match_operand:FP 0 "nonimmediate_operand" "")
(sqrt:FP (match_operand:FP 1 "general_operand" "")))]
- "TARGET_HARD_FLOAT"
+ "(TARGET_68881 && TARGET_68040) || TARGET_COLDFIRE_FPU"
"")
(define_insn "sqrt<mode>2_68881"
[(set (match_operand:FP 0 "nonimmediate_operand" "=f")
(sqrt:FP (match_operand:FP 1 "general_operand" "f<FP:dreg>m")))]
- "TARGET_68881"
+ "TARGET_68881 && TARGET_68040"
{
if (FP_REG_P (operands[1]))
return "f<FP:round>sqrt%.x %1,%0";

View File

@ -0,0 +1,19 @@
diff -ur a/libgcc/unwind-pe.h b/libgcc/unwind-pe.h
--- a/libgcc/unwind-pe.h 2020-05-07 05:50:02.000000000 -0500
+++ b/libgcc/unwind-pe.h 2020-05-07 22:03:49.602635844 -0500
@@ -29,6 +29,15 @@
#ifndef GCC_UNWIND_PE_H
#define GCC_UNWIND_PE_H
+#ifdef __SH2__
+_Unwind_Ptr __attribute__((weak)) __gnu_Unwind_Find_got (_Unwind_Ptr);
+
+static inline _Unwind_Ptr _Unwind_gnu_Find_got (_Unwind_Ptr ptr)
+{
+ return __gnu_Unwind_Find_got (ptr);
+}
+#endif
+
/* If using C++, references to abort have to be qualified with std::. */
#if __cplusplus
#define __gxx_abort std::abort

View File

@ -0,0 +1,12 @@
diff -ur a/Makefile b/Makefile
--- a/Makefile 2023-05-02 12:02:41.917191831 -0500
+++ b/Makefile 2023-05-02 12:03:10.625929997 -0500
@@ -1280,7 +1280,7 @@
PHONY += prepare archprepare
-archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \
+archprepare: outputmakefile archheaders scripts include/config/kernel.release \
asm-generic $(version_h) $(autoksyms_h) include/generated/utsrelease.h \
include/generated/compile.h include/generated/autoconf.h remove-stale-files

View File

@ -0,0 +1,35 @@
From 718f363bc2067b6487900eddc9180c84e7739f80 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Tue, 2 May 2023 11:45:28 -0400
Subject: [PATCH] move fallocate64 declaration under _LARGEFILE64_SOURCE
feature test
overlooked in commit 25e6fee27f4a293728dd15b659170e7b9c7db9bc,
probably because the fallocate function itself is nonstandard and
already under _GNU_SOURCE.
diff --git a/include/fcntl.h b/include/fcntl.h
index 515f255d..53f98a8b 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -184,7 +184,6 @@ struct f_owner_ex {
#define SPLICE_F_MORE 4
#define SPLICE_F_GIFT 8
int fallocate(int, int, off_t, off_t);
-#define fallocate64 fallocate
int name_to_handle_at(int, const char *, struct file_handle *, int *, int);
int open_by_handle_at(int, struct file_handle *, int);
ssize_t readahead(int, off_t, size_t);
@@ -207,6 +206,9 @@ ssize_t tee(int, int, size_t, unsigned);
#define posix_fadvise64 posix_fadvise
#define posix_fallocate64 posix_fallocate
#define off64_t off_t
+#if defined(_GNU_SOURCE)
+#define fallocate64 fallocate
+#endif
#endif
#ifdef __cplusplus
--
2.40.0

File diff suppressed because it is too large Load Diff

74
scripts/build Executable file
View File

@ -0,0 +1,74 @@
#!/bin/sh -e
HERE=$(dirname $(readlink -f ${0}))
LOGS=${HERE}/../logs
BINS=${HERE}/../output
OBJS=${HERE}/../build
CSUF=cross
NSUF=native
KALE="${PATH}"
MCMT=;
##
# Check whether target triple is specified.
#
test ${#} != 1 && printf "No target triple specified!\n" && exit 1;
##
# When 'MCMTOOLS' is specified, ensure it is valid (at first glance).
#
if ! test -z ${MCMTOOLS}; then
MCMT="${MCMTOOLS%/}";
fail=0;
test -d "${MCMT}/sys/bin" || fail=1;
test -d "${MCMT}/host/bin" || fail=1;
test -d "${MCMT}/musl/bin" || fail=1;
test $fail -eq 1 && printf "Using 'MCMTOOLS=%s' is not valid.\n" "${MCMTOOLS}" && exit 1;
fi
mkdir -p ${LOGS} ${BINS}
# CROSS BUILD INSTALL
if ! test -z ${MCMT}; then
export PATH="${MCMT}/sys/bin:${MCMT}/musl/bin";
else
export PATH="${KALE}";
fi
[ -d ${BINS}/${1}-${CSUF} ] || make install \
TARGET=${1} OUTPUT=${BINS}/${1}-${CSUF} \
2>&1 | tee ${LOGS}/${1}-${CSUF}.log
# CROSS SCRATCH CLEANUP
rm -fr ${OBJS}/local/${1}
# CROSS PACKAGE
[ -h ${BINS}/${1}-${CSUF}/usr ] || (cd ${BINS}/${1}-${CSUF} && ln -s . usr)
[ -e ${BINS}/${1}-${CSUF}.tgz ] || (cd ${BINS} && tar pczf ${1}-${CSUF}.tgz ${1}-${CSUF})
# NATIVE BUILD INSTALL
if ! test -z ${MCMT}; then
export PATH="${MCMT}/sys/bin:${MCMT}/host/bin:${BINS}/${1}-${CSUF}/bin";
else
export PATH="${KALE}:${BINS}/${1}-${CSUF}/bin";
fi
if [ -d ${BINS}/${1}-${CSUF} ]; then
[ -d ${BINS}/${1}-${NSUF} ] || make install NATIVE=1 \
TARGET=${1} CROSS_COMPILE=${1}- OUTPUT=${BINS}/${1}-${NSUF} \
2>&1 | tee ${LOGS}/${1}-${NSUF}.log
fi;
# CROSS DIRECTORY CLEANUP (if native fails, this remains)
rm -fr ${BINS}/${1}-${CSUF};
# NATIVE PACKAGE
[ -h ${BINS}/${1}-${NSUF}/usr ] || (cd ${BINS}/${1}-${NSUF} && ln -s . usr)
[ -e ${BINS}/${1}-${NSUF}.tgz ] || (cd ${BINS} && tar pczf ${1}-${NSUF}.tgz ${1}-${NSUF});
# NATIVE SCRATCH CLEANUP
rm -fr ${OBJS}/${1}
# NATIVE DIRECTORY CLEANUP
rm -fr ${BINS}/${1}-${NSUF};

34
scripts/buildall Executable file
View File

@ -0,0 +1,34 @@
#!/bin/sh
HERE=$(dirname $(readlink -f ${0}))
LIST=${HERE}/triples.txt
CFGS=${HERE}/../sources/config.sub
##
# When 'MCMTOOLS' is specified, ensure it is valid (at first glance).
#
if ! test -z ${MCMTOOLS}; then
MCMT="${MCMTOOLS%/}";
fail=0;
test -d "${MCMT}/sys/bin" || fail=1;
test -d "${MCMT}/host/bin" || fail=1;
test -d "${MCMT}/musl/bin" || fail=1;
test $fail -eq 1 && printf "Using 'MCMTOOLS=%s' is not valid.\n" "${MCMTOOLS}" && exit 1;
fi
export MCMTOOLS="${MCMT}";
##
# WARNING: YOU MUST BE INSANE TO USE A VALUE GREATER THAN 1 HERE.
# This means: "Run N jobs, each job with M threads" where M is 'nproc'.
# Why? Useful for bruteforcing toolchain builds and keeping CPU busy.
# You may destroy an SSD with too high of a value. Use a ramdisk only.
#
JOBS=6;
if ! test -z ${MCMTOOLS}; then
export PATH="${MCMT}/sys/bin";
fi
make extract_all;
grep -v ^# "${LIST}" | parallel --eta --bar --progress --plain -j${JOBS} -a - "${HERE}/build";

34
scripts/buildallcross Executable file
View File

@ -0,0 +1,34 @@
#!/bin/sh
HERE=$(dirname $(readlink -f ${0}))
LIST=${HERE}/triples.txt
CFGS=${HERE}/../sources/config.sub
##
# When 'MCMTOOLS' is specified, ensure it is valid (at first glance).
#
if ! test -z ${MCMTOOLS}; then
MCMT="${MCMTOOLS%/}";
fail=0;
test -d "${MCMT}/sys/bin" || fail=1;
test -d "${MCMT}/host/bin" || fail=1;
test -d "${MCMT}/musl/bin" || fail=1;
test $fail -eq 1 && printf "Using 'MCMTOOLS=%s' is not valid.\n" "${MCMTOOLS}" && exit 1;
fi
export MCMTOOLS="${MCMT}";
##
# WARNING: YOU MUST BE INSANE TO USE A VALUE GREATER THAN 1 HERE.
# This means: "Run N jobs, each job with M threads" where M is 'nproc'.
# Why? Useful for bruteforcing toolchain builds and keeping CPU busy.
# You may destroy an SSD with too high of a value. Use a ramdisk only.
#
JOBS=6;
if ! test -z ${MCMTOOLS}; then
export PATH="${MCMT}/sys/bin";
fi
make extract_all;
grep -v ^# "${LIST}" | parallel --eta --bar --progress --plain -j${JOBS} -a - "${HERE}/buildcross";

28
scripts/buildallmac Executable file
View File

@ -0,0 +1,28 @@
#!/bin/sh
# https://stackoverflow.com/a/1116890
s=$(pwd)
_=$0
cd `dirname $0`
_=`basename $_`
#while [ -L "$_" ]; do
# _=`readlink $_`;
# cd `dirname $_`;
# _=`basename $_`;
#done
HERE=`pwd -P`/$_
cd $s
LIST=${HERE}/triples.txt
CFGS=${HERE}/../sources/config.sub
##
# WARNING: YOU MUST BE INSANE TO USE A VALUE GREATER THAN 1 HERE.
# This means: "Run N jobs, each job with M threads" where M is 'nproc'.
# Why? Useful for bruteforcing toolchain builds and keeping CPU busy.
# You may destroy an SSD with too high of a value. Use a ramdisk only.
#
JOBS=2;
make extract_all;
grep -v ^# "${LIST}" | parallel --eta --bar --progress --plain -j${JOBS} -a - ${HERE}/buildmac;

52
scripts/buildcross Executable file
View File

@ -0,0 +1,52 @@
#!/bin/sh -e
HERE=$(dirname $(readlink -f ${0}))
LOGS=${HERE}/../logs
BINS=${HERE}/../output
OBJS=${HERE}/../build
CSUF=cross
NSUF=native
KALE="${PATH}"
MCMT=;
##
# Check whether target triple is specified.
#
test ${#} != 1 && printf "No target triple specified!\n" && exit 1;
##
# When 'MCMTOOLS' is specified, ensure it is valid (at first glance).
#
if ! test -z ${MCMTOOLS}; then
MCMT="${MCMTOOLS%/}";
fail=0;
test -d "${MCMT}/sys/bin" || fail=1;
test -d "${MCMT}/host/bin" || fail=1;
test -d "${MCMT}/musl/bin" || fail=1;
test $fail -eq 1 && printf "Using 'MCMTOOLS=%s' is not valid.\n" "${MCMTOOLS}" && exit 1;
fi
mkdir -p ${LOGS} ${BINS}
# CROSS BUILD INSTALL
if ! test -z ${MCMT}; then
export PATH="${MCMT}/sys/bin:${MCMT}/musl/bin";
else
export PATH="${KALE}";
fi
[ -d ${BINS}/${1}-${CSUF} ] || make install \
TARGET=${1} OUTPUT=${BINS}/${1}-${CSUF} \
2>&1 | tee ${LOGS}/${1}-${CSUF}.log
# CROSS SCRATCH CLEANUP
rm -fr ${OBJS}/local/${1}
# CROSS PACKAGE
[ -h ${BINS}/${1}-${CSUF}/usr ] || (cd ${BINS}/${1}-${CSUF} && ln -s . usr)
[ -e ${BINS}/${1}-${CSUF}.tgz ] || (cd ${BINS} && tar pczf ${1}-${CSUF}.tgz ${1}-${CSUF})
# CROSS DIRECTORY CLEANUP (if native fails, this remains)
rm -fr ${BINS}/${1}-${CSUF};

39
scripts/buildmac Executable file
View File

@ -0,0 +1,39 @@
#!/bin/sh
# https://stackoverflow.com/a/1116890
s=$(pwd)
_=$0
cd `dirname $0`
_=`basename $_`
#while [ -L "$_" ]; do
# _=`readlink $_`;
# cd `dirname $_`;
# _=`basename $_`;
#done
HERE=`pwd -P`/$_
cd $s
LOGS=${HERE}/../logs
BINS=${HERE}/../output
OBJS=${HERE}/../build
CSUF=cross
KALE="${PATH}"
mkdir -p ${LOGS} ${BINS}
# CROSS BUILD
[ -d ${BINS}/${1}-${CSUF} ] || make install \
TARGET=${1} OUTPUT=${BINS}/${1}-${CSUF} \
2>&1 | tee ${LOGS}/${1}-${CSUF}.log
# CROSS PACKAGE
[ -h ${BINS}/${1}-${CSUF}/usr ] || (cd ${BINS}/${1}-${CSUF} && ln -s . usr)
[ -e ${BINS}/${1}-${CSUF}.tgz ] || (cd ${BINS} && tar pczf ${1}-${CSUF}.tgz ${1}-${CSUF})
# CROSS CLEANUP
rm -fr ${OBJS}/local/${1}
# DIRECTORY CLEANUP
rm -fr ${BINS}/${1}-${CSUF};

260
scripts/macsimum Executable file
View File

@ -0,0 +1,260 @@
#!/bin/sh -e
#===============================================================
# Filename : macsimum
# Purpose : Builds Mac-to-Linux cross-compiler toolchains.
# Authors : Zach van Rijn <me@zv.io>
# License : MIT
# Revision : 20200303
#===============================================================
#---------------------------------------------------------------
# README
#
# overview
# --------
#
# This script builds "musl-cross-make" cross-compiler toolchains
# that are hosted on macOS and target Linux. For example, your
# Macintosh machine can use up-to-date versions of GCC to build
# code (C, C++, Fortran) for your MIPS router. The libc used is
# called 'musl': https://www.musl-libc.org/faq.html
#
# Others have tried and failed to deliver what you're able to do
# with this tiny script.
#
# What does this look like? Modern GCC that does:
#
# * macOS --> ARM, Motorola 68000, MIPS, OpenRISC, PowerPC,
# RISC-V, S/390, SuperH, x86-based, more?
#
# The goal, of course, is to achieve parity with musl.cc's Linux
# offerings. A link to pre-built macOS binaries is now public,
# and this is the script to reproduce them. https://mac.musl.cc/
#
#
# requirements
# ------------
#
# Basically, you need XCode Command Line Tools. I don't know any
# specific version requirements, but if you encounter problems I
# would appreciate a heads up.
#
# This document may be useful: https://git.zv.io/snippets/34/raw
#
# You'll also need a working internet connection.
#
# A previous version of this script relied on Homebrew for some
# of the utilities that we're using. This, contrary to intent,
# created a Homebrew dependency. No longer! Build products are
# now fully portable (across compatible macOS / OS X versions).
#---------------------------------------------------------------
# Dependency versions (for bootstrap compiler and tooling)
V_SED=4.7 ;
V_PAT=2.7.6 ;
V_GMP=6.1.2 ;
V_MPF=4.0.2 ;
V_MPC=1.1.0 ;
V_ISL=0.21 ;
V_GCC=9.2.0 ;
V_BUT=2.34 ;
V_GM4=1.4.18;
V_BIS=3.4.2 ;
V_FLX=2.6.4 ;
V_CUT=8.31 ;
#---------------------------------------------------------------
# Production compiler configuration data (or use heredoc)
tool=musl-cross-make; # musl-cross-make repository
conf=$(curl -s https://conf.musl.cc/mac_20200229_9-2-1.txt);
#---------------------------------------------------------------
# Dependency mirrors
M_GNU=https://ftp.gnu.org/gnu;
M_ISL=http://isl.gforge.inria.fr;
M_FLX=https://github.com/westes/flex/releases/download;
#---------------------------------------------------------------
# Build configuration
##
# It is possible to build all library and utility dependencies
# for the building of musl-cross-make production toolchains on a
# RAM disk. This may improve performance on systems with slow
# disks, and requires approximately 3GB of space. 4GB is safe:
#
# $ diskutil erasevolume HFS+ "RAMDISK" \
# `hdiutil attach -nomount ram://$((2048 * 1024 * 4))`
#
# The '4' in the above example represents gigabytes.
rdsk=/Volumes/RAMDISK; # dependency build prefix
##
# When the production toolchains are built, a significant bit of
# disk space is required. Do not attempt to build them in RAM if
# you are not on a server server with several dozen gigabytes of
# RAM and the assurance that your system won't crash :)
bdsk=/tmp; # production build prefix
##
# This directory will contain dependency build trees. It can be
# deleted after the toolchains are built.
bdir=${rdsk}/tmp; # scratch directory location
##
# Within each dependency build tree, we want to perform an out-
# of-tree build. This is the (arbitrary) name of that directory.
tdir=x; # out-of-tree directory name
##
# This directory will contain the dependency libraries and tools
# and can also be deleted after the toolchains are built, but it
# may be useful to maintain this directory for future builds.
sdir=${rdsk}/sys; # system installation directory
#---------------------------------------------------------------
# Supporting routines
# prep <URL> <TARFLAG> <STRIP> [<CONFIG> ...]
prep ()
{
_tar="${1}"; shift;
_str="${1}"; shift;
_url="${1}"; shift;
_cnf="${@}";
base=$(basename ${_url}); # name of file being downloaded
name=${base%-*}; # name of project w/o version
[ ! -f "${sdir}/._${base}" ] || return 0;
rm -fr "${bdir}/${name}";
mkdir -p "${bdir}/${name}/${tdir}";
cd "${bdir}/${name}";
curl -sL ${_url} \
| tar --strip-components=${_str} -x${_tar}f -;
cd "${tdir}";
( # subshell for isolation
export PATH="${sdir}/bin:$PATH";
export CPPFLAGS="-I${sdir}/include";
export CFLAGS="";
export CXXFLAGS="";
export LDFLAGS="-L${sdir}/lib";
../configure --prefix="${sdir}" ${_cnf};
make && make install;
touch "${sdir}/._${base}";
)
}
# (no args) Builds production toolchains for mac.musl.cc
musl ()
{
cd "${bdsk}";
if [ ! -d "${tool}" ]; then
git clone https://git.zv.io/toolchains/${tool}.git;
fi
cd ${tool};
printf > config.mak "%s\n" "${conf}";
PATH="${sdir}/bin:$PATH" ./scripts/buildmac;
}
#---------------------------------------------------------------
# Stage 1: Bootstrap compiler
prep j 1 ${M_GNU}/sed/sed-${V_SED}.tar.xz \
;
prep j 1 ${M_GNU}/patch/patch-${V_PAT}.tar.xz \
;
prep j 1 ${M_GNU}/m4/m4-${V_GM4}.tar.xz \
;
prep j 1 ${M_GNU}/bison/bison-${V_BIS}.tar.xz \
;
prep z 1 ${M_FLX}/v${V_FLX}/flex-${V_FLX}.tar.gz \
--disable-shared \
--enable-static \
;
prep j 1 ${M_GNU}/gmp/gmp-${V_GMP}.tar.xz \
--disable-shared \
--enable-static \
--enable-cxx \
;
prep j 1 ${M_GNU}/mpfr/mpfr-${V_MPF}.tar.xz \
--disable-shared \
--enable-static \
--with-gmp="${sdir}" \
;
prep z 1 ${M_GNU}/mpc/mpc-${V_MPC}.tar.gz \
--disable-shared \
--enable-static \
--with-gmp="${sdir}" \
;
prep j 1 ${M_ISL}/isl-${V_ISL}.tar.xz \
--disable-shared \
--enable-static \
--with-gmp-prefix="${sdir}" \
;
prep j 1 ${M_GNU}/coreutils/coreutils-${V_CUT}.tar.xz \
--disable-shared \
--enable-static \
FORCE_UNSAFE_CONFIGURE=1 \
;
prep j 1 ${M_GNU}/gcc/gcc-${V_GCC}/gcc-${V_GCC}.tar.xz \
--enable-languages=c,c++ \
--with-gmp="${sdir}" \
--with-mpfr="${sdir}" \
--with-mpc="${sdir}" \
--with-isl="${sdir}" \
--enable-multilib \
--disable-bootstrap \
;
if false; then
prep j 1 ${M_GNU}/binutils/binutils-${V_BUT}.tar.xz \
--disable-shared \
--enable-static \
--disable-multilib \
;
fi
#---------------------------------------------------------------
# Stage 2: Production toolchains
musl;

63
scripts/matrix Executable file
View File

@ -0,0 +1,63 @@
#!/bin/sh
LIST=$(dirname $(which ${0}))/triples.txt
LOGS=$(dirname $(which ${0}))/../logs
BINS=$(dirname $(which ${0}))/../output
KALE="${PATH}"
OVER=""
optics()
{
# flags
case ${1} in
*microblaze*)
# ICE in GCC; temporarily disable gfortran support.
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87438
OVER="GCC_CONFIG=\"--enable-languages=c,c++\""
;;
*)
OVER=""
;;
esac
}
# host toolchains (still static)
mkdir -p ${LOGS} ${BINS}
for s in $(cat ${LIST} | grep -v "#"); do
# flags
optics ${s}
# host
[ -d ${BINS}/${s}-host ] || make ${OVER} install \
TARGET=${s} \
OUTPUT=${BINS}/${s}-host \
2>&1 | tee ${LOGS}/${s}-host.log
done;
# enter the matrix
for s in $(cat ${LIST} | grep -v "#"); do
#make -C $(dirname $(which ${0}))/../ clean
mkdir -p ${BINS}/matrix/${s}
for t in $(cat ${LIST} | grep -v "#"); do
# flags
optics ${t}
# matrix
if [ -d ${BINS}/${s}-host ]; then
export PATH="${KALE}:${BINS}/${s}-host/bin"
[ -d ${BINS}/matrix/${s}/${t} ] || make ${OVER} install \
CROSS_COMPILE=${s}- \
HOST=${s} \
TARGET=${t} \
OUTPUT=${BINS}/matrix/${s}/${t} \
2>&1 | tee ${LOGS}/${s}-${t}.log
export PATH="${KALE}"
fi;
done;
done;
#cd ${BINS}
#for t in $(find . -mindepth 1 -maxdepth 1 -type d); do
# [ -e ${t}.tgz ] || tar pczf ${t}.tgz ${t};
#done

361
scripts/sinner Executable file
View File

@ -0,0 +1,361 @@
#!/bin/sh
#===============================================================
# Filename : scripts/sinner
# Purpose : Builds Linux-to-Windows cross-compiler toolchains.
# Authors : Zach van Rijn <me@zv.io>
# License : MIT
# Revision : 20190531
#===============================================================
#---------------------------------------------------------------
# README
#
# overview
# --------
#
# This script builds "musl-cross-make" cross-compiler toolchains
# that are hosted on Linux and target Windows. For example, your
# MIPS router can use up-to-date versions of GCC to build code
# (C, C++, Fortran) for your Windows XP machine. The libc used
# is called 'musl': https://www.musl-libc.org/faq.html
#
# Others have tried and failed to deliver what you're able to do
# with this tiny script. Additions to this list are welcome:
#
# What does this look like? Modern GCC that does:
#
# * Linux on ARM, Motorola 68000, MIPS, OpenRISC, PowerPC,
# RISC-V, S/390, SuperH, x86-based, more?
#
# --> Windows XP to 10, and possibly older.
#
# The goal, of course, is to achieve parity with musl.cc's Linux
# offerings. This is the script to build the binaries located at
# https://more.musl.cc/YOUR-HOST-ARCHITECTURE/*-w64-mingw32.zip
#
#
# build platforms
# ---------------
#
# You need Linux to build these, and an architecture that runs a
# toolchain from musl.cc.
#
#
# requirements
# ------------
#
# Consider running this script inside of an isolated environment
# such as a container or virtual machine. While not required, we
# do not recommend running any foreign scripts or binaries in an
# important environment. You'll need the following packages:
#
# * cmake
# * curl
# * git
# * make
# * patch (GNU)
# * tar
# * xz
# * zip
#
# e.g., apk add cmake curl git make patch rsync tar xz zip
#
#
# other notes
# -----------
#
# * A prior version of this script ('prepare') relies on Linux
# 'binfmt_misc' and QEMU to emulate certain build byproducts
# and requires root privileges to install (but not use) that
# setup. This version cross-compiles the toolchains purely.
#
# * This script uses the 'mingw-cross-make' flavor maintained
# at https://git.zv.io/toolchains/mingw-cross-make to build
# MinGW toolchains. Issues should be addressed there.
#
#
# usage
# -----
#
# $ ./scripts/sinner [TRIPLE ...]
#
# $ ./scripts/sinner i686-w64-mingw32 x86_64-w64-mingw32
#---------------------------------------------------------------
# Configuration.
## Component Versions
#
# These options are self explanatory, but *must* correspond to a
# supported version within the "musl-cross-make" repository. One
# other factor to consider is that kernel headers and musl libc
# will be harvested from a "donor" toolchain; these versions do
# not necessarily correspond to what is built here (yet, TODO).
#
GCC_VER=9.1.0
BINUTILS_VER=2.32
MUSL_VER=git-a60b9e06861e56c0810bae0249b421e1758d281a
GMP_VER=6.1.2
MPC_VER=1.1.0
MPFR_VER=4.0.2
MINGW_VER=git-3e6c10aeba81c589a7b2ed1e7daee4d4d75b646e
## Directories
#
# By default, all toolchains that can be built, are built. This
# requires a significant amount of disk space. Please ensure you
# have at least 50GB of free disk space in these directories:
#
base="${HOME}/sinner_src" # base source directory
huge="${HOME}/sinner_bld" # base build directory
logs="${HOME}/sinner_log" # suite build log directory
zips="${HOME}/sinner_bin" # completed toolchains go here
## Toolchain Mirror
#
# If you have access to an x86_64 Linux machine, or one that has
# an x86_64 QEMU user-mode emulator registered in 'binfmt_misc',
# you will always be using the latest available software.
#
musl=https://more.musl.cc # more.musl.cc or mirror
## Toolchain Naming Conventions
#
# The musl.cc toolchains follow a simple naming convention: all
# cross compilers are suffixed with '-cross', native '-native'.
# If you're using a different mirror or convention, set it here.
#
csuf=-cross # cross suffix
nsuf=-native # native suffix
## Toolchain Tuples
#
# Values can be found at 'https://more.musl.cc/' where the $user
# variable corresponds to your build platform, and $host to your
# intended Linux development environment. Note that unless the
# website says otherwise, only the 'x86_64-linux-musl' toolchain
# directory is up-to-date. If you can't find what you're looking
# for you must build a MinGW-w64 suitable toolchain from source.
#
user=x86_64-linux-musl # platform that builds suite
## Build Environment
#
# This variable is extended during the toolchain download step.
#
kale="${base}/${user}${csuf}/bin";
## Repositories
#
# The build infrastructure used is called "musl-cross-make" and
# is upstream https://github.com/richfelker/musl-cross-make, but
# this version is incompatible with the current script. It's out
# of date, too, so please leave the default unless you fork it.
#
name=musl-cross-make
repo=https://git.zv.io/toolchains/${name}
brch=musl-git # branch name (no assumptions!)
sinn=mingw-cross-make
sinr=https://git.zv.io/toolchains/${sinn}
sinb=mingw
## Suite Targets
#
# Now that RISC-V patches are (unofficially) merged into musl, a
# single text file with target tuples (which comprise the suite)
# may now be used. Modify this with e.g. a pastebin link if you
# wish to use a different list (this one is self-updating).
#
list=${repo}/raw/${brch}/scripts/triples.txt
filt=tuples.txt # filename of saved tuples list
## Suite Configuration
#
# To facilitate users' needs in customizing the toolchain suite,
# a configuration file is embedded below. These settings *must*
# be supported by the repository specified above.
#
# Note: items that are prefixed/suffixed with double underscores
# are automatically populated later. Do not modify them here!
#
conf=$(cat <<'EOF'
STAT = -static --static
FLAG = -g0 -O2 -fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels
COMMON_CONFIG += CC="$(HOST)-gcc ${STAT}" CXX="$(HOST)-g++ ${STAT}" FC="$(HOST)-gfortran -${STAT}"
COMMON_CONFIG += CFLAGS="${FLAG}" CXXFLAGS="${FLAG}" FFLAGS="${FLAG}" LDFLAGS="-s ${STAT}"
COMMON_CONFIG += --disable-nls --disable-bootstrap --build=__USER__ --host=__HOST__ --target=__TARG__
GCC_CONFIG += --enable-threads=__THREADS__
OVERRIDE = --enable-libquadmath --enable-libquadmath-support
GCC_VER = __GCC_VER__
BINUTILS_VER = __BINUTILS_VER__
MUSL_VER = __MUSL_VER__
GMP_VER = __GMP_VER__
MPC_VER = __MPC_VER__
MPFR_VER = __MPFR_VER__
MINGW_VER = __MINGW_VER__
LINUX_VER =
EOF
);
## Thread Configuration
#
# By popular demand, both Win32 and POSIX thread models will are
# supported. Edit this variable if you don't wish to build both.
#
tmod="posix" # default: "win32 posix"
#---------------------------------------------------------------
# Subroutines.
# Download preliminary toolchains.
#
get_tool ()
{
mkdir -p "${base}";
# build
if [ ! -d "${base}/${user}${csuf}" ]; then
curl ${musl}/${user}/${user}${csuf}.tgz \
| tar 2>/dev/null -C "${base}" -xzf -;
fi
}
# Clone a suitable "musl-cross-make" repository.
#
get_repo ()
{
[ -d "${base}" ] || exit 1;
[ ! -d "${base}/${sinn}" ] || return;
git clone ${sinr} "${base}/${sinn}";
}
# Overwrite any existing configuration (config.mak) template.
#
get_conf ()
{
[ -d "${base}/${sinn}" ] || exit 1;
printf > "${base}/${sinn}/config.mak" "%s\n" \
"${conf}";
}
# Fetch an up-to-date list of possible target tuples. Allow the
# user to edit this list, if the line is uncommented, before DL.
#
get_list ()
{
[ ! -f "${base}/${filt}" ] || return;
curl -o "${base}/${filt}" ${list};
sed -i "${base}/${filt}" -e '/mingw/d';
nano "${base}/${filt}";
}
# Download all necessary target toolchains.
#
get_targ ()
{
# targets (if different from build)
cat "${base}/${filt}" | grep -v "#" | while read k; do
if [ ! -d "${base}/${k}${csuf}" ]; then
curl ${musl}/${user}/${k}${csuf}.tgz \
| tar 2>/dev/null -C "${base}" -xzf -;
fi
done;
}
# Build the compiler suite. Note: the '-ik' in 'make' is used to
# ignore an error:
#
# The directory that should contain system headers does not
# exist: //mingw/include
#
# We use 'make clean' to ensure that the updated configuration
# takes full effect (relevant to thread model settings).
#
run_make ()
{
cat "${base}/${filt}" | grep -v "#" | while read k; do
for tget in ${@}; do # command-line argument list
for t in ${tmod}; do # thread model list
mkdir -p "${huge}/${k}";
mkdir -p "${logs}/${k}";
get_conf; sed -i "${base}/${sinn}/config.mak" \
-e "s@__USER__@${user}@" \
-e "s@__HOST__@${k}@" \
-e "s@__TARG__@${tget}@" \
\
-e "s@__GCC_VER__@${GCC_VER}@" \
-e "s@__BINUTILS_VER__@${BINUTILS_VER}@" \
-e "s@__MUSL_VER__@${MUSL_VER}@" \
-e "s@__GMP_VER__@${GMP_VER}@" \
-e "s@__MPC_VER__@${MPC_VER}@" \
-e "s@__MPFR_VER__@${MPFR_VER}@" \
-e "s@__MINGW_VER__@${MINGW_VER}@" \
\
-e "s@__THREADS__@${t}@";
if [ ! -d "${huge}/${k}/${tget}${csuf}-${t}" ]; then
PATH="${kale}:${base}/${k}${csuf}/bin:${base}/${tget}${csuf}/bin:${PATH}" \
\
CC="${k}-gcc" \
CXX="${k}-g++" \
RANLIB="${k}-ranlib" \
\
CC_FOR_BUILD="${user}-gcc" \
CXX_FOR_BUILD="${user}-g++" \
RANLIB_FOR_BUILD="${user}-ranlib" \
\
make -ik -C "${base}/${sinn}" -O clean install \
HOST=${k} \
TARGET=${tget} \
OUTPUT="${huge}/${k}/${tget}${csuf}-${t}" \
2>&1 | tee \
"${logs}/${k}/${tget}${csuf}-${t}.log";
fi
done; # thread model list
done; # command-line argument list
done; # source list (hosts)
}
# Pack the toolchains into tgz files. They're ready for distro.
#
run_pack ()
{
cat "${base}/${filt}" | grep -v "#" | while read k; do
for tget in ${@}; do # command-line argument list
for t in ${tmod}; do # thread model list
mkdir -p "${zips}/${k}";
if [ ! -e "${zips}/${k}/${tget}${csuf}-${t}.tgz" ]; then
(
cd "${huge}/${k}";
tar -pczf "${zips}/${k}/${tget}${csuf}-${t}.tgz" \
${tget}${csuf}-${t};
)
fi
done; # thread model list
done; # command-line argument list
done; # source list (hosts)
}
#---------------------------------------------------------------
# Driver.
get_tool; # Download initial toolchains.
get_repo; # Clone "musl-cross-make" repo.
get_conf; # Write toolchain configuration.
get_list; # Generate list of targets.
get_targ; # Fetch "donor" toolchains.
run_make ${@}; # Build specified toolchains.
run_pack ${@}; # Pack output for distribution.

54
scripts/triples.txt Normal file
View File

@ -0,0 +1,54 @@
# Comment out lines you do not wish to build.
# Do not leave any blank lines in this file.
#
aarch64-linux-musl
aarch64_be-linux-musl
arm-linux-musleabi
arm-linux-musleabihf
armeb-linux-musleabi
armeb-linux-musleabihf
armel-linux-musleabi
armel-linux-musleabihf
armv5l-linux-musleabi
armv5l-linux-musleabihf
armv6-linux-musleabi
armv6-linux-musleabihf
armv7l-linux-musleabihf
armv7m-linux-musleabi
armv7r-linux-musleabihf
i486-linux-musl
i686-linux-musl
m68k-linux-musl
microblaze-linux-musl
microblazeel-linux-musl
mips-linux-musl
mips-linux-muslsf
mips-linux-musln32sf
mips64-linux-musl
mips64-linux-musln32
mips64-linux-musln32sf
mips64el-linux-musl
mips64el-linux-musln32
mips64el-linux-musln32sf
mipsel-linux-musl
mipsel-linux-musln32
mipsel-linux-musln32sf
mipsel-linux-muslsf
or1k-linux-musl
powerpc-linux-musl
powerpc-linux-muslsf
powerpc64-linux-musl
powerpc64le-linux-musl
powerpcle-linux-musl
powerpcle-linux-muslsf
riscv32-linux-musl
riscv64-linux-musl
s390x-linux-musl
sh2-linux-musl
sh2-linux-muslfdpic
sh2eb-linux-musl
sh2eb-linux-muslfdpic
sh4-linux-musl
sh4eb-linux-musl
x86_64-linux-musl
x86_64-linux-muslx32

387
scripts/winner Executable file
View File

@ -0,0 +1,387 @@
#!/bin/sh
#===============================================================
# Filename : scripts/winner
# Purpose : Builds Windows-to-Linux cross-compiler toolchains.
# Authors : Zach van Rijn <me@zv.io>
# License : MIT
# Revision : 20200303
#===============================================================
#---------------------------------------------------------------
# README
#
# overview
# --------
#
# This script builds "musl-cross-make" cross-compiler toolchains
# that are hosted on Windows and target Linux. For example, your
# Windows XP machine can use up-to-date versions of GCC to build
# code (C, C++, Fortran) for your MIPS router. The libc used is
# called 'musl': https://www.musl-libc.org/faq.html
#
# Others have tried and failed to deliver what you're able to do
# with this tiny script. Additions to this list are welcome:
#
# * https://gnutoolchains.com/download/
# * (um?)
#
# What does this look like? Modern GCC that does:
#
# * Win32 --> ARM, Motorola 68000, MIPS, OpenRISC, PowerPC,
# RISC-V, S/390, SuperH, x86-based, more?
#
# The goal, of course, is to achieve parity with musl.cc's Linux
# offerings. A link to pre-built Windows binaries is now public,
# and this is the script to reproduce them. https://win.musl.cc/
#
#
# build platforms
# ---------------
#
# In absolute theory, one can build this toolchain suite using a
# "native" toolchain from 'musl.cc' suitable for your platform,
# to build a MinGW-w64 cross-compiler (hosted on your platform,
# targeting i686- or x86_64- Windows), then use that toolchain
# to build the suite. Some may exist here: https://more.musl.cc/
#
# In practice, you just need 'i686-w64-mingw32-cross' for 32-bit
# or 'x86_64-w64-mingw32-cross' for 64-bit that runs on your own
# Linux (or Windows, with Cygwin or MSYS2) system.
#
#
# requirements
# ------------
#
# Consider running this script inside of an isolated environment
# such as a container or virtual machine. While not required, we
# do not recommend running any foreign scripts or binaries in an
# important environment. You'll need the following packages:
#
# * cmake
# * curl
# * git
# * make
# * patch (GNU)
# * rsync
# * tar
# * xz
# * zip
#
# e.g., apk add cmake curl git make patch rsync tar xz zip
#
# You'll also need an internet connection (or manually do so) to
# obtain corresponding "donor" toolchains from musl.cc; what we
# are doing is pulling musl and the Linux kernel headers from an
# existing toolchain, rather than fuss with getting them to play
# nicely with the "Canadian" cross infrastructure.
#
#
# other notes
# -----------
#
# * Toolchains cannot be built with kernel headers; these are
# copied into the output directory after the initial build.
# Kernel version is that of donor toolchain.
#
# * Toolchains cannot be built with the musl library; this is
# copied into the output directory after the initial build.
# musl version is that of donor toolchain, but may be flaky.
#
# * If you do not uncomment the 'nano' line, you will build a
# large number of toolchains. This requires an exceptional
# amount of disk space and time. This is what I use it for.
#
#
# to-do
# -----
#
# * Fix underlying issue causing kernel headers and musl to be
# not built or installed correctly.
#
# * Generate Cygwin (and/or MSYS2) packages for distribution.
#---------------------------------------------------------------
# Configuration.
## Component Versions
#
# These options are self explanatory, but *must* correspond to a
# supported version within the "musl-cross-make" repository. One
# other factor to consider is that kernel headers and musl libc
# will be harvested from a "donor" toolchain; these versions do
# not necessarily correspond to what is built here (yet, TODO).
#
GCC_VER=9.3.0
BINUTILS_VER=2.34
MUSL_VER=git-0a005f499cf39822166dd4db3d2d31f0639f1b1b
GMP_VER=6.2.0
MPC_VER=1.1.0
MPFR_VER=4.1.0
LINUX_VER=5.4.50 # TODO: proper install, no rsync
## Directories
#
# By default, all toolchains that can be built, are built. This
# requires a significant amount of disk space. Please ensure you
# have at least 50GB of free disk space in these directories:
#
base="/tmp/winner_src" # base source directory
huge="/tmp/winner_bld" # base build directory
logs="/tmp/winner_log" # suite build log directory
zips="/tmp/winner_bin" # completed toolchains go here
## Toolchain Mirror
#
# If you have access to an x86_64 Linux machine, or one that has
# an x86_64 QEMU user-mode emulator registered in 'binfmt_misc',
# you will always be using the latest available software.
#
musl=https://more.musl.cc # more.musl.cc or mirror
## Toolchain Naming Conventions
#
# The musl.cc toolchains follow a simple naming convention: all
# cross compilers are suffixed with '-cross', native '-native'.
# If you're using a different mirror or convention, set it here.
#
csuf=-cross # cross suffix
nsuf=-native # native suffix
## Toolchain Tuples
#
# Values can be found at 'https://more.musl.cc/' where the $user
# variable corresponds to your build platform, and $host to your
# intended Windows development environment. Note that unless the
# website says otherwise, only the 'i686-linux-musl' toolchain
# directory is up-to-date. If you can't find what you're looking
# for you must build a MinGW-w64 suitable toolchain from source.
#
user=i686-linux-musl # platform that builds suite
host=i686-w64-mingw32 # platform that runs suite
## Build Environment
#
# This variable is extended during the toolchain download step.
#
kale="${base}/${host}${csuf}/bin:${base}/${user}${csuf}/bin";
## Repositories
#
# The build infrastructure used is called "musl-cross-make" and
# is upstream https://github.com/richfelker/musl-cross-make, but
# this version is incompatible with the current script. It's out
# of date, too, so please leave the default unless you fork it.
#
name=musl-cross-make
repo=https://git.zv.io/toolchains/${name}
brch=master # branch name (no assumptions!)
## Suite Targets
#
# Now that RISC-V patches are (unofficially) merged into musl, a
# single text file with target tuples (which comprise the suite)
# may now be used. Modify this with e.g. a pastebin link if you
# wish to use a different list (this one is self-updating).
#
list=${repo}/raw/${brch}/scripts/triples.txt
filt=tuples.txt # filename of saved tuples list
## Suite Configuration
#
# To facilitate users' needs in customizing the toolchain suite,
# a configuration file is embedded below. These settings *must*
# be supported by the repository specified above.
#
# Note: items that are prefixed/suffixed with double underscores
# are automatically populated later. Do not modify them here!
#
conf=$(cat <<'EOF'
STAT = -static --static
FLAG = -g0 -O2 -fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels
ifneq ($(NATIVE),)
COMMON_CONFIG += CC="$(HOST)-gcc ${STAT}" CXX="$(HOST)-g++ ${STAT}" FC="$(HOST)-gfortran ${STAT}"
else
COMMON_CONFIG += CC="gcc ${STAT}" CXX="g++ ${STAT}" FC="gfortran ${STAT}"
endif
COMMON_CONFIG += CFLAGS="${FLAG}" CXXFLAGS="${FLAG}" FFLAGS="${FLAG}" LDFLAGS="-s ${STAT}"
COMMON_CONFIG += --disable-nls --disable-bootstrap --build=__USER__ --host=__HOST__ --target=__TARG__
GCC_VER = __GCC_VER__
BINUTILS_VER = __BINUTILS_VER__
MUSL_VER = __MUSL_VER__
GMP_VER = __GMP_VER__
MPC_VER = __MPC_VER__
MPFR_VER = __MPFR_VER__
LINUX_VER = __LINUX_VER__
EOF
);
#---------------------------------------------------------------
# Subroutines.
# Download preliminary toolchains.
#
get_tool ()
{
mkdir -p "${base}";
# host
if [ ! -d "${base}/${host}${csuf}" ]; then
curl ${musl}/${user}/${host}${csuf}.tgz \
| tar 2>/dev/null -C "${base}" -xzf -;
(
cd "${base}/${host}${csuf}/bin";
find . -maxdepth 1 -type f | while read k; do
ln -sf ${k} ${k#*-*-*-};
done;
)
fi
# build
if [ ! -d "${base}/${user}${csuf}" ]; then
curl ${musl}/${user}/${user}${csuf}.tgz \
| tar 2>/dev/null -C "${base}" -xzf -;
fi
}
# Clone a suitable "musl-cross-make" repository.
#
get_repo ()
{
[ -d "${base}" ] || exit 1;
[ ! -d "${base}/${name}" ] || return;
git clone ${repo} "${base}/${name}";
}
# Overwrite any existing configuration (config.mak) template.
#
get_conf ()
{
[ -d "${base}/${name}" ] || exit 1;
printf > "${base}/${name}/config.mak" "%s\n" \
"${conf}";
}
# Fetch an up-to-date list of possible target tuples. Allow the
# user to edit this list, if the line is uncommented, before DL.
#
get_list ()
{
[ ! -f "${base}/${filt}" ] || return;
curl -o "${base}/${filt}" ${list};
sed -i "${base}/${filt}" -e '/mingw/d';
#nano "${base}/${filt}";
}
# Download all necessary target toolchains.
#
get_targ ()
{
# targets (if different from build)
cat "${base}/${filt}" | grep -v "#" | while read k; do
if [ ! -d "${base}/${k}${csuf}" ]; then
curl ${musl}/${user}/${k}${csuf}.tgz \
| tar 2>/dev/null -C "${base}" -xzf -;
fi
done;
}
# Build the compiler suite without musl or kernel headers. Note:
# the '-ik' in the 'make' command is required to avoid issues in
# areas that have not yet been investigated but don't affect the
# correctness of the resulting toolchain.
#
run_make ()
{
mkdir -p "${huge}";
mkdir -p "${logs}";
cat "${base}/${filt}" | grep -v "#" | while read k; do
get_conf; sed -i "${base}/${name}/config.mak" \
-e "s@__USER__@${user}@" \
-e "s@__HOST__@${host}@" \
-e "s@__TARG__@${k}@" \
\
-e "s@__GCC_VER__@${GCC_VER}@" \
-e "s@__BINUTILS_VER__@${BINUTILS_VER}@" \
-e "s@__MUSL_VER__@${MUSL_VER}@" \
-e "s@__GMP_VER__@${GMP_VER}@" \
-e "s@__MPC_VER__@${MPC_VER}@" \
-e "s@__MPFR_VER__@${MPFR_VER}@" \
-e "s@__LINUX_VER__@@";
if [ ! -d "${huge}/${k}${csuf}" ]; then
PATH="${kale}:${base}/${k}${csuf}/bin:${PATH}" \
\
CC="${host}-gcc" \
CXX="${host}-g++" \
RANLIB="${host}-ranlib" \
\
CC_FOR_BUILD="${user}-gcc" \
CXX_FOR_BUILD="${user}-g++" \
RANLIB_FOR_BUILD="${user}-ranlib" \
\
CC_FOR_TARGET="${k}-gcc" \
CXX_FOR_TARGET="${k}-g++" \
RANLIB_FOR_TARGET="${k}-ranlib" \
\
make -ik -C "${base}/${name}" -O install \
TARGET=${k} OUTPUT="${huge}/${k}${csuf}" \
2>&1 | tee "${logs}/${k}${csuf}.log";
fi
done;
}
# Synchronize a donor toolchain's libraries and headers (for the
# sole purposes of musl and kernel headers) with the newly-built
# Windows-hosted toolchain.
#
run_sync ()
{
cat "${base}/${filt}" | grep -v "#" | while read k; do
sync=$(cat <<EOF
${k}${csuf}/${k}/include/
${k}${csuf}/${k}/lib/
EOF
);
for n in ${sync}; do rsync -raz --ignore-existing \
"${base}/${n}" "${huge}/${n}";
done;
done;
}
# Windows does not appreciate symbolic links. Delete them. Then
# pack the toolchains into zip files. They're ready for distro.
#
run_pack ()
{
mkdir -p "${zips}";
cat "${base}/${filt}" | grep -v "#" | while read k; do
if [ ! -e "${zips}/${k}${csuf}.zip" ]; then
(
cd "${huge}";
find ${k}${csuf} -type l -delete;
zip -rq "${zips}/${k}${csuf}.zip" ${k}${csuf};
)
fi
done
}
#---------------------------------------------------------------
# Driver.
get_tool; # Download initial toolchains.
get_repo; # Clone "musl-cross-make" repo.
get_conf; # Write toolchain configuration.
get_list; # Generate list of targets.
get_targ; # Fetch "donor" toolchains.
run_make; # Build specified toolchains.
run_sync; # Harvest/inject "donor" organs.
run_pack; # Pack output for distribution.