Skip to content

fix(cmake): detect libatomic with a link probe instead of find_library (#453)#454

Open
got3nks wants to merge 1 commit into
amule-org:masterfrom
got3nks:fix/libatomic-gcc-detection
Open

fix(cmake): detect libatomic with a link probe instead of find_library (#453)#454
got3nks wants to merge 1 commit into
amule-org:masterfrom
got3nks:fix/libatomic-gcc-detection

Conversation

@got3nks

@got3nks got3nks commented Jul 12, 2026

Copy link
Copy Markdown

On 32-bit targets the download-bandwidth throttler holds its byte budget as std::atomic<int64_t>, whose ops expand to __atomic_*_8 library calls that live in libatomic. The availability check used find_library(atomic), which only searches standard filesystem paths. With GCC, libatomic ships inside the compiler's own runtime dir (e.g. .../lib/gcc14/), which isn't on that path — so find_library false-fails and configure aborts with the "libatomic was not found" FATAL_ERROR, even though -latomic links fine because the GCC driver resolves its internal copy. Reported on MacPorts in #453.

This replaces find_library with check_library_exists(atomic __atomic_load_8 "" HAVE_LIBATOMIC), which links a probe with -latomic through the compiler driver. It succeeds wherever the flag actually links — GCC's internal libatomic, or a system libatomic (Clang / distro -dev packages, versioned or not) — and only errors when the flag genuinely can't link. The 32-bit "require libatomic" decision and the FATAL_ERROR guidance are unchanged; only the availability probe changes.

Test plan

  • check_library_exists probe executes cleanly (verified standalone)
  • 64-bit configure unaffected — the block is CMAKE_SIZEOF_VOID_P EQUAL 4-gated
  • @barracuda156 confirms configure now succeeds on the 32-bit GCC / MacPorts target (the reporting toolchain)

Closes #453.

On 32-bit targets the throttler's std::atomic<int64_t> needs libatomic
(the ops expand to __atomic_*_8 library calls). The availability check
used find_library(atomic), which only searches standard filesystem
paths. With GCC, libatomic ships inside the compiler's own runtime dir
(e.g. .../lib/gcc14/), which isn't on that path, so find_library
false-fails and configure aborts -- even though `-latomic` links fine
because the GCC driver resolves its internal copy (reported on MacPorts,
amule-project#453).

Replace find_library with check_library_exists(atomic __atomic_load_8),
which links a probe with `-latomic` through the compiler driver. It
succeeds wherever the flag actually links -- GCC's internal libatomic or
a system libatomic (Clang / distro packages, versioned or not) -- and
only errors when the flag genuinely can't link. The 32-bit "require
libatomic" decision and the FATAL_ERROR guidance are unchanged; only the
availability probe changes.

Closes amule-project#453.
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.

Need for libatomic is correctly determined, but CMake cannot “find” it then, which breaks configure

1 participant