<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>312975</bug_id>
          
          <creation_ts>2026-04-22 01:14:06 -0700</creation_ts>
          <short_desc>The libatomic check in WebKitCompilerFlags.cmake does not always work correctly</short_desc>
          <delta_ts>2026-04-24 00:59:37 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>CMake</component>
          <version>Other</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>313214</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Alberto Garcia">berto</reporter>
          <assigned_to name="Alberto Garcia">berto</assigned_to>
          <cc>aperez</cc>
    
    <cc>cgarcia</cc>
    
    <cc>mcatanzaro</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2203086</commentid>
    <comment_count>0</comment_count>
    <who name="Alberto Garcia">berto</who>
    <bug_when>2026-04-22 01:14:06 -0700</bug_when>
    <thetext>The WebKitCompilerFlags.cmake file contains a test to detect whether
the compiler needs to link against libatomic.

https://github.com/WebKit/WebKit/blob/wpewebkit-2.53.1/Source/cmake/WebKitCompilerFlags.cmake#L448

The compiler tries to build this test code with the standard flags,
and failure indicates that it needs to be linked against libatomic.

However in some cases this test fails to detect if libatomic is needed
because the atomic code gets optimized away by the compiler.

Here&apos;s the expected behavior:

$ clang++ --version
Debian clang version 19.1.7 (3+b1)
Target: arm-unknown-linux-gnueabihf
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin

$ clang++ -o test.o -c test.cc

$ clang++ -o test test.o
/usr/bin/arm-linux-gnueabihf-ld: test.o: in function `std::atomic&lt;std::optional&lt;double&gt; &gt;::load(std::memory_order) const&apos;:
test.cc:(.text._ZNKSt6atomicISt8optionalIdEE4loadESt12memory_order[_ZNKSt6atomicISt8optionalIdEE4loadESt12memory_order]+0x68): undefined reference to `__atomic_load&apos;
[...]

$ nm test.o | grep atomic
00000000 W _ZNKSt6atomicISt8optionalIdEE4loadESt12memory_order
00000000 W _ZNSt6atomicISt8optionalIdEE5storeES1_St12memory_order
00000000 W _ZNSt6atomicISt8optionalIdEEC2Ev
00000000 W _ZNSt6atomicISt8optionalIdEEaSES1_
         U __atomic_load
         U __atomic_store


And now with -O2:

$ clang++ -o test.o -c -O2 test.cc
$ clang++ -o test test.o
$ nm test.o | grep atomic

-----------------

The problem seems to be that &apos;std::atomic&lt;std::optional&lt;double&gt;&gt; d&apos;
is a variable local to the main() function, and it gets optimized away
with -O2. Turning it into a global variable fixes this.


$ clang++ -o test.o -c -O2 test.cc
$ clang++ -o test test.o
/usr/bin/arm-linux-gnueabihf-ld: test.o: in function `main&apos;:
test.cc:(.text+0x34): undefined reference to `__atomic_store&apos;
/usr/bin/arm-linux-gnueabihf-ld: test.cc:(.text+0xc8): undefined reference to `__atomic_load&apos;
clang++: error: linker command failed with exit code 1 (use -v to see invocation)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2203087</commentid>
    <comment_count>1</comment_count>
    <who name="Alberto Garcia">berto</who>
    <bug_when>2026-04-22 01:16:48 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/63310</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2203907</commentid>
    <comment_count>2</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-04-23 15:41:30 -0700</bug_when>
    <thetext>Committed 311900@main (d65258118b1e): &lt;https://commits.webkit.org/311900@main&gt;

Reviewed commits have been landed. Closing PR #63310 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>