From e829fe1ca01ea3f8148a88e9a11435ce41d1b7ef Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 11 Nov 2023 13:52:30 -0600 Subject: Remove old TODO block, people can ask if they want more features. --- toys/other/nbd_client.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/toys/other/nbd_client.c b/toys/other/nbd_client.c index caa7da61..636c64ca 100644 --- a/toys/other/nbd_client.c +++ b/toys/other/nbd_client.c @@ -21,16 +21,6 @@ config NBD_CLIENT -s nbd swap support (lock server into memory) */ -/* TODO: - usage: nbd-client [-Sp] [-t SECS] [-N name] HOST PORT DEVICE - - -t timeout in seconds - -S sdp - -p persist - -d DEVICE - -c DEVICE -*/ - #define FOR_nbd_client #include "toys.h" #include -- cgit v1.2.3 From 500a0f93e879244c878c92c83aabf92d871f600a Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 12 Nov 2023 20:08:55 -0600 Subject: Don't try to free old optargs in toy_init(). The shell frees it after running a NOFORK and the minor memory leak in a "nice nohup setsid taskset xargs nsenter chroot" stack isn't enough return to try to make sure it always points to something sufficiently known: you can't free(++toys.optargs). --- main.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/main.c b/main.c index 6fc27099..c6f5a873 100644 --- a/main.c +++ b/main.c @@ -195,9 +195,6 @@ void toy_init(struct toy_list *which, char *argv[]) } } - // Free old toys contents (to be reentrant), but leave rebound if any - // don't blank old optargs if our new argc lives in the old optargs. - if (argvtoys.optargs+toys.optc) free(toys.optargs); memset(&toys, 0, offsetof(struct toy_context, rebound)); if (oldwhich) memset(&this, 0, sizeof(this)); -- cgit v1.2.3 From ef46c278697020671bf97647af22f896b823f715 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 13 Nov 2023 10:40:36 -0600 Subject: Add scripts/probes directory with script to measure GLOBALS() size, and move findglobals and showasm into it. --- scripts/findglobals.sh | 6 ------ scripts/probes/GLOBALS | 8 ++++++++ scripts/probes/findglobals | 7 +++++++ scripts/probes/showasm | 20 ++++++++++++++++++++ scripts/showasm | 20 -------------------- 5 files changed, 35 insertions(+), 26 deletions(-) delete mode 100755 scripts/findglobals.sh create mode 100755 scripts/probes/GLOBALS create mode 100755 scripts/probes/findglobals create mode 100755 scripts/probes/showasm delete mode 100755 scripts/showasm diff --git a/scripts/findglobals.sh b/scripts/findglobals.sh deleted file mode 100755 index 2bb94d69..00000000 --- a/scripts/findglobals.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# Quick and dirty check to see if anybody's leaked global variables. -# We should have this, toy_list, toybuf, and toys. - -nm --size-sort generated/unstripped/toybox | grep '[0-9A-Fa-f]* [BCDGRS]' #| cut -d ' ' -f 3 diff --git a/scripts/probes/GLOBALS b/scripts/probes/GLOBALS new file mode 100755 index 00000000..0ec57627 --- /dev/null +++ b/scripts/probes/GLOBALS @@ -0,0 +1,8 @@ +#!/bin/bash + +# Show bytes used by each command's GLOBALS() block, based on last build +{ + echo -e '#include "toys.h"\nint main(void) {' + sed -n 's/^\tstruct \(.*\)_data .*/printf("%d \1\\n", (int)sizeof(struct \1_data));/p' generated/globals.h + echo '}' +} | "${CROSS_COMPILE}"cc -xc - && ./a.out | sort -n diff --git a/scripts/probes/findglobals b/scripts/probes/findglobals new file mode 100755 index 00000000..c4855dec --- /dev/null +++ b/scripts/probes/findglobals @@ -0,0 +1,7 @@ +#!/bin/bash + +# Quick and dirty check to see if anybody's leaked global variables. +# We should have this, toy_list, toybuf, and toys. + +nm --size-sort generated/unstripped/toybox | grep '[0-9A-Fa-f]* [BCDGRS]' | \ + grep -v GLIBC diff --git a/scripts/probes/showasm b/scripts/probes/showasm new file mode 100755 index 00000000..75a6efd7 --- /dev/null +++ b/scripts/probes/showasm @@ -0,0 +1,20 @@ +#!/bin/sh + +# Copyright 2006 Rob Landley + +# Dumb little utility function to print out the assembly dump of a single +# function, or list the functions so dumpable in an executable. You'd think +# there would be a way to get objdump to do this, but I can't find it. + +[ $# -lt 1 ] || [ $# -gt 2 ] && { echo "usage: showasm file function"; exit 1; } + +[ ! -f $1 ] && { echo "File $1 not found"; exit 1; } + +if [ $# -eq 1 ] +then + objdump -d $1 | sed -n -e 's/^[0-9a-fA-F]* <\(.*\)>:$/\1/p' + exit 0 +fi + +objdump -d $1 | sed -n -e '/./{H;$!d}' -e "x;/^.[0-9a-fA-F]* <$2>:/p" + diff --git a/scripts/showasm b/scripts/showasm deleted file mode 100755 index 75a6efd7..00000000 --- a/scripts/showasm +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -# Copyright 2006 Rob Landley - -# Dumb little utility function to print out the assembly dump of a single -# function, or list the functions so dumpable in an executable. You'd think -# there would be a way to get objdump to do this, but I can't find it. - -[ $# -lt 1 ] || [ $# -gt 2 ] && { echo "usage: showasm file function"; exit 1; } - -[ ! -f $1 ] && { echo "File $1 not found"; exit 1; } - -if [ $# -eq 1 ] -then - objdump -d $1 | sed -n -e 's/^[0-9a-fA-F]* <\(.*\)>:$/\1/p' - exit 0 -fi - -objdump -d $1 | sed -n -e '/./{H;$!d}' -e "x;/^.[0-9a-fA-F]* <$2>:/p" - -- cgit v1.2.3 From e54ab9010cfd944f893d1871b8578de313d851ca Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 13 Nov 2023 10:50:29 -0600 Subject: Let run-qemu.sh be run from other directories. --- mkroot/mkroot.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mkroot/mkroot.sh b/mkroot/mkroot.sh index 689faa4f..f65515fc 100755 --- a/mkroot/mkroot.sh +++ b/mkroot/mkroot.sh @@ -247,9 +247,10 @@ else # Write the qemu launch script if [ -n "$QEMU" ]; then - [ -z "$BUILTIN" ] && INITRD="-initrd initramfs.cpio.gz" - { echo qemu-system-"$QEMU" -m 256 '"$@"' $QEMU_MORE -nographic -no-reboot \ - -kernel linux-kernel $INITRD ${DTB:+-dtb linux.dtb} \ + [ -z "$BUILTIN" ] && INITRD='-initrd "$DIR"/initramfs.cpio.gz' + { echo DIR='"$(dirname $0)";' qemu-system-"$QEMU" -m 256 '"$@"' $QEMU_MORE \ + -nographic -no-reboot -kernel '"$DIR"'/linux-kernel $INITRD \ + ${DTB:+-dtb '"$DIR"'/linux.dtb} \ "-append \"panic=1 HOST=$CROSS console=$KARGS \$KARGS\"" && echo "echo -e '\\e[?7h'" } > "$OUTPUT"/run-qemu.sh && @@ -261,7 +262,7 @@ else cp -sfR "$LINUX" "$TEMP/linux" && pushd "$TEMP/linux" && # Write linux-miniconfig - mkdir "$OUTDOC" && + mkdir -p "$OUTDOC" && { echo "# make ARCH=$KARCH allnoconfig KCONFIG_ALLCONFIG=linux-miniconfig" echo -e "# make ARCH=$KARCH -j \$(nproc)\n# boot $VMLINUX\n\n" -- cgit v1.2.3 From fb2e8ff8133a746a655691887784d7e4873e7341 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 13 Nov 2023 11:33:57 -0600 Subject: Fix sed --help to show full help. --- toys/posix/sed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toys/posix/sed.c b/toys/posix/sed.c index e6e13972..f7a49f2a 100644 --- a/toys/posix/sed.c +++ b/toys/posix/sed.c @@ -1087,7 +1087,7 @@ void sed_main(void) } // Handling our own --version means we handle our own --help too. - if (FLAG(help)) help_exit(0); + if (FLAG(help)) return show_help(stdout, 0); // Parse pattern into commands. -- cgit v1.2.3 From b166aa7e6240e601219c92a5f289272b3f286a29 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 13 Nov 2023 13:17:06 -0600 Subject: Add probes README and move bloatcheck into probes, adjusting makefile. --- Makefile | 2 +- scripts/bloatcheck | 57 ----------------------------------------------- scripts/probes/README | 1 + scripts/probes/bloatcheck | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 58 deletions(-) delete mode 100755 scripts/bloatcheck create mode 100644 scripts/probes/README create mode 100755 scripts/probes/bloatcheck diff --git a/Makefile b/Makefile index 0ffc3533..100fd30e 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ baseline: generated/unstripped/toybox @cp generated/unstripped/toybox generated/unstripped/toybox_old bloatcheck: generated/unstripped/toybox_old generated/unstripped/toybox - @scripts/bloatcheck generated/unstripped/toybox_old generated/unstripped/toybox + @scripts/probes/bloatcheck generated/unstripped/toybox_old generated/unstripped/toybox install_flat: toybox scripts/install.sh --symlink --force diff --git a/scripts/bloatcheck b/scripts/bloatcheck deleted file mode 100755 index d62b4ea2..00000000 --- a/scripts/bloatcheck +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -if [ $# -ne 2 ] -then - echo "usage: bloatcheck old new" - exit 1 -fi - -addline() -{ - NEXT="$(printf "%s% $((50-${#LASTNAME}))d% 10d %10d" "$LASTNAME" "$OLD" "$NEW" "$DELTA")" - [ -z "$STUFF" ] && - STUFF="$NEXT" || - STUFF="$(printf "%s\n%s" "$STUFF" "$NEXT")" -} - -do_bloatcheck() -{ - LASTNAME= DELTA=0 TOTAL=0 OLD=0 NEW=0 STUFF= - - printf "name% 46s% 10s% 11s\n" old new delta - echo "-----------------------------------------------------------------------" - while read a b c d - do - THISNAME=$(echo "$d" | sed 's/[.][0-9]*$//') - - if [ "$LASTNAME" != "$THISNAME" ] - then - TOTAL=$(($TOTAL+$DELTA)) - [ $DELTA -ne 0 ] && addline - LASTNAME="$THISNAME" - DELTA=0 - OLD=0 - NEW=0 - fi - - SIZE=$(printf "%d" "0x$b") - if [ "$a" == "-" ] - then - OLD=$(($OLD+$SIZE)) - SIZE=$((-1*$SIZE)) - else - NEW=$(($NEW+$SIZE)) - fi - DELTA=$(($DELTA+$SIZE)) - done - - TOTAL=$(($TOTAL+$DELTA)) - [ $DELTA -ne 0 ] && addline - - echo "$STUFF" | sort -k4,4nr - echo "-----------------------------------------------------------------------" - printf "% 71d total\n" "$TOTAL" -} - -diff -U 0 <(nm --size-sort "$1"|sort -k 3,3) <(nm --size-sort "$2"|sort -k 3,3)\ - | tail -n +3 | sed -n 's/^\([-+]\)/\1 /p' | sort -k4,4 | do_bloatcheck diff --git a/scripts/probes/README b/scripts/probes/README new file mode 100644 index 00000000..db8efd3d --- /dev/null +++ b/scripts/probes/README @@ -0,0 +1 @@ +Various development scripts to ask questions about a toybox binary. diff --git a/scripts/probes/bloatcheck b/scripts/probes/bloatcheck new file mode 100755 index 00000000..d62b4ea2 --- /dev/null +++ b/scripts/probes/bloatcheck @@ -0,0 +1,57 @@ +#!/bin/bash + +if [ $# -ne 2 ] +then + echo "usage: bloatcheck old new" + exit 1 +fi + +addline() +{ + NEXT="$(printf "%s% $((50-${#LASTNAME}))d% 10d %10d" "$LASTNAME" "$OLD" "$NEW" "$DELTA")" + [ -z "$STUFF" ] && + STUFF="$NEXT" || + STUFF="$(printf "%s\n%s" "$STUFF" "$NEXT")" +} + +do_bloatcheck() +{ + LASTNAME= DELTA=0 TOTAL=0 OLD=0 NEW=0 STUFF= + + printf "name% 46s% 10s% 11s\n" old new delta + echo "-----------------------------------------------------------------------" + while read a b c d + do + THISNAME=$(echo "$d" | sed 's/[.][0-9]*$//') + + if [ "$LASTNAME" != "$THISNAME" ] + then + TOTAL=$(($TOTAL+$DELTA)) + [ $DELTA -ne 0 ] && addline + LASTNAME="$THISNAME" + DELTA=0 + OLD=0 + NEW=0 + fi + + SIZE=$(printf "%d" "0x$b") + if [ "$a" == "-" ] + then + OLD=$(($OLD+$SIZE)) + SIZE=$((-1*$SIZE)) + else + NEW=$(($NEW+$SIZE)) + fi + DELTA=$(($DELTA+$SIZE)) + done + + TOTAL=$(($TOTAL+$DELTA)) + [ $DELTA -ne 0 ] && addline + + echo "$STUFF" | sort -k4,4nr + echo "-----------------------------------------------------------------------" + printf "% 71d total\n" "$TOTAL" +} + +diff -U 0 <(nm --size-sort "$1"|sort -k 3,3) <(nm --size-sort "$2"|sort -k 3,3)\ + | tail -n +3 | sed -n 's/^\([-+]\)/\1 /p' | sort -k4,4 | do_bloatcheck -- cgit v1.2.3 From 979ee153b217683eba8e4b996429e8a6bda4c5eb Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 13 Nov 2023 22:26:14 -0600 Subject: Update package version and hit build with a rock until it finishes. --- mkroot/packages/busybox | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/mkroot/packages/busybox b/mkroot/packages/busybox index fa2d1c22..b1e9e4f7 100755 --- a/mkroot/packages/busybox +++ b/mkroot/packages/busybox @@ -1,28 +1,33 @@ #!/bin/echo Try "scripts/mkroot.sh dropbear" -echo === download source - -download d5514f5cf8eb89a3b20ac3b965f4463f14a5709a \ - http://www.busybox.net/downloads/busybox-1.31.1.tar.bz2 - -echo === $HOST Native build static dropbear +download a5d40ca0201b20909f7a8a561adf57adccc8a877 \ + http://www.busybox.net/downloads/busybox-1.36.1.tar.bz2 # 4 commands: ash, route, udhcpc, stty setupfor busybox make defconfig && -sed -Ei 's/# CONFIG_NOMMU is not set/CONFIG_NOMMU=y/;s/CONFIG_(RUNSV|MONOTONIC_SYSCALL)=y/# CONFIG_\1 is not set/' .config && -make silentoldconfig && -LDFLAGS=--static make SKIP_STRIP=y && +# Busybox checks for host bzip2, which toybox does not provide. +sed -i 's/^bzip2/true bzip2/' scripts/{mkconfigs,embedded_scripts} && +# zap script that wants diff +ln -sf /bin/true scripts/generate_BUFSIZ.sh && +echo '#define COMMON_BUFSIZE (4096) +extern char bb_common_bufsiz1[]; +#define setup_common_bufsiz()' > include/common_bufsiz.h && +LDFLAGS=--static make SKIP_STRIP=y -j $(nproc) && cp busybox "$ROOT/bin" && -ln -sf busybox "$ROOT/bin/sh" && +make busybox.links && +mkdir -p "$ROOT/busybox" || exit 1 +while read i; do ln -sf /bin/busybox "$ROOT/busybox/$(basename "$i")" || exit 1 +done < busybox.links cp .config "$ROOT/../busybox-config" cleanup -# busybox doesn't support $( \ - "$ROOT/etc/rc/busybox.sh" && +# busybox ash doesn't support $( \ +# "$ROOT/etc/rc/busybox.sh" && cat > "$ROOT"/etc/dhcp.sh << 'EOF' && #!/bin/sh -- cgit v1.2.3 From 8aad4f42671818fd94b7f94d5f6ecead3d3b1e01 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 14 Nov 2023 14:37:33 -0600 Subject: Elliott wants to use CTRL(), and glibc implicitly pulls this in anyway. (The explicit #include is because musl and bionic don't.) --- toys.h | 1 + toys/net/microcom.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/toys.h b/toys.h index bde3d90d..88b7a837 100644 --- a/toys.h +++ b/toys.h @@ -66,6 +66,7 @@ // Non-posix headers #include #include +#include #include "lib/lib.h" #include "lib/lsm.h" diff --git a/toys/net/microcom.c b/toys/net/microcom.c index 770afa0b..d805a062 100644 --- a/toys/net/microcom.c +++ b/toys/net/microcom.c @@ -38,7 +38,7 @@ static void handle_esc(void) char input; xputsn("\r\n[b]reak, [p]aste file, [q]uit: "); - if (read(0, &input, 1)<1 || input == 'D'-64 || input == 'q') { + if (read(0, &input, 1)<1 || input == CTRL('D') || input == 'q') { xputs("exit\r"); xexit(); } @@ -53,12 +53,12 @@ static void handle_esc(void) memset(toybuf, 0, sizeof(toybuf)); while (1) { xprintf("\r\e[2K\e[1mFilename: \e[0m%s", toybuf); - if (read(0, &input, 1) <= 0 || input == '['-64) { + if (read(0, &input, 1) <= 0 || input == CTRL('[')) { return; } if (input == '\r') break; if (input == 0x7f && len > 0) toybuf[--len] = 0; - else if (input == 'U'-64) while (len > 0) toybuf[--len] = 0; + else if (input == CTRL('U')) while (len > 0) toybuf[--len] = 0; else if (input >= ' ' && input <= 0x7f && len < sizeof(toybuf)) toybuf[len++] = input; } @@ -122,7 +122,7 @@ void microcom_main(void) // Read from stdin, write to connection. if (fds[1].revents) { if (read(0, toybuf, 1) != 1) break; - if (!FLAG(X) && *toybuf == ']'-64) handle_esc(); + if (!FLAG(X) && *toybuf == CTRL(']')) handle_esc(); else xwrite(TT.fd, toybuf, 1); } } -- cgit v1.2.3 From 117c020ebcdb6bfcbfed48fa1a6754471a355ecb Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 14 Nov 2023 14:44:37 -0600 Subject: Make changes to help text size show up in bloatcheck. --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index c6f5a873..3d9f612e 100644 --- a/main.c +++ b/main.c @@ -72,7 +72,7 @@ static const int NEED_OPTIONS = #endif #include "generated/help.h" -static char *help_data = +static const char help_data[] = #include "generated/newtoys.h" ; @@ -88,7 +88,7 @@ void show_help(FILE *out, int flags) : " (see https://landley.net/toybox)"); for (;;) { - s = help_data; + s = (void *)help_data; while (i--) s += strlen(s) + 1; // If it's an alias, restart search for real name if (*s != 255) break; -- cgit v1.2.3 From 3690494282cf06b58f60b083d3b1c1484077897f Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 17 Nov 2023 13:07:10 -0600 Subject: Update mcm-buildall.sh wrapper to autodetect host type and automatically select package versions. This means it now builds arm hosted toolchains on arm, builds x86-64 (not i686) on x86-64, and you should just be able to clone and copy a "sources" directory in and build without net access. Also backported a bugfix patch for the x86-64 host build. --- scripts/mcm-buildall.sh | 146 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 113 insertions(+), 33 deletions(-) diff --git a/scripts/mcm-buildall.sh b/scripts/mcm-buildall.sh index 11a10136..e9081d05 100755 --- a/scripts/mcm-buildall.sh +++ b/scripts/mcm-buildall.sh @@ -15,25 +15,55 @@ then exit 1 fi +# List of known targets. The format is TARGET[@RENAME]:EXTRA:CONFIG resulting +# in a gcc tuple TARGET-linux-muslEXTRA with CONFIG appended to $GCC_CONFIG +# (and thus the gcc ./configure command line). So i686:: builds i686-linux-musl +# and sh2eb::fdpic:--with-cpu=mj2 builds sh2eb-linux-muslfdpic adding +# --with-cpu=mj2 to the gcc ./configure command line. @RENAME (if present) +# changes the TARGET part of the toolchain prefix names afterwards. + +TARGETS=(i686:: aarch64:eabi: + armv4l:eabihf:"--with-arch=armv5t --with-float=soft" + "armv5l:eabihf:--with-arch=armv5t --with-fpu=vfpv2 --with-float=hard" + "armv7l:eabihf:--with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard" + "armv7m:eabi:--with-arch=armv7-m --with-mode=thumb --disable-libatomic --enable-default-pie" + armv7r:eabihf:"--with-arch=armv7-r --enable-default-pie" + i486:: m68k:: microblaze:: mips:: mips64:: mipsel:: powerpc:: + powerpc64:: powerpc64le:: s390x:: sh2eb:fdpic:--with-cpu=mj2 + sh4::--enable-incomplete-targets x86_64::--with-mtune=nocona + x86_64@x32:x32: +) + # All toolchains after the first are themselves cross compiled (so they # can be statically linked against musl on the host, for binary portability.) -# static i686 binaries are basically "poor man's x32". -BOOTSTRAP=i686-linux-musl +: ${BOOTSTRAP:=$(uname -m)} ${OUTPUT:="$PWD/ccc"} -[ -z "$OUTPUT" ] && OUTPUT="$PWD/ccc" +# Move the corresponding target to the front so rest of targets get built +# with full instead of partial -host compiler (missing threads and NLS and such) +unset TEMP +for i in $(seq 0 $((${#TARGETS[@]}-1))); +do + [ "${TARGETS[$i]}" == "${TARGETS[$i]#"$BOOTSTRAP:"}" ] && continue + TEMP="${TARGETS[$i]}" + TARGETS[$i]="$TARGETS[0]" + TARGETS[0]="$TEMP" + break; +done +[ -z "$TEMP" ] && { echo unknown target "$BOOTSTRAP"; exit 1; } if [ "$1" == clean ] then - rm -rf "$OUTPUT" host-* *.log + rm -rf ccc host-* *.log # Not gonna rm -rf "$OUTPUT" blindly, could be $HOME make clean exit fi make_toolchain() { + # Set cross compiler path LP="$PATH" - if [ -z "$TYPE" ] + if [ "$TYPE" == host ] then OUTPUT="$PWD/host-$TARGET" EXTRASUB=y @@ -57,6 +87,7 @@ make_toolchain() OUTPUT="$OUTPUT/${RENAME:-$TARGET}-$TYPE" fi + # Skip outputs that already exist if [ -e "$OUTPUT.sqf" ] || [ -e "$OUTPUT/bin/$TARGET-cc" ] || [ -e "$OUTPUT/bin/cc" ] then @@ -69,12 +100,11 @@ make_toolchain() echo -en "\033]2;$TARGET-$TYPE\007" rm -rf build/"$TARGET" "$OUTPUT" && - [ -z "$CPUS" ] && CPUS=$(($(nproc)+1)) set -x && PATH="$LP" make OUTPUT="$OUTPUT" TARGET="$TARGET" \ GCC_CONFIG="--disable-nls --disable-libquadmath --disable-decimal-float --disable-multilib --enable-languages=c,c++ $GCC_CONFIG" \ - COMMON_CONFIG="CFLAGS=\"$CFLAGS -g0 -Os\" CXXFLAGS=\"$CXXFLAGS -g0 -Os\" LDFLAGS=\"$LDFLAGS -s\" $COMMON_CONFIG" \ - install -j$CPUS || exit 1 + COMMON_CONFIG="CFLAGS=\"$CFLAGS -g0 -O2\" CXXFLAGS=\"$CXXFLAGS -g0 -O2\" \ + LDFLAGS=\"$LDFLAGS -s\" $COMMON_CONFIG" install -j$(nproc) || exit 1 set +x echo -e '#ifndef __MUSL__\n#define __MUSL__ 1\n#endif' \ >> "$OUTPUT/${EXTRASUB:+$TARGET/}include/features.h" @@ -109,8 +139,7 @@ make_toolchain() fi } -# Expand compressed target into binutils/gcc "tuple" and call make_toolchain -make_tuple() +split_tuple() { PART1=${1/:*/} PART3=${1/*:/} @@ -121,27 +150,50 @@ make_tuple() [ "$RENAME" == "$PART1" ] && RENAME= PART1=${PART1/@*/} TARGET=${PART1}-linux-musl${PART2} +} + +# Expand compressed target into binutils/gcc "tuple" and call make_toolchain +make_tuple() +{ + split_tuple "$@" [ -z "$NOCLEAN" ] && rm -rf build - for TYPE in static native + for TYPE in "${@:2}" do TYPE=$TYPE TARGET=$TARGET GCC_CONFIG="$PART3" RENAME="$RENAME" \ make_toolchain 2>&1 | tee "$OUTPUT"/log/${RENAME:-$PART1}-${TYPE}.log done } -# Packages detect nommu via the absence of fork(). Musl provides a broken fork() -# on nommu builds that always returns -ENOSYS at runtime. Rip it out. -# (Currently only for superh/jcore.) -fix_nommu() +patch_mcm() { - # Rich won't merge this - sed -i 's/--enable-fdpic$/& --enable-twoprocess/' litecross/Makefile + # musl-cross-make commit fe915821b652 has been current for a year and a half, + # and doesn't even use the latest musl release by default, so fix it up. + + # Select newer package versions and don't use dodgy mirrors + sed -i 's/mirror//;s/\(LINUX_VER =\).*/\1 6.6/;s/\(GCC_VER =\).*/\1 11.2.0/;s/\(MUSL_VER =\).*/\1 1.2.4/' \ + Makefile && + echo 'c8dbfa8285f1a90596a227690653d84b9eb2debe linux-6.6.tar.xz' > \ + hashes/linux-6.6.tar.xz.sha1 && + echo '78eb982244b857dbacb2ead25cc0f631ce44204d musl-1.2.4.tar.gz' > \ + hashes/musl-1.2.4.tar.gz.sha1 && + # mcm redundantly downloads tarball if hash file has newer timestamp, + # and it whack-a-moles how to download kernels by version for some reason. + touch -d @1 hashes/linux-6.6.tar.xz.sha1 && + touch -d @1 hashes/musl-1.2.4.tar.xz.sha1 && + sed -i 's/\(.*linux-\)3\(.*\)v3.x/\16\2v6.x/' Makefile && + + # Rich won't merge this: nommu toolchains need to vfork() and pipe. + sed -i 's/--enable-fdpic$/& --enable-twoprocess/' litecross/Makefile && - PP=patches/musl-"$(sed -n 's/MUSL_VER[ \t]*=[ \t]*//p' Makefile)" + # Packages detect nommu via the absence of fork(). Musl provides a broken + # fork() on nommu builds that always returns -ENOSYS at runtime. Rip it out. + # (Currently only for superh/jcore since no generic #ifdef __FDPIC__ symbol.) + + PP=patches/musl-"$(sed -n 's/MUSL_VER[ \t]*=[ \t]*//p' Makefile)" && mkdir -p "$PP" && - cat > "$PP"/0001-nommu.patch << 'EOF' + cat > "$PP"/0001-nommu.patch << 'EOF' && --- a/src/legacy/daemon.c +++ b/src/legacy/daemon.c @@ -17,3 +17,3 @@ @@ -209,39 +261,67 @@ EOF + ch_id = vfork (); switch (ch_id) EOF + + # Fix a gcc bug that breaks x86-64 build in gcc 11.2.0, + # from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100017#c20 + + PP=patches/gcc-"$(sed -n 's/GCC_VER[ \t]*=[ \t]*//p' Makefile)" && + mkdir -p "$PP" && + cat > "$PP"/0006-fixinc.patch << 'EOF' && +diff -ruN gcc-11.2.0.orig/configure gcc-11.2.0/configure +--- gcc-11.2.0.orig/configure 2021-07-28 01:55:06.628278148 -0500 ++++ gcc-11.2.0/configure 2023-11-17 03:07:53.819283027 -0600 +@@ -16478,7 +16478,7 @@ + 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 -ruN gcc-11.2.0.orig/configure.ac gcc-11.2.0/configure.ac +--- gcc-11.2.0.orig/configure.ac 2021-07-28 01:55:06.628278148 -0500 ++++ gcc-11.2.0/configure.ac 2023-11-17 03:08:05.975282593 -0600 +@@ -3520,7 +3520,7 @@ + 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]) +EOF + + # So the && chain above is easier to extend + true } -fix_nommu || exit 1 +patch_mcm || exit 1 mkdir -p "$OUTPUT"/log # Make bootstrap compiler (no $TYPE, dynamically linked against host libc) # We build the rest of the cross compilers with this so they're linked against # musl-libc, because glibc doesn't fully support static linking and dynamic # binaries aren't really portable between distributions -TARGET=$BOOTSTRAP make_toolchain 2>&1 | tee -a "$OUTPUT/log/$BOOTSTRAP"-host.log +make_tuple "${TARGETS[0]}" host 2>&1 | tee -a "$OUTPUT/log/$BOOTSTRAP"-host.log +split_tuple "${TARGETS[0]}" +BOOTSTRAP="$TARGET" if [ $# -gt 0 ] then for i in "$@" do - make_tuple "$i" + make_tuple "$i" static native done else # Here's the list of cross compilers supported by this build script. # First target builds a proper version of the $BOOTSTRAP compiler above, # which is used to build the rest (in alphabetical order) - for i in i686:: \ - aarch64:eabi: armv4l:eabihf:"--with-arch=armv5t --with-float=soft" \ - "armv5l:eabihf:--with-arch=armv5t --with-fpu=vfpv2 --with-float=hard" \ - "armv7l:eabihf:--with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard" \ - "armv7m:eabi:--with-arch=armv7-m --with-mode=thumb --disable-libatomic --enable-default-pie" \ - armv7r:eabihf:"--with-arch=armv7-r --enable-default-pie" \ - i486:: m68k:: microblaze:: mips:: mips64:: mipsel:: powerpc:: \ - powerpc64:: powerpc64le:: s390x:: sh2eb:fdpic:--with-cpu=mj2 \ - sh4::--enable-incomplete-targets x86_64::--with-mtune=nocona \ - x86_64@x32:x32: + for i in $(seq 0 $((${#TARGETS[@]}-1))) do - make_tuple "$i" + make_tuple "${TARGETS[$i]}" static native done fi -- cgit v1.2.3 From b5be73ab5e18fcf3a4c6710e01190f633f17a52b Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 18 Nov 2023 14:47:45 -0600 Subject: Fix gz/xz mismatch. --- scripts/mcm-buildall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mcm-buildall.sh b/scripts/mcm-buildall.sh index e9081d05..7ea52903 100755 --- a/scripts/mcm-buildall.sh +++ b/scripts/mcm-buildall.sh @@ -181,7 +181,7 @@ patch_mcm() # mcm redundantly downloads tarball if hash file has newer timestamp, # and it whack-a-moles how to download kernels by version for some reason. touch -d @1 hashes/linux-6.6.tar.xz.sha1 && - touch -d @1 hashes/musl-1.2.4.tar.xz.sha1 && + touch -d @1 hashes/musl-1.2.4.tar.gz.sha1 && sed -i 's/\(.*linux-\)3\(.*\)v3.x/\16\2v6.x/' Makefile && # Rich won't merge this: nommu toolchains need to vfork() and pipe. -- cgit v1.2.3 From c570ab47b03797c460873bf127c497d6133a43c2 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 20 Nov 2023 13:33:53 -0600 Subject: Cleanup pass. --- toys/pending/dhcpd.c | 132 +++++++++++++++++++++------------------------------ 1 file changed, 54 insertions(+), 78 deletions(-) diff --git a/toys/pending/dhcpd.c b/toys/pending/dhcpd.c index c5125e71..f6d063d6 100644 --- a/toys/pending/dhcpd.c +++ b/toys/pending/dhcpd.c @@ -123,8 +123,8 @@ config DEBUG_DHCP #define DHCP6_DUID_UUID 4 GLOBALS( - char *iface; - long port; + char *i; + long p; ) struct config_keyword { @@ -134,29 +134,18 @@ struct config_keyword { char *def; }; -typedef struct __attribute__((packed)) dhcp_msg_s { - uint8_t op; - uint8_t htype; - uint8_t hlen; - uint8_t hops; - uint32_t xid; - uint16_t secs; - uint16_t flags; - uint32_t ciaddr; - uint32_t yiaddr; - uint32_t nsiaddr; - uint32_t ngiaddr; - uint8_t chaddr[16]; - uint8_t sname[64]; - uint8_t file[128]; - uint32_t cookie; - uint8_t options[308]; +typedef struct dhcp_msg_s { + char op, htype, hlen, hops; + unsigned xid; + unsigned short secs, flags; + unsigned ciaddr, yiaddr, nsiaddr, ngiaddr; + char chaddr[16], sname[64], file[128]; + unsigned cookie; + char options[308]; } dhcp_msg_t; -typedef struct __attribute__((packed)) dhcp6_msg_s { - uint8_t msgtype; - uint8_t transaction_id[3]; - uint8_t options[524]; +typedef struct dhcp6_msg_s { + char msgtype, transaction_id[3], options[524]; } dhcp6_msg_t; typedef struct __attribute__((packed)) dhcp_raw_s { @@ -173,63 +162,53 @@ typedef struct __attribute__((packed)) dhcp6_raw_s { typedef struct static_lease_s { struct static_lease_s *next; - uint32_t nip; + unsigned nip; int mac[6]; } static_lease; typedef struct static_lease6_s { struct static_lease6_s *next; - uint16_t duid_len; - uint16_t ia_type; - uint32_t iaid; - uint8_t nip6[16]; - uint8_t duid[20]; + unsigned short duid_len, ia_type; + unsigned iaid; + char nip6[16], duid[20]; } static_lease6; typedef struct { - uint32_t expires; - uint32_t lease_nip; - uint8_t lease_mac[6]; - char hostname[20]; - uint8_t pad[2]; + unsigned expires, lease_nip; + char lease_mac[6], hostname[20], pad[2]; } dyn_lease; typedef struct { - uint16_t duid_len; - uint16_t ia_type; - uint32_t expires; - uint32_t iaid; - uint8_t lease_nip6[16]; - uint8_t duid[20]; + unsigned short duid_len, ia_type; + unsigned expires, iaid; + char lease_nip6[16], duid[20]; } dyn_lease6; typedef struct option_val_s { char *key; - uint16_t code; + unsigned short code; void *val; size_t len; } option_val_t; -struct __attribute__((packed)) optval_duid_llt { - uint16_t type; - uint16_t hwtype; - uint32_t time; - uint8_t lladdr[]; //flexible +struct optval_duid_llt { + unsigned short type, hwtype; + unsigned time; + char lladdr[]; }; -struct __attribute__((packed)) optval_ia_na { - uint32_t iaid; - uint32_t t1, t2; - uint8_t optval[]; //flexible +struct optval_ia_na { + unsigned iaid, t1, t2; + char optval[]; }; -struct __attribute__((packed)) optval_ia_addr { - uint8_t ipv6_addr[16]; - uint32_t pref_lifetime; - uint32_t valid_lifetime; + +struct optval_ia_addr { + char ipv6_addr[16]; + unsigned pref_lifetime, valid_lifetime; }; -struct __attribute__((packed)) optval_status_code { - uint16_t status_code; - uint8_t status_msg[]; //flexible +struct optval_status_code { + unsigned short status_code; + char status_msg[]; }; typedef struct __attribute__((__may_alias__)) server_config_s { @@ -907,7 +886,7 @@ static int send_packet(uint8_t broadcast) dhcp_raw_t packet; unsigned padding; int fd, result = -1; - uint8_t bmacaddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + char bmacaddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; memset(&packet, 0, sizeof(dhcp_raw_t)); memcpy(&packet.dhcp, &gstate.send.send_pkt, sizeof(dhcp_msg_t)); @@ -1606,36 +1585,35 @@ void dhcpd_main(void) { struct timeval tv; int retval, i; - uint8_t *optptr, msgtype = 0; - uint16_t optlen = 0; - uint32_t waited = 0, serverid = 0, requested_nip = 0; - uint8_t transactionid[3] = {0,}; - uint32_t reqested_lease = 0, ip_pool_size = 0; - char *hstname = NULL; + char *optptr, msgtype = 0, *hstname = 0, transactionid[3] = {0}; + unsigned short optlen = 0; + unsigned waited = 0, serverid = 0, requested_nip = 0, reqested_lease = 0, + ip_pool_size = 0; fd_set rfds; infomode = LOG_CONSOLE; - if (!(toys.optflags & FLAG_f)) { - daemon(0,0); + if (!FLAG(f)) { + daemon(0, 0); infomode = LOG_SILENT; } - if (toys.optflags & FLAG_S) { - openlog("UDHCPD :", LOG_PID, LOG_DAEMON); - infomode |= LOG_SYSTEM; + if (FLAG(S)) { + openlog("UDHCPD :", LOG_PID, LOG_DAEMON); + infomode |= LOG_SYSTEM; } setlinebuf(stdout); //DHCPD_CONF_FILE - parse_server_config((toys.optc==1)?toys.optargs[0]:"/etc/dhcpd.conf", keywords); + parse_server_config((toys.optc==1) ? *toys.optargs: "/etc/dhcpd.conf", + keywords); infomsg(infomode, "toybox dhcpd started"); - if (toys.optflags & FLAG_6){ + if (FLAG(6)) { addr_version = AF_INET6; gconfig.t1 = ntohl(gconfig.t1); gconfig.t2 = ntohl(gconfig.t2); gconfig.pref_lifetime = ntohl(gconfig.pref_lifetime); gconfig.valid_lifetime = ntohl(gconfig.valid_lifetime); gconfig.port = 547; - for(i=0;i<4;i++) + for(i=0; i<4; i++) ip_pool_size += (gconfig.end_ip6[i]-gconfig.start_ip6[i])<<((3-i)*8); } else { gconfig.start_ip = ntohl(gconfig.start_ip); @@ -1650,19 +1628,17 @@ void dhcpd_main(void) } write_pid(gconfig.pidfile); set_maxlease(); - if(TT.iface) gconfig.interface = TT.iface; - if(TT.port) gconfig.port = TT.port; + if (TT.i) gconfig.interface = TT.i; + if (TT.p) gconfig.port = TT.p; (addr_version==AF_INET6) ? read_lease6file() : read_leasefile(); - if (get_interface(gconfig.interface, &gconfig.ifindex, (addr_version==AF_INET6)? (void*)gconfig.server_nip6 : (void*)&gconfig.server_nip, gconfig.server_mac) < 0) perror_exit("Failed to get interface %s", gconfig.interface); setup_signal(); - if (addr_version==AF_INET6) { - open_listensock6(); - } else { + if (addr_version==AF_INET6) open_listensock6(); + else { gconfig.server_nip = htonl(gconfig.server_nip); open_listensock(); } -- cgit v1.2.3 From 7fac232b4d25e51372ee22512c92e724ce97734e Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 21 Nov 2023 17:13:47 -0600 Subject: Don't trigger ASAN leak detector. --- toys/pending/sh.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/toys/pending/sh.c b/toys/pending/sh.c index f65c478a..9299d8d6 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -4394,7 +4394,8 @@ void cd_main(void) void exit_main(void) { - exit(*toys.optargs ? atoi(*toys.optargs) : 0); + toys.exitval = *toys.optargs ? atoi(*toys.optargs) : 0; + xexit(); } // lib/args.c can't +prefix & "+o history" needs space so parse cmdline here -- cgit v1.2.3