Skip to content

Build: link glibc libm ahead of the Rust staticlib so math calls use VFP - #821

Merged
GLinnik21 merged 1 commit into
mainfrom
link-libm-first
Oct 16, 2026
Merged

GLinnik21 merged 1 commit into
mainfrom
link-libm-first

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

Part of #768. Follow-up to #816.

Cause

With stable Rust's prebuilt compiler_builtins, every libm name our code calls (roundf, round, floorf, ceilf, ceil, trunc, fmodf, fmod, cbrtf, sqrtf, sqrt, fma) bound to compiler_builtins' WEAK soft-float copy instead of the TV's glibc libm (VFPv3, softfp). $(RUST_LIB) precedes -lm on the link line, and a definition extracted from an archive is never overridden by a shared library that comes later. roundf alone has 119 call sites in draw paths, and nanosvg's C calls in src/svg.o went soft too. The fix names -lm ahead of $(RUST_LIB) so libm.so already defines the names and the archive members are never extracted.

Before / after (make ARM_PROFILE=release, relink only for the second row)

before after
soft arithmetic bl __aeabi_[fd](add/sub/rsub/mul/div/cmp*/2f/2d) 57 9 (core's float parsing)
bl __aeabi_fmul 5 2
local libm bodies 12 (ceilf trunc sqrt fmod floorf sqrtf cbrtf fmodf ceil roundf round fma) 0
UND ...@GLIBC_2.4 math symbols 0 11
vmul.f32 / vsqrt.f32 3057 / 29 3057 / 29
size 19,110,232 B 18,981,788 B (-128,444)
DT_NEEDED 15 15 (unchanged)
undefined dynamic symbols 349 360

i64 to float conversions (__aeabi_d2lz, __aeabi_l2d, ...) remain libcalls on ARMv7 regardless of ABI, since VFPv3 has no instruction for them.

fw-compat review (manual, .agents/agents/fw-compat-reviewer.md)

Verdict: PASS, graded on a binary built from this diff. The change is link order only: no new -l, no dynlib!/extern/dlopen change, DT_NEEDED unchanged (15 entries, check-elf.sh). tools/fwcompat.py --min-release 4.4.2: OK on 4.4.2, 4.10.0, 5.3.1, 6.4.0, 7.4.0, 8.3.0, 9.2.0, 10.2.0, 11.2.0; the same verdicts as the pre-change binary (the older rows below the floor also match). The 11 new undefined math symbols are all resolved by libm on every gated release. This grades starting, not behavior; TV timing is separate.

Tests

  • python3 ci/test_check_elf.py: Ran 20 tests, OK. New cases: red for a local body of each of the 12 names, red for more than 16 soft arithmetic calls, green for the fixed shape.
  • Red/green: without the Makefile change ci/check-elf.sh fails ("local definitions of libm functions (...)"); with it, "ok - no local libm bodies, 9 soft-float arithmetic calls", all ELF assertions passed.
  • python3 ci/check-vfp.py: ok.
  • New ci/check-elf.sh section; corrected the "about 5 calls" comments in it and rust-modules/.cargo/config.toml.

Pending / notes

  • TV timing is pending (the TV is busy).
  • Build-bench: the Makefile changed, but this is link order only. A local make build-bench was not run because the Mac is congested; CI gates.

🤖 Generated with Claude Code

With stable Rust's prebuilt compiler_builtins, roundf/round/floorf/ceilf/ceil/trunc/fmodf/fmod/
cbrtf/sqrtf/sqrt/fma bound to compiler_builtins' weak soft-float copies because $(RUST_LIB)
precedes -lm. Name -lm first so libm.so already defines them; add a check-elf.sh section and unit
cases that fail on a local libm body or more than 16 soft arithmetic libcalls; correct the
'about 5 calls' comments.

Part of #768. Follow-up to #816.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit 0aa486d into main Oct 16, 2026
24 checks passed
@GLinnik21
GLinnik21 deleted the link-libm-first branch October 16, 2026 15:50
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