Skip to content

waf: detect -ld_classic linker support instead of assuming it - #34928

Open
AdemiseG wants to merge 1 commit into
ArduPilot:masterfrom
AdemiseG:darwin-ld-classic-probe
Open

AdemiseG wants to merge 1 commit into
ArduPilot:masterfrom
AdemiseG:darwin-ld-classic-probe

Conversation

@AdemiseG

Copy link
Copy Markdown

Follow-up to #34924, as discussed there: #34924 (comment)

-ld_classic is gated on cc_version_gte(cfg, 15, 0) with no upper bound, so every clang from 15 upward is passed it. Apple has since removed the classic linker, so on current Xcode every macOS link emits:

ld: warning: -ld_classic is no longer supported and will be ignored

The flag was added for Xcode 15.3 for a real reason, so it cannot simply be dropped. This probes for it at configure time instead, following the check_librt pattern in cxx_checks.py. The complication is that the flag only produces a warning, not an error, so a plain link test succeeds on both old and new linkers; the check links a trivial program with -fatal_warnings to turn that warning into a failure.

Linkers that still accept -ld_classic are unaffected and keep the flag.

Testing

macOS 27.0.1 (26A434), Apple Silicon arm64, Apple clang 21.0.0 (clang-2100.3.34.2), ld PROJECT:ld-27037.1.

Configure reports the new check alongside the existing ones:

CXX Compiler                             : clang++ 21.0.0
Checking for -ld_classic linker support  : unavailable

and -ld_classic is absent from the stored LINKFLAGS, with -dead_strip retained:

LINKFLAGS = ['-Wl,-dead_strip', '-pthread', '-fno-builtin']

./waf copter links with no linker warnings, and the resulting binary boots and runs the SITL sim loop.

To check that the probe discriminates rather than always failing, I re-ran it against a flag this linker does accept (-dead_strip): it reports available and the flag is kept. That is the Xcode 15.3 path, exercised by proxy -- I do not have a 15.3 toolchain to test directly, so confirmation from someone who does would be welcome.

Note on the build: master alone does not link on this toolchain until #34924 lands, so the build and run above were done with #34924 merged in locally. This branch itself contains only the two waf files.

-ld_classic was added for Xcode 15.3, gated on clang >= 15.0 with no upper
bound. Apple has since removed the classic linker, so every clang from 15
upward was passed a flag that newer linkers only warn about and ignore:

    ld: warning: -ld_classic is no longer supported and will be ignored

Probe for it at configure time instead. The flag only produces a warning,
not an error, so the check links a trivial program with -fatal_warnings to
turn that warning into a failure. Linkers that still support the flag are
unaffected and keep it.
@github-actions

Copy link
Copy Markdown

Global Size Summary (Total Flash delta in bytes)

Built from 05ae33c rebased onto 6743a33

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 * _ _ _ _ _ _ _ _ _

@AdemiseG

Copy link
Copy Markdown
Author

CI note: the one red check, autotest (sitltest-quadplane-tests1c), is a pre-existing flake and not caused by this PR.

It fails in QAUTOTUNE with NotAchievedException('autotune did not succeed'), after the vehicle reports AutoTune: Failed to level, please tune manually. The same job failed on master at 3cd7c7d (27 Oct) and 3d06638 (26 Oct).

This change also cannot reach that test: check_ld_classic() returns early unless DEST_OS == 'darwin', and ld_classic appears nowhere in that job's log. Happy to rebase if you'd like a clean run.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant