Boost logo

Boost Users :

Subject: Re: [Boost-users] undefined reference to '__sync_add_and_fetch_4'when cross-compiling boost::asio fors mips
From: Jayne (jayne_at_[hidden])
Date: 2012-02-17 06:39:28


 Hello Andreas,

 Thank you for the reply. I have made some progress since my initial post,
I have found that part of the problem is that I am using gcc 4.2 and the
various #defines for atomics assume that 4.2 will have the appropriate
support. The compiler expects that `__sync_add_and_fetch_4' will be
provided. I've found there is some assembler provided with the compiler
which gives a 'atomic_exchange_and_add' macro which I've had working
correctly in a demo programme, but I haven't yet got it integrated with
boost, though that would be a nice long-term solution.

 Back to the problem though. I've tried a clean build with
BOOST_ASIO_DISABLE_FENCED_BLOCK but I'm still getting the same problem.
I've attached the build output below. Here are the steps I took to make
the clean build:

 1.    unzip boost_1_48_0.zip
 2.    mkdir boost-binary
 3.    set and export
 Â Â Â  BOOST_BUILD_ROOT=/home/jayne/boost-stb/boost_1_48_0
 Â Â Â  export BOOST_BUILD_ROOT
 Â Â Â  BOOST_BIN_ROOT=$BOOST_BUILD_ROOT/boost-binary
 Â Â Â  export BOOST_BIN_ROOT
 4.    ./bootstrap.sh
 5.    Edit the resulting project-config.jam file (which has been
generated for the host x86 system)
 Â Â Â  using gcc : mipsel : mipsel-linux-g++ ;
 and
 Â Â Â  option.set prefix : /opt/brcm/stblinux-2.6.31 ;
 Â Â Â  option.set exec-prefix : /opt/brcm/stblinux-2.6.31 ;
 Â Â Â  option.set libdir : /opt/brcm/stblinux-2.6.31/lib ;
 Â Â Â  option.set includedir : /opt/brcm/stblinux-2.6.31/include/linux ;

 6.    Edit tools/build/v2/tools/gcc.jam to remove ‘-pendantic’
option (otherwise the string library assembler will not compile)
 7.    Run  ./b2 cxxflags=-DBOOST_ASIO_DISABLE_FENCED_BLOCK
--without-python --without-mpi
 8.    Run ./b2 threading=multi variant=release link=shared toolset=gcc
--build-dir=$BOOST_BIN_ROOT --prefix=/tmp/boost --without-python
--without-mpi install

 While compiling in step 7, a typical compiler line is:

"mipsel-linux-g++"  -ftemplate-depth-128 -O3 -finline-functions
-Wno-inline -Wall -pthread -fPIC -DBOOST_ASIO_DISABLE_FENCED_BLOCK -Wextra
-Wno-long-long -pedantic -DBOOST_ALL_DYN_LINK=1 -DBOOST_ALL_NO_LIB=1
-DBOOST_SYSTEM_DYN_LINK=1 -DBOOST_SYSTEM_NO_DEPRECATED -DNDEBUG  -I"." -c
-o
"bin.v2/libs/chrono/build/gcc-mipsel/release/threading-multi/process_cpu_clocks.o"
"libs/chrono/src/process_cpu_clocks.cpp"

 This is the output from build:

 /opt/bcmtools/bin/mipsel-linux-g++  -O2 -I/tmp/boost/include
echo_server.o network_utilities.o sha1.o base64.o md5.o uri.o
hybi_header.o data.o atomic.o -o echo_server -L/tmp/boost/lib
-lboost_regex -lboost_date_time -lboost_program_options -lboost_system 
-lboost_thread
 echo_server.o: In function
`boost::asio::detail::wait_handler::do_complete(boost::asio::detail::task_io_service*,
boost::asio::detail::task_io_service_operation*, boost::system::error_code
const&, unsigned int)':

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail12wait_handlerINS_3_bi6bind_tIvNS_4_mfi3mf0IvN11websocketpp4role6serverINS7_8endpointIS9_NS7_6socket5plainENS7_3log6loggerEEEEEEENS3_5list1INS3_5valueIPSG_EEEEEEE11do_completeEPNS1_15task_io_serviceEPNS1_25task_io_service_operationERKNS_6system10error_codeEj+0x94):
undefined reference to `__sync_lock_test_and_set_4'
 echo_server.o: In function
`boost::asio::detail::wait_handler::do_complete(boost::asio::detail::task_io_service*,
boost::asio::detail::task_io_service_operation*, boost::system::error_code
const&, unsigned int)':

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail12wait_handlerINS_3_bi6bind_tIvNS_4_mfi3mf1IvN11websocketpp10connectionINS7_8endpointINS7_4role6serverENS7_6socket5plainENS7_3log6loggerEEENSB_ISG_E10connectionENSD_ISG_E10connectionEEERKNS_6system10error_codeEEENS3_5list2INS3_5valueINS_10shared_ptrISL_EEEEPFNS_3argILi1EEEvEEEEEE11do_completeEPNS1_15task_io_serviceEPNS1_25task_io_service_operationESP_j+0xd4):
undefined reference to `__sync_lock_test_and_set_4'
 echo_server.o: In function
`boost::asio::detail::reactive_socket_accept_op::do_complete(boost::asio::detail::task_io_service*,
boost::asio::detail::task_io_service_operation*, boost::system::error_code
const&, unsigned int)':

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail25reactive_socket_accept_opINS0_12basic_socketINS0_2ip3tcpENS0_21stream_socket_serviceIS5_EEEES5_NS_3_bi6bind_tIvNS_4_mfi3mf2IvN11websocketpp4role6serverINSD_8endpointISF_NSD_6socket5plainENSD_3log6loggerEEEEENS_10shared_ptrINSD_10connectionISL_NSM_10connectionENSI_ISL_E10connectionEEEEERKNS_6system10error_codeEEENS9_5list3INS9_5valueIPSM_EENS10_IST_EEPFNS_3argILi1EEEvEEEEEE11do_completeEPNS1_15task_io_serviceEPNS1_25task_io_service_operationESX_j+0xdc):
undefined reference to `__sync_lock_test_and_set_4'
 echo_server.o: In function
`boost::asio::detail::reactive_socket_service_base::start_op(boost::asio::detail::reactive_socket_service_base::base_implementation_type&,
int, boost::asio::detail::reactor_op*, bool, bool)':

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail28reactive_socket_service_base8start_opERNS2_24base_implementation_typeEiPNS1_10reactor_opEbb+0x1b0):
undefined reference to `__sync_fetch_and_add_4'

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail28reactive_socket_service_base8start_opERNS2_24base_implementation_typeEiPNS1_10reactor_opEbb+0x2b4):
undefined reference to `__sync_fetch_and_add_4'

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail28reactive_socket_service_base8start_opERNS2_24base_implementation_typeEiPNS1_10reactor_opEbb+0x2ec):
undefined reference to `__sync_fetch_and_add_4'

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail28reactive_socket_service_base8start_opERNS2_24base_implementation_typeEiPNS1_10reactor_opEbb+0x3cc):
undefined reference to `__sync_fetch_and_add_4'

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail28reactive_socket_service_base8start_opERNS2_24base_implementation_typeEiPNS1_10reactor_opEbb+0x548):
undefined reference to `__sync_fetch_and_add_4'

echo_server.o:echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail28reactive_socket_service_base8start_opERNS2_24base_implementation_typeEiPNS1_10reactor_opEbb+0x65c):
more undefined references to `__sync_fetch_and_add_4' follow
 echo_server.o: In function
