Skip to content

DMTCP requires __atomic_compare_exchange_16 ; clang++ wasn't finding it - #1242

Merged
gc00 merged 1 commit into
dmtcp:mainfrom
gc00:fix-clang-configure
Mar 27, 2026
Merged

gc00 merged 1 commit into
dmtcp:mainfrom
gc00:fix-clang-configure

Conversation

@gc00

@gc00 gc00 commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

In clang++, it wasn't finding the libatomic to support that. This commit provides recommendations for the user about which Linux distro packages to load, to support libatomic in clang++.

Summary by CodeRabbit

  • Chores

    • Enhanced build configuration to detect 128-bit atomic support, record required link libraries, and emit a visible warning when missing.
    • Added a clang-specific failure path that provides actionable package-install guidance when 128-bit atomic support is unavailable.
  • Documentation

    • Clarified and corrected several build-related comments for accuracy.

@gc00
gc00 requested review from karya0 and xuyao00 March 15, 2026 04:23
@gc00 gc00 added the bug label Mar 15, 2026
@coderabbitai

coderabbitai Bot commented Mar 15, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds Autoconf checks to detect 128-bit atomic support by probing __atomic_compare_exchange_16 (with -latomic fallback), caches and appends any needed library to LIBS, warns when absent, and adds a clang-specific configure failure when builtin atomics are unavailable.

Changes

