cross compiling error undefined reference to `__sync_fetch_and_sub_4'

Hi all,

I am compiling orocos for MicroBlaze (FPGA soft core). I received the following error:

Linking CXX shared library liborocos-rtt-gnulinux.so
CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/ConnPolicy.cpp.o: In function `atomic_decrement':
/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/ConnPolicy.cpp.o:/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: more undefined references to `__sync_fetch_and_add_4' follow
CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/Service.cpp.o: In function `boost::enable_shared_from_this2<RTT::Service>::shared_from_this()':
/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:66: undefined reference to `__sync_val_compare_and_swap_4'

Tool chain information:
$ microblaze-unknown-linux-gnu-gcc -v
Using built-in specs.
Target: microblaze-unknown-linux-gnu
Configured with: /home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/crosstool-ng-microblaze/targets/src/gcc-4.1.2/configure --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu --target=microblaze-unknown-linux-gnu --prefix=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build --with-sysroot=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build/microblaze-unknown-linux-gnu//sys-root --enable-languages=c,c++ --enable-multilib --enable-__cxa_atexit --with-local-prefix=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build/microblaze-unknown-linux-gnu//sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
Thread model: posix
gcc version 4.1.2

Maybe it is because of flag missing in the toolchain? The toolchain itself is 32bit version, my Ubuntu 10.04 is 64bit. How can I solve this problem?

Thanks in advance!

Greetings,
Lin

cross compiling error undefined reference to `__sync_fetch_and_s

2012/4/13 Lin Zhang <Lin [dot] Zhang [..] ...>

> Hi all,
>
> I am compiling orocos for MicroBlaze (FPGA soft core). I received the
> following error:
>
> Linking CXX shared library liborocos-rtt-gnulinux.so
> CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/ConnPolicy.cpp.o: In function
> `atomic_decrement':
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48:
> undefined reference to `__sync_fetch_and_add_4'
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48:
> undefined reference to `__sync_fetch_and_add_4'
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48:
> undefined reference to `__sync_fetch_and_add_4'
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48:
> undefined reference to `__sync_fetch_and_add_4'
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48:
> undefined reference to `__sync_fetch_and_add_4'
> CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/ConnPolicy.cpp.o:/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48:
> more undefined references to `__sync_fetch_and_add_4' follow
> CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/Service.cpp.o: In function
> `boost::enable_shared_from_this2<RTT::Service>::shared_from_this()':
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:66:
> undefined reference to `__sync_val_compare_and_swap_4'
>
> Tool chain information:
> $ microblaze-unknown-linux-gnu-gcc -v
> Using built-in specs.
> Target: microblaze-unknown-linux-gnu
> Configured with:
> /home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/crosstool-ng-microblaze/targets/src/gcc-4.1.2/configure
> --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu
> --target=microblaze-unknown-linux-gnu
> --prefix=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build
> --with-sysroot=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build/microblaze-unknown-linux-gnu//sys-root
> --enable-languages=c,c++ --enable-multilib --enable-__cxa_atexit
> --with-local-prefix=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build/microblaze-unknown-linux-gnu//sys-root
> --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99
> --enable-long-long --enable-target-optspace
> Thread model: posix
> gcc version 4.1.2
>
> Maybe it is because of flag missing in the toolchain? The toolchain itself
> is 32bit version, my Ubuntu 10.04 is 64bit. How can I solve this problem?
>
>
Hello Lin,

Lock-free primitives of Orocos are achievable thanks to the atomic
operations, which are hardware-dependent. Some times ago, this part of
Orocos was refactored so in most cases we now don't have to code the
assembler instructions that accomplish this, but rather to build on those
included in GCC (GCC Atomic builtins [1]) since version 4.1.0. Hence, it
seems that your compiler for the MicroBlaze does not provide these
functions. Here is an excerpt from the provided reference:

"Not all operations are supported by all target processors. If a particular
operation cannot be implemented on the target processor, a warning will be
generated and a call an external function will be generated. The external
function will carry the same name as the builtin, with an additional suffix
`_n' where n is the size of the data type."

In such a case, you have two options:

1. Build Orocos without lock-free primitives by enabling the ORO_NO_ASM
flag in CMake;
2. Code the assembler instructions by yourself to perform atomic operations
based on your hardware.

Philippe Hamelin

[1] http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html

