logo

bootstrap-initrd

Linux initrd to bootstrap from a small binary seed git clone https://hacktivis.me/git/make-initrd.git
commit: 47ee008304e9362601b2be7addb63f8e3b38aa1f
parent 10ab63e45859c1c5e20e1a6152a0482c1b5da8e1
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri,  3 May 2024 16:15:27 +0200

Turns out tcc can work as an ar(1), just needs a wrapper

Diffstat:

MREADME.md5+++++
Aar-stub.sh3+++
Mdistfiles.SHA512SUM1-
Mfetch.sh1-
Minit.sh11++++++-----
Mmake-root.sh21+++++----------------
6 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/README.md b/README.md @@ -25,8 +25,13 @@ The reason to not pick Guile+MesCC instead is because I find Guile Scheme to be Need a libc to start somewhere, tryhards could maybe compile it from source with TCC to reduce the seed further but this hasn't been tried. It's `libc.a` is removed, to shave off 9.1MB from the binary seed, going from 11MB total to 1.2MB total, you're likely going to rebuild musl anyway since this is a sort of stage0. +### TCC as ar(1) implementation +Meanwhile: +- Binutils: 300+ MiB repository of sources, generated artifacts frequently over 1MB, and test fixtures also often over 1MB. Nope. + ### loksh Linux/portable-port of OpenBSD Korn Shell, buildable with only a C compiler while being nicely complete (maybe even too much). + Meanwhile: - mrsh: Too incomplete for actual use, but trivial to build with only a C Compiler - heirloom-sh: Also buildable with only a C Compiler but fails to allocate memory at launch diff --git a/ar-stub.sh b/ar-stub.sh @@ -0,0 +1,3 @@ +#!/bin/sh +# tcc -ar [crstvx] lib [files] +exec tcc -ar "$@" diff --git a/distfiles.SHA512SUM b/distfiles.SHA512SUM @@ -1,4 +1,3 @@ -1e4ee462513eadd3c540e4782f9661df62ecbcd4d6297d61dcc0845ae7d30243c57571787706af3bb4d561e4350609d7057307290e81d76290a301f159a6abc5 distfiles/binutils-2.42.tar.gz 50622aee8024b3e0385974a8f446a4b5df0ba494b6133ab91ebbe63c408154b112f62c9df8521f4f1beaf28cdd6e7da178c3334337f6b14c8bced532029d8ba5 distfiles/bmake-20230909.tar.gz 083f5e675d73f3233c7930ebe20425a533feedeaaa9d8cc86831312a6581cefbe6ed0d08d2fa89be81082f2a5abdabca8b3c080bf97218a1bd59dc118a30b9f3 distfiles/bzip2-1.0.8.tar.gz 0b30b0f4c4c92a10ee2da263ea44666f445d96bac86ca4afb7bbb50d8278986e4145a7bcdf3ed9f75611bb956e93e16fc0e19874498ce3ae1a00e6fbb4f910c9 distfiles/heirloom-070715.tar.bz2 diff --git a/fetch.sh b/fetch.sh @@ -10,7 +10,6 @@ URLS=" https://www.zlib.net/pigz/pigz-2.8.tar.gz https://downloads.sourceforge.net/heirloom/heirloom/070715/heirloom-070715.tar.bz2 https://downloads.sourceforge.net/project/heirloom/heirloom-devtools/070527/heirloom-devtools-070527.tar.bz2 - https://sourceware.org/pub/binutils/releases/binutils-2.42.tar.gz " WORKDIR="$(dirname "$0")" diff --git a/init.sh b/init.sh @@ -82,19 +82,19 @@ build_hierloom_devtools() { for cmd in lex m4 do bmake "$cmd/Makefile" - bmake AR=true RANLIB=true -C "$cmd" - bmake AR=true RANLIB=true -C "$cmd" install + bmake RANLIB=true -C "$cmd" + bmake RANLIB=true -C "$cmd" install done } build_hierloom() { cd /heirloom-0*/ mkdir -p /usr/5bin /usr/5lib /etc/default - for cmd in diff tar + for cmd in libcommon diff tar do bmake "$cmd/Makefile" - bmake CC=$CC -C "$cmd" - bmake CC=$CC -C "$cmd" install + bmake CC=$CC AR="ar" RANLIB=true -C "$cmd" + bmake CC=$CC AR="ar" RANLIB=true -C "$cmd" install done } @@ -113,6 +113,7 @@ profile_export PATH="$PATH:$PWD/cmd/" profile_export YACC="yacc" profile_export STRIP="true" profile_export INSTALL="install" +profile_export AR="ar" # re-export due to prior lack of echo profile_export CC="$CC" profile_export CFLAGS="$CFLAGS" diff --git a/make-root.sh b/make-root.sh @@ -55,16 +55,6 @@ for i in $tarballs; do done rm yacc-1.9.1/yacc || die -# This way you go from 300+ MiB extracted to ~110.4 MiB. -# Not exactly something I'd call reviewable but still much better, -# could likely shave off ~20 MiB with generated files like removing -# the 2.2MiB Makefile.in at the root but I'd need to build autotools -# and then hope it regenerates somewhat similar files… -tar xf "${WORKDIR}/distfiles/binutils-2.42.tar.gz" \ - --exclude binutils-2.42/gas \ - --exclude binutils-2.42/zlib \ - --exclude testsuite \ - --exclude po || die "Failed extracting binutils-2.42.tar.gz" deblob @@ -85,6 +75,7 @@ for i in init.sh ls-stub.c mv-stub.c grep-stub.c cp-stub.c do cp -p "${WORKDIR}/$i" ./ || die "failed copying $i" done +cp -p "${WORKDIR}/ar-stub.sh" ./bin/ar for apk in $APKS_main $APKS_testing do @@ -120,13 +111,10 @@ sed -i \ heirloom-devtools-*/mk.config \ || die "Failed configuring heirloom-devtools" -sed -i -e '/$(LIBDIR)\/libl.a/d' heirloom-devtools-*/lex/Makefile.mk || die "Failed disabling static lib lex" - -patch -p0 <"${WORKDIR}/heirloom-070715-diff-no-AR.patch" || die - -# - Replace LCOMMON as we don't have AR yet # - maninst Fails to create parent dir, just noop it, we don't have man anyway # -e 's;MANINST =.*;MANINST = $(SHELL) ../build/maninst.sh;' \ +# - Turns out tcc comes with an ar(1) +# -e 's;LCOMMON =.*;LCOMMON = ../libcommon/*.c;' \ sed -i \ -e 's;DEFBIN =.*;DEFBIN = /bin;' \ -e 's;DEFSBIN =.*;DEFSBIN = /bin;' \ @@ -134,7 +122,6 @@ sed -i \ -e 's;SPELLHIST =.*;SPELLHIST = /dev/null;' \ -e 's;UCBINST =.*;UCBINST = install;' \ -e 's;MANINST =.*;MANINST = true;' \ - -e 's;LCOMMON =.*;LCOMMON = ../libcommon/*.c;' \ heirloom-0*/build/mk.config \ || die "Failed configuring heirloom (toolchest)" @@ -148,6 +135,8 @@ sed -i \ -e '/static int utf8/avoid writerr(struct oblok *op, int count, int written) {}' \ heirloom-070715/tar/tar.c || die "Failed fixing heirloom libcommon for musl" +sed -i -e 's;libwchar.a: fake;libwchar.a:;' heirloom-070715/libwchar/Makefile.mk || die + deblob -n | tee /dev/stderr | awk '/detected: /{ print $2 }' | xargs du -bach | sort -h cd "${WORKDIR}"