Cohort / File(s) Summary
Top-level configure
configure
New Autoconf link-test for __atomic_compare_exchange_16 that searches with and without -latomic, caches result in ac_cv_search___atomic_compare_exchange_16, and updates LIBS or emits a WARNING when support is missing.
Autoconf template
configure.ac
Adds AC_SEARCH_LIBS probe for 128-bit atomic symbol, emits a warning if not found, and adds a clang-specific failure branch that aborts configure with package installation advice when gcc atomic builtins are unavailable; preserves original non-clang fallback.
Config header template
include/config.h.in
Only edits comment text for existing macros (ENABLE_PRGNAME_PREFIX, HAVE_LIBATOMIC, STDC_HEADERS); no macro definitions changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I poked at configure, sniffed the bits,
For sixteen-byte hops and linking fits.
If libatomic hides or clang complains,
I warn, I fail, I tweak the chains.
Hooray — now builds know where to sit!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support for clang++ to find __atomic_compare_exchange_16 in libatomic, which is the core issue addressed across the configure and configure.ac changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@configure`:
- Around line 12325-12416: The configure probe that tries -latomic should add
the flag to LIBS (so it appears after object files) instead of putting it into
LDFLAGS: save and restore the original LDFLAGS (e.g. save into
ac_func_search_save_LDFLAGS), set LIBS="-latomic $ac_func_search_save_LIBS" for
the probe (remove any assignment to LDFLAGS), run the existing ac_fn_c_try_link
probe that sets ac_cv_search___atomic_compare_exchange_16, then restore both
LIBS and LDFLAGS from the saved variables; this keeps the later logic that
inspects gccAtomicBuiltins and ac_cv_search___atomic_compare_exchange_16
correct.

In `@configure.ac`:
- Around line 939-958: The libatomic probe (AC_SEARCH_LIBS for
__atomic_compare_exchange_16) must be moved into or reconciled with the C++
probe so the C++ decision uses its result: either run AC_SEARCH_LIBS inside the
same C++ link test that sets gccAtomicBuiltins (or immediately rerun the C++
AC_LINK_IFELSE/AC_LINK_IFELSE-equivalent after AC_SEARCH_LIBS) and update the
variable used to indicate 128-bit atomic support (gccAtomicBuiltins or a new
flag) so that AC_DEFINE([HAS_128_ATOMIC],[1]) is emitted when either the gcc
builtins or libatomic check succeeds; also change the clang-specific failure
check (the if that tests gccAtomicBuiltins and is_clang_cpp) to test the
updated/combined result so the "Missing Linux packages" error only fires if
neither probe found 128-bit atomic support.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 95a52a00-cc9d-40e2-b168-13a2e99951a3

📥 Commits

Reviewing files that changed from the base of the PR and between f1f03e8 and 901885e.

📒 Files selected for processing (2)
  • configure
  • configure.ac

Comment thread configure
Comment thread configure.ac
Comment on lines +939 to +958
dnl __atomic_compare_exchange_16 is often in libatomic
AC_SEARCH_LIBS([__atomic_compare_exchange_16], [atomic], [], [
AC_MSG_WARN([Could not find 128-bit atomic support in libatomic.])
])

if test "$gccAtomicBuiltins" = "yes"; then
AC_DEFINE([HAS_128_ATOMIC],[1],[Define to 1 if 'gcc test.c -latomic' works for __atomic_compare_exchange])
fi
dnl $CXX might be "clang++ -std=c++14". Further, we need "-x c++"
dnl or else clang++ defaults to assuming a C file.
is_clang_cpp=no
$CXX -x c++ -dM -E - < /dev/null | grep -q "__clang__" && is_clang_cpp=yes
if test "$gccAtomicBuiltins" = "no" -a "$is_clang_cpp" = "yes"; then
AC_MSG_FAILURE([Using C++14 with clang++ to support atomic built-ins.
Missing Linux packages. If Ubuntu/Debian, consider:
sudo apt install clang libclang-rt-dev libc++abi-dev
libstdc++-14-dev (or later version of libstdc++-14-dev).
If Red Hat/Fedora/CentOS/Rocky Linux, consider:
sudo dnf install clang-devel libstdc++-devel libatomic])
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Atomic capability block:"
nl -ba configure.ac | sed -n '903,958p'

echo
echo "Assignments/references for gccAtomicBuiltins and the new libatomic search:"
rg -n -C2 'gccAtomicBuiltins|AC_SEARCH_LIBS\(\[__atomic_compare_exchange_16\]' configure.ac

Repository: dmtcp/dmtcp

Length of output: 139


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Atomic capability block (lines 903-958) ==="
sed -n '903,958p' configure.ac

echo
echo "=== All gccAtomicBuiltins assignments ==="
rg -n 'gccAtomicBuiltins=' configure.ac

echo
echo "=== AC_SEARCH_LIBS for atomic ==="
rg -n -A3 'AC_SEARCH_LIBS.*atomic' configure.ac

echo
echo "=== Lines 940-958 in detail ==="
sed -n '940,958p' configure.ac

Repository: dmtcp/dmtcp

Length of output: 3844


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Check rwlock.cpp for atomic usage ==="
sed -n '1,62p' src/rwlock.cpp | head -40

echo
echo "=== Search for __atomic_compare_exchange usage across codebase ==="
rg -n '__atomic_compare_exchange' --type cpp src/

echo
echo "=== Check if HAS_128_ATOMIC guards exist in source files ==="
rg -n 'HAS_128_ATOMIC' src/

Repository: dmtcp/dmtcp

Length of output: 1609


Move the libatomic probe into the actual C++ decision path.

Lines 944 and 951 still branch only on gccAtomicBuiltins, but that variable is assigned by the earlier C++ AC_LINK_IFELSE and never updated by the new AC_SEARCH_LIBS on Line 940. So this added probe cannot recover a failed atomic check: HAS_128_ATOMIC stays unset and the clang-specific "Missing Linux packages" failure still fires even if the later search finds the library. That configure verdict is load-bearing because src/rwlock.cpp uses __atomic_compare_exchange unconditionally. Please run the libatomic search inside the same C++ probe, or rerun the C++ link test after the search and base the later failure path on that result instead.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@configure.ac` around lines 939 - 958, The libatomic probe (AC_SEARCH_LIBS for
__atomic_compare_exchange_16) must be moved into or reconciled with the C++
probe so the C++ decision uses its result: either run AC_SEARCH_LIBS inside the
same C++ link test that sets gccAtomicBuiltins (or immediately rerun the C++
AC_LINK_IFELSE/AC_LINK_IFELSE-equivalent after AC_SEARCH_LIBS) and update the
variable used to indicate 128-bit atomic support (gccAtomicBuiltins or a new
flag) so that AC_DEFINE([HAS_128_ATOMIC],[1]) is emitted when either the gcc
builtins or libatomic check succeeds; also change the clang-specific failure
check (the if that tests gccAtomicBuiltins and is_clang_cpp) to test the
updated/combined result so the "Missing Linux packages" error only fires if
neither probe found 128-bit atomic support.

