Skip to content

platforms: prefer picolibc where the distro keeps it outside the sysroot - #279

Open
TurkeyMan wants to merge 1 commit into
masterfrom
ow/picolibc-libc-probe
Open

TurkeyMan wants to merge 1 commit into
masterfrom
ow/picolibc-libc-probe

Conversation

@TurkeyMan

Copy link
Copy Markdown
Member

--print-file-name resolves against the compiler's own search directories and
does not consult the library paths a specs file adds. On a distro where picolibc
is the toolchain sysroot (Debian) that goes unnoticed, because the answer is
picolibc either way. On a distro that keeps picolibc outside the sysroot (Ubuntu,
/usr/lib/picolibc/<triple>/lib/) the same probe answers with newlib whenever
libnewlib-* is also installed, and the image silently links a libc that is not
the one being shipped.

The existing tail fallback was already the correct lookup, but hardcoded to
riscv64-unknown-elf and unreachable: the probe ahead of it returns a path
rather than nothing, so $(or ...) never advances to it.

This generalises that lookup to the triple and asks it first. Debian is
unaffected (the directory does not exist, so it falls through to the specs probe
exactly as before); Ubuntu arm targets switch from newlib to picolibc, which is
what the released firmware links. Measured on openwatt's bk7231n, where newlib
costs about 20KB of flash against a 0.4% margin.

--print-file-name cannot see the library paths the specs add, so on a distro
that ships picolibc outside the toolchain sysroot it answers with newlib and
the image silently links a libc that is not the one being shipped.
@TurkeyMan
TurkeyMan force-pushed the ow/picolibc-libc-probe branch from 1defcd4 to 0ae1f50 Compare September 10, 2026 15:11
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