commit: 8e571d8c2e94cdbdf81f079be352461cf7b7b2f6
parent 8cc2769f2a299cd355ce18556a3fdee1b8b6ef74
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Mon, 30 Dec 2024 09:12:22 +0100
switch to ibara port of OpenBSD ksh
Diffstat:
7 files changed, 53 insertions(+), 41 deletions(-)
diff --git a/README.md b/README.md
@@ -46,10 +46,12 @@ It's `libc.a` is removed, to shave off 9.1MB from the binary seed, going from 11
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).
+### OpenBSD ksh
+Portable version done by Dr. Brian Robert Callahan aka ibara@, of OpenBSD.
+Buildable with only a C compiler while being nicely complete (maybe even too much).
Meanwhile:
+- loksh: similar port but header names overrides the libc ones
- 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
- bash, yash: autoconf, so needs an existing shell
@@ -58,7 +60,7 @@ Meanwhile:
- AT&T ksh: Way too big to even try, might as well try Perl
### OpenBSD yacc
-Portable version done by Dr. Brian Robert Callahan aka ibara, of OpenBSD.
+Portable version done by Dr. Brian Robert Callahan aka ibara@, of OpenBSD.
Uses a BSD-style configure script, trivial to diff between versions and adjust hardcoded compiler flags (no utilities to run said script yet).
diff --git a/distfiles.SHA512SUM b/distfiles.SHA512SUM
@@ -14,8 +14,6 @@ e347a10cc737477353a9417473c5b40c864b3f631708eb8d169823814879b976cebcb80a47808d53
9dec4551e3d95186d56d346134e6dc8206be5c8efa850dd3bddc31c4afdddd1d4b745d87435ab95932b3a850d7a607955f209d2d795573344bac26edb8871cb7 distfiles/linux-headers-6.6-r1.apk.riscv64
6efd805a27b331ebc3aa2d1be714675a4c6c57364d9810c9fbad040f46d29bab6810067fc869920bd5158804fec684d0dcc5942a48049ce6367a4a570d68ddd1 distfiles/linux-headers-6.6-r1.apk.x86
70cad53b5b999cddc7c64488da4207cf71335bdf9b0f8e60de523104160d736511b82497f3287a248ca9af53adb57a952a180c77dd3b2e654b38690674c497d7 distfiles/linux-headers-6.6-r1.apk.x86_64
-75e979e13f321eab4598cb95c1023ea4512a5a2a2dc0b3ba31e4531e8258fa17e34374ef2bc4f24c669cf3a459e446ab818ebb12219b5fecbd36ae5f9f5d7663 distfiles/loksh-7.6.tar.gz
-571dbc55587dc30338731d4e3b29198bc0e40d7970fec949de01b88e4d9abedf628d4c216325eede9475c85c4816c977549d36ba4a8a8281a04d165dbcdc4fec distfiles/lolibc-96b2b7e.tar.gz
d90c6903355ee1309cb0d92a8a024522ff049091a117ea21efb585b5de35776191cd67d17a65b18c2f9d374795b7c944f047576f0e3fe818d094b26f0e4845c5 distfiles/lua-5.4.6.tar.gz
145260cbd6a8226cef3dfef0c8baba31847beaebc7e6b65d39d02715fd4f4cab9b139b6c3772e550088d4f9ae80c6d3ed20b9a7664c693644dfb96b4cb60e67c distfiles/make-4.4.1.tar.gz
4435fac14887f12ba429099f8ad9c9215a6fc3966a5f836a48684ecdd2fa38ccbcdaf363af7e8397b4dc741b92fad0998179919e12fc5c0404b914370db13f1b distfiles/mdevd-0.1.6.4.tar.gz
@@ -38,6 +36,7 @@ d3df9a8bb1a5b61cc84f805e0e1926dd52fae77929b5839ffe37c694a7a494728166aff52a37b3ce
4f7a8f664ac3bb7880600f050c63809e3455db3de3b9ef228b690cec919c510d8f557c8788b010cd9e5ca9f07292031767526542cfdaa2b13bf626a1c36ad5a4 distfiles/musl-libintl-1.2.5-r8.apk.x86
dbb7e665e5a8a13a6b2da4fb1ac89a7a8fcbb8e5edc6890c55a19aa82b21f3133c0eb36b2022af97542682cd6e7416ef10be5261cd0ec2fe47ccd8d2cbfd6df5 distfiles/musl-libintl-1.2.5-r8.apk.x86_64
2d5168664a721b866dd04259bf55138fd51c7934c46829c8cb63f50a15f62c93f83479d707292408f8eeaf9caf16a38cc7f65d5c0c59e4416dcd624a3428df6a distfiles/nawk-20240728.tar.gz
+934099408667070537c7e92eafd3a63956959a987f08f77f33968b6890142aa07381678381a5fc69033e3c279ca2603ad0507a6c34beba85d87ce38904acd090 distfiles/oksh-7.6.tar.gz
b2ea989baed5e2328c6957b940744c82fa2d8bbf541418fcb6bd3fe49192242dc38ee9f2d20cc1b0e9de967c17a5f46d5c5e0a16701504d83f76a8b5586860df distfiles/pdpmake-2.0.1.tgz
ae3d9d593e1645d65f9ab77aa828600c9af4bb30d0a073da7ae3dd805e65b87efaf6a0efb980f2d0168e475ae506eba194547d6479956dabb9d88293a9078a7f distfiles/pigz-2.8.tar.gz
0759e63b9bfdc1e0b2f95e4c5c7be24b4ffa22e06a08cfad7f8e8be9faf99c256b1cbc72159e4ec805791d6b507a80fc344d05d63a1d273c3285dac868bf6ca0 distfiles/pkgconf-pkgconf-2.3.0.tar.gz
diff --git a/fetch.sh b/fetch.sh
@@ -57,8 +57,7 @@ test -e lanodan-2024.pub || curl ${CURL_OPTS} -o lanodan-2024.pub https://hackti
test -e nawk-20240728.tar.gz || curl ${CURL_OPTS} -o nawk-20240728.tar.gz https://github.com/onetrueawk/awk/archive/20240728.tar.gz
-test -e loksh-7.6.tar.gz || curl ${CURL_OPTS} -o loksh-7.6.tar.gz https://github.com/dimkr/loksh/archive/refs/tags/7.6.tar.gz
-test -e lolibc-96b2b7e.tar.gz || curl ${CURL_OPTS} -o lolibc-96b2b7e.tar.gz https://github.com/dimkr/lolibc/archive/96b2b7e.tar.gz
+test -e oksh-7.6.tar.gz || curl ${CURL_OPTS} -o oksh-7.6.tar.gz https://github.com/ibara/oksh/archive/refs/tags/oksh-7.6.tar.gz
test -e yacc-oyacc-6.6.tar.gz || curl ${CURL_OPTS} -o yacc-oyacc-6.6.tar.gz https://github.com/ibara/yacc/archive/refs/tags/oyacc-6.6.tar.gz
diff --git a/init.c b/init.c
@@ -5,7 +5,7 @@
#define _POSIX_C_SOURCE 200809L
#define _XOPEN_SOURCE 700 // mknod
-#include "src/loksh_tcc.h"
+#include "src/oksh_tcc.h"
#include <errno.h>
#include <fcntl.h> // O_RDONLY
@@ -44,15 +44,15 @@ exec_wait(char *args[])
}
static int
-build_loksh()
+build_oksh()
{
- chdir("/src/loksh-7.6");
+ chdir("/src/oksh-oksh-7.6");
- fprintf(stderr, "Compiling loksh-7.6\n");
+ fprintf(stderr, "Compiling oksh-7.6\n");
- if(exec_wait(loksh_tcc_cmd) < 0) return -1;
+ if(exec_wait(oksh_tcc_cmd) < 0) return -1;
- fprintf(stderr, "Compiled loksh !\n");
+ fprintf(stderr, "Compiled oksh !\n");
return 0;
}
@@ -64,7 +64,7 @@ main(int argc, char *argv[])
setenv("HOME", "/root", 1);
setenv("LOGNAME", "root", 1);
- if(build_loksh() < 0) return 1;
+ if(build_oksh() < 0) return 1;
if(mount("sysfs", "/sys", "sysfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, NULL) < 0)
fprintf(stderr, "Failed to mount /sys: %s\n", strerror(errno));
@@ -87,9 +87,9 @@ main(int argc, char *argv[])
// and oksh also doesn't sources ksh-specific files by default
setenv("PS1", "$? $PWD # ", 1);
- fprintf(stderr, "Launching: /bin/loksh /init.sh\n");
+ fprintf(stderr, "Launching: /bin/oksh /init.sh\n");
- if(execl("/bin/loksh", "/bin/loksh", "/init.sh", (char *)0) < 0)
+ if(execl("/bin/oksh", "/bin/oksh", "/init.sh", (char *)0) < 0)
{
fprintf(stderr, "Failed to execute: %s\n", strerror(errno));
return 1;
diff --git a/init.sh b/init.sh
@@ -1,4 +1,4 @@
-#!/bin/loksh
+#!/bin/oksh
# bootstrap-initrd: Linux initrd to bootstrap from a small binary seed
# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
# SPDX-License-Identifier: MPL-2.0
@@ -116,8 +116,8 @@ build_utils_std() {
oldpath="$PATH"
export PATH="$PATH:$PWD/cmd/"
- loksh ./bootstrap.sh || die
- MAKE=pdpmake loksh ./configure PREFIX=/usr M4=true || die
+ oksh ./bootstrap.sh || die
+ MAKE=pdpmake oksh ./configure PREFIX=/usr M4=true || die
rm cmd/cat cmd/printf cmd/tr || die
pdpmake || die
pdpmake selfcheck || die
@@ -152,7 +152,7 @@ export CFLAGS="-Os -Wall -Wextra"
build_oyacc
-export SHELL="/bin/loksh"
+export SHELL="/bin/oksh"
build_pdpmake || die
diff --git a/make-root.sh b/make-root.sh
@@ -4,8 +4,7 @@
# SPDX-License-Identifier: MPL-2.0
tarballs="
- lolibc-96b2b7e.tar.gz
- loksh-7.6.tar.gz
+ oksh-7.6.tar.gz
yacc-oyacc-6.6.tar.gz
utils-std-0.0.1.tar.gz
pdpmake-2.0.1.tgz
@@ -67,16 +66,22 @@ out_base="${WORKDIR}/${name_base}/${ALPINE_ARCH}"
test -z "${EXCLUDE_EXTRAS}" && out_base="${out_base}+extras"
-gen_loksh_tcc_h() {
- cd loksh-*/ || die
- printf 'char *loksh_tcc_cmd[] = {'
+gen_oksh_tcc_h() {
+ set -e
+
+ cd oksh-*/
+
+ cp "${WORKDIR}/src/oksh-7.6_pconfig.h" ./pconfig.h
+
+ echo 'char *oksh_tcc_cmd[] = {'
# -DSMALL to not need ncurses
- printf '"%s", ' /usr/bin/tcc -o /bin/loksh \
- -D_GNU_SOURCE -DEMACS -DVI -DSMALL -DHAVE_STRLCPY -DHAVE_STRLCAT -DHAVE_ISSETUGID \
- -I ../lolibc-*/include/ *.c \
- ../lolibc-*/sys_signame.c ../lolibc-*/strsignals.c ../lolibc-*/unvis.c ../lolibc-*/vis.c ../lolibc-*/strtonum.c
- printf '0};'
- cd "$out_base" || die "Failed: cd $out_base"
+ printf '\t"%s",\n' /usr/bin/tcc -o /bin/oksh \
+ -D_GNU_SOURCE -DEMACS -DVI -DSMALL \
+ *.c
+ printf '\t0\n'
+ echo '};'
+
+ cd - >/dev/null
}
set -e
@@ -154,17 +159,9 @@ rm usr/lib/libc.a
cd "${out_base}/src"
-# For CLOCK_MONOTONIC and clock_gettime
-sed -i -e '1a#include <time.h>' loksh-*/c_sh.c || die "Failed patching loksh/c_sh.c"
-# For u_char
-sed -i -e '1a#include <sys/types.h>' loksh-*/edit.c || die "Failed patching loksh/c_sh.c"
-# For int64_t
-sed -i -e '1a#include <stdint.h>' loksh-*/table.h || die "Failed patching loksh/table.h"
-sed -i -e '1a#include <limits.h>' -e 's;_PW_NAME_LEN;LOGIN_NAME_MAX;' loksh-*/main.c || die "Failed patching loksh/main.c"
-
-ln -s loksh "${out_base}/bin/sh"
+ln -s oksh "${out_base}/bin/sh"
-gen_loksh_tcc_h > loksh_tcc.h
+gen_oksh_tcc_h > oksh_tcc.h
cd "${out_base}/src"
diff --git a/src/oksh-7.6_pconfig.h b/src/oksh-7.6_pconfig.h
@@ -0,0 +1,15 @@
+#define __dead __attribute__((__noreturn__))
+#define HAVE_ASPRINTF
+#define HAVE_CONFSTR
+#define NO_CURSES
+#define HAVE_ISSETUGID
+#define HAVE_REALLOCARRAY
+#define HAVE_SETRESGID
+#define HAVE_SETRESUID
+#define HAVE_SIG_T
+#define HAVE_ST_MTIM
+#define HAVE_STRLCAT
+#define HAVE_STRLCPY
+#define HAVE_TIMERADD
+#define HAVE_TIMERCLEAR
+#define HAVE_TIMERSUB