aarch64-linux: link libgcc for outline atomic helpers - #32
Merged
Conversation
rust_binary targets built with the ferrocene_aarch64_unknown_linux_gnu
toolchain fail to link when they pull in C/C++ code that performs atomic
operations (e.g. std::atomic, std::shared_ptr refcounts, mutexes via C++
interop):
undefined reference to `__aarch64_ldadd4_acq_rel'
undefined reference to `__aarch64_cas2_acq_rel'
undefined reference to `__aarch64_swp4_acq_rel'
Root cause: GCC 10+ defaults to "outline atomics" on aarch64. Rather than
emitting LSE (ARMv8.1) or LL/SC atomics inline, the compiler emits calls to
helper functions in libgcc that select an LSE or a backward-compatible path
at runtime. Those helpers are defined only in the static libgcc.a; the shared
libgcc_s.so does not export them. rustc links with -nodefaultlibs and adds
-lgcc_s but not -lgcc, so the helpers are never offered to the linker.
Fix: append -Clink-arg=-lgcc to the aarch64-unknown-linux-gnu toolchain's
extra_rustc_flags so libgcc.a is on the link line. It is placed last because
the linker resolves a static archive only against symbols already referenced
to its left, so libgcc.a must follow the C/C++ objects and libraries
(-lstdc++ etc.) that reference the helpers.
This resolves the outline-atomics half of the aarch64 GCC link failure
without requiring downstream repositories to inject the flag via .bazelrc.
MODULE.bazel.lock is regenerated (bazel mod deps --lockfile_mode=update) to
reflect the added flag.
Refs: #27, eclipse-score/communication#328
dcalavrezo-qorix
requested review from
AlexanderLanin,
MaximilianSoerenPollak and
nradakovic
as code owners
July 17, 2026 06:25
pawelrutkaq
approved these changes
Jul 17, 2026
Comment on lines
69
to
+70
| "-Clink-arg=-lc", | ||
| "-Clink-arg=-lgcc", |
Member
There was a problem hiding this comment.
AI-assisted review (Claude):
This line is now the only difference between the x86_64 and aarch64 linux flag lists, and its placement is load-bearing. Since CI only validates lockfile consistency and the repo has no build/link test, a future maintainer aligning the toolchains or reordering flags could silently drop it and reintroduce the __aarch64_*_acq_rel link failure with no CI signal. A short comment makes the intent and the ordering constraint durable:
Suggested change
| "-Clink-arg=-lc", | |
| "-Clink-arg=-lgcc", | |
| "-Clink-arg=-lc", | |
| # aarch64 GCC uses outline atomics; the __aarch64_*_acq_rel helpers live | |
| # only in static libgcc.a. Must stay last so it follows the C/C++ objects | |
| # that reference them (static archives resolve left-to-right). | |
| "-Clink-arg=-lgcc", |
MaximilianSoerenPollak
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rust_binary targets built with the ferrocene_aarch64_unknown_linux_gnu toolchain fail to link when they pull in C/C++ code that performs atomic operations (e.g. std::atomic, std::shared_ptr refcounts, mutexes via C++ interop):
Root cause: GCC 10+ defaults to "outline atomics" on aarch64. Rather than emitting LSE (ARMv8.1) or LL/SC atomics inline, the compiler emits calls to helper functions in libgcc that select an LSE or a backward-compatible path at runtime. Those helpers are defined only in the static libgcc.a; the shared libgcc_s.so does not export them. rustc links with -nodefaultlibs and adds -lgcc_s but not -lgcc, so the helpers are never offered to the linker.
Fix: append -Clink-arg=-lgcc to the aarch64-unknown-linux-gnu toolchain's extra_rustc_flags so libgcc.a is on the link line. It is placed last because the linker resolves a static archive only against symbols already referenced to its left, so libgcc.a must follow the C/C++ objects and libraries (-lstdc++ etc.) that reference the helpers.
This resolves the outline-atomics half of the aarch64 GCC link failure without requiring downstream repositories to inject the flag via .bazelrc.
MODULE.bazel.lock is regenerated (bazel mod deps --lockfile_mode=update) to reflect the added flag.
Refs: #27, eclipse-score/communication#328