From 1eb8520be461880c4f582bb5c963e922eaa0c256 Mon Sep 17 00:00:00 2001
From: zijiren233 <pyh1670605849@gmail.com>
Date: Wed, 10 Jan 2024 03:39:51 +0800
Subject: [PATCH] Feat: init

---
 Makefile                                      |   19 +-
 hashes/binutils-2.34.tar.xz.sha1              |    1 +
 hashes/binutils-2.35.1.tar.xz.sha1            |    1 +
 hashes/binutils-2.35.2.tar.xz.sha1            |    1 +
 hashes/binutils-2.35.tar.xz.sha1              |    1 +
 hashes/binutils-2.36.1.tar.xz.sha1            |    1 +
 hashes/binutils-2.36.tar.xz.sha1              |    1 +
 hashes/binutils-2.37.tar.xz.sha1              |    1 +
 hashes/binutils-2.38.tar.xz.sha1              |    1 +
 hashes/binutils-2.39.tar.xz.sha1              |    1 +
 hashes/binutils-2.40.tar.xz.sha1              |    1 +
 hashes/config.sub.4ad4bb7c30ac.sha1           |    1 +
 hashes/config.sub.888c8e3d5f7b.sha1           |    1 +
 hashes/gcc-11.4.0.tar.xz.sha1                 |    1 +
 hashes/gmp-6.2.0.tar.bz2.sha1                 |    1 +
 hashes/gmp-6.2.1.tar.bz2.sha1                 |    1 +
 hashes/gmp-6.3.0.tar.bz2.sha1                 |    1 +
 hashes/linux-6.1.36.tar.xz.sha1               |    1 +
 hashes/mpc-1.2.0.tar.gz.sha1                  |    1 +
 hashes/mpc-1.2.1.tar.gz.sha1                  |    1 +
 hashes/mpc-1.3.1.tar.gz.sha1                  |    1 +
 hashes/mpfr-3.1.5.tar.bz2.sha1                |    1 +
 hashes/mpfr-3.1.6.tar.bz2.sha1                |    1 +
 hashes/mpfr-4.0.1.tar.bz2.sha1                |    1 +
 hashes/mpfr-4.0.1.tar.xz.sha1                 |    1 +
 hashes/mpfr-4.0.2.tar.xz.sha1                 |    1 +
 hashes/mpfr-4.1.0.tar.bz2.sha1                |    1 +
 hashes/mpfr-4.1.0.tar.xz.sha1                 |    1 +
 hashes/mpfr-4.2.0.tar.bz2.sha1                |    1 +
 hashes/mpfr-4.2.0.tar.xz.sha1                 |    1 +
 hashes/mpfr-4.2.1.tar.bz2.sha1                |    1 +
 hashes/musl-1.2.4.tar.gz.sha1                 |    1 +
 litecross/Makefile                            |   27 +-
 patches/gcc-11.4.0/0000-nostdinc.diff         |   26 +
 patches/gcc-11.4.0/0001-ssp_nonshared.diff    |   14 +
 patches/gcc-11.4.0/0002-posix_memalign.diff   |   30 +
 patches/gcc-11.4.0/0003-j2.diff               |  346 +++++
 patches/gcc-11.4.0/0004-static-pie.diff       |   92 ++
 patches/gcc-11.4.0/0005-m68k-sqrt.diff        |   20 +
 .../0100-hack-sh2fdpic-unwind-nonsense.diff   |   19 +
 ...ot-build-archscripts-for-headers-only.diff |   12 +
 ...-declaration-under-_LARGEFILE64_SOUR.patch |   35 +
 .../0002-add-loongarch64-port-v7.patch        | 1384 +++++++++++++++++
 scripts/build                                 |   74 +
 scripts/buildall                              |   34 +
 scripts/buildallcross                         |   34 +
 scripts/buildallmac                           |   28 +
 scripts/buildcross                            |   52 +
 scripts/buildmac                              |   39 +
 scripts/macsimum                              |  260 ++++
 scripts/matrix                                |   63 +
 scripts/sinner                                |  361 +++++
 scripts/triples.txt                           |   54 +
 scripts/winner                                |  387 +++++
 54 files changed, 3429 insertions(+), 12 deletions(-)
 create mode 100644 hashes/binutils-2.34.tar.xz.sha1
 create mode 100644 hashes/binutils-2.35.1.tar.xz.sha1
 create mode 100644 hashes/binutils-2.35.2.tar.xz.sha1
 create mode 100644 hashes/binutils-2.35.tar.xz.sha1
 create mode 100644 hashes/binutils-2.36.1.tar.xz.sha1
 create mode 100644 hashes/binutils-2.36.tar.xz.sha1
 create mode 100644 hashes/binutils-2.37.tar.xz.sha1
 create mode 100644 hashes/binutils-2.38.tar.xz.sha1
 create mode 100644 hashes/binutils-2.39.tar.xz.sha1
 create mode 100644 hashes/binutils-2.40.tar.xz.sha1
 create mode 100644 hashes/config.sub.4ad4bb7c30ac.sha1
 create mode 100644 hashes/config.sub.888c8e3d5f7b.sha1
 create mode 100644 hashes/gcc-11.4.0.tar.xz.sha1
 create mode 100644 hashes/gmp-6.2.0.tar.bz2.sha1
 create mode 100644 hashes/gmp-6.2.1.tar.bz2.sha1
 create mode 100644 hashes/gmp-6.3.0.tar.bz2.sha1
 create mode 100644 hashes/linux-6.1.36.tar.xz.sha1
 create mode 100644 hashes/mpc-1.2.0.tar.gz.sha1
 create mode 100644 hashes/mpc-1.2.1.tar.gz.sha1
 create mode 100644 hashes/mpc-1.3.1.tar.gz.sha1
 create mode 100644 hashes/mpfr-3.1.5.tar.bz2.sha1
 create mode 100644 hashes/mpfr-3.1.6.tar.bz2.sha1
 create mode 100644 hashes/mpfr-4.0.1.tar.bz2.sha1
 create mode 100644 hashes/mpfr-4.0.1.tar.xz.sha1
 create mode 100644 hashes/mpfr-4.0.2.tar.xz.sha1
 create mode 100644 hashes/mpfr-4.1.0.tar.bz2.sha1
 create mode 100644 hashes/mpfr-4.1.0.tar.xz.sha1
 create mode 100644 hashes/mpfr-4.2.0.tar.bz2.sha1
 create mode 100644 hashes/mpfr-4.2.0.tar.xz.sha1
 create mode 100644 hashes/mpfr-4.2.1.tar.bz2.sha1
 create mode 100644 hashes/musl-1.2.4.tar.gz.sha1
 create mode 100644 patches/gcc-11.4.0/0000-nostdinc.diff
 create mode 100644 patches/gcc-11.4.0/0001-ssp_nonshared.diff
 create mode 100644 patches/gcc-11.4.0/0002-posix_memalign.diff
 create mode 100644 patches/gcc-11.4.0/0003-j2.diff
 create mode 100644 patches/gcc-11.4.0/0004-static-pie.diff
 create mode 100644 patches/gcc-11.4.0/0005-m68k-sqrt.diff
 create mode 100644 patches/gcc-11.4.0/0100-hack-sh2fdpic-unwind-nonsense.diff
 create mode 100644 patches/linux-6.1.36/0000-do-not-build-archscripts-for-headers-only.diff
 create mode 100644 patches/musl-1.2.4/0001-move-fallocate64-declaration-under-_LARGEFILE64_SOUR.patch
 create mode 100644 patches/musl-1.2.4/0002-add-loongarch64-port-v7.patch
 create mode 100755 scripts/build
 create mode 100755 scripts/buildall
 create mode 100755 scripts/buildallcross
 create mode 100755 scripts/buildallmac
 create mode 100755 scripts/buildcross
 create mode 100755 scripts/buildmac
 create mode 100755 scripts/macsimum
 create mode 100755 scripts/matrix
 create mode 100755 scripts/sinner
 create mode 100644 scripts/triples.txt
 create mode 100755 scripts/winner

