boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

commit 79c5cce3f31c1bb066907dc8c456db129d5922b0
parent 539aef860248022becef03c2f96222e0630832b6
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Mon,  4 May 2026 16:24:17 -0700

boot4: simplify struct timespec in alltypes.h to silence tcc warning

tcc 0.9.26 emits "will touch memory past end of the struct (internal
limitation)" for any struct ending in a zero-width bitfield. musl wraps
tv_nsec in two such bitfields to handle 32-bit-time_t arches:

  struct timespec { time_t tv_sec;
    int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER==4321);
    long tv_nsec;
    int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER!=4321);
  };

On all three boot4 arches sizeof(time_t)==sizeof(long)==8, so both
bitfields are 0 width and the layout matches the simple two-field form.
The leading bitfield does not warn (a sibling follows); the trailing
one fired 387 times per build.

musl-vendor.sh now post-processes the mkalltypes output to substitute
the simple form. boot4 aarch64 build is now warning-free; libc.a drops
4 bytes (presumably tcc bitfield metadata in the archive); hello still
links, runs, and produces identical output.

Diffstat:
Mscripts/musl-vendor.sh | 25++++++++++++++++++++++++-
Mvendor/upstream/musl-1.2.5-generated/aarch64/alltypes.h | 2+-
Mvendor/upstream/musl-1.2.5-generated/riscv64/alltypes.h | 2+-
Mvendor/upstream/musl-1.2.5-generated/x86_64/alltypes.h | 2+-
4 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/scripts/musl-vendor.sh b/scripts/musl-vendor.sh @@ -131,10 +131,33 @@ rm -rf "$ROOT/$GENERATED" for MARCH in aarch64 x86_64 riscv64; do out=$ROOT/$GENERATED/$MARCH mkdir -p "$out" + # Post-process: simplify struct timespec to drop the trailing + # zero-width bitfield (see comment above the awk pipeline below). awk -f "$ROOT/$MKALLTYPES_AWK" \ "$POST/musl-1.2.5/arch/$MARCH/bits/alltypes.h.in" \ "$POST/musl-1.2.5/include/alltypes.h.in" \ - > "$out/alltypes.h" + | awk ' + /^struct timespec \{.*tv_nsec/ { + print "struct timespec { time_t tv_sec; long tv_nsec; };" + next + } + { print } + ' > "$out/alltypes.h" + # Why the post-process: tcc 0.9.26 emits "will touch memory past + # end of the struct (internal limitation)" for any struct ending + # in a zero-width bitfield. The musl alltypes.h definition wraps + # tv_nsec in two bitfield-padding tricks for 32-bit-time_t arches: + # + # struct timespec { time_t tv_sec; + # int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER==4321); + # long tv_nsec; + # int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER!=4321); + # }; + # + # On all three boot4 arches sizeof(time_t)==sizeof(long)==8, so + # both bitfields are 0 width and the layout is identical to the + # simple two-field form. The leading bitfield does not warn (a + # sibling follows); the trailing one does, 387 times per build. cp "$POST/musl-1.2.5/arch/$MARCH/bits/syscall.h.in" "$out/syscall.h" awk 'sub(/__NR_/, "SYS_") { print }' \ < "$POST/musl-1.2.5/arch/$MARCH/bits/syscall.h.in" \ diff --git a/vendor/upstream/musl-1.2.5-generated/aarch64/alltypes.h b/vendor/upstream/musl-1.2.5-generated/aarch64/alltypes.h @@ -234,7 +234,7 @@ struct timeval { time_t tv_sec; suseconds_t tv_usec; }; #endif #if defined(__NEED_struct_timespec) && !defined(__DEFINED_struct_timespec) -struct timespec { time_t tv_sec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER==4321); long tv_nsec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER!=4321); }; +struct timespec { time_t tv_sec; long tv_nsec; }; #define __DEFINED_struct_timespec #endif diff --git a/vendor/upstream/musl-1.2.5-generated/riscv64/alltypes.h b/vendor/upstream/musl-1.2.5-generated/riscv64/alltypes.h @@ -224,7 +224,7 @@ struct timeval { time_t tv_sec; suseconds_t tv_usec; }; #endif #if defined(__NEED_struct_timespec) && !defined(__DEFINED_struct_timespec) -struct timespec { time_t tv_sec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER==4321); long tv_nsec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER!=4321); }; +struct timespec { time_t tv_sec; long tv_nsec; }; #define __DEFINED_struct_timespec #endif diff --git a/vendor/upstream/musl-1.2.5-generated/x86_64/alltypes.h b/vendor/upstream/musl-1.2.5-generated/x86_64/alltypes.h @@ -226,7 +226,7 @@ struct timeval { time_t tv_sec; suseconds_t tv_usec; }; #endif #if defined(__NEED_struct_timespec) && !defined(__DEFINED_struct_timespec) -struct timespec { time_t tv_sec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER==4321); long tv_nsec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER!=4321); }; +struct timespec { time_t tv_sec; long tv_nsec; }; #define __DEFINED_struct_timespec #endif