Page 1 of 1

where is libatomic?

Posted: Sat Nov 02, 2019 12:13 am
by greengnu
I'm tying to compile something like this:

Code: Select all

#include <atomic>

static int test()
{
    std::atomic<long long> x;
    return x;
}

int main()
{
    return test();
}
but I get

Code: Select all

c:/users/username/.espressif/tools/xtensa-esp32-elf/esp32-2019r1-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: CMakeFiles/cmTC_bfb5d.dir/atomic_check.cpp.obj:(.literal._ZNKSt13__atomic_baseIxEcvxEv[std::__atomic_base<long long>::operator long long() const]+0x8): undefined reference to `__atomic_load_8'
if I try to link with -latomic linker flag this fails too as there is no libatomic in the toolchain. Where is libatomic or how can I make use of std::atomic?

Re: where is libatomic?

Posted: Sat Nov 02, 2019 1:31 am
by WiFive

Re: where is libatomic?

Posted: Tue Nov 05, 2019 6:17 pm
by warren
Have you tried std::atomic<long> x, that is just one "long" (or try int)?

Code: Select all

static int test()
{
    std::atomic<long> x; // long, not long long
    return x;
}
It is likely that the platform does not support an atomic that large.

Re: where is libatomic?

Posted: Wed Nov 06, 2019 5:08 pm
by greengnu
yes, using std::atomic<long> x; works - but it means I have to change existing library code. Would be great to have a software implementation of 64bit atomics

Re: where is libatomic?

Posted: Sat Nov 09, 2019 5:03 am
by warren
The ESP is a 32-bit platform after all, so probably doesn't support a 64-bit atomics. You'll need to look at the xtensa instruction set to confirm but I wouldn't be holding my breath.

Re: where is libatomic?

Posted: Fri Nov 15, 2019 3:24 pm
by greengnu
but functions like __atomic_load_8 could still be implemented using semaphores - so just because the hardware doesn't support it doesn't mean the functionality gotta be missing from the library