commit 85ca53b7d3dfe775399b30f30a1531c64d6c4726
parent 0493f0042030ecca28f7d0d67039372cf165a4b8
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Fri, 5 Jun 2026 19:26:02 -0700
Fix rv64 toy TLS cross startup
Diffstat:
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/doc/plan/TODO.md b/doc/plan/TODO.md
@@ -5,10 +5,6 @@ fixed, remove it instead of checking it off or keeping a closed entry.
Add new deferred fixes below as they are discovered.
-## MISC
-
-- [ ] test-toy failures: 141_threadlocal_mutate/X-O0:rv64 141_threadlocal_mutate/X-O1:rv64
-
## aarch64-windows: `118_decl_extra_attrs` fails to link (ADRP out of range)
`kit cc -target aarch64-windows` on `test/toy/cases/118_decl_extra_attrs.toy`
diff --git a/test/toy/run.sh b/test/toy/run.sh
@@ -209,9 +209,24 @@ cross_tag_for() {
esac
}
+cross_start_triple_for() {
+ local arch="$1" triple="$2"
+ case "$arch" in
+ rv64|riscv64)
+ # The X lane links a no-libc static image with this custom _start.
+ # Compile the rv64 startup object as freestanding so kit ld keeps
+ # the same +16 TCB-biased TLS convention that the stub installs,
+ # while the Toy object itself still exercises the Linux target.
+ printf 'riscv64-none-elf' ;;
+ *)
+ printf '%s' "$triple" ;;
+ esac
+}
+
cross_make_start_obj() {
- local arch="$1" triple="$2" work="$3"
+ local arch="$1" triple="$2" work="$3" start_triple
local start_c="$work/$arch.start.c" start_o="$work/$arch.start.o"
+ start_triple="$(cross_start_triple_for "$arch" "$triple")"
cat > "$start_c" <<'EOF_START'
extern int main(void);
@@ -297,7 +312,7 @@ EOF_START
# included. -fno-PIC/-fno-pie give absolute (non-GOT) relocations for the
# kit-ld-synthesized __tdata_{start,end} boundary symbols, matching the
# static ET_EXEC the link produces. (kit cc has no -fno-stack-protector.)
- if ! "$KIT" cc -O1 -target "$triple" -ffreestanding \
+ if ! "$KIT" cc -O1 -target "$start_triple" -ffreestanding \
-fno-PIC -fno-pie -c "$start_c" -o "$start_o" \
> "$work/$arch.start.out" 2> "$work/$arch.start.err"; then
return 1
@@ -402,7 +417,7 @@ cross_one() {
# The stub is compiled by kit cc (the tool under test), so a failure here
# is a real codegen bug, not a missing host toolchain — surface it as FAIL.
start_obj="$(cross_make_start_obj "$arch" "$triple" "$KIT_WORK")" || {
- kit_fail "$label" "kit cc -target $triple failed on startup stub"
+ kit_fail "$label" "kit cc failed on startup stub"
sed 's/^/ | /' "$KIT_WORK/$arch.start.err"
return
}
@@ -626,7 +641,15 @@ KIT_LABEL=toy KIT_BUILD_DIR="$BUILD_DIR" \
# the native compile paths (R/L/X) is enabled.
if [ "$RUN_R" -eq 1 ] || [ "$RUN_L" -eq 1 ] || [ "$RUN_X" -eq 1 ]; then
err_cases=("$TEST_DIR"/err/*.toy)
- if [ "${#err_cases[@]}" -gt 0 ]; then
+ err_have_match=1
+ if [ -n "${KIT_TEST_FILTER:-}" ]; then
+ err_have_match=0
+ for src in "${err_cases[@]}"; do
+ base="$(basename "${src%.toy}")"
+ case "$base" in *"$KIT_TEST_FILTER"*) err_have_match=1; break ;; esac
+ done
+ fi
+ if [ "${#err_cases[@]}" -gt 0 ] && [ "$err_have_match" -eq 1 ]; then
KIT_LABEL=toy KIT_BUILD_DIR="$BUILD_DIR/err" \
KIT_CORPUS_GLOBS="$TEST_DIR/err/*.toy" KIT_CORPUS_EXT=toy \
KIT_SIDECAR_DIR="$TEST_DIR/err" \