`boost::asio::detail::reactive_socket_send_op::do_complete(boost::asio::detail::task_io_service*,
boost::asio::detail::task_io_service_operation*, boost::system::error_code
const&, unsigned int)':

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail23reactive_socket_send_opINS1_17consuming_buffersINS0_12const_bufferEN11websocketpp19shared_const_bufferEEENS1_8write_opINS0_19basic_stream_socketINS0_2ip3tcpENS0_21stream_socket_serviceISB_EEEES6_NS1_14transfer_all_tENS_3_bi6bind_tIvNS_4_mfi3mf1IvNS5_4role6serverINS5_8endpointISL_NS5_6socket5plainENS5_3log6loggerEEEE10connectionINS5_10connectionISR_NSS_10connectionENSO_ISR_E10connectionEEEEERKNS_6system10error_codeEEENSG_5list2INSG_5valueINS_10shared_ptrISY_EEEEPFNS_3argILi1EEEvEEEEEEEE11do_completeEPNS1_15task_io_serviceEPNS1_25task_io_service_operationES13_j+0x1a8):
undefined reference to `__sync_lock_test_and_set_4'
 echo_server.o: In function
`boost::asio::detail::reactive_socket_send_op::do_complete(boost::asio::detail::task_io_service*,
boost::asio::detail::task_io_service_operation*, boost::system::error_code
const&, unsigned int)':

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail23reactive_socket_send_opINS1_17consuming_buffersINS0_12const_bufferESt6vectorIS4_SaIS4_EEEENS1_8write_opINS0_19basic_stream_socketINS0_2ip3tcpENS0_21stream_socket_serviceISC_EEEES7_NS1_14transfer_all_tENS_3_bi6bind_tIvNS_4_mfi3mf1IvN11websocketpp10connectionINSL_8endpointINSL_4role6serverENSL_6socket5plainENSL_3log6loggerEEENSP_ISU_E10connectionENSR_ISU_E10connectionEEERKNS_6system10error_codeEEENSH_5list2INSH_5valueINS_10shared_ptrISZ_EEEEPFNS_3argILi1EEEvEEEEEEEE11do_completeEPNS1_15task_io_serviceEPNS1_25task_io_service_operationES13_j+0x208):
undefined reference to `__sync_lock_test_and_set_4'
 echo_server.o: In function
