WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
312975
The libatomic check in WebKitCompilerFlags.cmake does not always work correctly
https://bugs.webkit.org/show_bug.cgi?id=312975
Summary
The libatomic check in WebKitCompilerFlags.cmake does not always work correctly
Alberto Garcia
Reported
2026-04-22 01:14:06 PDT
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'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<std::optional<double> >::load(std::memory_order) const': test.cc:(.text._ZNKSt6atomicISt8optionalIdEE4loadESt12memory_order[_ZNKSt6atomicISt8optionalIdEE4loadESt12memory_order]+0x68): undefined reference to `__atomic_load' [...] $ 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 'std::atomic<std::optional<double>> d' 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': test.cc:(.text+0x34): undefined reference to `__atomic_store' /usr/bin/arm-linux-gnueabihf-ld: test.cc:(.text+0xc8): undefined reference to `__atomic_load' clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Attachments
Add attachment
proposed patch, testcase, etc.
Alberto Garcia
Comment 1
2026-04-22 01:16:48 PDT
Pull request:
https://github.com/WebKit/WebKit/pull/63310
EWS
Comment 2
2026-04-23 15:41:30 PDT
Committed
311900@main
(d65258118b1e): <
https://commits.webkit.org/311900@main
> Reviewed commits have been landed. Closing PR #63310 and removing active labels.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug