where is libatomic?

greengnu
Posts: 27
Joined: Wed May 08, 2019 8:45 pm

where is libatomic?

Postby greengnu » Sat Nov 02, 2019 12:13 am

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?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: where is libatomic?

Postby WiFive » Sat Nov 02, 2019 1:31 am


warren
Posts: 15
Joined: Thu May 02, 2019 3:16 pm

Re: where is libatomic?

Postby warren » Tue Nov 05, 2019 6:17 pm

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.

greengnu
Posts: 27
Joined: Wed May 08, 2019 8:45 pm

Re: where is libatomic?

Postby greengnu » Wed Nov 06, 2019 5:08 pm

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

warren
Posts: 15
Joined: Thu May 02, 2019 3:16 pm

Re: where is libatomic?

Postby warren » Sat Nov 09, 2019 5:03 am

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.

greengnu
Posts: 27
Joined: Wed May 08, 2019 8:45 pm

Re: where is libatomic?

Postby greengnu » Fri Nov 15, 2019 3:24 pm

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

Who is online

Users browsing this forum: Google [Bot] and 163 guests