`boost::asio::detail::epoll_reactor::descriptor_state::perform_io(unsigned
int)':

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail13epoll_reactor16descriptor_state10perform_ioEj+0x244):
undefined reference to `__sync_fetch_and_add_4'

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail13epoll_reactor16descriptor_state10perform_ioEj+0x324):
undefined reference to `__sync_fetch_and_add_4'
 echo_server.o: In function
`boost::asio::detail::epoll_reactor::descriptor_state::do_complete(boost::asio::detail::task_io_service*,
boost::asio::detail::task_io_service_operation*, boost::system::error_code
const&, unsigned int)':

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail13epoll_reactor16descriptor_state11do_completeEPNS1_15task_io_serviceEPNS1_25task_io_service_operationERKNS_6system10error_codeEj+0x21c):
undefined reference to `__sync_fetch_and_add_4'

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail13epoll_reactor16descriptor_state11do_completeEPNS1_15task_io_serviceEPNS1_25task_io_service_operationERKNS_6system10error_codeEj+0x340):
undefined reference to `__sync_fetch_and_add_4'
 echo_server.o: In function
`boost::asio::detail::reactive_socket_recv_op::do_complete(boost::asio::detail::task_io_service*,
boost::asio::detail::task_io_service_operation*, boost::system::error_code
const&, unsigned int)':

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail23reactive_socket_recv_opINS0_17mutable_buffers_1ENS1_26read_until_delim_string_opINS0_19basic_stream_socketINS0_2ip3tcpENS0_21stream_socket_serviceIS7_EEEESaIcENS_3_bi6bind_tIvNS_4_mfi3mf2IvN11websocketpp4role6serverINSG_8endpointISI_NSG_6socket5plainENSG_3log6loggerEEEE10connectionINSG_10connectionISO_NSP_10connectionENSL_ISO_E10connectionEEEEERKNS_6system10error_codeEjEENSC_5list3INSC_5valueINS_10shared_ptrISV_EEEEPFNS_3argILi1EEEvEPFNS17_ILi2EEEvEEEEEEEE11do_completeEPNS1_15task_io_serviceEPNS1_25task_io_service_operationES10_j+0x13c):
undefined reference to `__sync_lock_test_and_set_4'
 echo_server.o: In function
`boost::asio::detail::reactive_socket_recv_op::do_complete(boost::asio::detail::task_io_service*,
boost::asio::detail::task_io_service_operation*, boost::system::error_code
const&, unsigned int)':

echo_server.cpp:(.gnu.linkonce.t._ZN5boost4asio6detail23reactive_socket_recv_opINS0_17mutable_buffers_1ENS1_17read_streambuf_opINS0_19basic_stream_socketINS0_2ip3tcpENS0_21stream_socket_serviceIS7_EEEESaIcENS1_19transfer_at_least_tENS_3_bi6bind_tIvNS_4_mfi3mf1IvN11websocketpp10connectionINSH_8endpointINSH_4role6serverENSH_6socket5plainENSH_3log6loggerEEENSL_ISQ_E10connectionENSN_ISQ_E10connectionEEERKNS_6system10error_codeEEENSD_5list2INSD_5valueINS_10shared_ptrISV_EEEEPFNS_3argILi1EEEvEEEEEEEE11do_completeEPNS1_15task_io_serviceEPNS1_25task_io_service_operationESZ_j+0x104):
undefined reference to `__sync_lock_test_and_set_4'
 echo_server.o: In function
`websocketpp::message::intrusive_ptr_release(websocketpp::message::data
const*)':

echo_server.cpp:(.gnu.linkonce.t._ZN11websocketpp7message21intrusive_ptr_releaseEPKNS0_4dataE+0x34):
undefined reference to `__sync_fetch_and_add_4'

echo_server.cpp:(.gnu.linkonce.t._ZN11websocketpp7message21intrusive_ptr_releaseEPKNS0_4dataE+0x114):
undefined reference to `__sync_fetch_and_add_4'

echo_server.cpp:(.gnu.linkonce.t._ZN11websocketpp7message21intrusive_ptr_releaseEPKNS0_4dataE+0x244):
undefined reference to `__sync_fetch_and_add_4'
 echo_server.o: In function
`std::deque::_M_push_back_aux(boost::intrusive_ptr const">On Fri 17/02/12
07:01 , "Andreas Wehrmann" a.wehrmann_at_[hidden] sent:
 On 02/16/2012 10:06 AM, Jayne wrote:
>
> Hello,
>
> I'm trying to build Boost 1.48.0 for use with the WebSockets++ library
> on a MIPS based embedded Linux board.
>
> My build machine reports itself as: Linux version
2.6.40.4-5.fc15.x86_64
> (mockbuild_at_[hidden]) (gcc version 4.6.0 20110603
> (Red Hat 4.6.0-10) (GCC) ) #1 SMP Tue Aug 30 14:38:32 UTC 2011
>
> My cross-compiler version is: mipsel-linux-g++ (GCC) 4.2.0 20070124
> (prerelease) - BRCM 11ts-20090508. I don't have any control over this
as
> its provided by the chip manufacturer.
>
> I can build Boost without any reported errors and can link to and use
> most of the libraries without any problems. However, when WebSockets
> tries to link to the Boost::asio library I get link errors like this:
>
>
(.gnu.linkonce.t._ZNSt5dequeIN5boost13intrusive_ptrIN11websocketpp7message4dataEEESaIS5_EE16_M_push_back_auxERKS5_+0x30):
> undefined reference to `__sync_add_and_fetch_4'
>
>
(.gnu.linkonce.t._ZNSt5dequeIN5boost13intrusive_ptrIN11websocketpp7message4dataEEESaIS5_EE16_M_push_back_auxERKS5_+0x80):
> undefined reference to `__sync_add_and_fetch_4'
>
>
(.gnu.linkonce.t._ZN11websocketpp9processor4hybiINS_10connectionINS_8endpointINS_4role6serverENS_6socket5plainENS_3log6loggerEEENS5_ISA_E10connectionENS7_ISA_E10connectionEEEE19prepare_close_frameEN5boost13intrusive_ptrINS_7message4dataEEENS_5close6status5valueERKSs+0xc8):
> more undefined references to `__sync_add_and_fetch_4' follow
>
> I've done enough research to find this has been a problem in the past
> with ARM chips and is to do with atomic transactions not being
> implemented by gcc for the target machine. I've tried the suggested
> fixes for ARM which were to build with either BOOST_SP_DISABLE_THREADS
> or BOOST_SP_USE_PTHREADS but that didn't help with my MIPS environment.
>
> Can anyone make any suggestions as to what I could try next?
>
> thanks,
>
> Jayne.
>

 Try this #define:

 BOOST_ASIO_DISABLE_FENCED_BLOCK

 --
 Dipl.-Ing. (FH) Andreas Wehrmann
 Software Development
 --------------------------------------------------------------
 Center Communication Systems GmbH

 Sitz in Wien
 FN 796 88p, Firmenbuchgericht Wien
 http://www.centersystems.com [1]">www.centersystems.com

 Tel.: +43 (0) 190 199 - 3616
 Mobile: +43 (0) 664 884 75916
 Fax: +43 (0) 190 199 - 2110
 E-Mail: a.wehrmann_at_[hidden]
 _______________________________________________
 Boost-users mailing list
 Boost-users_at_[hidden]
 http://lists.boost.org/mailman/listinfo.cgi/boost-users
[2]">http://lists.boost.org/mailman/listinfo.cgi/boost-users

 

Links:
------
[1] http://www.centersystems.com
[2] http://lists.boost.org/mailman/listinfo.cgi/boost-users



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net