diff --git a/Makefile b/Makefile
index 09f8c2d..8d33d0e 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/hashes/binutils-2.34.tar.xz.sha1 b/hashes/binutils-2.34.tar.xz.sha1
new file mode 100644
index 0000000..b834311
--- /dev/null
+++ b/hashes/binutils-2.34.tar.xz.sha1
@@ -0,0 +1 @@
+78f7ba4c0775ae75f5b906dc9af03d70b39b0785  binutils-2.34.tar.xz
diff --git a/hashes/binutils-2.35.1.tar.xz.sha1 b/hashes/binutils-2.35.1.tar.xz.sha1
new file mode 100644
index 0000000..f27bd5c
--- /dev/null
+++ b/hashes/binutils-2.35.1.tar.xz.sha1
@@ -0,0 +1 @@
+45f7a96a2580a422f44b78317f0abf13935fecb6  binutils-2.35.1.tar.xz
diff --git a/hashes/binutils-2.35.2.tar.xz.sha1 b/hashes/binutils-2.35.2.tar.xz.sha1
new file mode 100644
index 0000000..2abe395
--- /dev/null
+++ b/hashes/binutils-2.35.2.tar.xz.sha1
@@ -0,0 +1 @@
+2dd8d1ce34dc7b1cb2073123e30c4901221835b0  binutils-2.35.2.tar.xz
diff --git a/hashes/binutils-2.35.tar.xz.sha1 b/hashes/binutils-2.35.tar.xz.sha1
new file mode 100644
index 0000000..cef2c6c
--- /dev/null
+++ b/hashes/binutils-2.35.tar.xz.sha1
@@ -0,0 +1 @@
+6bdd090ce268b6d6c3442516021c4e4b5019e303  binutils-2.35.tar.xz
diff --git a/hashes/binutils-2.36.1.tar.xz.sha1 b/hashes/binutils-2.36.1.tar.xz.sha1
new file mode 100644
index 0000000..4478e9c
--- /dev/null
+++ b/hashes/binutils-2.36.1.tar.xz.sha1
@@ -0,0 +1 @@
+021c97cc0e751e989afb8db025fbd2ae48391831  binutils-2.36.1.tar.xz
diff --git a/hashes/binutils-2.36.tar.xz.sha1 b/hashes/binutils-2.36.tar.xz.sha1
new file mode 100644
index 0000000..994097c
--- /dev/null
+++ b/hashes/binutils-2.36.tar.xz.sha1
@@ -0,0 +1 @@
+3767185ed0bd82c0682ed026f202cc7872b4c55b  binutils-2.36.tar.xz
diff --git a/hashes/binutils-2.37.tar.xz.sha1 b/hashes/binutils-2.37.tar.xz.sha1
new file mode 100644
index 0000000..4afa7f2
--- /dev/null
+++ b/hashes/binutils-2.37.tar.xz.sha1
@@ -0,0 +1 @@
+e9cf391b000010d6c752771974b394c9c743c928  binutils-2.37.tar.xz
diff --git a/hashes/binutils-2.38.tar.xz.sha1 b/hashes/binutils-2.38.tar.xz.sha1
new file mode 100644
index 0000000..ed5fabc
--- /dev/null
+++ b/hashes/binutils-2.38.tar.xz.sha1
@@ -0,0 +1 @@
+15d42de8f15404a4a43a912440cf367f994779d7  binutils-2.38.tar.xz
diff --git a/hashes/binutils-2.39.tar.xz.sha1 b/hashes/binutils-2.39.tar.xz.sha1
new file mode 100644
index 0000000..d77f605
--- /dev/null
+++ b/hashes/binutils-2.39.tar.xz.sha1
@@ -0,0 +1 @@
+f17653e7b1d1fa5242a408919845da23e8cc5141  binutils-2.39.tar.xz
diff --git a/hashes/binutils-2.40.tar.xz.sha1 b/hashes/binutils-2.40.tar.xz.sha1
new file mode 100644
index 0000000..e7350be
--- /dev/null
+++ b/hashes/binutils-2.40.tar.xz.sha1
@@ -0,0 +1 @@
+fee4fbef9d632afc1988dd631d7f75d4394b7f8d  binutils-2.40.tar.xz
diff --git a/hashes/config.sub.4ad4bb7c30ac.sha1 b/hashes/config.sub.4ad4bb7c30ac.sha1
new file mode 100644
index 0000000..ec44d69
--- /dev/null
+++ b/hashes/config.sub.4ad4bb7c30ac.sha1
@@ -0,0 +1 @@
+71d4a097984191a1d6fc53dd247ecdd187ad7201  config.sub
diff --git a/hashes/config.sub.888c8e3d5f7b.sha1 b/hashes/config.sub.888c8e3d5f7b.sha1
new file mode 100644
index 0000000..536837e
--- /dev/null
+++ b/hashes/config.sub.888c8e3d5f7b.sha1
@@ -0,0 +1 @@
+675e70687f262748fcd2468768147ae8a0e50ddf  config.sub
diff --git a/hashes/gcc-11.4.0.tar.xz.sha1 b/hashes/gcc-11.4.0.tar.xz.sha1
new file mode 100644
index 0000000..704439f
--- /dev/null
+++ b/hashes/gcc-11.4.0.tar.xz.sha1
@@ -0,0 +1 @@
+03f21dce9edf9092e38b4e23dd27b29f6ab56f63  gcc-11.4.0.tar.xz
diff --git a/hashes/gmp-6.2.0.tar.bz2.sha1 b/hashes/gmp-6.2.0.tar.bz2.sha1
new file mode 100644
index 0000000..2120204
--- /dev/null
+++ b/hashes/gmp-6.2.0.tar.bz2.sha1
@@ -0,0 +1 @@
+5e9341d3807bc7505376f9ed9f5c1c6c57050aa6  gmp-6.2.0.tar.bz2
diff --git a/hashes/gmp-6.2.1.tar.bz2.sha1 b/hashes/gmp-6.2.1.tar.bz2.sha1
new file mode 100644
index 0000000..1585a47
--- /dev/null
+++ b/hashes/gmp-6.2.1.tar.bz2.sha1
@@ -0,0 +1 @@
+2dcf34d4a432dbe6cce1475a835d20fe44f75822  gmp-6.2.1.tar.bz2
diff --git a/hashes/gmp-6.3.0.tar.bz2.sha1 b/hashes/gmp-6.3.0.tar.bz2.sha1
new file mode 100644
index 0000000..b020d0e
--- /dev/null
+++ b/hashes/gmp-6.3.0.tar.bz2.sha1
@@ -0,0 +1 @@
+32d21c4fae046de45e8fce37bf4002236d283b71  gmp-6.3.0.tar.bz2
diff --git a/hashes/linux-6.1.36.tar.xz.sha1 b/hashes/linux-6.1.36.tar.xz.sha1
new file mode 100644
index 0000000..33722df
--- /dev/null
+++ b/hashes/linux-6.1.36.tar.xz.sha1
@@ -0,0 +1 @@
+afa6c0129d08bd9476a642095112b7c49c9455e4  linux-6.1.36.tar.xz
diff --git a/hashes/mpc-1.2.0.tar.gz.sha1 b/hashes/mpc-1.2.0.tar.gz.sha1
new file mode 100644
index 0000000..46270c4
--- /dev/null
+++ b/hashes/mpc-1.2.0.tar.gz.sha1
@@ -0,0 +1 @@
+0abdc94acab0c9bfdaa391347cdfd7bbdb1cf017  mpc-1.2.0.tar.gz
diff --git a/hashes/mpc-1.2.1.tar.gz.sha1 b/hashes/mpc-1.2.1.tar.gz.sha1
new file mode 100644
index 0000000..d5a88f9
--- /dev/null
+++ b/hashes/mpc-1.2.1.tar.gz.sha1
@@ -0,0 +1 @@
+2a4919abf445c6eda4e120cd669b8733ce337227  mpc-1.2.1.tar.gz
diff --git a/hashes/mpc-1.3.1.tar.gz.sha1 b/hashes/mpc-1.3.1.tar.gz.sha1
new file mode 100644
index 0000000..a2856f8
--- /dev/null
+++ b/hashes/mpc-1.3.1.tar.gz.sha1
@@ -0,0 +1 @@
+bac1c1fa79f5602df1e29e4684e103ad55714e02  mpc-1.3.1.tar.gz
diff --git a/hashes/mpfr-3.1.5.tar.bz2.sha1 b/hashes/mpfr-3.1.5.tar.bz2.sha1
new file mode 100644
index 0000000..92743da
--- /dev/null
+++ b/hashes/mpfr-3.1.5.tar.bz2.sha1
@@ -0,0 +1 @@
+874e84bb5959fd5a19c032cfb5d673dded4b5cff  mpfr-3.1.5.tar.bz2
diff --git a/hashes/mpfr-3.1.6.tar.bz2.sha1 b/hashes/mpfr-3.1.6.tar.bz2.sha1
new file mode 100644
index 0000000..fe88135
--- /dev/null
+++ b/hashes/mpfr-3.1.6.tar.bz2.sha1
@@ -0,0 +1 @@
+c207aada1c0af969d800c16f25e0a78e15b9c9cc  mpfr-3.1.6.tar.bz2
diff --git a/hashes/mpfr-4.0.1.tar.bz2.sha1 b/hashes/mpfr-4.0.1.tar.bz2.sha1
new file mode 100644
index 0000000..efac4c5
--- /dev/null
+++ b/hashes/mpfr-4.0.1.tar.bz2.sha1
@@ -0,0 +1 @@
+fcbbafb37c683898e585b926608d540ed037609e  mpfr-4.0.1.tar.bz2
diff --git a/hashes/mpfr-4.0.1.tar.xz.sha1 b/hashes/mpfr-4.0.1.tar.xz.sha1
new file mode 100644
index 0000000..c70bc16
--- /dev/null
+++ b/hashes/mpfr-4.0.1.tar.xz.sha1
@@ -0,0 +1 @@
+ae555c56a6fccd21a0ffe3dd3bdc5eb5cc1a5fce  mpfr-4.0.1.tar.xz
diff --git a/hashes/mpfr-4.0.2.tar.xz.sha1 b/hashes/mpfr-4.0.2.tar.xz.sha1
new file mode 100644
index 0000000..0801a08
--- /dev/null
+++ b/hashes/mpfr-4.0.2.tar.xz.sha1
@@ -0,0 +1 @@
+52c1f2a4c9a202f46cf3275a8d46b562aa584208  mpfr-4.0.2.tar.xz
diff --git a/hashes/mpfr-4.1.0.tar.bz2.sha1 b/hashes/mpfr-4.1.0.tar.bz2.sha1
new file mode 100644
index 0000000..163fa22
--- /dev/null
+++ b/hashes/mpfr-4.1.0.tar.bz2.sha1
@@ -0,0 +1 @@
+877d35a8a81a4d2d9446252e9b4ae944754d8ceb  mpfr-4.1.0.tar.bz2
diff --git a/hashes/mpfr-4.1.0.tar.xz.sha1 b/hashes/mpfr-4.1.0.tar.xz.sha1
new file mode 100644
index 0000000..074820a
--- /dev/null
+++ b/hashes/mpfr-4.1.0.tar.xz.sha1
@@ -0,0 +1 @@
+159c3a58705662bfde4dc93f2617f3660855ead6  mpfr-4.1.0.tar.xz
diff --git a/hashes/mpfr-4.2.0.tar.bz2.sha1 b/hashes/mpfr-4.2.0.tar.bz2.sha1
new file mode 100644
index 0000000..fd90b07
--- /dev/null
+++ b/hashes/mpfr-4.2.0.tar.bz2.sha1
@@ -0,0 +1 @@
+08390d482ffcb198329632c0bf76dace53016dd8  mpfr-4.2.0.tar.bz2
diff --git a/hashes/mpfr-4.2.0.tar.xz.sha1 b/hashes/mpfr-4.2.0.tar.xz.sha1
new file mode 100644
index 0000000..bef6cb9
--- /dev/null
+++ b/hashes/mpfr-4.2.0.tar.xz.sha1
@@ -0,0 +1 @@
+4f734ca3ebceac28e2f944b131a47133b19e2c5e  mpfr-4.2.0.tar.xz
diff --git a/hashes/mpfr-4.2.1.tar.bz2.sha1 b/hashes/mpfr-4.2.1.tar.bz2.sha1
new file mode 100644
index 0000000..7a2f8a3
--- /dev/null
+++ b/hashes/mpfr-4.2.1.tar.bz2.sha1
@@ -0,0 +1 @@
+f9dbe49b092e4c8e0a039e6d46c059696cc2f51c  mpfr-4.2.1.tar.bz2
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
diff --git a/litecross/Makefile b/litecross/Makefile
index 9cd691b..ef473f1 100644
--- a/litecross/Makefile
+++ b/litecross/Makefile
@@ -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
diff --git a/patches/gcc-11.4.0/0000-nostdinc.diff b/patches/gcc-11.4.0/0000-nostdinc.diff
new file mode 100644
index 0000000..f1ec338
--- /dev/null
+++ b/patches/gcc-11.4.0/0000-nostdinc.diff
@@ -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])
diff --git a/patches/gcc-11.4.0/0001-ssp_nonshared.diff b/patches/gcc-11.4.0/0001-ssp_nonshared.diff
new file mode 100644
index 0000000..0b991d9
--- /dev/null
+++ b/patches/gcc-11.4.0/0001-ssp_nonshared.diff
@@ -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" \
diff --git a/patches/gcc-11.4.0/0002-posix_memalign.diff b/patches/gcc-11.4.0/0002-posix_memalign.diff
new file mode 100644
index 0000000..1d80096
--- /dev/null
+++ b/patches/gcc-11.4.0/0002-posix_memalign.diff
@@ -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;
diff --git a/patches/gcc-11.4.0/0003-j2.diff b/patches/gcc-11.4.0/0003-j2.diff
new file mode 100644
index 0000000..245b910
--- /dev/null
+++ b/patches/gcc-11.4.0/0003-j2.diff
@@ -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
diff --git a/patches/gcc-11.4.0/0004-static-pie.diff b/patches/gcc-11.4.0/0004-static-pie.diff
new file mode 100644
index 0000000..232dc5d
--- /dev/null
+++ b/patches/gcc-11.4.0/0004-static-pie.diff
@@ -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
diff --git a/patches/gcc-11.4.0/0005-m68k-sqrt.diff b/patches/gcc-11.4.0/0005-m68k-sqrt.diff
new file mode 100644
index 0000000..652efb1
--- /dev/null
+++ b/patches/gcc-11.4.0/0005-m68k-sqrt.diff
@@ -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";
diff --git a/patches/gcc-11.4.0/0100-hack-sh2fdpic-unwind-nonsense.diff b/patches/gcc-11.4.0/0100-hack-sh2fdpic-unwind-nonsense.diff
new file mode 100644
index 0000000..3336001
--- /dev/null
+++ b/patches/gcc-11.4.0/0100-hack-sh2fdpic-unwind-nonsense.diff
@@ -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
diff --git a/patches/linux-6.1.36/0000-do-not-build-archscripts-for-headers-only.diff b/patches/linux-6.1.36/0000-do-not-build-archscripts-for-headers-only.diff
new file mode 100644
index 0000000..1db5ef5
--- /dev/null
+++ b/patches/linux-6.1.36/0000-do-not-build-archscripts-for-headers-only.diff
@@ -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
+ 
diff --git a/patches/musl-1.2.4/0001-move-fallocate64-declaration-under-_LARGEFILE64_SOUR.patch b/patches/musl-1.2.4/0001-move-fallocate64-declaration-under-_LARGEFILE64_SOUR.patch
new file mode 100644
index 0000000..2266915
--- /dev/null
+++ b/patches/musl-1.2.4/0001-move-fallocate64-declaration-under-_LARGEFILE64_SOUR.patch
@@ -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
+
diff --git a/patches/musl-1.2.4/0002-add-loongarch64-port-v7.patch b/patches/musl-1.2.4/0002-add-loongarch64-port-v7.patch
new file mode 100644
index 0000000..37a5fab
--- /dev/null
+++ b/patches/musl-1.2.4/0002-add-loongarch64-port-v7.patch
@@ -0,0 +1,1384 @@
+From 504db4b4c357385a0a39d220cfc3eee1737f49ff Mon Sep 17 00:00:00 2001
+From: wanghongliang <wanghongliang@loongson.cn>
+Date: Mon, 17 Apr 2023 15:54:57 +0800
+Subject: [PATCH] add loongarch64 port v7.
+
+Author: Xiaojuan Zhai <zhaixiaojuan@loongson.cn>
+Author: Meidan Li <limeidan@loongson.cn>
+Author: Guoqi Chen <chenguoqi@loongson.cn>
+Author: Xiaolin Zhao <zhaoxiaolin@loongson.cn>
+Author: Fan peng <fanpeng@loongson.cn>
+Author: Jiantao Shan <shanjiantao@loongson.cn>
+Author: Xuhui Qiang <qiangxuhui@loongson.cn>
+Author: Jingyun Hua <huajingyun@loongson.cn>
+Author: Liu xue <liuxue@loongson.cn>
+Author: Hongliang Wang <wanghongliang@loongson.cn>
+
+Signed-off-by: wanghongliang <wanghongliang@loongson.cn>
+---
+ arch/loongarch64/atomic_arch.h             |  53 ++++
+ arch/loongarch64/bits/alltypes.h.in        |  18 ++
+ arch/loongarch64/bits/fenv.h               |  20 ++
+ arch/loongarch64/bits/float.h              |  16 ++
+ arch/loongarch64/bits/posix.h              |   2 +
+ arch/loongarch64/bits/ptrace.h             |   4 +
+ arch/loongarch64/bits/reg.h                |   2 +
+ arch/loongarch64/bits/setjmp.h             |   1 +
+ arch/loongarch64/bits/signal.h             |  91 +++++++
+ arch/loongarch64/bits/stat.h               |  18 ++
+ arch/loongarch64/bits/stdint.h             |  20 ++
+ arch/loongarch64/bits/syscall.h.in         | 303 +++++++++++++++++++++
+ arch/loongarch64/bits/user.h               |   5 +
+ arch/loongarch64/crt_arch.h                |  13 +
+ arch/loongarch64/pthread_arch.h            |  11 +
+ arch/loongarch64/reloc.h                   |  20 ++
+ arch/loongarch64/syscall_arch.h            | 137 ++++++++++
+ configure                                  |   5 +
+ include/elf.h                              | 104 ++++++-
+ src/fenv/loongarch64/fenv.S                |  78 ++++++
+ src/ldso/loongarch64/dlsym.s               |   7 +
+ src/setjmp/loongarch64/longjmp.S           |  32 +++
+ src/setjmp/loongarch64/setjmp.S            |  34 +++
+ src/signal/loongarch64/restore.s           |  10 +
+ src/signal/loongarch64/sigsetjmp.s         |  25 ++
+ src/thread/loongarch64/__set_thread_area.s |   7 +
+ src/thread/loongarch64/__unmapself.s       |   7 +
+ src/thread/loongarch64/clone.s             |  28 ++
+ src/thread/loongarch64/syscall_cp.s        |  29 ++
+ 29 files changed, 1099 insertions(+), 1 deletion(-)
+ create mode 100644 arch/loongarch64/atomic_arch.h
+ create mode 100644 arch/loongarch64/bits/alltypes.h.in
+ create mode 100644 arch/loongarch64/bits/fenv.h
+ create mode 100644 arch/loongarch64/bits/float.h
+ create mode 100644 arch/loongarch64/bits/posix.h
+ create mode 100644 arch/loongarch64/bits/ptrace.h
+ create mode 100644 arch/loongarch64/bits/reg.h
+ create mode 100644 arch/loongarch64/bits/setjmp.h
+ create mode 100644 arch/loongarch64/bits/signal.h
+ create mode 100644 arch/loongarch64/bits/stat.h
+ create mode 100644 arch/loongarch64/bits/stdint.h
+ create mode 100644 arch/loongarch64/bits/syscall.h.in
+ create mode 100644 arch/loongarch64/bits/user.h
+ create mode 100644 arch/loongarch64/crt_arch.h
+ create mode 100644 arch/loongarch64/pthread_arch.h
+ create mode 100644 arch/loongarch64/reloc.h
+ create mode 100644 arch/loongarch64/syscall_arch.h
+ create mode 100644 src/fenv/loongarch64/fenv.S
+ create mode 100644 src/ldso/loongarch64/dlsym.s
+ create mode 100644 src/setjmp/loongarch64/longjmp.S
+ create mode 100644 src/setjmp/loongarch64/setjmp.S
+ create mode 100644 src/signal/loongarch64/restore.s
+ create mode 100644 src/signal/loongarch64/sigsetjmp.s
+ create mode 100644 src/thread/loongarch64/__set_thread_area.s
+ create mode 100644 src/thread/loongarch64/__unmapself.s
+ create mode 100644 src/thread/loongarch64/clone.s
+ create mode 100644 src/thread/loongarch64/syscall_cp.s
+
+diff --git a/arch/loongarch64/atomic_arch.h b/arch/loongarch64/atomic_arch.h
+new file mode 100644
+index 00000000..2225d027
+--- /dev/null
++++ b/arch/loongarch64/atomic_arch.h
+@@ -0,0 +1,53 @@
++#define a_ll a_ll
++static inline int a_ll(volatile int *p)
++{
++	int v;
++	__asm__ __volatile__ (
++		"ll.w %0, %1"
++		: "=r"(v)
++		: "ZC"(*p));
++	return v;
++}
++
++#define a_sc a_sc
++static inline int a_sc(volatile int *p, int v)
++{
++	int r;
++	__asm__ __volatile__ (
++		"sc.w %0, %1"
++		: "=r"(r), "=ZC"(*p)
++		: "0"(v) : "memory");
++	return r;
++}
++
++#define a_ll_p a_ll_p
++static inline void *a_ll_p(volatile void *p)
++{
++	void *v;
++	__asm__ __volatile__ (
++		"ll.d %0, %1"
++		: "=r"(v)
++		: "ZC"(*(void *volatile *)p));
++	return v;
++}
++
++#define a_sc_p a_sc_p
++static inline int a_sc_p(volatile void *p, void *v)
++{
++	long r;
++	__asm__ __volatile__ (
++		"sc.d %0, %1"
++		: "=r"(r), "=ZC"(*(void *volatile *)p)
++		: "0"(v)
++		: "memory");
++	return r;
++}
++
++#define a_barrier a_barrier
++static inline void a_barrier()
++{
++	__asm__ __volatile__ ("dbar 0" : : : "memory");
++}
++
++#define a_pre_llsc  a_barrier
++#define a_post_llsc a_barrier
+diff --git a/arch/loongarch64/bits/alltypes.h.in b/arch/loongarch64/bits/alltypes.h.in
+new file mode 100644
+index 00000000..084f5a7c
+--- /dev/null
++++ b/arch/loongarch64/bits/alltypes.h.in
+@@ -0,0 +1,18 @@
++#define _Addr  long
++#define _Int64 long
++#define _Reg   long
++
++#define __BYTE_ORDER  __LITTLE_ENDIAN
++#define __LONG_MAX    0x7fffffffffffffffL
++
++#ifndef __cplusplus
++TYPEDEF int wchar_t;
++#endif
++
++TYPEDEF float  float_t;
++TYPEDEF double double_t;
++
++TYPEDEF struct { long long __ll; long double __ld; } max_align_t;
++
++TYPEDEF unsigned int nlink_t;
++TYPEDEF int blksize_t;
+diff --git a/arch/loongarch64/bits/fenv.h b/arch/loongarch64/bits/fenv.h
+new file mode 100644
+index 00000000..99e916e1
+--- /dev/null
++++ b/arch/loongarch64/bits/fenv.h
+@@ -0,0 +1,20 @@
++#define FE_INEXACT    0x010000
++#define FE_UNDERFLOW  0x020000
++#define FE_OVERFLOW   0x040000
++#define FE_DIVBYZERO  0x080000
++#define FE_INVALID    0x100000
++
++#define FE_ALL_EXCEPT 0x1F0000
++
++#define FE_TONEAREST  0x000
++#define FE_TOWARDZERO 0x100
++#define FE_UPWARD     0x200
++#define FE_DOWNWARD   0x300
++
++typedef unsigned fexcept_t;
++
++typedef struct {
++	unsigned int __cw;
++} fenv_t;
++
++#define FE_DFL_ENV ((const fenv_t *) -1)
+diff --git a/arch/loongarch64/bits/float.h b/arch/loongarch64/bits/float.h
+new file mode 100644
+index 00000000..63e86d44
+--- /dev/null
++++ b/arch/loongarch64/bits/float.h
+@@ -0,0 +1,16 @@
++#define FLT_EVAL_METHOD 0
++
++#define LDBL_TRUE_MIN   6.47517511943802511092443895822764655e-4966L
++#define LDBL_MIN        3.36210314311209350626267781732175260e-4932L
++#define LDBL_MAX        1.18973149535723176508575932662800702e+4932L
++#define LDBL_EPSILON    1.92592994438723585305597794258492732e-34L
++
++#define LDBL_MANT_DIG   113
++#define LDBL_MIN_EXP    (-16381)
++#define LDBL_MAX_EXP    16384
++
++#define LDBL_DIG        33
++#define LDBL_MIN_10_EXP (-4931)
++#define LDBL_MAX_10_EXP 4932
++
++#define DECIMAL_DIG     36
+diff --git a/arch/loongarch64/bits/posix.h b/arch/loongarch64/bits/posix.h
+new file mode 100644
+index 00000000..c37b94c1
+--- /dev/null
++++ b/arch/loongarch64/bits/posix.h
+@@ -0,0 +1,2 @@
++#define _POSIX_V6_LP64_OFF64  1
++#define _POSIX_V7_LP64_OFF64  1
+diff --git a/arch/loongarch64/bits/ptrace.h b/arch/loongarch64/bits/ptrace.h
+new file mode 100644
+index 00000000..dce2fa51
+--- /dev/null
++++ b/arch/loongarch64/bits/ptrace.h
+@@ -0,0 +1,4 @@
++#define PTRACE_GET_THREAD_AREA  25
++#define PTRACE_SET_THREAD_AREA  26
++#define PTRACE_GET_WATCH_REGS   0xd0
++#define PTRACE_SET_WATCH_REGS   0xd1
+diff --git a/arch/loongarch64/bits/reg.h b/arch/loongarch64/bits/reg.h
+new file mode 100644
+index 00000000..2633f39d
+--- /dev/null
++++ b/arch/loongarch64/bits/reg.h
+@@ -0,0 +1,2 @@
++#undef __WORDSIZE
++#define __WORDSIZE 64
+diff --git a/arch/loongarch64/bits/setjmp.h b/arch/loongarch64/bits/setjmp.h
+new file mode 100644
+index 00000000..4bfa374d
+--- /dev/null
++++ b/arch/loongarch64/bits/setjmp.h
+@@ -0,0 +1 @@
++typedef unsigned long  __jmp_buf[23];
+diff --git a/arch/loongarch64/bits/signal.h b/arch/loongarch64/bits/signal.h
+new file mode 100644
+index 00000000..c56fe243
+--- /dev/null
++++ b/arch/loongarch64/bits/signal.h
+@@ -0,0 +1,91 @@
++#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
++ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
++
++#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
++#define MINSIGSTKSZ 4096
++#define SIGSTKSZ    16384
++#endif
++
++#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
++typedef unsigned long greg_t, gregset_t[32];
++
++struct sigcontext {
++	unsigned long sc_pc;
++	unsigned long sc_regs[32];
++	unsigned int sc_flags;
++	unsigned long sc_extcontext[] __attribute__((__aligned__(16)));
++};
++
++typedef struct {
++	unsigned long __pc;
++	unsigned long __gregs[32];
++	unsigned int __flags;
++	unsigned long __extcontext[] __attribute__((__aligned__(16)));
++} mcontext_t;
++#else
++typedef struct {
++	unsigned long __space[34];
++} mcontext_t;
++#endif
++
++struct sigaltstack {
++	void   *ss_sp;
++	int    ss_flags;
++	size_t ss_size;
++};
++
++typedef struct __ucontext
++{
++	unsigned long      __uc_flags;
++	struct __ucontext  *uc_link;
++	stack_t            uc_stack;
++	sigset_t           uc_sigmask;
++	mcontext_t         uc_mcontext;
++} ucontext_t;
++
++#define SA_NOCLDSTOP     1
++#define SA_NOCLDWAIT     2
++#define SA_SIGINFO       4
++#define SA_ONSTACK       0x08000000
++#define SA_RESTART       0x10000000
++#define SA_NODEFER       0x40000000
++#define SA_RESETHAND     0x80000000
++#define SA_RESTORER      0x0
++
++#endif
++
++#define SIGHUP           1
++#define SIGINT           2
++#define SIGQUIT          3
++#define SIGILL           4
++#define SIGTRAP          5
++#define SIGABRT          6
++#define SIGIOT           SIGABRT
++#define SIGBUS           7
++#define SIGFPE           8
++#define SIGKILL          9
++#define SIGUSR1         10
++#define SIGSEGV         11
++#define SIGUSR2         12
++#define SIGPIPE         13
++#define SIGALRM         14
++#define SIGTERM         15
++#define SIGSTKFLT       16
++#define SIGCHLD         17
++#define SIGCONT         18
++#define SIGSTOP         19
++#define SIGTSTP         20
++#define SIGTTIN         21
++#define SIGTTOU         22
++#define SIGURG          23
++#define SIGXCPU         24
++#define SIGXFSZ         25
++#define SIGVTALRM       26
++#define SIGPROF         27
++#define SIGWINCH        28
++#define SIGIO           29
++#define SIGPOLL         SIGIO
++#define SIGPWR          30
++#define SIGSYS          31
++#define SIGUNUSED       SIGSYS
++#define _NSIG           65
+diff --git a/arch/loongarch64/bits/stat.h b/arch/loongarch64/bits/stat.h
+new file mode 100644
+index 00000000..b604fb8f
+--- /dev/null
++++ b/arch/loongarch64/bits/stat.h
+@@ -0,0 +1,18 @@
++struct stat {
++	dev_t st_dev;
++	ino_t st_ino;
++	mode_t st_mode;
++	nlink_t st_nlink;
++	uid_t st_uid;
++	gid_t st_gid;
++	dev_t st_rdev;
++	unsigned long __pad1;
++	off_t st_size;
++	blksize_t st_blksize;
++	int __pad2;
++	blkcnt_t st_blocks;
++	struct timespec st_atim;
++	struct timespec st_mtim;
++	struct timespec st_ctim;
++	unsigned __unused[2];
++};
+diff --git a/arch/loongarch64/bits/stdint.h b/arch/loongarch64/bits/stdint.h
+new file mode 100644
+index 00000000..60c12499
+--- /dev/null
++++ b/arch/loongarch64/bits/stdint.h
+@@ -0,0 +1,20 @@
++typedef int32_t  int_fast16_t;
++typedef int32_t  int_fast32_t;
++typedef uint32_t uint_fast16_t;
++typedef uint32_t uint_fast32_t;
++
++#define INT_FAST16_MIN  INT32_MIN
++#define INT_FAST32_MIN  INT32_MIN
++
++#define INT_FAST16_MAX  INT32_MAX
++#define INT_FAST32_MAX  INT32_MAX
++
++#define UINT_FAST16_MAX UINT32_MAX
++#define UINT_FAST32_MAX UINT32_MAX
++
++#define INTPTR_MIN      INT64_MIN
++#define INTPTR_MAX      INT64_MAX
++#define UINTPTR_MAX     UINT64_MAX
++#define PTRDIFF_MIN     INT64_MIN
++#define PTRDIFF_MAX     INT64_MAX
++#define SIZE_MAX        UINT64_MAX
+diff --git a/arch/loongarch64/bits/syscall.h.in b/arch/loongarch64/bits/syscall.h.in
+new file mode 100644
+index 00000000..0980e533
+--- /dev/null
++++ b/arch/loongarch64/bits/syscall.h.in
+@@ -0,0 +1,303 @@
++#define __NR_io_setup                   0
++#define __NR_io_destroy                 1
++#define __NR_io_submit                  2
++#define __NR_io_cancel                  3
++#define __NR_io_getevents               4
++#define __NR_setxattr                   5
++#define __NR_lsetxattr                  6
++#define __NR_fsetxattr                  7
++#define __NR_getxattr                   8
++#define __NR_lgetxattr                  9
++#define __NR_fgetxattr                  10
++#define __NR_listxattr                  11
++#define __NR_llistxattr                 12
++#define __NR_flistxattr                 13
++#define __NR_removexattr                14
++#define __NR_lremovexattr               15
++#define __NR_fremovexattr               16
++#define __NR_getcwd                     17
++#define __NR_lookup_dcookie             18
++#define __NR_eventfd2                   19
++#define __NR_epoll_create1              20
++#define __NR_epoll_ctl                  21
++#define __NR_epoll_pwait                22
++#define __NR_dup                        23
++#define __NR_dup3                       24
++#define __NR3264_fcntl                  25
++#define __NR_inotify_init1              26
++#define __NR_inotify_add_watch          27
++#define __NR_inotify_rm_watch           28
++#define __NR_ioctl                      29
++#define __NR_ioprio_set                 30
++#define __NR_ioprio_get                 31
++#define __NR_flock                      32
++#define __NR_mknodat                    33
++#define __NR_mkdirat                    34
++#define __NR_unlinkat                   35
++#define __NR_symlinkat                  36
++#define __NR_linkat                     37
++#define __NR_umount2                    39
++#define __NR_mount                      40
++#define __NR_pivot_root                 41
++#define __NR_nfsservctl                 42
++#define __NR3264_statfs                 43
++#define __NR3264_fstatfs                44
++#define __NR3264_truncate               45
++#define __NR3264_ftruncate              46
++#define __NR_fallocate                  47
++#define __NR_faccessat                  48
++#define __NR_chdir                      49
++#define __NR_fchdir                     50
++#define __NR_chroot                     51
++#define __NR_fchmod                     52
++#define __NR_fchmodat                   53
++#define __NR_fchownat                   54
++#define __NR_fchown                     55
++#define __NR_openat                     56
++#define __NR_close                      57
++#define __NR_vhangup                    58
++#define __NR_pipe2                      59
++#define __NR_quotactl                   60
++#define __NR_getdents64                 61
++#define __NR3264_lseek                  62
++#define __NR_read                       63
++#define __NR_write                      64
++#define __NR_readv                      65
++#define __NR_writev                     66
++#define __NR_pread64                    67
++#define __NR_pwrite64                   68
++#define __NR_preadv                     69
++#define __NR_pwritev                    70
++#define __NR3264_sendfile               71
++#define __NR_pselect6                   72
++#define __NR_ppoll                      73
++#define __NR_signalfd4                  74
++#define __NR_vmsplice                   75
++#define __NR_splice                     76
++#define __NR_tee                        77
++#define __NR_readlinkat                 78
++#define __NR_sync                       81
++#define __NR_fsync                      82
++#define __NR_fdatasync                  83
++#define __NR_sync_file_range            84
++#define __NR_timerfd_create             85
++#define __NR_timerfd_settime            86
++#define __NR_timerfd_gettime            87
++#define __NR_utimensat                  88
++#define __NR_acct                       89
++#define __NR_capget                     90
++#define __NR_capset                     91
++#define __NR_personality                92
++#define __NR_exit                       93
++#define __NR_exit_group                 94
++#define __NR_waitid                     95
++#define __NR_set_tid_address            96
++#define __NR_unshare                    97
++#define __NR_futex                      98
++#define __NR_set_robust_list            99
++#define __NR_get_robust_list            100
++#define __NR_nanosleep                  101
++#define __NR_getitimer                  102
++#define __NR_setitimer                  103
++#define __NR_kexec_load                 104
++#define __NR_init_module                105
++#define __NR_delete_module              106
++#define __NR_timer_create               107
++#define __NR_timer_gettime              108
++#define __NR_timer_getoverrun           109
++#define __NR_timer_settime              110
++#define __NR_timer_delete               111
++#define __NR_clock_settime              112
++#define __NR_clock_gettime              113
++#define __NR_clock_getres               114
++#define __NR_clock_nanosleep            115
++#define __NR_syslog                     116
++#define __NR_ptrace                     117
++#define __NR_sched_setparam             118
++#define __NR_sched_setscheduler         119
++#define __NR_sched_getscheduler         120
++#define __NR_sched_getparam             121
++#define __NR_sched_setaffinity          122
++#define __NR_sched_getaffinity          123
++#define __NR_sched_yield                124
++#define __NR_sched_get_priority_max     125
++#define __NR_sched_get_priority_min     126
++#define __NR_sched_rr_get_interval      127
++#define __NR_restart_syscall            128
++#define __NR_kill                       129
++#define __NR_tkill                      130
++#define __NR_tgkill                     131
++#define __NR_sigaltstack                132
++#define __NR_rt_sigsuspend              133
++#define __NR_rt_sigaction               134
++#define __NR_rt_sigprocmask             135
++#define __NR_rt_sigpending              136
++#define __NR_rt_sigtimedwait            137
++#define __NR_rt_sigqueueinfo            138
++#define __NR_rt_sigreturn               139
++#define __NR_setpriority                140
++#define __NR_getpriority                141
++#define __NR_reboot                     142
++#define __NR_setregid                   143
++#define __NR_setgid                     144
++#define __NR_setreuid                   145
++#define __NR_setuid                     146
++#define __NR_setresuid                  147
++#define __NR_getresuid                  148
++#define __NR_setresgid                  149
++#define __NR_getresgid                  150
++#define __NR_setfsuid                   151
++#define __NR_setfsgid                   152
++#define __NR_times                      153
++#define __NR_setpgid                    154
++#define __NR_getpgid                    155
++#define __NR_getsid                     156
++#define __NR_setsid                     157
++#define __NR_getgroups                  158
++#define __NR_setgroups                  159
++#define __NR_uname                      160
++#define __NR_sethostname                161
++#define __NR_setdomainname              162
++#define __NR_getrlimit                  163
++#define __NR_setrlimit                  164
++#define __NR_getrusage                  165
++#define __NR_umask                      166
++#define __NR_prctl                      167
++#define __NR_getcpu                     168
++#define __NR_gettimeofday               169
++#define __NR_settimeofday               170
++#define __NR_adjtimex                   171
++#define __NR_getpid                     172
++#define __NR_getppid                    173
++#define __NR_getuid                     174
++#define __NR_geteuid                    175
++#define __NR_getgid                     176
++#define __NR_getegid                    177
++#define __NR_gettid                     178
++#define __NR_sysinfo                    179
++#define __NR_mq_open                    180
++#define __NR_mq_unlink                  181
++#define __NR_mq_timedsend               182
++#define __NR_mq_timedreceive            183
++#define __NR_mq_notify                  184
++#define __NR_mq_getsetattr              185
++#define __NR_msgget                     186
++#define __NR_msgctl                     187
++#define __NR_msgrcv                     188
++#define __NR_msgsnd                     189
++#define __NR_semget                     190
++#define __NR_semctl                     191
++#define __NR_semtimedop                 192
++#define __NR_semop                      193
++#define __NR_shmget                     194
++#define __NR_shmctl                     195
++#define __NR_shmat                      196
++#define __NR_shmdt                      197
++#define __NR_socket                     198
++#define __NR_socketpair                 199
++#define __NR_bind                       200
++#define __NR_listen                     201
++#define __NR_accept                     202
++#define __NR_connect                    203
++#define __NR_getsockname                204
++#define __NR_getpeername                205
++#define __NR_sendto                     206
++#define __NR_recvfrom                   207
++#define __NR_setsockopt                 208
++#define __NR_getsockopt                 209
++#define __NR_shutdown                   210
++#define __NR_sendmsg                    211
++#define __NR_recvmsg                    212
++#define __NR_readahead                  213
++#define __NR_brk                        214
++#define __NR_munmap                     215
++#define __NR_mremap                     216
++#define __NR_add_key                    217
++#define __NR_request_key                218
++#define __NR_keyctl                     219
++#define __NR_clone                      220
++#define __NR_execve                     221
++#define __NR3264_mmap                   222
++#define __NR3264_fadvise64              223
++#define __NR_swapon                     224
++#define __NR_swapoff                    225
++#define __NR_mprotect                   226
++#define __NR_msync                      227
++#define __NR_mlock                      228
++#define __NR_munlock                    229
++#define __NR_mlockall                   230
++#define __NR_munlockall                 231
++#define __NR_mincore                    232
++#define __NR_madvise                    233
++#define __NR_remap_file_pages           234
++#define __NR_mbind                      235
++#define __NR_get_mempolicy              236
++#define __NR_set_mempolicy              237
++#define __NR_migrate_pages              238
++#define __NR_move_pages                 239
++#define __NR_rt_tgsigqueueinfo          240
++#define __NR_perf_event_open            241
++#define __NR_accept4                    242
++#define __NR_recvmmsg                   243
++#define __NR_arch_specific_syscall      244
++#define __NR_wait4                      260
++#define __NR_prlimit64                  261
++#define __NR_fanotify_init              262
++#define __NR_fanotify_mark              263
++#define __NR_name_to_handle_at          264
++#define __NR_open_by_handle_at          265
++#define __NR_clock_adjtime              266
++#define __NR_syncfs                     267
++#define __NR_setns                      268
++#define __NR_sendmmsg                   269
++#define __NR_process_vm_readv           270
++#define __NR_process_vm_writev          271
++#define __NR_kcmp                       272
++#define __NR_finit_module               273
++#define __NR_sched_setattr              274
++#define __NR_sched_getattr              275
++#define __NR_renameat2                  276
++#define __NR_seccomp                    277
++#define __NR_getrandom                  278
++#define __NR_memfd_create               279
++#define __NR_bpf                        280
++#define __NR_execveat                   281
++#define __NR_userfaultfd                282
++#define __NR_membarrier                 283
++#define __NR_mlock2                     284
++#define __NR_copy_file_range            285
++#define __NR_preadv2                    286
++#define __NR_pwritev2                   287
++#define __NR_pkey_mprotect              288
++#define __NR_pkey_alloc                 289
++#define __NR_pkey_free                  290
++#define __NR_statx                      291
++#define __NR_io_pgetevents              292
++#define __NR_rseq                       293
++#define __NR_kexec_file_load            294
++#define __NR_pidfd_send_signal          424
++#define __NR_io_uring_setup             425
++#define __NR_io_uring_enter             426
++#define __NR_io_uring_register          427
++#define __NR_open_tree                  428
++#define __NR_move_mount                 429
++#define __NR_fsopen                     430
++#define __NR_fsconfig                   431
++#define __NR_fsmount                    432
++#define __NR_fspick                     433
++#define __NR_pidfd_open                 434
++#define __NR_clone3                     435
++#define __NR_close_range                436
++#define __NR_openat2                    437
++#define __NR_pidfd_getfd                438
++#define __NR_faccessat2                 439
++#define __NR_process_madvise            440
++#define __NR_fcntl                      __NR3264_fcntl
++#define __NR_statfs                     __NR3264_statfs
++#define __NR_fstatfs                    __NR3264_fstatfs
++#define __NR_truncate                   __NR3264_truncate
++#define __NR_ftruncate                  __NR3264_ftruncate
++#define __NR_lseek                      __NR3264_lseek
++#define __NR_sendfile                   __NR3264_sendfile
++#define __NR_mmap                       __NR3264_mmap
++#define __NR_fadvise64                  __NR3264_fadvise64
+diff --git a/arch/loongarch64/bits/user.h b/arch/loongarch64/bits/user.h
+new file mode 100644
+index 00000000..5a71d132
+--- /dev/null
++++ b/arch/loongarch64/bits/user.h
+@@ -0,0 +1,5 @@
++#define ELF_NGREG    45
++#define ELF_NFPREG   33
++
++typedef unsigned long elf_greg_t, elf_gregset_t[ELF_NGREG];
++typedef double elf_fpreg_t, elf_fpregset_t[ELF_NFPREG];
+diff --git a/arch/loongarch64/crt_arch.h b/arch/loongarch64/crt_arch.h
+new file mode 100644
+index 00000000..e0760d9e
+--- /dev/null
++++ b/arch/loongarch64/crt_arch.h
+@@ -0,0 +1,13 @@
++__asm__(
++".text \n"
++".global " START "\n"
++".type   " START ", @function\n"
++START ":\n"
++"	move $fp, $zero\n"
++"	move $a0, $sp\n"
++".weak _DYNAMIC\n"
++".hidden _DYNAMIC\n"
++"	la.local $a1, _DYNAMIC\n"
++"	bstrins.d $sp, $zero, 3, 0\n"
++"	b " START "_c\n"
++);
+diff --git a/arch/loongarch64/pthread_arch.h b/arch/loongarch64/pthread_arch.h
+new file mode 100644
+index 00000000..28fbfcd1
+--- /dev/null
++++ b/arch/loongarch64/pthread_arch.h
+@@ -0,0 +1,11 @@
++static inline uintptr_t __get_tp()
++{
++	uintptr_t tp;
++	__asm__ __volatile__("move %0, $tp" : "=r"(tp));
++	return tp;
++}
++
++#define TLS_ABOVE_TP
++#define GAP_ABOVE_TP   0
++#define DTP_OFFSET     0
++#define MC_PC          __pc
+diff --git a/arch/loongarch64/reloc.h b/arch/loongarch64/reloc.h
+new file mode 100644
+index 00000000..68212320
+--- /dev/null
++++ b/arch/loongarch64/reloc.h
+@@ -0,0 +1,20 @@
++#ifdef __loongarch_soft_float
++#define FP_SUFFIX "-sf"
++#else
++#define FP_SUFFIX ""
++#endif
++
++#define LDSO_ARCH "loongarch64"  FP_SUFFIX
++
++#define TPOFF_K         0
++
++#define REL_PLT         R_LARCH_JUMP_SLOT
++#define REL_COPY        R_LARCH_COPY
++#define REL_DTPMOD      R_LARCH_TLS_DTPMOD64
++#define REL_DTPOFF      R_LARCH_TLS_DTPREL64
++#define REL_TPOFF       R_LARCH_TLS_TPREL64
++#define REL_RELATIVE    R_LARCH_RELATIVE
++#define REL_SYMBOLIC    R_LARCH_64
++
++#define CRTJMP(pc,sp) __asm__ __volatile__( \
++	"move $sp, %1 ; jr %0" : : "r"(pc), "r"(sp) : "memory" )
+diff --git a/arch/loongarch64/syscall_arch.h b/arch/loongarch64/syscall_arch.h
+new file mode 100644
+index 00000000..4d5e1885
+--- /dev/null
++++ b/arch/loongarch64/syscall_arch.h
+@@ -0,0 +1,137 @@
++#define __SYSCALL_LL_E(x) (x)
++#define __SYSCALL_LL_O(x) (x)
++
++#define SYSCALL_CLOBBERLIST \
++	"$t0", "$t1", "$t2", "$t3", \
++	"$t4", "$t5", "$t6", "$t7", "$t8", "memory"
++
++static inline long __syscall0(long n)
++{
++	register long a7 __asm__("$a7") = n;
++	register long a0 __asm__("$a0");
++
++	__asm__ __volatile__ (
++		"syscall 0"
++		: "=r"(a0)
++		: "r"(a7)
++		: SYSCALL_CLOBBERLIST);
++	return a0;
++}
++
++static inline long __syscall1(long n, long a)
++{
++	register long a7 __asm__("$a7") = n;
++	register long a0 __asm__("$a0") = a;
++
++	__asm__ __volatile__ (
++		"syscall 0"
++		: "+r"(a0)
++		: "r"(a7)
++		: SYSCALL_CLOBBERLIST);
++	return a0;
++}
++
++static inline long __syscall2(long n, long a, long b)
++{
++	register long a7 __asm__("$a7") = n;
++	register long a0 __asm__("$a0") = a;
++	register long a1 __asm__("$a1") = b;
++
++	__asm__ __volatile__ (
++		"syscall 0"
++		: "+r"(a0)
++	        : "r"(a7), "r"(a1)
++		: SYSCALL_CLOBBERLIST);
++	return a0;
++}
++
++static inline long __syscall3(long n, long a, long b, long c)
++{
++	register long a7 __asm__("$a7") = n;
++	register long a0 __asm__("$a0") = a;
++	register long a1 __asm__("$a1") = b;
++	register long a2 __asm__("$a2") = c;
++
++	__asm__ __volatile__ (
++		"syscall 0"
++		: "+r"(a0)
++	        : "r"(a7), "r"(a1), "r"(a2)
++		: SYSCALL_CLOBBERLIST);
++	return a0;
++}
++
++static inline long __syscall4(long n, long a, long b, long c, long d)
++{
++	register long a7 __asm__("$a7") = n;
++	register long a0 __asm__("$a0") = a;
++	register long a1 __asm__("$a1") = b;
++	register long a2 __asm__("$a2") = c;
++	register long a3 __asm__("$a3") = d;
++
++	__asm__ __volatile__ (
++		"syscall 0"
++		: "+r"(a0)
++	        : "r"(a7), "r"(a1), "r"(a2), "r"(a3)
++		: SYSCALL_CLOBBERLIST);
++	return a0;
++}
++
++static inline long __syscall5(long n, long a, long b, long c, long d, long e)
++{
++	register long a7 __asm__("$a7") = n;
++	register long a0 __asm__("$a0") = a;
++	register long a1 __asm__("$a1") = b;
++	register long a2 __asm__("$a2") = c;
++	register long a3 __asm__("$a3") = d;
++	register long a4 __asm__("$a4") = e;
++
++	__asm__ __volatile__ (
++		"syscall 0"
++		: "+r"(a0)
++	        : "r"(a7), "r"(a1), "r"(a2), "r"(a3), "r"(a4)
++		: SYSCALL_CLOBBERLIST);
++	return a0;
++}
++
++static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
++{
++	register long a7 __asm__("$a7") = n;
++	register long a0 __asm__("$a0") = a;
++	register long a1 __asm__("$a1") = b;
++	register long a2 __asm__("$a2") = c;
++	register long a3 __asm__("$a3") = d;
++	register long a4 __asm__("$a4") = e;
++	register long a5 __asm__("$a5") = f;
++
++	__asm__ __volatile__ (
++		"syscall 0"
++		: "+r"(a0)
++	        : "r"(a7), "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5)
++		: SYSCALL_CLOBBERLIST);
++	return a0;
++}
++
++static inline long __syscall7(long n, long a, long b, long c, long d, long e, long f, long g)
++{
++	register long a7 __asm__("$a7") = n;
++	register long a0 __asm__("$a0") = a;
++	register long a1 __asm__("$a1") = b;
++	register long a2 __asm__("$a2") = c;
++	register long a3 __asm__("$a3") = d;
++	register long a4 __asm__("$a4") = e;
++	register long a5 __asm__("$a5") = f;
++	register long a6 __asm__("$a6") = g;
++
++	__asm__ __volatile__ (
++		"syscall 0"
++		: "+r"(a0)
++	        : "r"(a7), "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a6)
++		: SYSCALL_CLOBBERLIST);
++	return a0;
++}
++
++#define VDSO_USEFUL
++#define VDSO_CGT_SYM "__vdso_clock_gettime"
++#define VDSO_CGT_VER "LINUX_5.10"
++
++#define IPC_64  0
+diff --git a/configure b/configure
+index 853bf05e..4d2ecc9f 100755
+--- a/configure
++++ b/configure
+@@ -328,6 +328,7 @@ i?86*) ARCH=i386 ;;
+ x86_64-x32*|x32*|x86_64*x32) ARCH=x32 ;;
+ x86_64-nt64*) ARCH=nt64 ;;
+ x86_64*) ARCH=x86_64 ;;
++loongarch64*) ARCH=loongarch64 ;;
+ m68k*) ARCH=m68k ;;
+ mips64*|mipsisa64*) ARCH=mips64 ;;
+ mips*) ARCH=mips ;;
+@@ -658,6 +659,10 @@ if test "$ARCH" = "aarch64" ; then
+ trycppif __AARCH64EB__ "$t" && SUBARCH=${SUBARCH}_be
+ fi
+ 
++if test "$ARCH" = "loongarch64" ; then
++trycppif __loongarch_soft_float "$t" && SUBARCH=${SUBARCH}-sf
++fi
++
+ if test "$ARCH" = "m68k" ; then
+ if trycppif "__HAVE_68881__" ; then : ;
+ elif trycppif "__mcffpu__" ; then SUBARCH="-fp64"
+diff --git a/include/elf.h b/include/elf.h
+index 23f2c4bc..7114f262 100644
+--- a/include/elf.h
++++ b/include/elf.h
+@@ -315,7 +315,8 @@ typedef struct {
+ #define EM_RISCV	243
+ #define EM_BPF		247
+ #define EM_CSKY		252
+-#define EM_NUM		253
++#define EM_LOONGARCH	258
++#define EM_NUM		259
+ 
+ #define EM_ALPHA	0x9026
+ 
+@@ -699,6 +700,11 @@ typedef struct {
+ #define NT_MIPS_FP_MODE	0x801
+ #define NT_MIPS_MSA	0x802
+ #define NT_VERSION	1
++#define NT_LOONGARCH_CPUCFG	0xa00
++#define NT_LOONGARCH_CSR	0xa01
++#define NT_LOONGARCH_LSX	0xa02
++#define NT_LOONGARCH_LASX	0xa03
++#define NT_LOONGARCH_LBT	0xa04
+ 
+ 
+ 
+@@ -3293,6 +3299,102 @@ enum
+ #define R_RISCV_SET32           56
+ #define R_RISCV_32_PCREL        57
+ 
++#define EF_LARCH_ABI_MODIFIER_MASK    0x07
++#define EF_LARCH_ABI_SOFT_FLOAT       0x01
++#define EF_LARCH_ABI_SINGLE_FLOAT     0x02
++#define EF_LARCH_ABI_DOUBLE_FLOAT     0x03
++#define EF_LARCH_OBJABI_V1            0x40
++
++#define R_LARCH_NONE                        0
++#define R_LARCH_32                          1
++#define R_LARCH_64                          2
++#define R_LARCH_RELATIVE                    3
++#define R_LARCH_COPY                        4
++#define R_LARCH_JUMP_SLOT                   5
++#define R_LARCH_TLS_DTPMOD32                6
++#define R_LARCH_TLS_DTPMOD64                7
++#define R_LARCH_TLS_DTPREL32                8
++#define R_LARCH_TLS_DTPREL64                9
++#define R_LARCH_TLS_TPREL32                 10
++#define R_LARCH_TLS_TPREL64                 11
++#define R_LARCH_IRELATIVE                   12
++#define R_LARCH_MARK_LA                     20
++#define R_LARCH_MARK_PCREL                  21
++#define R_LARCH_SOP_PUSH_PCREL              22
++#define R_LARCH_SOP_PUSH_ABSOLUTE           23
++#define R_LARCH_SOP_PUSH_DUP                24
++#define R_LARCH_SOP_PUSH_GPREL              25
++#define R_LARCH_SOP_PUSH_TLS_TPREL          26
++#define R_LARCH_SOP_PUSH_TLS_GOT            27
++#define R_LARCH_SOP_PUSH_TLS_GD             28
++#define R_LARCH_SOP_PUSH_PLT_PCREL          29
++#define R_LARCH_SOP_ASSERT                  30
++#define R_LARCH_SOP_NOT                     31
++#define R_LARCH_SOP_SUB                     32
++#define R_LARCH_SOP_SL                      33
++#define R_LARCH_SOP_SR                      34
++#define R_LARCH_SOP_ADD                     35
++#define R_LARCH_SOP_AND                     36
++#define R_LARCH_SOP_IF_ELSE                 37
++#define R_LARCH_SOP_POP_32_S_10_5           38
++#define R_LARCH_SOP_POP_32_U_10_12          39
++#define R_LARCH_SOP_POP_32_S_10_12          40
++#define R_LARCH_SOP_POP_32_S_10_16          41
++#define R_LARCH_SOP_POP_32_S_10_16_S2       42
++#define R_LARCH_SOP_POP_32_S_5_20           43
++#define R_LARCH_SOP_POP_32_S_0_5_10_16_S2   44
++#define R_LARCH_SOP_POP_32_S_0_10_10_16_S2  45
++#define R_LARCH_SOP_POP_32_U                46
++#define R_LARCH_ADD8                        47
++#define R_LARCH_ADD16                       48
++#define R_LARCH_ADD24                       49
++#define R_LARCH_ADD32                       50
++#define R_LARCH_ADD64                       51
++#define R_LARCH_SUB8                        52
++#define R_LARCH_SUB16                       53
++#define R_LARCH_SUB24                       54
++#define R_LARCH_SUB32                       55
++#define R_LARCH_SUB64                       56
++#define R_LARCH_GNU_VTINHERIT               57
++#define R_LARCH_GNU_VTENTRY                 58
++#define R_LARCH_B16                         64
++#define R_LARCH_B21                         65
++#define R_LARCH_B26                         66
++#define R_LARCH_ABS_HI20                    67
++#define R_LARCH_ABS_LO12                    68
++#define R_LARCH_ABS64_LO20                  69
++#define R_LARCH_ABS64_HI12                  70
++#define R_LARCH_PCALA_HI20                  71
++#define R_LARCH_PCALA_LO12                  72
++#define R_LARCH_PCALA64_LO20                73
++#define R_LARCH_PCALA64_HI12                74
++#define R_LARCH_GOT_PC_HI20                 75
++#define R_LARCH_GOT_PC_LO12                 76
++#define R_LARCH_GOT64_PC_LO20               77
++#define R_LARCH_GOT64_PC_HI12               78
++#define R_LARCH_GOT_HI20                    79
++#define R_LARCH_GOT_LO12                    80
++#define R_LARCH_GOT64_LO20                  81
++#define R_LARCH_GOT64_HI12                  82
++#define R_LARCH_TLS_LE_HI20                 83
++#define R_LARCH_TLS_LE_LO12                 84
++#define R_LARCH_TLS_LE64_LO20               85
++#define R_LARCH_TLS_LE64_HI12               86
++#define R_LARCH_TLS_IE_PC_HI20              87
++#define R_LARCH_TLS_IE_PC_LO12              88
++#define R_LARCH_TLS_IE64_PC_LO20            89
++#define R_LARCH_TLS_IE64_PC_HI12            90
++#define R_LARCH_TLS_IE_HI20                 91
++#define R_LARCH_TLS_IE_LO12                 92
++#define R_LARCH_TLS_IE64_LO20               93
++#define R_LARCH_TLS_IE64_HI12               94
++#define R_LARCH_TLS_LD_PC_HI20              95
++#define R_LARCH_TLS_LD_HI20                 96
++#define R_LARCH_TLS_GD_PC_HI20              97
++#define R_LARCH_TLS_GD_HI20                 98
++#define R_LARCH_32_PCREL                    99
++#define R_LARCH_RELAX                       100
++
+ #ifdef __cplusplus
+ }
+ #endif
+diff --git a/src/fenv/loongarch64/fenv.S b/src/fenv/loongarch64/fenv.S
+new file mode 100644
+index 00000000..80e768ba
+--- /dev/null
++++ b/src/fenv/loongarch64/fenv.S
+@@ -0,0 +1,78 @@
++#ifndef __loongarch_soft_float
++
++#ifdef __clang__
++#define FCSR $fcsr0
++#else
++#define FCSR $r0
++#endif
++
++.global	feclearexcept
++.type   feclearexcept,@function
++feclearexcept:
++	li.w    $t0, 0x1f0000
++	and     $a0, $a0, $t0
++	movfcsr2gr $t1, FCSR
++	andn    $t1, $t1, $a0
++	movgr2fcsr FCSR, $t1
++	li.w    $a0, 0
++	jr      $ra
++
++.global	feraiseexcept
++.type   feraiseexcept,@function
++feraiseexcept:
++	li.w    $t0, 0x1f0000
++	and     $a0, $a0, $t0
++	movfcsr2gr $t1, FCSR
++	or      $t1, $t1, $a0
++	movgr2fcsr FCSR, $t1
++	li.w    $a0, 0
++	jr      $ra
++
++.global	fetestexcept
++.type   fetestexcept,@function
++fetestexcept:
++	li.w    $t0, 0x1f0000
++	and     $a0, $a0, $t0
++	movfcsr2gr $t1, FCSR
++	and     $a0, $t1, $a0
++	jr      $ra
++
++.global	fegetround
++.type   fegetround,@function
++fegetround:
++	movfcsr2gr $t0, FCSR
++	andi    $a0, $t0, 0x300
++	jr      $ra
++
++.global	__fesetround
++.hidden __fesetround
++.type   __fesetround,@function
++__fesetround:
++	li.w    $t0, 0x300
++	and     $a0, $a0, $t0
++	movfcsr2gr $t1, FCSR
++	andn    $t1, $t1, $t0
++	or      $t1, $t1, $a0
++	movgr2fcsr FCSR, $t1
++	li.w    $a0, 0
++	jr      $ra
++
++.global	fegetenv
++.type   fegetenv,@function
++fegetenv:
++	movfcsr2gr $t0, FCSR
++	st.w    $t0, $a0, 0
++	li.w    $a0, 0
++	jr      $ra
++
++.global	fesetenv
++.type   fesetenv,@function
++fesetenv:
++	addi.d  $t0, $a0, 1
++	beq     $t0, $r0, 1f
++	ld.w    $t0, $a0, 0
++1:	movgr2fcsr FCSR, $t0
++	li.w    $a0, 0
++	jr      $ra
++
++#endif
+diff --git a/src/ldso/loongarch64/dlsym.s b/src/ldso/loongarch64/dlsym.s
+new file mode 100644
+index 00000000..26fabcdb
+--- /dev/null
++++ b/src/ldso/loongarch64/dlsym.s
+@@ -0,0 +1,7 @@
++.global dlsym
++.hidden __dlsym
++.type   dlsym,@function
++dlsym:
++	move      $a2, $ra
++	la.global $t0, __dlsym
++	jr        $t0
+diff --git a/src/setjmp/loongarch64/longjmp.S b/src/setjmp/loongarch64/longjmp.S
+new file mode 100644
+index 00000000..896d2e26
+--- /dev/null
++++ b/src/setjmp/loongarch64/longjmp.S
+@@ -0,0 +1,32 @@
++.global _longjmp
++.global longjmp
++.type   _longjmp,@function
++.type   longjmp,@function
++_longjmp:
++longjmp:
++	ld.d    $ra, $a0, 0
++	ld.d    $sp, $a0, 8
++	ld.d    $r21,$a0, 16
++	ld.d    $fp, $a0, 24
++	ld.d    $s0, $a0, 32
++	ld.d    $s1, $a0, 40
++	ld.d    $s2, $a0, 48
++	ld.d    $s3, $a0, 56
++	ld.d    $s4, $a0, 64
++	ld.d    $s5, $a0, 72
++	ld.d    $s6, $a0, 80
++	ld.d    $s7, $a0, 88
++	ld.d    $s8, $a0, 96
++#ifndef __loongarch_soft_float
++	fld.d   $fs0, $a0, 104
++	fld.d   $fs1, $a0, 112
++	fld.d   $fs2, $a0, 120
++	fld.d   $fs3, $a0, 128
++	fld.d   $fs4, $a0, 136
++	fld.d   $fs5, $a0, 144
++	fld.d   $fs6, $a0, 152
++	fld.d   $fs7, $a0, 160
++#endif
++	sltui   $a0, $a1, 1
++	add.d   $a0, $a0, $a1
++	jr      $ra
+diff --git a/src/setjmp/loongarch64/setjmp.S b/src/setjmp/loongarch64/setjmp.S
+new file mode 100644
+index 00000000..d158a3d2
+--- /dev/null
++++ b/src/setjmp/loongarch64/setjmp.S
+@@ -0,0 +1,34 @@
++.global __setjmp
++.global _setjmp
++.global setjmp
++.type __setjmp,@function
++.type _setjmp,@function
++.type setjmp,@function
++__setjmp:
++_setjmp:
++setjmp:
++	st.d    $ra, $a0, 0
++	st.d    $sp, $a0, 8
++	st.d    $r21,$a0, 16
++	st.d    $fp, $a0, 24
++	st.d    $s0, $a0, 32
++	st.d    $s1, $a0, 40
++	st.d    $s2, $a0, 48
++	st.d    $s3, $a0, 56
++	st.d    $s4, $a0, 64
++	st.d    $s5, $a0, 72
++	st.d    $s6, $a0, 80
++	st.d    $s7, $a0, 88
++	st.d    $s8, $a0, 96
++#ifndef __loongarch_soft_float
++	fst.d   $fs0, $a0, 104
++	fst.d   $fs1, $a0, 112
++	fst.d   $fs2, $a0, 120
++	fst.d   $fs3, $a0, 128
++	fst.d   $fs4, $a0, 136
++	fst.d   $fs5, $a0, 144
++	fst.d   $fs6, $a0, 152
++	fst.d   $fs7, $a0, 160
++#endif
++	move    $a0, $zero
++	jr      $ra
+diff --git a/src/signal/loongarch64/restore.s b/src/signal/loongarch64/restore.s
+new file mode 100644
+index 00000000..f8e6daeb
+--- /dev/null
++++ b/src/signal/loongarch64/restore.s
+@@ -0,0 +1,10 @@
++.global	__restore_rt
++.global	__restore
++.hidden __restore_rt
++.hidden __restore
++.type   __restore_rt,@function
++.type   __restore,@function
++__restore_rt:
++__restore:
++	li.w    $a7, 139
++	syscall	0
+diff --git a/src/signal/loongarch64/sigsetjmp.s b/src/signal/loongarch64/sigsetjmp.s
+new file mode 100644
+index 00000000..992ab1a4
+--- /dev/null
++++ b/src/signal/loongarch64/sigsetjmp.s
+@@ -0,0 +1,25 @@
++.global sigsetjmp
++.global __sigsetjmp
++.type sigsetjmp,@function
++.type __sigsetjmp,@function
++sigsetjmp:
++__sigsetjmp:
++	beq     $a1, $zero, 1f
++	st.d    $ra, $a0, 168
++	st.d    $s0, $a0, 176
++	move    $s0, $a0
++
++	la.global  $t0, setjmp
++	jirl       $ra, $t0, 0
++
++	move    $a1, $a0        # Return from 'setjmp' or 'longjmp'
++	move    $a0, $s0
++	ld.d    $ra, $a0, 168
++	ld.d    $s0, $a0, 176
++
++.hidden __sigsetjmp_tail
++	la.global  $t0, __sigsetjmp_tail
++	jr         $t0
++1:
++	la.global  $t0, setjmp
++	jr         $t0
+diff --git a/src/thread/loongarch64/__set_thread_area.s b/src/thread/loongarch64/__set_thread_area.s
+new file mode 100644
+index 00000000..ffdd52f1
+--- /dev/null
++++ b/src/thread/loongarch64/__set_thread_area.s
+@@ -0,0 +1,7 @@
++.global	__set_thread_area
++.hidden __set_thread_area
++.type   __set_thread_area,@function
++__set_thread_area:
++	move $tp, $a0
++	move $a0, $zero
++	jr   $ra
+diff --git a/src/thread/loongarch64/__unmapself.s b/src/thread/loongarch64/__unmapself.s
+new file mode 100644
+index 00000000..1de334af
+--- /dev/null
++++ b/src/thread/loongarch64/__unmapself.s
+@@ -0,0 +1,7 @@
++.global	__unmapself
++.type   __unmapself, @function
++__unmapself:
++	li.d    $a7, 215   # call munmap
++	syscall	0
++	li.d    $a7, 93    # call exit
++	syscall	0
+diff --git a/src/thread/loongarch64/clone.s b/src/thread/loongarch64/clone.s
+new file mode 100644
+index 00000000..db9015e6
+--- /dev/null
++++ b/src/thread/loongarch64/clone.s
+@@ -0,0 +1,28 @@
++#__clone(func, stack, flags, arg, ptid, tls, ctid)
++#         a0,    a1,   a2,    a3,  a4,  a5,   a6
++# sys_clone(flags, stack, ptid, ctid, tls)
++#            a0,    a1,   a2,    a3,  a4
++
++.global	__clone
++.hidden __clone
++.type __clone,@function
++__clone:
++	# Save function pointer and argument pointer on new thread stack
++	addi.d  $a1, $a1, -16
++	st.d    $a0, $a1, 0     # save function pointer
++	st.d    $a3, $a1, 8     # save argument pointer
++	or      $a0, $a2, $zero
++	or      $a2, $a4, $zero
++	or      $a3, $a6, $zero
++	or      $a4, $a5, $zero
++	ori     $a7, $zero, 220
++	syscall 0               # call clone
++
++	beqz    $a0, 1f         # whether child process
++	jirl    $zero, $ra, 0   # parent process return
++1:
++	ld.d    $t8, $sp, 0     # function pointer
++	ld.d    $a0, $sp, 8     # argument pointer
++	jirl    $ra, $t8, 0     # call the user's function
++	ori     $a7, $zero, 93
++	syscall	0               # child process exit
+diff --git a/src/thread/loongarch64/syscall_cp.s b/src/thread/loongarch64/syscall_cp.s
+new file mode 100644
+index 00000000..0fbc7a47
+--- /dev/null
++++ b/src/thread/loongarch64/syscall_cp.s
+@@ -0,0 +1,29 @@
++.global	__cp_begin
++.hidden	__cp_begin
++.global	__cp_end
++.hidden	__cp_end
++.global	__cp_cancel
++.hidden	__cp_cancel
++.hidden	__cancel
++.global	__syscall_cp_asm
++.hidden	__syscall_cp_asm
++.type   __syscall_cp_asm,@function
++
++__syscall_cp_asm:
++__cp_begin:
++	ld.w $a0, $a0, 0
++	bnez $a0, __cp_cancel
++	move $t8, $a1    # reserve system call number
++	move $a0, $a2
++	move $a1, $a3
++	move $a2, $a4
++	move $a3, $a5
++	move $a4, $a6
++	move $a5, $a7
++	move $a7, $t8
++	syscall	0
++__cp_end:
++	jr $ra
++__cp_cancel:
++	la.local $t8, __cancel
++	jr $t8
+-- 
+2.31.1
+
diff --git a/scripts/build b/scripts/build
new file mode 100755
index 0000000..1b19f3c
--- /dev/null
+++ b/scripts/build
@@ -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};
diff --git a/scripts/buildall b/scripts/buildall
new file mode 100755
index 0000000..bae4c0e
--- /dev/null
+++ b/scripts/buildall
@@ -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";
diff --git a/scripts/buildallcross b/scripts/buildallcross
new file mode 100755
index 0000000..abc915d
--- /dev/null
+++ b/scripts/buildallcross
@@ -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";
diff --git a/scripts/buildallmac b/scripts/buildallmac
new file mode 100755
index 0000000..621ec6b
--- /dev/null
+++ b/scripts/buildallmac
@@ -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;
diff --git a/scripts/buildcross b/scripts/buildcross
new file mode 100755
index 0000000..2afe70d
--- /dev/null
+++ b/scripts/buildcross
@@ -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};
diff --git a/scripts/buildmac b/scripts/buildmac
new file mode 100755
index 0000000..2acbed6
--- /dev/null
+++ b/scripts/buildmac
@@ -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};
diff --git a/scripts/macsimum b/scripts/macsimum
new file mode 100755
index 0000000..6a3a306
--- /dev/null
+++ b/scripts/macsimum
@@ -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;
diff --git a/scripts/matrix b/scripts/matrix
new file mode 100755
index 0000000..36cf00e
--- /dev/null
+++ b/scripts/matrix
@@ -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
diff --git a/scripts/sinner b/scripts/sinner
new file mode 100755
index 0000000..6bcaf08
--- /dev/null
+++ b/scripts/sinner
@@ -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.
+
diff --git a/scripts/triples.txt b/scripts/triples.txt
new file mode 100644
index 0000000..bffba73
--- /dev/null
+++ b/scripts/triples.txt
@@ -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
diff --git a/scripts/winner b/scripts/winner
new file mode 100755
index 0000000..0bfbf19
--- /dev/null
+++ b/scripts/winner
@@ -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.
+