Skip to content

aarch64-linux: link libgcc for outline atomic helpers - #32

Merged
dcalavrezo-qorix merged 1 commit into
mainfrom
dcalavrezo_fix_lgcc
Jul 17, 2026
Merged

aarch64-linux: link libgcc for outline atomic helpers#32
dcalavrezo-qorix merged 1 commit into
mainfrom
dcalavrezo_fix_lgcc

Conversation

@dcalavrezo-qorix

Copy link
Copy Markdown
Contributor

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

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
Comment thread MODULE.bazel
Comment on lines 69 to +70
"-Clink-arg=-lc",
"-Clink-arg=-lgcc",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

@dcalavrezo-qorix
dcalavrezo-qorix merged commit a7af721 into main Jul 17, 2026
5 checks passed
@dcalavrezo-qorix
dcalavrezo-qorix deleted the dcalavrezo_fix_lgcc branch July 17, 2026 14:54
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.

4 participants