logo

bootstrap-initrd

Linux initrd to bootstrap from a small binary seed git clone https://hacktivis.me/git/make-initrd.git
commit: 7dc2f1c40a13673031f23dc59ee804d6c73ff457
parent 19d388c6f1b435706d8e86ca02264dd37aba5035
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 30 Apr 2024 11:20:07 +0200

Add zlib-1.3.1

Diffstat:

MREADME.md3+++
Minit.sh8++++++++
Mmake-root.sh5+++++
Azlib-1.3.1-use-LDFLAGS-in-configure.patch74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Azlib-1.3.1-use-LDFLAGS-in-configure_no_gcc.patch67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Azlib-1.3.1_no_staticlib.patch44++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 201 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -55,6 +55,9 @@ Builds with C Compiler + bmake. Meanwhile: - pbzip2: Requires C++ compiler +### zlib +Simple albeit slightly broken `./configure` script (see patches). + ## Launching in QEMU ``` $ qemu-system-x86_64 -enable-kvm -cpu host -m 1536 -kernel /boot/vmlinuz-6.6.21-gentoo -initrd /tmp/initramfs-tcc.cpio.xz -append 'init=/init console=ttyS0 panic=1' -nographic -no-reboot diff --git a/init.sh b/init.sh @@ -61,6 +61,12 @@ build_bzip2() { ln -s bzip2 /bin/bzcat } +build_zlib_libs() { + cd /zlib-*/ + ./configure + bmake install +} + set -ex -o pipefail export CC=tcc @@ -102,6 +108,8 @@ build_bmake build_bzip2 +build_zlib_libs + cd / rescueshell diff --git a/make-root.sh b/make-root.sh @@ -13,6 +13,7 @@ tarballs=" nawk-20240422.tar.gz loksh-7.3.tar.xz bzip2-1.0.8.tar.gz + zlib-1.3.1.tar.xz " WORKDIR="$(pwd)" name_base="initramfs-tcc" @@ -95,6 +96,10 @@ gen_loksh_tcc_h > loksh_tcc.h sed -i -e 's;bzip2-shared;bzip2;' bzip2-*/Makefile-libbz2_so || die "Failed patching /bzip2-*/Makefile-libbz2_so" sed -i -e 's;all: libbz2.a;all: libbz2.so;' -e 's;bzip2: libbz2.a;bzip2: libbz2.so;' bzip2-*/Makefile || die "Failed patching /bzip2-*/Makefile" +patch -p0 <"${WORKDIR}/zlib-1.3.1_no_staticlib.patch" +patch -p0 <"${WORKDIR}/zlib-1.3.1-use-LDFLAGS-in-configure.patch" +patch -p0 <"${WORKDIR}/zlib-1.3.1-use-LDFLAGS-in-configure_no_gcc.patch" + deblob -n cd "${WORKDIR}" diff --git a/zlib-1.3.1-use-LDFLAGS-in-configure.patch b/zlib-1.3.1-use-LDFLAGS-in-configure.patch @@ -0,0 +1,74 @@ +https://github.com/madler/zlib/pull/599 + +Rebased version of: + +From 37c9730ba474d274f4cc6a974943eef95087b9f6 Mon Sep 17 00:00:00 2001 +From: Khem Raj <raj.khem@gmail.com> +Date: Tue, 8 Mar 2022 22:38:47 -0800 +Subject: [PATCH] configure: Pass LDFLAGS to link tests + +LDFLAGS can contain critical flags without which linking wont succeed +therefore ensure that all configure tests involving link time checks are +using LDFLAGS on compiler commandline along with CFLAGS to ensure the +tests perform correctly. Without this some tests may fail resulting in +wrong confgure result, ending in miscompiling the package + +Signed-off-by: Khem Raj <raj.khem@gmail.com>k +--- zlib-1.3.1/configure ++++ zlib-1.3.1/configure +@@ -448,8 +448,8 @@ EOF + if test $shared -eq 1; then + echo Checking for shared library support... | tee -a configure.log + # we must test in two steps (cc then ld), required at least on SunOS 4.x +- if try $CC -c $SFLAGS $test.c && +- try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then ++ if try $CC -c $SFLAGS $LDFLAGS $test.c && ++ try $LDSHARED $SFLAGS $LDFLAGS -o $test$shared_ext $test.o; then + echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log + elif test -z "$old_cc" -a -z "$old_cflags"; then + echo No shared library support. | tee -a configure.log +@@ -511,7 +511,7 @@ int main(void) { + } + EOF + fi +- if try $CC $CFLAGS -o $test $test.c; then ++ if try $CC $CFLAGS $LDFLAGS -o $test $test.c; then + sizet=`./$test` + echo "Checking for a pointer-size integer type..." $sizet"." | tee -a configure.log + CFLAGS="${CFLAGS} -DNO_SIZE_T=${sizet}" +@@ -545,7 +545,7 @@ int main(void) { + return 0; + } + EOF +- if try $CC $CFLAGS -o $test $test.c; then ++ if try $CC $CFLAGS $LDFLAGS -o $test $test.c; then + echo "Checking for fseeko... Yes." | tee -a configure.log + else + CFLAGS="${CFLAGS} -DNO_FSEEKO" +@@ -562,7 +562,7 @@ cat > $test.c <<EOF + #include <errno.h> + int main() { return strlen(strerror(errno)); } + EOF +-if try $CC $CFLAGS -o $test $test.c; then ++if try $CC $CFLAGS $LDFLAGS -o $test $test.c; then + echo "Checking for strerror... Yes." | tee -a configure.log + else + CFLAGS="${CFLAGS} -DNO_STRERROR" +@@ -669,7 +669,7 @@ int main() + return (mytest("Hello%d\n", 1)); + } + EOF +- if try $CC $CFLAGS -o $test $test.c; then ++ if try $CC $CFLAGS $LDFLAGS -o $test $test.c; then + echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log + + echo >> configure.log +@@ -759,7 +759,7 @@ int main() + } + EOF + +- if try $CC $CFLAGS -o $test $test.c; then ++ if try $CC $CFLAGS $LDFLAGS -o $test $test.c; then + echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log + + echo >> configure.log diff --git a/zlib-1.3.1-use-LDFLAGS-in-configure_no_gcc.patch b/zlib-1.3.1-use-LDFLAGS-in-configure_no_gcc.patch @@ -0,0 +1,67 @@ +--- zlib-1.3.1/configure.old 2024-04-30 11:16:05.383361503 +0200 ++++ zlib-1.3.1/configure 2024-04-30 11:16:13.685327393 +0200 +@@ -299,25 +299,25 @@ + esac ;; + IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."} + CFLAGS=${CFLAGS-"-ansi -O2"} +- LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;; ++ LDSHARED=${LDSHARED-"$CC -shared -Wl,-soname,libz.so.1"} ;; + OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"} + CFLAGS=${CFLAGS-"-O -std1"} + LDFLAGS="${LDFLAGS} -Wl,-rpath,." +- LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;; ++ LDSHARED=${LDSHARED-"$CC -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;; + OSF1*) SFLAGS=${CFLAGS-"-O -std1"} + CFLAGS=${CFLAGS-"-O -std1"} +- LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;; ++ LDSHARED=${LDSHARED-"$CC -shared -Wl,-soname,libz.so.1"} ;; + QNX*) SFLAGS=${CFLAGS-"-4 -O"} + CFLAGS=${CFLAGS-"-4 -O"} +- LDSHARED=${LDSHARED-"cc"} ++ LDSHARED=${LDSHARED-"$CC"} + RANLIB=${RANLIB-"true"} + AR="cc" + ARFLAGS="-A" ;; + SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "} + CFLAGS=${CFLAGS-"-O3"} +- LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;; ++ LDSHARED=${LDSHARED-"$CC -dy -KPIC -G"} ;; + SunOS\ 5* | solaris*) +- LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"} ++ LDSHARED=${LDSHARED-"$CC -G -h libz$shared_ext.$VER1"} + SFLAGS=${CFLAGS-"-fast -KPIC"} + CFLAGS=${CFLAGS-"-fast"} + if test $build64 -eq 1; then +@@ -347,19 +347,19 @@ + LDSHARED=${LDSHARED-"ld"} ;; + SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"} + CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"} +- LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;; ++ LDSHARED=${LDSHARED-"$CC -xarch=v9b"} ;; + UNIX_System_V\ 4.2.0) + SFLAGS=${CFLAGS-"-KPIC -O"} + CFLAGS=${CFLAGS-"-O"} +- LDSHARED=${LDSHARED-"cc -G"} ;; ++ LDSHARED=${LDSHARED-"$CC -G"} ;; + UNIX_SV\ 4.2MP) + SFLAGS=${CFLAGS-"-Kconform_pic -O"} + CFLAGS=${CFLAGS-"-O"} +- LDSHARED=${LDSHARED-"cc -G"} ;; ++ LDSHARED=${LDSHARED-"$CC -G"} ;; + OpenUNIX\ 5) + SFLAGS=${CFLAGS-"-KPIC -O"} + CFLAGS=${CFLAGS-"-O"} +- LDSHARED=${LDSHARED-"cc -G"} ;; ++ LDSHARED=${LDSHARED-"$CC -G"} ;; + AIX*) # Courtesy of dbakker@arrayasolutions.com + SFLAGS=${CFLAGS-"-O -qmaxmem=8192"} + CFLAGS=${CFLAGS-"-O -qmaxmem=8192"} +@@ -367,7 +367,7 @@ + # send working options for other systems to zlib@gzip.org + *) SFLAGS=${CFLAGS-"-O"} + CFLAGS=${CFLAGS-"-O"} +- LDSHARED=${LDSHARED-"cc -shared"} ;; ++ LDSHARED=${LDSHARED-"$CC -shared"} ;; + esac + fi + diff --git a/zlib-1.3.1_no_staticlib.patch b/zlib-1.3.1_no_staticlib.patch @@ -0,0 +1,44 @@ +--- zlib-1.3.1/Makefile.in ++++ zlib-1.3.1/Makefile.in +@@ -30,7 +30,7 @@ STATICLIB=libz.a + SHAREDLIB=libz.so + SHAREDLIBV=libz.so.1.3.1 + SHAREDLIBM=libz.so.1 +-LIBS=$(STATICLIB) $(SHAREDLIBV) ++LIBS=$(SHAREDLIBV) + + AR=ar + ARFLAGS=rc +@@ -69,7 +69,7 @@ OBJS = $(OBJC) $(OBJA) + + PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA) + +-all: static shared ++all: shared + + static: example$(EXE) minigzip$(EXE) + +@@ -274,7 +274,7 @@ gzwrite.lo: $(SRCDIR)gzwrite.c + -@mv objs/gzwrite.o $@ + + +-placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a ++placebo $(SHAREDLIBV): $(PIC_OBJS) + $(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) $(LDSHAREDLIBC) $(LDFLAGS) + rm -f $(SHAREDLIB) $(SHAREDLIBM) + ln -s $@ $(SHAREDLIB) +@@ -305,10 +305,10 @@ install-libs: $(LIBS) + -@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi + -@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi + -@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi +- rm -f $(DESTDIR)$(libdir)/$(STATICLIB) +- cp $(STATICLIB) $(DESTDIR)$(libdir) +- chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB) +- -@($(RANLIB) $(DESTDIR)$(libdir)/libz.a || true) >/dev/null 2>&1 ++ #rm -f $(DESTDIR)$(libdir)/$(STATICLIB) ++ #cp $(STATICLIB) $(DESTDIR)$(libdir) ++ #chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB) ++ #-@($(RANLIB) $(DESTDIR)$(libdir)/libz.a || true) >/dev/null 2>&1 + -@if test -n "$(SHAREDLIBV)"; then \ + rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \ + cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir); \