Skip to content

waf: only require a Picolibc parser alias the binary actually uses - #35214

Draft
peterbarker wants to merge 1 commit into
ArduPilot:masterfrom
peterbarker:autotest-parallel/picolibc-darwin-strtod
Draft

peterbarker wants to merge 1 commit into
ArduPilot:masterfrom
peterbarker:autotest-parallel/picolibc-darwin-strtod

Conversation

@peterbarker

Copy link
Copy Markdown
Contributor

Summary

The SITL Picolibc parser check fails every macOS AP_Periph build:

waflib.Errors.WafError: Missing Picolibc SITL symbols in build/sitl_periph_universal/bin/AP_Periph: _strtod

The check requires both halves of each public/implementation symbol pair
whenever either appears. An implementation can be linked in on its own, so a
correct binary fails. Key the requirement on the public symbol instead, as the
malloc check beside it already does.

Classification & Testing (check all that apply and add your own)

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually, description below (e.g. SITL)
  • Tested on hardware
  • Logs attached
  • Logs available on request

Tools/ardupilotwaf/tests/test_symbols.py gains
test_sitl_parser_implementation_without_public_use, which presents an
implementation symbol with no public alias for each of the three parsers. It
fails 3/3 against the parent commit and passes with the fix; the file's suite
is 97 passed.

On a 10-core arm64 macOS host, at the parent commit:

[1066/1066] checking symbols build/sitl_periph_universal/bin/AP_Periph
Build failed
waflib.Errors.WafError: Missing Picolibc SITL symbols in .../bin/AP_Periph: _strtod

and with the fix applied:

[1066/1066] checking symbols build/sitl_periph_universal/bin/AP_Periph
'build' finished successfully (1.509s)
[1442/1442] checking symbols build/sitl/bin/arduplane
'plane' finished successfully (46.693s)

The arduplane build is there to show the check still runs and still passes
where both halves of a pair are present, rather than having been defanged.

Description

libraries/AP_Common/picolibc.cpp redirects atof, strtod and strtof to
Picolibc's implementations. On Darwin there is no --wrap, so it defines the
public symbol directly, via __asm__("_strtod") and friends. The check then
verifies that a binary which uses one of those parsers really does reach
Picolibc's version rather than the host's.

Its rule was "if either name of a pair appears, both must be defined". That
premise does not hold for the implementation half, for two reasons at once:

  • an implementation can arrive without anything asking for it, because
    Picolibc's own strtof calls its strtod; and
  • Darwin's linker drops a public alias nothing references.

AP_Periph on macOS lands in exactly that state. It defines _strtof,
_atof and all three _ap_picolibc_* symbols, and contains no _strtod at
all — nm -u lists no undefined reference to it and nm -a finds no
definition. Nothing in the firmware parses a double, so there is no host-libc
call to redirect, yet the presence of _ap_picolibc_strtod demanded a
_strtod which had been correctly omitted.

Requiring the pair only when the public symbol appears keeps the protection
that matters: a referenced-but-undefined _strtod still fails, which is the
case where a call would reach the host's locale-dependent parser. The malloc
check fifteen lines below already reasons this way — "a binary that never
calls malloc doesn't pull in the wrapper".

Linux is unaffected, which is why CI did not catch this: there the public
alias is a plain strong definition in the object file and is not stripped, so
all three pairs stay complete. The practical effect of the bug is that
build.SITLPeriphUniversal, build.SITLPeriphBattMon, test.CAN and
test.BattCAN cannot run on macOS at all, along with the autotests that need
a peripheral binary (DroneCANCompass, PeriphMultiUARTTunnel,
CircuitStatusScript).

An alternative fix would be to mark the public aliases
__attribute__((used)) in AP_Common/picolibc.cpp, guaranteeing the
interposition instead of detecting its absence, at the cost of carrying
unused functions in every binary. This PR takes the smaller change, on the
grounds that the check's premise was simply wrong.

This contribution was AI-assisted: the diagnosis, the change and this
description were produced with Claude Code, and reviewed by the submitter.

The SITL parser check required both halves of each public/implementation
pair whenever either of them appeared.  An implementation can be linked
in on its own, though: picolibc's strtof calls its strtod, so
ap_picolibc_strtod ends up defined in a binary which never names strtod.
On Darwin the public alias AP_Common defines for a parser nothing
references is then dropped by the linker, and the check failed a correct
binary:

    Missing Picolibc SITL symbols in build/sitl_periph_universal/bin/AP_Periph: _strtod

AP_Periph on macOS carries _strtof, _atof and all three _ap_picolibc_*
symbols, and no _strtod at all - neither defined nor undefined - so
nothing in it parses a double and there is no host-libc call to
redirect.  Key the requirement on the public symbol, as the malloc check
below it already does for the same reason.
@github-actions

Copy link
Copy Markdown

Global Size Summary (Total Flash delta in bytes)

Built from a8434af rebased onto a42f84a

Board Periph tracker blimp bootloader copter heli iofw plane rover sub
DrotekP3Pro _ _ _ * _ _ _ _ _ _
Durandal _ * * _ * * _ * * *
Hitec-Airspeed * _ _ _ _ _ _ _ _ _
KakuteF7 _ * * _ * * _ * * *
MambaH743v4 _ * * _ * * _ * * *
MatekF405-CAN _ _ _ * _ _ _ _ _ _
MatekF405 _ * * _ * * _ * * *
MatekH743-bdshot _ * * _ * * _ * * *
Pixhawk1-1M _ * * _ * * _ * * *
disco _ * * _ * * _ * * *
f103-GPS * _ _ _ _ _ _ _ _ _

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant