unvendor
This commit is contained in:
Dawid Sobczak 2025-04-18 12:41:04 +01:00
parent 9a4b261179
commit 404aa8ebbb
139 changed files with 8091 additions and 1178 deletions

View file

@ -0,0 +1,21 @@
#include <stdio.h>
#ifndef RECIPES_STAGE1
#define RECIPES_STAGE1 "/recipes/1-stage1"
#endif
#define SOURCE_PATH RECIPES_STAGE1"/hello.c"
int main(int argc, char** argv) {
printf("Hello world!\n2*2=%d\n", 2*2);
printf("Own source (%s):\n", SOURCE_PATH);
FILE* f = fopen(SOURCE_PATH, "r");
while (!feof(f)) {
fputc(fgetc(f), stdout);
}
if (ferror(f))
return 99;
fclose(f);
return 42;
}

View file

@ -0,0 +1,46 @@
extern int APPLET_MAIN(int argc, char** argv); // templated in
#include <string.h>
#include <unistd.h>
#include <errno.h>
static inline int *get_perrno(void) { return &errno; }
int *const bb_errno;
char bb_common_bufsiz1[1024];
const char *applet_name;
int _argc;
const char **_argv;
int main(int argc, char** argv) {
int** bb_errno_ptr = &((int*) bb_errno);
*bb_errno_ptr = ((int*) get_perrno());
asm volatile ("":::"memory"); // counter optimizations
_argc = argc; _argv = argv;
applet_name = strrchr(argv[0], '/') \
? strrchr(argv[0], '/') + 1 \
: argv[0];
return APPLET_MAIN(argc, argv);
}
void bb_show_usage(void) {
int i;
write(2 /* STDERR */, "protobusybox's show_usage stub\n", 31);
write(2 /* STDERR */, "ho help for you, sorry. argv[]: \n", 33);
for (i < 0; i < _argc; i++) {
write(2 /* STDERR */, "* `", 3);
write(2 /* STDERR */, _argv[i], strlen(_argv[i]));
write(2 /* STDERR */, "`\n", 2);
}
exit(1);
}
// appletlib replacement
unsigned string_array_len(char **argv) {
unsigned i;
for (i = 0; argv[i]; i++);
return i;
}

View file

@ -0,0 +1,240 @@
#define NUM_APPLETS 1
#define BB_GLOBAL_CONST
#define BB_VER "1.36.1"
#define AUTOCONF_TIMESTAMP
#define _GNU_SOURCE
extern char bb_common_bufsiz1[];
#define setup_common_bufsiz() ((void)0)
enum { COMMON_BUFSIZE = 1024 };
#define CONFIG_BUSYBOX_EXEC_PATH "/proc/self/exe"
#define CONFIG_FEATURE_COPYBUF_KB 256
#define CONFIG_FEATURE_EDITING_MAX_LEN 1024
#define CONFIG_GZIP_FAST 2
#define CONFIG_UNAME_OSNAME "Linux"
#define ENABLE_ASH_ALIAS 0
#define ENABLE_ASH_BASH_COMPAT 0
#define ENABLE_ASH_CMDCMD 1
#define ENABLE_ASH_ECHO 0
#define ENABLE_ASH_GETOPTS 1
#define ENABLE_ASH_JOB_CONTROL 0
#define ENABLE_ASH_MAIL 0
#define ENABLE_ASH_PRINTF 1
#define ENABLE_ASH_SLEEP 0
#define ENABLE_ASH_TEST 1
#define ENABLE_BB_ARCH 1
#define ENABLE_BUNZIP2 0
#define ENABLE_BZCAT 0
#define ENABLE_DEBUG 0
#define ENABLE_DESKTOP 1
#define ENABLE_EGREP 0
#define ENABLE_FEATURE_ALLOW_EXEC 0
#define ENABLE_FEATURE_AWK_LIBM 0
#define ENABLE_FEATURE_BZIP2_DECOMPRESS 1
#define ENABLE_FEATURE_CLEAN_UP 0
#define ENABLE_FEATURE_CP_REFLINK 0
#define ENABLE_FEATURE_CROND_D 0
#define ENABLE_FEATURE_CUT_REGEX 0
#define ENABLE_FEATURE_EDITING 0
#define ENABLE_FEATURE_FANCY_ECHO 1
#define ENABLE_FEATURE_FIND_NOT 1
#define ENABLE_FEATURE_FIND_PAREN 1
#define ENABLE_FEATURE_FIND_PRUNE 1
#define ENABLE_FEATURE_FIND_TYPE 1
#define ENABLE_FEATURE_GZIP_DECOMPRESS 1
#define ENABLE_FEATURE_HUMAN_READABLE 0
#define ENABLE_FEATURE_LS_COLOR 0
#define ENABLE_FEATURE_LS_FILETYPES 0
#define ENABLE_FEATURE_LS_FOLLOWLINKS 0
#define ENABLE_FEATURE_LS_RECURSIVE 0
#define ENABLE_FEATURE_LS_SORTFILES 0
#define ENABLE_FEATURE_LS_TIMESTAMPS 1
#define ENABLE_FEATURE_LS_WIDTH 0
#define ENABLE_FEATURE_NON_POSIX_CP 0
#define ENABLE_FEATURE_PRESERVE_HARDLINKS 0
#define ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS 0
#define ENABLE_FEATURE_SEAMLESS_BZ2 1
#define ENABLE_FEATURE_SEAMLESS_GZ 1
#define ENABLE_FEATURE_SEAMLESS_LZMA 0
#define ENABLE_FEATURE_SEAMLESS_XZ 1
#define ENABLE_FEATURE_SEAMLESS_Z 0
#define ENABLE_FEATURE_SHOW_THREADS 0
#define ENABLE_FEATURE_SH_MATH 1
#define ENABLE_FEATURE_SH_READ_FRAC 0
#define ENABLE_FEATURE_SYSLOG 0
#define ENABLE_FEATURE_TAR_AUTODETECT 1
#define ENABLE_FEATURE_TAR_CREATE 1
#define ENABLE_FEATURE_TAR_GNU_EXTENSIONS 1
#define ENABLE_FEATURE_TAR_LONG_OPTIONS 1
#define ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY 1
#define ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY 0
#define ENABLE_FEATURE_TOPMEM 1
#define ENABLE_FEATURE_TOP_SMP_PROCESS 0
#define ENABLE_FEATURE_TOUCH_SUSV3 1
#define ENABLE_FEATURE_TR_CLASSES 0
#define ENABLE_FEATURE_TR_EQUIV 0
#define ENABLE_FEATURE_USE_SENDFILE 0
#define ENABLE_FEATURE_VERBOSE 0
#define ENABLE_FGREP 0
#define ENABLE_FTPD 0
#define ENABLE_HUSH_PRINTF 0
#define ENABLE_HUSH_TEST 0
#define ENABLE_KILLALL 0
#define ENABLE_LOCALE_SUPPORT 1
#define ENABLE_LONG_OPTS 1
#define ENABLE_LZCAT 0
#define ENABLE_PGREP 0
#define ENABLE_PIDOF 0
#define ENABLE_PKILL 0
#define ENABLE_SELINUX 0
#define ENABLE_SESTATUS 0
#define ENABLE_TAR 1
#define ENABLE_TEST1 0
#define ENABLE_TEST2 0
#define ENABLE_UNAME 0
#define ENABLE_UNLZMA 0
#define ENABLE_ZCAT 0
#define IF_AR(...)
#define IF_ASH_ALIAS(...)
#define IF_ASH_BASH_COMPAT(...)
#define IF_ASH_EXPAND_PRMT(...)
#define IF_ASH_HELP(...)
#define IF_ASH_OPTIMIZE_FOR_SIZE(...)
#define IF_BASENAME(...)
#define IF_BUNZIP2(...)
#define IF_BZCAT(...)
#define IF_BZIP2(...) __VA_ARGS__
#define IF_CAT(...)
#define IF_CHGRP(...)
#define IF_CHMOD(...)
#define IF_CHOWN(...)
#define IF_CHROOT(...)
#define IF_CHVT(...)
#define IF_CKSUM(...)
#define IF_CLEAR(...)
#define IF_CPIO(...)
#define IF_DEALLOCVT(...)
#define IF_DESKTOP(...) __VA_ARGS__
#define IF_DPKG(...)
#define IF_DPKG_DEB(...)
#define IF_DUMPKMAP(...)
#define IF_ECHO(...) __VA_ARGS__
#define IF_EXTRA_COMPAT(...)
#define IF_FEATURE_AWK_GNU_EXTENSIONS(...)
#define IF_FEATURE_BZIP2_DECOMPRESS(...) __VA_ARGS__
#define IF_FEATURE_CATN(...)
#define IF_FEATURE_CATV(...)
#define IF_FEATURE_CP_REFLINK(...)
#define IF_FEATURE_CUT_REGEX(...)
#define IF_FEATURE_FIND_AMIN(...)
#define IF_FEATURE_FIND_ATIME(...)
#define IF_FEATURE_FIND_CMIN(...)
#define IF_FEATURE_FIND_CONTEXT(...)
#define IF_FEATURE_FIND_CTIME(...)
#define IF_FEATURE_FIND_DELETE(...)
#define IF_FEATURE_FIND_DEPTH(...)
#define IF_FEATURE_FIND_EMPTY(...)
#define IF_FEATURE_FIND_EXEC(...)
#define IF_FEATURE_FIND_EXECUTABLE(...)
#define IF_FEATURE_FIND_EXEC_PLUS(...)
#define IF_FEATURE_FIND_GROUP(...)
#define IF_FEATURE_FIND_INUM(...)
#define IF_FEATURE_FIND_LINKS(...)
#define IF_FEATURE_FIND_MAXDEPTH(...)
#define IF_FEATURE_FIND_MMIN(...)
#define IF_FEATURE_FIND_MTIME(...)
#define IF_FEATURE_FIND_NEWER(...)
#define IF_FEATURE_FIND_NOT(...) __VA_ARGS__
#define IF_FEATURE_FIND_PAREN(...) __VA_ARGS__
#define IF_FEATURE_FIND_PATH(...)
#define IF_FEATURE_FIND_PERM(...)
#define IF_FEATURE_FIND_PRINT0(...)
#define IF_FEATURE_FIND_PRUNE(...) __VA_ARGS__
#define IF_FEATURE_FIND_QUIT(...)
#define IF_FEATURE_FIND_REGEX(...)
#define IF_FEATURE_FIND_SAMEFILE(...)
#define IF_FEATURE_FIND_SIZE(...)
#define IF_FEATURE_FIND_TYPE(...) __VA_ARGS__
#define IF_FEATURE_FIND_USER(...)
#define IF_FEATURE_FIND_XDEV(...)
#define IF_FEATURE_GREP_CONTEXT(...)
#define IF_FEATURE_GZIP_DECOMPRESS(...) __VA_ARGS__
#define IF_FEATURE_HUMAN_READABLE(...)
#define IF_FEATURE_INSTALL_LONG_OPTIONS(...)
#define IF_FEATURE_LS_COLOR(...)
#define IF_FEATURE_LS_FILETYPES(...)
#define IF_FEATURE_LS_FOLLOWLINKS(...)
#define IF_FEATURE_LS_RECURSIVE(...)
#define IF_FEATURE_LS_SORTFILES(...)
#define IF_FEATURE_LS_TIMESTAMPS(...) __VA_ARGS__
#define IF_FEATURE_LS_WIDTH(...)
#define IF_FEATURE_SEAMLESS_BZ2(...) __VA_ARGS__
#define IF_FEATURE_SEAMLESS_GZ(...) __VA_ARGS__
#define IF_FEATURE_SEAMLESS_LZMA(...)
#define IF_FEATURE_SEAMLESS_XZ(...) __VA_ARGS__
#define IF_FEATURE_SEAMLESS_Z(...)
#define IF_FEATURE_SHOW_THREADS(...)
#define IF_FEATURE_SH_MATH(...) __VA_ARGS__
#define IF_FEATURE_TAR_AUTODETECT(...) __VA_ARGS__
#define IF_FEATURE_TAR_CREATE(...) __VA_ARGS__
#define IF_FEATURE_TAR_FROM(...) __VA_ARGS__
#define IF_FEATURE_TAR_LONG_OPTIONS(...) __VA_ARGS__
#define IF_FEATURE_TAR_NOPRESERVE_TIME(...) __VA_ARGS__
#define IF_FEATURE_TAR_OLDGNU_COMPATIBILITY(...) __VA_ARGS__
#define IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(...)
#define IF_FEATURE_TAR_TO_COMMAND(...)
#define IF_FEATURE_TIMEZONE(...)
#define IF_FEATURE_TOUCH_SUSV3(...) __VA_ARGS__
#define IF_FEATURE_VERBOSE(...)
#define IF_FEATURE_XARGS_SUPPORT_ARGS_FILE(...)
#define IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(...)
#define IF_FEATURE_XARGS_SUPPORT_PARALLEL(...)
#define IF_FEATURE_XARGS_SUPPORT_QUOTES(...)
#define IF_FEATURE_XARGS_SUPPORT_REPL_STR(...)
#define IF_FEATURE_XARGS_SUPPORT_TERMOPT(...)
#define IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(...)
#define IF_FGCONSOLE(...)
#define IF_GUNZIP(...) __VA_ARGS__
#define IF_GZIP(...) __VA_ARGS__
#define IF_KBD_MODE(...)
#define IF_LOADFONT(...)
#define IF_LOADKMAP(...)
#define IF_LONG_OPTS(...) __VA_ARGS__
#define IF_LS(...) __VA_ARGS__
#define IF_LZCAT(...)
#define IF_LZMA(...)
#define IF_LZOP(...)
#define IF_LZOPCAT(...)
#define IF_NOT_ASH_OPTIMIZE_FOR_SIZE(...) __VA_ARGS__
#define IF_NOT_DESKTOP(...)
#define IF_NOT_FEATURE_FIND_MAXDEPTH(...) __VA_ARGS__
#define IF_NOT_FEATURE_TAR_CREATE(...)
#define IF_NOT_FEATURE_TOUCH_SUSV3(...)
#define IF_OPENVT(...)
#define IF_PRINTF(...) __VA_ARGS__
#define IF_RESET(...)
#define IF_RESIZE(...)
#define IF_RPM(...)
#define IF_RPM2CPIO(...)
#define IF_SELINUX(...)
#define IF_SETCONSOLE(...)
#define IF_SETFONT(...)
#define IF_SETKEYCODES(...)
#define IF_SETLOGCONS(...)
#define IF_SHELL_ASH(...) __VA_ARGS__
#define IF_SHELL_HUSH(...)
#define IF_SHOWKEY(...)
#define IF_SLEEP(...)
#define IF_TAR(...)
#define IF_UNAME(...) __VA_ARGS__
#define IF_UNCOMPRESS(...)
#define IF_UNLZMA(...)
#define IF_UNLZOP(...)
#define IF_UNXZ(...) __VA_ARGS__
#define IF_UNZIP(...)
#define IF_XZ(...)
#define IF_XZCAT(...)
#define IF_ZCAT(...)

View file

@ -0,0 +1,89 @@
#!/usr/bin/env bash
# 1st stage is special
# in that we don't have any semblance of a system to start with,
# meaning we can't even unpack sources, let alone patch them or something.
# For stage 1, we pre-unpack sources on the host and then fix them up with
# host's sed.
#> FETCH 7a35eae33d5372a7c0da1188de798726f68825513b7ae3ebe97aaaa52114f039
#> FROM http://musl.libc.org/releases/musl-1.2.4.tar.gz
#> FETCH f5a71d05664340ae46cda9579c6079a0f2fa809d24386d284f0d091e4d576a4e
#> FROM https://github.com/TinyCC/tinycc/archive/af1abf1f45d45b34f0b02437f559f4dfdba7d23c.tar.gz
#> AS tinycc-mob-af1abf1.tar.gz
#> FETCH b8cc24c9574d809e7279c3be349795c5d5ceb6fdf19ca709f80cde50e47de314
#> FROM https://busybox.net/downloads/busybox-1.36.1.tar.bz2
set -ueo pipefail
TGT="$DESTDIR/tmp/1-stage1"
echo "### $0: unpacking protomusl sources..."
mkdir -p "$DESTDIR/protosrc/protomusl"
tar --strip-components=1 -xzf downloads/musl-1.2.4.tar.gz \
-C "$DESTDIR/protosrc/protomusl"
echo "### $0: unpacking tinycc sources..."
mkdir -p "$DESTDIR/protosrc/tinycc"
tar --strip-components=1 -xzf downloads/tinycc-mob-af1abf1.tar.gz \
-C $DESTDIR/protosrc/tinycc
echo "### $0: unpacking protobusybox sources..."
mkdir -p "$DESTDIR/protosrc/protobusybox"
tar --strip-components=1 -xjf downloads/busybox-1.36.1.tar.bz2 \
-C "$DESTDIR/protosrc/protobusybox"
echo "### $0: patching up protomusl stage 1 sources..."
# original syscall_arch.h is not tcc-compatible, our syscall.h is dual-role
cp recipes/1-stage1/syscall.h \
"$DESTDIR/protosrc/protomusl/arch/x86_64/syscall_arch.h"
pushd "$DESTDIR/protosrc/protomusl/" >/dev/null
# eliminiate a source path reference
sed -i 's/__FILE__/"__FILE__"/' include/assert.h
# two files have to be generated with host sed
mkdir -p host-generated/{sed1,sed2}/bits
sed -f ./tools/mkalltypes.sed \
./arch/x86_64/bits/alltypes.h.in \
./include/alltypes.h.in \
> host-generated/sed1/bits/alltypes.h
sed -n -e s/__NR_/SYS_/p \
< arch/x86_64/bits/syscall.h.in \
> host-generated/sed2/bits/syscall.h
# more frivolous patching
echo '#define VERSION "1.2.2"' > src/internal/version.h
sed -i 's/@PLT//' src/signal/x86_64/sigsetjmp.s
rm -f src/signal/restore.c # *BIG URGH*
rm -f src/thread/clone.c # *BIG URGH #2*
rm -f src/thread/__set_thread_area.c # possible double-define
rm -f src/thread/__unmapself.c # double-define
rm -f src/math/sqrtl.c # tcc-incompatible
rm -f src/math/{acoshl,acosl,asinhl,asinl,hypotl}.c # sqrtl dep
sed -i 's|posix_spawn(&pid, "/bin/sh",|posix_spawnp(\&pid, "sh",|' \
src/stdio/popen.c src/process/system.c
sed -i 's|execl("/bin/sh", "sh", "-c",|execlp("sh", "-c",|'\
src/misc/wordexp.c
popd >/dev/null
echo "### $0: patching up tinycc stage 1 sources..."
pushd "$DESTDIR/protosrc/tinycc" >/dev/null
:> config.h
# eliminate a source path reference
sed -i 's/__FILE__/"__FILE__"/' tcc.h
# don't hardcode paths
sed -i 's/SHN_ABS, filename);/SHN_ABS, "FILE stub");/' tccdbg.c
# break a circular dependency
sed -i 's/abort();//' lib/va_list.c
popd >/dev/null
echo "### $0: patching up protobusybox stage 1 sources..."
pushd "$DESTDIR/protosrc/protobusybox" >/dev/null
:> include/NUM_APPLETS.h
:> include/common_bufsiz.h
# eliminate a source path reference
sed -i 's/__FILE__/"__FILE__"/' miscutils/fbsplash.c include/libbb.h
# already fixed in an unreleased version
sed -i 's/extern struct test_statics \*const test_ptr_to_statics/extern struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics/' coreutils/test.c
popd >/dev/null
echo "### $0: done"

View file

@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: 2021 Alexander Sosedkin <monk@unboiled.info>
// SPDX-License-Identifier: MIT
// constants/macro for this file to serve as a drop-in replacement
// for musl-1.2.2's arch/x86_64/syscall_arch.h
#define __SYSCALL_LL_E(x) (x)
#define __SYSCALL_LL_O(x) (x)
#define VDSO_USEFUL
#define VDSO_CGT_SYM "__vdso_clock_gettime"
#define VDSO_CGT_VER "LINUX_2.6"
#define VDSO_GETCPU_SYM "__vdso_getcpu"
#define VDSO_GETCPU_VER "LINUX_2.6"
#define IPC_64 0
// a different, tcc-compatible implementation of syscall invocations functions
static long __syscall6(long n, long a1, long a2, long a3, long a4, long a5, long a6);
asm (
//".globl __syscall6;"
".type __syscall6, @function;"
"__syscall6:;"
"movq %rdi, %rax;"
"movq %rsi, %rdi;"
"movq %rdx, %rsi;"
"movq %rcx, %rdx;"
"movq %r8, %r10;"
"movq %r9, %r8;"
"movq 8(%rsp),%r9;"
"syscall;"
"ret"
);
static __inline long __syscall5(long n, long a1, long a2, long a3, long a4, long a5) {
return __syscall6(n, a1, a2, a3, a4, a5, 0);
}
static __inline long __syscall4(long n, long a1, long a2, long a3, long a4) {
return __syscall6(n, a1, a2, a3, a4, 0, 0);
}
static __inline long __syscall3(long n, long a1, long a2, long a3) {
return __syscall6(n, a1, a2, a3, 0, 0, 0);
}
static __inline long __syscall2(long n, long a1, long a2) {
return __syscall6(n, a1, a2, 0, 0, 0, 0);
}
static __inline long __syscall1(long n, long a1) {
return __syscall6(n, a1, 0, 0, 0, 0, 0);
}
static __inline long __syscall0(long n) {
return __syscall6(n, 0, 0, 0, 0, 0, 0);
}