@gc00
gc00 force-pushed the fix-clang-configure branch from 901885e to 0013902 Compare March 26, 2026 23:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
configure.ac (1)

937-941: ⚠️ Potential issue | 🟠 Major

AC_SEARCH_LIBS result is not used to update the decision variable.

The AC_SEARCH_LIBS probe cannot recover a failed atomic check: gccAtomicBuiltins is set by the earlier C++ AC_LINK_IFELSE (lines 911-934) and is never updated by this search. Even if AC_SEARCH_LIBS finds libatomic and adds it to LIBS, gccAtomicBuiltins remains no, so:

  1. HAS_128_ATOMIC is not defined (line 946)
  2. The clang-specific failure (lines 952-959) still fires
  3. src/rwlock.cpp and jalib/jalloc.cpp use __atomic_compare_exchange unconditionally when HAS_128_ATOMIC is defined

Consider either:

  • Running AC_SEARCH_LIBS before the C++ link test and letting that test pick up -latomic from LIBS, or
  • Re-running the C++ link test after AC_SEARCH_LIBS succeeds and updating gccAtomicBuiltins based on the combined result
    ,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@configure.ac` around lines 937 - 941, The AC_SEARCH_LIBS probe currently runs
after the C++ link test and its success is not used to update the decision
variable gccAtomicBuiltins, so HAS_128_ATOMIC may remain unset even when
-latomic is available; fix by either moving the
AC_SEARCH_LIBS([__atomic_compare_exchange_16], [atomic]) call to run before the
C++ AC_LINK_IFELSE so the link test can pick up -latomic from LIBS, or if you
keep the current order, re-run the C++ link test (the same check that sets
gccAtomicBuiltins) after AC_SEARCH_LIBS succeeds and explicitly set
gccAtomicBuiltins to yes when the combined link succeeds so that HAS_128_ATOMIC
and the clang-specific checks reflect the actual available libraries.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@configure.ac`:
- Around line 948-959: Update the failure message emitted when test
"$gccAtomicBuiltins" = "no" and "$is_clang_cpp" = "yes": include Debian/Ubuntu's
libatomic package name (libatomic1) in the apt install suggestions alongside
clang, libclang-rt-dev, libc++abi-dev and libstdc++-14-dev; also clarify that
this path is triggered by the gccAtomicBuiltins predicate (and that
AC_SEARCH_LIBS may not have updated it), so either adjust the message to mention
checking that libatomic1 is installed or modify the surrounding logic that sets
gccAtomicBuiltins to ensure it reflects the result of the prior
AC_SEARCH_LIBS/link test before printing the AC_MSG_FAILURE (referencing
is_clang_cpp, gccAtomicBuiltins and the AC_MSG_FAILURE block).

---

Duplicate comments:
In `@configure.ac`:
- Around line 937-941: The AC_SEARCH_LIBS probe currently runs after the C++
link test and its success is not used to update the decision variable
gccAtomicBuiltins, so HAS_128_ATOMIC may remain unset even when -latomic is
available; fix by either moving the
AC_SEARCH_LIBS([__atomic_compare_exchange_16], [atomic]) call to run before the
C++ AC_LINK_IFELSE so the link test can pick up -latomic from LIBS, or if you
keep the current order, re-run the C++ link test (the same check that sets
gccAtomicBuiltins) after AC_SEARCH_LIBS succeeds and explicitly set
gccAtomicBuiltins to yes when the combined link succeeds so that HAS_128_ATOMIC
and the clang-specific checks reflect the actual available libraries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ff610a15-1a01-4811-9c63-6b54fcc5fb21

📥 Commits

Reviewing files that changed from the base of the PR and between 901885e and 0013902.

📒 Files selected for processing (3)
  • configure
  • configure.ac
  • include/config.h.in
✅ Files skipped from review due to trivial changes (1)
  • include/config.h.in
🚧 Files skipped from review as they are similar to previous changes (1)
  • configure

