Consider the following c11 code (lib + executable): ``` :::::::::::::: foo.c :::::::::::::: _Atomic(long long) ll; int foo(void) { ++ll; return 42; } :::::::::::::: prog.c :::::::::::::: int foo(void); int main(int argc, char* argv[]) { return foo(); } ``` On Debian armel arch, most built system will fail to compile the above. The error reported is: ``` /usr/bin/ld: libfoo.a(foo.c.o): in function `foo': foo.c:(.text+0x40): undefined reference to `__atomic_fetch_add_8' ``` One need to carefully pass `atomic` library on the compilation line. So if you are lucky this is just: LDFLAGS=-latomic ... some other time this more complex as in this above case where a static library is build, thus one needs to: ``` cc -rdynamic prog.o -o prog libfoo.a -Wl,-Bstatic -latomic -Wl,-Bdynamic ``` --- I see that on some other arch (riscv), the spec file for gcc has been updated to pass automatically (?) the proper flag: `--as-needed -latomic` [1] Could someone from gcc/arm team please describe what is the reason for not doing something equivalent for the spec file in armel case ? Thanks for your time. [1] https://github.com/riscv-collab/riscv-gcc/issues/12#issuecomment-276587351
In case that help, cmake instructions for the test case is: ``` project(p C) set(CMAKE_C_STANDARD 11) add_library(foo STATIC foo.c) add_executable(prog prog.c) target_link_libraries(prog foo) ```
This is a general problem with architectures not implementing all atomic operations inline.
@Andreas the specific issue I am raising is the difference between the approach of riscv vs armel. The riscv team is taking the responsability for putting the missing `-latomic`, while armel expect the user to understand how c11 atomics are implemented on a particular architecture and fix the link line at the build system level (eg. cmake / meson ...). In summary: what is the risk (if any) to update the gcc spec file on armel ?
Dup of bug 81358. Note riscv atomics are messed up too(there is a bug report for that). *** This bug has been marked as a duplicate of bug 81358 ***