Bug 220822 - Missing libatomic.a for clang?
Summary: Missing libatomic.a for clang?
Status: Closed DUPLICATE of bug 230888
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 11.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
Depends on:
Reported: 2017-07-18 09:03 UTC by Yuri Victorovich
Modified: 2020-08-07 14:36 UTC (History)
9 users (show)

See Also:

testcase: shar of audio/jack port (34.65 KB, text/plain)
2017-07-18 09:03 UTC, Yuri Victorovich
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer 2017-07-18 09:03:22 UTC
Created attachment 184466 [details]
testcase: shar of audio/jack port

The latest version of audio/jack fails to link an executable: undefined reference to `__atomic_store'
Adding any of these gcc libraries makes the linking stage to succeed:

But jack is built with clang and shouldn't depend on anything gcc, and there are no other libatomic.a available.

What should be the resolution of this problem?

Attaching the failing port.
Comment 1 Yuri Victorovich freebsd_committer 2017-07-18 17:34:51 UTC
Hi Brooks,

Do you happen to know where `__atomic_store' should come from in clang? Is there supposed to be libatomic.a?

Comment 2 Brooks Davis freebsd_committer 2017-07-18 17:53:54 UTC
It looks like an __atomic_store() implementation exists in contrib/compiler-rt/lib/builtins/atomic.c, but we don't build it in lib/libcompiler_rt.  I'm not sure if it's as simple as adding that or if we need to/can do it only on certain platforms.  Adding some CC's of people who have touched lib/libcompiler_rt recently.
Comment 3 Ed Maste freebsd_committer 2017-07-19 00:03:51 UTC
int foo(int x, int y) {
 _Atomic int result = x * y;
 return result;

I suspect that we can just add atomic.c on archs that now build with Clang
Comment 4 Dimitry Andric freebsd_committer 2017-07-19 11:01:15 UTC
As far as I know, we have never had libatomic support. The problem is that we still support arches and CPUs which lack a way to do 64 bit atomic operations, like i486.

The implementations in compiler-rt/lib/builtins are rather unknown to me, and I am unsure whether we can simply enable these and hope that they work correctly.
Comment 5 Yuri Victorovich freebsd_committer 2017-07-20 08:41:57 UTC
Apparently, nobody else uses c++ atomic functions. Out of all ports built with clang jack is the only one.

-D__STDC_NO_ATOMICS__ is a workaround for jack, so this isn't a pressing issue.
Comment 6 Yuri Victorovich freebsd_committer 2017-07-20 09:49:07 UTC
As it turned out, atomic_fetch_add_explicit is a standard C built-in function, and __atomic_fetch_add is a gcc extension. Strangely, this gcc extension is supported by clang.
Comment 7 Danilo G. Baio freebsd_committer 2018-05-15 13:07:10 UTC
I am getting this error when building dns/knot2 only in FreeBSD 12 i386, clang 6.0.0, pr #227620.

./.libs/libknotd.a(libknotd_la-query_module.o): In function `knotd_mod_stats_incr':
query_module.c:(.text+0x9d0): undefined reference to `__atomic_fetch_add_8'
./.libs/libknotd.a(libknotd_la-query_module.o): In function `knotd_mod_stats_decr':
query_module.c:(.text+0xa80): undefined reference to `__atomic_fetch_sub_8'
./.libs/libknotd.a(libknotd_la-query_module.o): In function `knotd_mod_stats_store':
query_module.c:(.text+0xb30): undefined reference to `__atomic_store_8'
cc: error: linker command failed with exit code 1 (use -v to see invocation)

root@12-i386-head:~ # gcc6 -dM -E -x c /dev/null | grep LLONG_LOCK

root@12-i386-head:~ # clang -dM -E -x c /dev/null | grep LLONG_LOCK

root@12-i386-head:~ # clang --version
FreeBSD clang version 6.0.0 (tags/RELEASE_600/final 326565) (based on LLVM 6.0.0)

root@11-i386-head:~ # gcc6 -dM -E -x c /dev/null | grep LLONG_LOCK

root@11-i386-head:~ # clang -dM -E -x c /dev/null | grep LLONG_LOCK

root@11-i386-head:~ # clang --version
FreeBSD clang version 4.0.0 (tags/RELEASE_400/final 297347) (based on LLVM 4.0.0)
Comment 8 Jack 2019-03-09 10:13:54 UTC
audio/audacity also has the same issue.

ld: error: unable to find library -latomic
c++: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 9 Dimitry Andric freebsd_committer 2019-03-09 15:14:52 UTC

*** This bug has been marked as a duplicate of bug 230888 ***