Comment thread configure.ac
Comment on lines +948 to +959
dnl $CXX might be "clang++ -std=c++14". Further, we need "-x c++"
dnl or else clang++ defaults to assuming a C file.
is_clang_cpp=no
$CXX -x c++ -dM -E - < /dev/null | grep -q "__clang__" && is_clang_cpp=yes
if test "$gccAtomicBuiltins" = "no" -a "$is_clang_cpp" = "yes"; then
AC_MSG_FAILURE([Using C++14 with clang++ to support atomic built-ins.
Missing Linux packages. If Ubuntu/Debian, consider:
sudo apt install clang libclang-rt-dev libc++abi-dev
libstdc++-14-dev (or later version of libstdc++-14-dev).
If Red Hat/Fedora/CentOS/Rocky Linux, consider:
sudo dnf install clang-devel libstdc++-devel libatomic])
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Debian/Ubuntu package list missing libatomic1.

The error message recommends libatomic for Red Hat/Fedora but omits it for Debian/Ubuntu. On Debian/Ubuntu, the package providing libatomic.so is libatomic1. Since this PR addresses clang++ not finding libatomic, consider adding it:

🛠️ Suggested fix
 if test "$gccAtomicBuiltins" = "no" -a "$is_clang_cpp" = "yes"; then
   AC_MSG_FAILURE([Using C++14 with clang++ to support atomic built-ins.
                   Missing Linux packages.  If Ubuntu/Debian, consider:
-                  sudo apt install clang libclang-rt-dev libc++abi-dev
+                  sudo apt install clang libclang-rt-dev libc++abi-dev libatomic1
                   libstdc++-14-dev (or later version of libstdc++-14-dev).
                   If Red Hat/Fedora/CentOS/Rocky Linux, consider:
                   sudo dnf install clang-devel libstdc++-devel libatomic])
 fi

