FS#53732 - [arm-none-eabi-gcc] Compile fails with : undefined reference to `__sync_synchronize'

Attached to Project: Community Packages
Opened by Brendan Fennell (bfarch) - Friday, 21 April 2017, 04:59 GMT
Last edited by Anatol Pomozov (anatolik) - Friday, 28 April 2017, 13:59 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Anatol Pomozov (anatolik)
Architecture All
Severity High
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

Compilation of a simple C++ program with arm-none-eabi-g++ fails with:

...
...
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/lib/libstdc++.a(future.o): In function `std::future_category()':
future.cc:(.text._ZSt15future_categoryv+0xc): undefined reference to `__sync_synchronize'
...
..

Note: there are other undefined references to the syscall wrappers, they can be ignored as it due to newlib being compiled with --disable-newlib-supplied-syscalls.

Additional info:
* community/arm-none-eabi-gcc 6.3.1-1


Steps to reproduce:

// main.cc
#include <iostream>

int main()
{
auto lambda = [](auto x){ return x; };
std::cout << lambda("Hello\n");
return 0;
}
// end main.cc

$ arm-none-eabi-g++ main.cc



This task depends upon

Closed by  Anatol Pomozov (anatolik)
Friday, 28 April 2017, 13:59 GMT
Reason for closing:  Not a bug
Comment by Anatol Pomozov (anatolik) - Wednesday, 26 April 2017, 18:08 GMT
Is it a regression from previous version or something that never worked?
Comment by Brendan Fennell (bfarch) - Thursday, 27 April 2017, 16:57 GMT
I didn't try to compile this code with any older version.
Comment by Brendan Fennell (bfarch) - Thursday, 27 April 2017, 17:01 GMT
There isn't anything special about the code, simply including iostream can show the problem:

//main.cc
#include <iostream>

int main()
{
return 0;
}

$ arm-none-eabi-g++ main.cc
...
...
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/lib/libstdc++.a(future.o): In function `std::future_category()':
future.cc:(.text._ZSt15future_categoryv+0xc): undefined reference to `__sync_synchronize'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/lib/libstdc++.a(locale.o): In function `std::locale::_Impl::_M_install_cache(std::locale::facet const*, unsigned int)':
locale.cc:(.text._ZNSt6locale5_Impl16_M_install_cacheEPKNS_5facetEj+0x18): undefined reference to `__sync_synchronize'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/lib/libstdc++.a(locale_init.o): In function `(anonymous namespace)::get_locale_mutex()':
locale_init.cc:(.text._ZN12_GLOBAL__N_116get_locale_mutexEv+0xc): undefined reference to `__sync_synchronize'
...
...
Comment by Anatol Pomozov (anatolik) - Friday, 28 April 2017, 13:58 GMT
1) Without any flags gcc tries to compile binary for your current target which is x86. But arm cross compiler is not intended to do it. You need to specify target ARM architecture.
2) Install requireed newlib library arm-none-eabi-newlib

Compiling a file like this make the trick:
arm-none-eabi-g++ -specs=nosys.specs -mthumb -mcpu=cortex-m3 main.cc


In the future please contact upstream maillist for more help on g++ usage.

Loading...