cross compiling error undefined reference to `__sync_fetch_and_s

Hi Philippe,

Thanks for your reply, It helped me a lot!

Following your suggestion, I did:
1. Enable ORO_NO_ASM for OROCOS
2. Define BOOST_SP_NO_SYNC when compiling boost (v1.49).

The error related with OROCOS disappears after enabling ORO_NO_ASM, but boost error remains there.
Then I thought I should disable something when compiling boost. Finally I found BOOST_SP_NO_SYNC in boost 1.49, which does not exist in 1.45.

Thanks again! I am running deployer-gnulinux on Microblaze now. :-)

Lin

________________________________________
From: Philippe Hamelin [philippe [dot] hamelin [..] ...]
Sent: Friday, April 13, 2012 7:34 PM
To: Lin Zhang
Cc: orocos-users [..] ...
Subject: Re: [Orocos-users] cross compiling error undefined reference to `__sync_fetch_and_sub_4'

2012/4/13 Lin Zhang <Lin [dot] Zhang [..] ...Lin [dot] Zhang [..] ...>>
Hi all,

I am compiling orocos for MicroBlaze (FPGA soft core). I received the following error:

Linking CXX shared library liborocos-rtt-gnulinux.so
CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/ConnPolicy.cpp.o: In function `atomic_decrement':
/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/ConnPolicy.cpp.o:/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: more undefined references to `__sync_fetch_and_add_4' follow
CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/Service.cpp.o: In function `boost::enable_shared_from_this2<RTT::Service>::shared_from_this()':
/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:66: undefined reference to `__sync_val_compare_and_swap_4'

Tool chain information:
$ microblaze-unknown-linux-gnu-gcc -v
Using built-in specs.
Target: microblaze-unknown-linux-gnu
Configured with: /home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/crosstool-ng-microblaze/targets/src/gcc-4.1.2/configure --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu --target=microblaze-unknown-linux-gnu --prefix=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build --with-sysroot=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build/microblaze-unknown-linux-gnu//sys-root --enable-languages=c,c++ --enable-multilib --enable-__cxa_atexit --with-local-prefix=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build/microblaze-unknown-linux-gnu//sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
Thread model: posix
gcc version 4.1.2

Maybe it is because of flag missing in the toolchain? The toolchain itself is 32bit version, my Ubuntu 10.04 is 64bit. How can I solve this problem?

Hello Lin,

Lock-free primitives of Orocos are achievable thanks to the atomic operations, which are hardware-dependent. Some times ago, this part of Orocos was refactored so in most cases we now don't have to code the assembler instructions that accomplish this, but rather to build on those included in GCC (GCC Atomic builtins [1]) since version 4.1.0. Hence, it seems that your compiler for the MicroBlaze does not provide these functions. Here is an excerpt from the provided reference:

"Not all operations are supported by all target processors. If a particular operation cannot be implemented on the target processor, a warning will be generated and a call an external function will be generated. The external function will carry the same name as the builtin, with an additional suffix `_n' where n is the size of the data type."

In such a case, you have two options:

1. Build Orocos without lock-free primitives by enabling the ORO_NO_ASM flag in CMake;
2. Code the assembler instructions by yourself to perform atomic operations based on your hardware.

Philippe Hamelin

[1] http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html

cross compiling error undefined reference to `__sync_fetch_and_s

2012/4/14 Lin Zhang <Lin [dot] Zhang [..] ...>

> Hi Philippe,
>
> Thanks for your reply, It helped me a lot!
>
> Following your suggestion, I did:
> 1. Enable ORO_NO_ASM for OROCOS
> 2. Define BOOST_SP_NO_SYNC when compiling boost (v1.49).
>
> The error related with OROCOS disappears after enabling ORO_NO_ASM, but
> boost error remains there.
> Then I thought I should disable something when compiling boost. Finally I
> found BOOST_SP_NO_SYNC in boost 1.49, which does not exist in 1.45.
>
>
I didn't know for BOOST_SP_NO_SYNC because I'm using Boost 1.44.

> Thanks again! I am running deployer-gnulinux on Microblaze now. :-)
>
>
You're welcome!

Philippe Hmalein

cross compiling error undefined reference to `__sync_fetch_and_s

2012/4/13 Lin Zhang <Lin [dot] Zhang [..] ...>:
> Hi all,
>
> I am compiling orocos for MicroBlaze (FPGA soft core). I received the following error:
>

waow Orocos on a soft core ^^ nice. Has it been done before ?
BTW is there any place on the Orocos wiki that shows current know to
work (or haved worked;p) architectures ?