Additionally, note that this failure path depends on gccAtomicBuiltins, which is not updated by the preceding AC_SEARCH_LIBS check—so users may see this error even if libatomic is installed but the C++ link test failed for other reasons.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dnl $CXX might be "clang++ -std=c++14". Further, we need "-x c++"
dnl or else clang++ defaults to assuming a C file.
is_clang_cpp=no
$CXX -x c++ -dM -E - < /dev/null | grep -q "__clang__" && is_clang_cpp=yes
if test "$gccAtomicBuiltins" = "no" -a "$is_clang_cpp" = "yes"; then
AC_MSG_FAILURE([Using C++14 with clang++ to support atomic built-ins.
Missing Linux packages. If Ubuntu/Debian, consider:
sudo apt install clang libclang-rt-dev libc++abi-dev
libstdc++-14-dev (or later version of libstdc++-14-dev).
If Red Hat/Fedora/CentOS/Rocky Linux, consider:
sudo dnf install clang-devel libstdc++-devel libatomic])
fi
dnl $CXX might be "clang++ -std=c++14". Further, we need "-x c++"
dnl or else clang++ defaults to assuming a C file.
is_clang_cpp=no
$CXX -x c++ -dM -E - < /dev/null | grep -q "__clang__" && is_clang_cpp=yes
if test "$gccAtomicBuiltins" = "no" -a "$is_clang_cpp" = "yes"; then
AC_MSG_FAILURE([Using C++14 with clang++ to support atomic built-ins.
Missing Linux packages. If Ubuntu/Debian, consider:
sudo apt install clang libclang-rt-dev libc++abi-dev libatomic1
libstdc++-14-dev (or later version of libstdc++-14-dev).
If Red Hat/Fedora/CentOS/Rocky Linux, consider:
sudo dnf install clang-devel libstdc++-devel libatomic])
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@configure.ac` around lines 948 - 959, Update the failure message emitted when
test "$gccAtomicBuiltins" = "no" and "$is_clang_cpp" = "yes": include
Debian/Ubuntu's libatomic package name (libatomic1) in the apt install
suggestions alongside clang, libclang-rt-dev, libc++abi-dev and
libstdc++-14-dev; also clarify that this path is triggered by the
gccAtomicBuiltins predicate (and that AC_SEARCH_LIBS may not have updated it),
so either adjust the message to mention checking that libatomic1 is installed or
modify the surrounding logic that sets gccAtomicBuiltins to ensure it reflects
the result of the prior AC_SEARCH_LIBS/link test before printing the
AC_MSG_FAILURE (referencing is_clang_cpp, gccAtomicBuiltins and the
AC_MSG_FAILURE block).

 * In clang++, it wasn't finding the libatomic to support that.
   This commit provides recommendations for the user about
     which Linux distro packages to load, to support libatomic in clang++.
@gc00
gc00 force-pushed the fix-clang-configure branch from 0013902 to dbbbf2f Compare March 27, 2026 00:00

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
configure (1)

12325-12416: ⚠️ Potential issue | 🔴 Critical

Stale gccAtomicBuiltins gate can still trigger a false configure failure.

Line 12388 can successfully add -latomic to LIBS, but HAS_128_ATOMIC and the clang hard-fail at Line 12406 still rely on gccAtomicBuiltins computed earlier with -latomic in LDFLAGS. Because link tests place $LDFLAGS before objects, this can remain a false negative and abort even when the later library search succeeds.

🔧 Proposed fix (apply around the earlier C++ builtin probe near Line 12277)
-# It seems to be undocumented that this needs '-latomic' as of 2024.
-LDFLAGS_orig="$LDFLAGS"
-LDFLAGS="$LDFLAGS -latomic"
+# Keep test libs in LIBS so they appear after objects in link commands.
+LIBS_orig="$LIBS"
+LIBS="-latomic $LIBS"
@@
-LDFLAGS="$LDFLAGS_orig"
+LIBS="$LIBS_orig"
#!/bin/bash
set -euo pipefail

# Verify link-command ordering and stale gating flow.
rg -n -C3 'ac_link=.*\$LDFLAGS conftest\.\$ac_ext \$LIBS|LDFLAGS="\$LDFLAGS -latomic"|gccAtomicBuiltins=|ac_cv_search___atomic_compare_exchange_16|if test "\$gccAtomicBuiltins" = "no" -a "\$is_clang_cpp" = "yes"' configure

Expected result: confirms gccAtomicBuiltins is set before the new search block and still gates the clang error path, with the first probe using LDFLAGS for -latomic.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@configure` around lines 12325 - 12416, The configure script can false-fail
because the earlier gccAtomicBuiltins probe is evaluated before the libatomic
search; update the gating so the clang hard-fail uses the result of the later
library probe (ac_cv_search___atomic_compare_exchange_16 or the generated
HAS_128_ATOMIC) rather than the stale gccAtomicBuiltins, or recompute
gccAtomicBuiltins after trying to add -latomic to LIBS/LDFLAGS; specifically,
adjust the logic around the symbols gccAtomicBuiltins,
ac_cv_search___atomic_compare_exchange_16, HAS_128_ATOMIC, is_clang_cpp, LIBS
and LDFLAGS so that the clang error path checks the post-library-search state
(e.g., test ac_cv_search___atomic_compare_exchange_16 or HAS_128_ATOMIC before
erroring) or rerun the C++ builtin probe after modifying LDFLAGS.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@configure`:
- Around line 12325-12416: The configure script can false-fail because the
earlier gccAtomicBuiltins probe is evaluated before the libatomic search; update
the gating so the clang hard-fail uses the result of the later library probe
(ac_cv_search___atomic_compare_exchange_16 or the generated HAS_128_ATOMIC)
rather than the stale gccAtomicBuiltins, or recompute gccAtomicBuiltins after
trying to add -latomic to LIBS/LDFLAGS; specifically, adjust the logic around
the symbols gccAtomicBuiltins, ac_cv_search___atomic_compare_exchange_16,
HAS_128_ATOMIC, is_clang_cpp, LIBS and LDFLAGS so that the clang error path
checks the post-library-search state (e.g., test
ac_cv_search___atomic_compare_exchange_16 or HAS_128_ATOMIC before erroring) or
rerun the C++ builtin probe after modifying LDFLAGS.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3b024b34-5b86-4b75-953f-9cfb82c14ce0

📥 Commits

Reviewing files that changed from the base of the PR and between 0013902 and dbbbf2f.

📒 Files selected for processing (3)
  • configure
  • configure.ac
  • include/config.h.in
✅ Files skipped from review due to trivial changes (1)
  • include/config.h.in
🚧 Files skipped from review as they are similar to previous changes (1)
  • configure.ac

@gc00
gc00 merged commit 6896e12 into dmtcp:main Mar 27, 2026
2 checks passed
@gc00
gc00 deleted the fix-clang-configure branch March 27, 2026 00:08
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.

2 participants