I am trying to update the tool-chain for a bare metal embedded project. We are building on windows an up to now we have been using version 5.4.1 20160609 (release) [ARM/embedded-5-branch revision 237715].
Now I am trying version 9.3.1 20200408 (release) (9-2020-q2-update), but I have an issue with an undefined symbol while linking: __sync_synchronize is reported as missing and I have no idea from which source this symbol should be resolved. Do I have to link a library that I am missing? Should I give different flags to the compiler so that it generates the code for that function?
Below is a sample that compiles and links just fine with the old tool-chain, but fails with the new one. In both cases this command line was used:
arm-none-eabi-g++ -mthumb -specs=nosys.specs sample.cpp
The exact failure message is:
c:/projects/cpt_tools/gcc-arm-none-eabi/9.3.1/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\noone\AppData\Local\Temp\ccSZkMXN.o: in function 'use_static_inst(int)': sample.cpp:(.text+0xc): undefined reference to '__sync_synchronize' collect2.exe: error: ld returned 1 exit status
BTW: There is no difference when I run my test on Linux:
noone@nowhere:~/gcc-arm-none-eabi-9-2020-q2-update/bin$ ./arm-none-eabi-g++ -mthumb -specs=nosys.specs sample.cpp /media/persistent_storage/home/rmatano/gcc-arm-none-eabi-9-2020-q2-update/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccltslyj.o: in function 'use_static_inst(int)': />sample.cpp:(.text+0xc): undefined reference to '__sync_synchronize' collect2: error: ld returned 1 exit status
I found this question GCC Linaro cross compile fails on linker step on a Windows host that seems to deal with the same problem. But I cannot use the suggested solution of specifying -mcpu=cortex-a9
since my code should run on a quite old hardware ('-cpu=arm926ej-s').
Here is the content of sample.cpp:
// compile with 'arm-none-eabi-g++.exe -mthumb -specs=nosys.specs sample.cpp'
//
// result: in function `use_static_inst(int)':
// sample.cpp:(.text+0x18): undefined reference to `__sync_synchronize'
class A
{
int m_i;
public:
A(int i) : m_i(i)
{
}
int value(int x)
{
return m_i + x;
}
};
int use_static_inst(int x)
{
// in preparation for calling the ctor of this static instance
// the compiler generates a call to __sync_synchronize
static A a(0);
return a.value(x);
}
int main(int argc, char* argv[])
{
return use_static_inst(argc);
}
__sync_synchronize
using the command line argument-fno-threadsafe-statics
. – Codo Nov 3 '20 at 9:04-fno-threadsafe-statics
makes the linker problem go away. Unfortunately I have to deal with threads and that flag not only suppresses the call to__sync_synchronize
but also the ones to__cxa_guard_acquire
and__cxa_guard_release
which I would like to keep. – RoMa Nov 3 '20 at 12:06