> Linking CXX shared library liborocos-rtt-gnulinux.so
> CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/ConnPolicy.cpp.o: In function `atomic_decrement':
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
> CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/ConnPolicy.cpp.o:/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: more undefined references to `__sync_fetch_and_add_4' follow
> CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/Service.cpp.o: In function `boost::enable_shared_from_this2<RTT::Service>::shared_from_this()':
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:66: undefined reference to `__sync_val_compare_and_swap_4'
>
> Tool chain information:
> $ microblaze-unknown-linux-gnu-gcc -v
> Using built-in specs.
> Target: microblaze-unknown-linux-gnu
> Configured with: /home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/crosstool-ng-microblaze/targets/src/gcc-4.1.2/configure --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu --target=microblaze-unknown-linux-gnu --prefix=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build --with-sysroot=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build/microblaze-unknown-linux-gnu//sys-root --enable-languages=c,c++ --enable-multilib --enable-__cxa_atexit --with-local-prefix=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build/microblaze-unknown-linux-gnu//sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
> Thread model: posix
> gcc version 4.1.2
>
> Maybe it is because of flag missing in the toolchain? The toolchain itself is 32bit version, my Ubuntu 10.04 is 64bit. How can I solve this problem?
>
> Thanks in advance!
>
> Greetings,
> Lin
> --
> Orocos-Users mailing list
> Orocos-Users [..] ...
> http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users

cross compiling error undefined reference to `__sync_fetch_and_s

I don't think it has been done before, at least no on MicroBlaze.
We can see some architectures in rtt/rtt/os/oro_arch.h, but I only have experience on PowerPC/FPGA OROCOS, and it works well. :-)

Best regards,
Lin

________________________________________
From: Willy Lambert [lambert [dot] willy [..] ...]
Sent: Friday, April 13, 2012 1:57 PM
To: Lin Zhang
Cc: orocos-users [..] ...
Subject: Re: [Orocos-users] cross compiling error undefined reference to `__sync_fetch_and_sub_4'

2012/4/13 Lin Zhang <Lin [dot] Zhang [..] ...>:
> Hi all,
>
> I am compiling orocos for MicroBlaze (FPGA soft core). I received the following error:
>

waow Orocos on a soft core ^^ nice. Has it been done before ?
BTW is there any place on the Orocos wiki that shows current know to
work (or haved worked;p) architectures ?

> Linking CXX shared library liborocos-rtt-gnulinux.so
> CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/ConnPolicy.cpp.o: In function `atomic_decrement':
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: undefined reference to `__sync_fetch_and_add_4'
> CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/ConnPolicy.cpp.o:/home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:48: more undefined references to `__sync_fetch_and_add_4' follow
> CMakeFiles/orocos-rtt-gnulinux_dynamic.dir/Service.cpp.o: In function `boost::enable_shared_from_this2<RTT::Service>::shared_from_this()':
> /home/zhanglin/embedded/romfs_libs_and_includes/usr/include/boost/smart_ptr/detail/sp_counted_base_sync.hpp:66: undefined reference to `__sync_val_compare_and_swap_4'
>
> Tool chain information:
> $ microblaze-unknown-linux-gnu-gcc -v
> Using built-in specs.
> Target: microblaze-unknown-linux-gnu
> Configured with: /home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/crosstool-ng-microblaze/targets/src/gcc-4.1.2/configure --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu --target=microblaze-unknown-linux-gnu --prefix=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build --with-sysroot=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build/microblaze-unknown-linux-gnu//sys-root --enable-languages=c,c++ --enable-multilib --enable-__cxa_atexit --with-local-prefix=/home/buildbot/plgx_bld/Petalinux-v2.2/2011_11_21/toolchains/microblaze-unknown-linux-gnu/tool-build/microblaze-unknown-linux-gnu//sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
> Thread model: posix
> gcc version 4.1.2
>
> Maybe it is because of flag missing in the toolchain? The toolchain itself is 32bit version, my Ubuntu 10.04 is 64bit. How can I solve this problem?
>
> Thanks in advance!
>
> Greetings,
> Lin
> --
> Orocos-Users mailing list
> Orocos-Users [..] ...
> http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users

cross compiling error undefined reference to `__sync_fetch_and_s

2012/4/13 Lin Zhang <Lin [dot] Zhang [..] ...>

> I don't think it has been done before, at least no on MicroBlaze.
> We can see some architectures in rtt/rtt/os/oro_arch.h, but I only have
> experience on PowerPC/FPGA OROCOS, and it works well. :-)
>
>
I also did it on the PPC440 of the Xilinx Virtex-5. Also, I'm currently
working on a ARM Cortex-A8/A9 and it also works well (even with atomic
operations!).

Philippe Hamelin