cancel
Showing results for 
Search instead for 
Did you mean: 

No support for large atomics

CTapp.1
Senior III

I'm trying to use _Atomic with 64 bit objects, but I get a link failure:

undefined reference to `__atomic_load_8'

The internet says I need to add an option to the link command:

-latomic

However, it looks as if that library is not included with the ST tool chain:

cannot find -latomic: No such file or directory

Has anyone managed to get this working?

There are a number of workarounds that could be used here, but it would be much easier to use the native C feature that's been available since C11.

I'm using STM32CubeIDE V 1.18.1 with GNU Tools 13.3

All posts are made in a personal capacity
MISRA C++ Chair
MISRA C WG Member
Director The MISRA Consortium Limited (TMCL)
1 ACCEPTED SOLUTION

Accepted Solutions
CTapp.1
Senior III

Thanks all,

I've worked round the issue by changing my design so that I only need 32 bit atomics.

All posts are made in a personal capacity
MISRA C++ Chair
MISRA C WG Member
Director The MISRA Consortium Limited (TMCL)

View solution in original post

4 REPLIES 4

In addition to the previous reply: the GNU C++ toolchain (likely, also in Clang) defines C-compatible _Atomic(x) so it can be used seamlessly in both C and C++ code:

See  ... arm-none-eabi/include/c++/version/stdatomic.h

#if __cplusplus > 202002L
#include <atomic>
#define __cpp_lib_stdatomic_h 202011L

#define _Atomic(_Tp) std::atomic<_Tp>

#ifdef _GLIBCXX_USE_C99_STDINT_TR1
using std::atomic_int8_t;
using std::atomic_uint8_t;
//..... etc ....
CTapp.1
Senior III

Thanks all,

I've worked round the issue by changing my design so that I only need 32 bit atomics.

All posts are made in a personal capacity
MISRA C++ Chair
MISRA C WG Member
Director The MISRA Consortium Limited (TMCL)

I suppose the 64b atomic would work with GCC on a 64 bit cpu, with 64b bus.

Because on a 32b machine you cannot access 64 bit memory in one access/cycle,

so just 8...32 bit is possible on a 32 bit cpu.

If you feel a post has answered your question, please click "Accept as Solution".