Skip to content

yaff: rodata anchor without GOT relocations; 912 on the RP2350 DCP; chk_calls in libtcc1 - #30

Merged
matgla merged 3 commits into
mobfrom
fix/yaff-rodata-anchor
Dec 1, 2026
Merged

matgla merged 3 commits into
mobfrom
fix/yaff-rodata-anchor

Conversation

@matgla

@matgla matgla commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

912_complex_div_runtime failed on the device, for two unrelated reasons.

QEMU (an524): crash. Under -share-rodata, code reads .rodata through GOT index 3 ([r9, #24]). The loader fills that slot from a local relocation. tcc_yaff_write_local_relocations returned before writing it when .got had no relocations, i.e. for a module that imports nothing. libsoftfp.so became such a module once divc3.c gave it constants. Its anchor slot stayed 0, so __divsc3 faulted reading address 4. libm.so has the same shape and was affected too.

  • Fix: the anchor relocation is now written by one helper, called on both the early-return path and the normal path.
  • Test: test_yaff_rodata_anchor.py (needs a YasOS cross; it skips on CI's "ARM Linux" cross, which reserves no anchor slot).

Pico Plus 2: FAIL divdc3 0. The board links the runtime statically, so the anchor was not the problem there. The RP2350 double coprocessor reads a subnormal operand as zero. That is why yasos already skips ieee/cdivchkd on the device, and 912's double vectors are cdivchkd's.

  • Change: where a subnormal double compares equal to zero, 912 skips the double vectors that hold a subnormal. (1+2i)/(3+4i), cdivchkd's normal vector and the Annex G cases still run.
  • Check: on x86 with DAZ/FTZ on for doubles, the old test fails with the board's exact message (0 18446744073709551615 ulps) and the new one passes.

libtcc1: chk_calls moved in from yasos libc. libtcc1's __tcc_*_chk functions increment a counter that gcc's builtins chk tests read. Until now yasos libc defined it (bounds.c) and libtcc1 only held a weak reference.

  • Change: lib/builtin.c now defines it, weak, so it works with any libc and a program's own definition (gcc's builtins/lib/chk.c) still wins. The yasos libc PR removes bounds.c.
  • Found on the way: without a libc definition, a program reading chk_calls linked anyway and read address 0. libtcc1's weak reference left the symbol weak-undefined, and tcc's linker accepted the program's strong reference. GNU ld would report an undefined reference. Not fixed here.
  • Test: test_fortify.py::test_chk_calls_counter on QEMU at -O0/-O2, once with libtcc1's counter and once with the program's own. The libtcc1 case printed junk before the change. test_fortify.py passes 32/32 with the yasos libc headers.

Verification:

  • yasos qemu_gate passed with the anchor fix.
  • 912 passes at -O0/-O1/-O2/-Os on the host with a CI-configured cross.

🤖 Generated with Claude Code

matgla and others added 2 commits November 25, 2026 23:42
Code under -share-rodata reaches .rodata through GOT index 3 ([r9, #24]),
which the loader fills from a local relocation.  The writer returned before
emitting it when .got had no relocations -- a module that imports nothing.
libsoftfp.so is one since divc3.c gave it constants: its anchor stayed 0, so
__divsc3 faulted on QEMU and __divdc3 read the board's ROM as constants
(912_complex_div_runtime on the device).  libm.so had the same latent hole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The RP2350's double coprocessor reads a subnormal operand as zero (the
reason yasos skips ieee/cdivchkd on the device), and 912's double vectors
are cdivchkd's: on the board __divdc3 of vector 0 came out +0 for
-0x1.e9095e311e706p-900.  Where a subnormal double compares equal to zero
the vectors holding one are skipped; (1+2i)/(3+4i), cdivchkd's normal
vector and the Annex G cases still run.  Checked against x86 with
DAZ/FTZ on for doubles: the old test fails exactly as the board did, the
new one passes.

test_yaff_rodata_anchor skips on a cross without TARGETOS_YasOS: only a
YasOS cross reserves the anchor slot and shares .rodata by default (CI's
cross is "ARM Linux").  Its docstring no longer blames the board's failure
on the anchor -- the board links the runtime statically.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matgla matgla changed the title yaff: emit the rodata anchor when the GOT has no relocations yaff: rodata anchor without GOT relocations; 912 on the RP2350 DCP Nov 26, 2026
yasos libc defined chk_calls (bounds.c) for libtcc1's __tcc_*_chk functions
to count into; libtcc1 only referenced it weakly.  It is now a weak
definition in builtin.c, so the counter works with any libc, and a program's
own definition (gcc's builtins/lib/chk.c) still wins.

Without a libc definition a program reading chk_calls linked anyway and read
address 0: libtcc1's weak reference left the symbol weak-undefined.
test_fortify.py: test_chk_calls_counter, both ways, at -O0 and -O2 on QEMU.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matgla matgla changed the title yaff: rodata anchor without GOT relocations; 912 on the RP2350 DCP yaff: rodata anchor without GOT relocations; 912 on the RP2350 DCP; chk_calls in libtcc1 Nov 26, 2026
@matgla
matgla merged commit c79fd48 into mob Dec 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant