skip to Main Content

When I use co_spawn across multiple modules and enable optimization levels O2 or O3, I encounter a linker error during the linking phase. It appears that the compiler discards some symbols it deems unused during the linking stage.

Minimal reproduce code

ctx.h

#pragma once
#include <boost/asio/io_context.hpp>

extern boost::asio::io_context io_context_;`

ctx.cpp

#include "ctx.h"
boost::asio::io_context io_context_;

test_link.h

#pragma once
#include <boost/asio/awaitable.hpp>
#include "ctx.h"

boost::asio::awaitable<int> test_link1();

boost::asio::awaitable<void> test_link();

test_link.cpp

#include "test_link.h"

#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>

boost::asio::awaitable<int> test_link1() { co_return 0; }

boost::asio::awaitable<void> test_link() {
  boost::asio::co_spawn(io_context_, test_link1(), boost::asio::detached);
  co_return;
}

test_linka.h

#pragma once
#include <boost/asio/awaitable.hpp>

boost::asio::awaitable<int> test_linka1();

boost::asio::awaitable<void> test_linka();

test_linka.cpp

#include "test_linka.h"

#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>

#include "ctx.h"

boost::asio::awaitable<int> test_linka1() { co_return 0; }

boost::asio::awaitable<void> test_linka() {
  boost::asio::co_spawn(io_context_, test_linka1(), boost::asio::detached);
  co_return;
}

main.cpp

#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/signal_set.hpp>

#include "ctx.h"
#include "test_link.h"
#include "test_linka.h"

int main() {
  try {
    boost::asio::signal_set signals(io_context_, SIGINT, SIGTERM);
    signals.async_wait([&](auto, auto) { io_context_.stop(); });

    boost::asio::co_spawn(io_context_, test_link(), boost::asio::detached);
    boost::asio::co_spawn(io_context_, test_linka(), boost::asio::detached);

    io_context_.run();
  } catch (std::exception& e) {
    // exception
  }
  return 0;
}

My development environment

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/gcc-toolset-13/root/usr/libexec/gcc/x86_64-redhat-linux/13/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/gcc-toolset-13/root/usr --mandir=/opt/rh/gcc-toolset-13/root/usr/share/man --infodir=/opt/rh/gcc-toolset-13/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-libstdcxx-zoneinfo=/opt/rh/gcc-toolset-13/root/usr/share/zoneinfo --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-13.1.1-20230614/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-offload-defaulted --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.1.1 20230614 (Red Hat 13.1.1-4) (GCC) 

Compilation

g++ -c -x c++ /home/duanyu/projects/asio/ctx.cpp -I "/home/duanyu/sk-server-base/include" -g1 -o "/home/duanyu/projects/asio/obj/x64/Release/ctx.o" -Wall -Wswitch -W"no-deprecated-declarations" -W"empty-body" -Wconversion -W"return-type" -Wparentheses -W"no-format" -Wuninitialized -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -O3 -fno-strict-aliasing -fomit-frame-pointer -DBOOST_ASIO_HAS_STD_COROUTINE -DBOOST_ASIO_HAS_CO_AWAIT -DNDEBUG -DNDEBUG -fthreadsafe-statics -fexceptions -frtti -std=c++20 -fno-inline
g++ -c -x c++ /home/duanyu/projects/asio/main.cpp -I "/home/duanyu/sk-server-base/include" -g1 -o "/home/duanyu/projects/asio/obj/x64/Release/main.o" -Wall -Wswitch -W"no-deprecated-declarations" -W"empty-body" -Wconversion -W"return-type" -Wparentheses -W"no-format" -Wuninitialized -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -O3 -fno-strict-aliasing -fomit-frame-pointer -DBOOST_ASIO_HAS_STD_COROUTINE -DBOOST_ASIO_HAS_CO_AWAIT -DNDEBUG -DNDEBUG -fthreadsafe-statics -fexceptions -frtti -std=c++20 -fno-inline
g++ -c -x c++ /home/duanyu/projects/asio/test_link.cpp -I "/home/duanyu/sk-server-base/include" -g1 -o "/home/duanyu/projects/asio/obj/x64/Release/test_link.o" -Wall -Wswitch -W"no-deprecated-declarations" -W"empty-body" -Wconversion -W"return-type" -Wparentheses -W"no-format" -Wuninitialized -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -O3 -fno-strict-aliasing -fomit-frame-pointer -DBOOST_ASIO_HAS_STD_COROUTINE -DBOOST_ASIO_HAS_CO_AWAIT -DNDEBUG -DNDEBUG -fthreadsafe-statics -fexceptions -frtti -std=c++20 -fno-inline
g++ -c -x c++ /home/duanyu/projects/asio/test_linka.cpp -I "/home/duanyu/sk-server-base/include" -g1 -o "/home/duanyu/projects/asio/obj/x64/Release/test_linka.o" -Wall -Wswitch -W"no-deprecated-declarations" -W"empty-body" -Wconversion -W"return-type" -Wparentheses -W"no-format" -Wuninitialized -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -O3 -fno-strict-aliasing -fomit-frame-pointer -DBOOST_ASIO_HAS_STD_COROUTINE -DBOOST_ASIO_HAS_CO_AWAIT -DNDEBUG -DNDEBUG -fthreadsafe-statics -fexceptions -frtti -std=c++20 -fno-inline

Link

g++ -o "/home/duanyu/projects/asio/bin/x64/Release/asio.out" -Wl,--no-undefined -Wl,-L"/home/duanyu/sk-server-base/lib/boost/release" -Wl,-L"/home/duanyu/sk-server-base/lib/tclog/release" -Wl,-L"/home/duanyu/sk-server-base/lib/log4cplus/release" -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack /home/duanyu/projects/asio/obj/x64/Release/ctx.o /home/duanyu/projects/asio/obj/x64/Release/main.o /home/duanyu/projects/asio/obj/x64/Release/test_link.o /home/duanyu/projects/asio/obj/x64/Release/test_linka.o -llog4cplus -ltclog -lboost_system -lboost_thread -lboost_date_time -lboost_regex -lboost_serialization -lboost_context -lpthread

ErrorInfo

`_ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.destroy' referenced in section `.rodata.cst8' of /home/duanyu/projects/asio/obj/x64/Release/test_linka.o: defined in discarded section `.text._ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.destroy[_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE]' of /home/duanyu/projects/asio/obj/x64/Release/test_linka.o

It seems that during the linking phase, the compiler has performed optimizations and removed some symbols. I tried using O0, which is the optimization level where optimization is not enabled, and the linking works fine.

I used the nm command to view all symbols related to co_spawn in both test_link.o and test_linka.o, and the exported content of the two files is consistent.

==========================================================

Apologies, I forgot to mention my dependency information.
The Boost version is either 1.86.0 or 1.84.0; I have tried both versions.
The os info:

$ cat /etc/os-release
NAME="Alibaba Cloud Linux"
VERSION="3 (Soaring Falcon)"
ID="alinux"
ID_LIKE="rhel fedora centos anolis"
VERSION_ID="3"
PLATFORM_ID="platform:al8"
PRETTY_NAME="Alibaba Cloud Linux 3 (Soaring Falcon)"
ANSI_COLOR="0;31"
HOME_URL="https://www.aliyun.com/"

I tried the script of @sehe, but the same issue persisted after execution; Perhaps it is an issue with the system; I hadn’t considered that before. I will try switching to CentOS to see if it makes a difference.

2

Answers


  1. Chosen as BEST ANSWER

    My new environment is not set up yet, but by reading some materials on "COMDAT section," I found the "-fPIC" compilation option, which solved my problem. Although it is usually used to address the issue of dynamic library sharing, it was indeed useful for me. I don't quite understand it, and any friends who know about it are welcome to give guidance.

    I compared the exported symbols of test_link.o compiled with and without the "-fPIC" option regarding co_spawn.

    no fPIC

    0000000000000000 r .rodata._ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.actor
    0000000000000000 r .rodata._ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.actor.str1.1
    0000000000000000 r .rodata._ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.actor.str1.8
    0000000000000000 t .text._ZN5boost4asio6detail14co_spawn_stateINS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEvED2Ev
    0000000000000000 t .text._ZN5boost4asio6detail17executor_function8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE0_EESaIvEEEvPNS2_9impl_baseEb
    0000000000000000 t .text._ZN5boost4asio6detail17executor_function8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE_EESaIvEEEvPNS2_9impl_baseEb
    0000000000000000 t .text._ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.actor
    0000000000000000 t .text._ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.destroy
    0000000000000000 t .text._ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE
    0000000000000000 t .text._ZN5boost4asio6detail22executor_function_view8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE0_EEEEvPv
    0000000000000000 t .text._ZN5boost4asio6detail22executor_function_view8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE_EEEEvPv
    0000000000000000 t .text._ZZN5boost4asio6detail18awaitable_async_opIFvvENS1_13co_spawn_postENS0_15any_io_executorEE13await_suspendENSt7__n486116coroutine_handleIvEEENUlPvE_4_FUNESA_
    0000000000000000 t .text._ZZN5boost4asio6detail18awaitable_async_opIFvvENS1_17co_spawn_dispatchENS0_15any_io_executorEE13await_suspendENSt7__n486116coroutine_handleIvEEENUlPvE_4_FUNESA_
    0000000000000000 W _ZN5boost4asio6detail14co_spawn_stateINS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEvED1Ev
    0000000000000000 W _ZN5boost4asio6detail14co_spawn_stateINS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEvED2Ev
    0000000000000000 n _ZN5boost4asio6detail14co_spawn_stateINS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEvED5Ev
    0000000000000000 W _ZN5boost4asio6detail17executor_function8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE0_EESaIvEEEvPNS2_9impl_baseEb
    0000000000000000 W _ZN5boost4asio6detail17executor_function8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE_EESaIvEEEvPNS2_9impl_baseEb
    0000000000000000 t _ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.actor
    0000000000000000 t _ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.destroy
    0000000000000000 W _ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE
    0000000000000000 W _ZN5boost4asio6detail22executor_function_view8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE0_EEEEvPv
    0000000000000000 W _ZN5boost4asio6detail22executor_function_view8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE_EEEEvPv
    0000000000000430 t _ZN5boost4asio8co_spawnINS0_10io_contextEiNS0_15any_io_executorERKNS0_10detached_tEEEDaRT_NS0_9awaitableIT0_T1_EEOT2_NS0_10constraintIXaasrSt14is_convertibleIS8_RNS0_17execution_contextEE5valuesrSG_INS7_13executor_typeESB_E5valueEiE4typeE.isra.0
    000000000000011d t _ZN5boost4asio8co_spawnINS0_10io_contextEiNS0_15any_io_executorERKNS0_10detached_tEEEDaRT_NS0_9awaitableIT0_T1_EEOT2_NS0_10constraintIXaasrSt14is_convertibleIS8_RNS0_17execution_contextEE5valuesrSG_INS7_13executor_typeESB_E5valueEiE4typeE.isra.0.cold
    0000000000000000 W _ZZN5boost4asio6detail18awaitable_async_opIFvvENS1_13co_spawn_postENS0_15any_io_executorEE13await_suspendENSt7__n486116coroutine_handleIvEEENUlPvE_4_FUNESA_
    0000000000000000 W _ZZN5boost4asio6detail18awaitable_async_opIFvvENS1_17co_spawn_dispatchENS0_15any_io_executorEE13await_suspendENSt7__n486116coroutine_handleIvEEENUlPvE_4_FUNESA_
    

    with fPic

    0000000000000000 r .rodata._ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.actor
    0000000000000000 t .text._ZN5boost4asio6detail14co_spawn_stateINS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEvED2Ev
    0000000000000000 t .text._ZN5boost4asio6detail17executor_function8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE0_EESaIvEEEvPNS2_9impl_baseEb
    0000000000000000 t .text._ZN5boost4asio6detail17executor_function8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE_EESaIvEEEvPNS2_9impl_baseEb
    0000000000000000 t .text._ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.actor
    0000000000000000 t .text._ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.destroy
    0000000000000000 t .text._ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE
    0000000000000000 t .text._ZN5boost4asio6detail22executor_function_view8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE0_EEEEvPv
    0000000000000000 t .text._ZN5boost4asio6detail22executor_function_view8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE_EEEEvPv
    0000000000000000 t .text._ZZN5boost4asio6detail18awaitable_async_opIFvvENS1_13co_spawn_postENS0_15any_io_executorEE13await_suspendENSt7__n486116coroutine_handleIvEEENUlPvE_4_FUNESA_
    0000000000000000 t .text._ZZN5boost4asio6detail18awaitable_async_opIFvvENS1_17co_spawn_dispatchENS0_15any_io_executorEE13await_suspendENSt7__n486116coroutine_handleIvEEENUlPvE_4_FUNESA_
    0000000000000000 W _ZN5boost4asio6detail14co_spawn_stateINS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEvED1Ev
    0000000000000000 W _ZN5boost4asio6detail14co_spawn_stateINS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEvED2Ev
    0000000000000000 n _ZN5boost4asio6detail14co_spawn_stateINS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEvED5Ev
    0000000000000000 W _ZN5boost4asio6detail17executor_function8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE0_EESaIvEEEvPNS2_9impl_baseEb
    0000000000000000 W _ZN5boost4asio6detail17executor_function8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE_EESaIvEEEvPNS2_9impl_baseEb
    0000000000000000 t _ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.actor
    0000000000000000 t _ZN5boost4asio6detail20co_spawn_entry_pointEPZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEEE233_ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE.Frame.destroy
    0000000000000000 W _ZN5boost4asio6detail20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS4_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNS7_IT_S9_EENS1_14co_spawn_stateIT0_S9_T2_vEE
    0000000000000000 W _ZN5boost4asio6detail22executor_function_view8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE0_EEEEvPv
    0000000000000000 W _ZN5boost4asio6detail22executor_function_view8completeINS1_7binder0IZNS1_20co_spawn_entry_pointIiNS1_16detached_handlerENS0_15any_io_executorENS1_21awaitable_as_functionIiS7_EEEENS0_9awaitableINS1_28awaitable_thread_entry_pointET1_EEPNSA_IT_SC_EENS1_14co_spawn_stateIT0_SC_T2_vEEEUlvE_EEEEvPv
    0000000000000460 t _ZN5boost4asio8co_spawnINS0_10io_contextEiNS0_15any_io_executorERKNS0_10detached_tEEEDaRT_NS0_9awaitableIT0_T1_EEOT2_NS0_10constraintIXaasrSt14is_convertibleIS8_RNS0_17execution_contextEE5valuesrSG_INS7_13executor_typeESB_E5valueEiE4typeE.isra.0
    0000000000000167 t _ZN5boost4asio8co_spawnINS0_10io_contextEiNS0_15any_io_executorERKNS0_10detached_tEEEDaRT_NS0_9awaitableIT0_T1_EEOT2_NS0_10constraintIXaasrSt14is_convertibleIS8_RNS0_17execution_contextEE5valuesrSG_INS7_13executor_typeESB_E5valueEiE4typeE.isra.0.cold
    0000000000000000 W _ZZN5boost4asio6detail18awaitable_async_opIFvvENS1_13co_spawn_postENS0_15any_io_executorEE13await_suspendENSt7__n486116coroutine_handleIvEEENUlPvE_4_FUNESA_
    0000000000000000 W _ZZN5boost4asio6detail18awaitable_async_opIFvvENS1_17co_spawn_dispatchENS0_15any_io_executorEE13await_suspendENSt7__n486116coroutine_handleIvEEENUlPvE_4_FUNESA_
    

    It can be observed that the exported symbols for "spawn_entry_point" are missing two lines with the ".str1.x" suffix; I suspect that this might be the source of the issue.


  2. You will probably need to describe your system in way more detail. I’ve created a self-contained version of your code with a simplified build script (commenting the things that didn’t work as given):

    #!/bin/bash
    set -x -e -u
    set -o pipefail
    
    base64 -d <<SOURCE | lzcat | cpio -iv
    XQAAAAT//////////wBjnEggAymjkBfvf/VnXwrq8Ss9uPnCLlGWXJv1gJu1huFD2TPNi6KkMQlSuWxWxVQPpFeDOtH8yN7pxzHA3JTzrtUR7s3nwLwMe7+TGbudMoJ9ABiUZPMds7WJ0toVZP1f2KemMUYnKehvVqA4NgAc9YTd7Fc3lacwst5iEnmxci1K5HGO1CxeorVVY5KG13SMr+3b1uYUUNMP4OIiKRiqFn849Oq0HCM8ZoeTsVud78AFn4sJaZlV90r3frXhSGqVPc6XtYr1ugRoBtDFm36l9PpqyuyYuUtBZ3wrtBsPDagMdoSfKJxlAZT0RwAETb3F+JTutAdKqYv9002s3U83P1OIAoTJCHEUMesda72atexzfxiqjMBS5kh2lGenT5bQSMQHRmU0t1nR7jG0SXlekmkNdwNvcJyI0plp+aTCn2+6C6dKy1BTxPSAmNDhFDUgIAM5Z/h30vSIqd5YvEzCrB4XaDJGVO2sSeSWiTcS2/XjQRJCYT76FPmD+qmferwQQE2AwezAR9Y1liiHpl8XpK64qFj35JsqyForIu+lZnu2KZYtVr65NJFjEPvOX3U5f7Ztab1dkWI5CsBpin7fopCCspeSHBVolN65XIqXbjIbiQ+zwvF6dlOkTgzvw9NdNfZgh7Gm3BY2NFqDmW9UpqOVu6iIoFfzBSKwWewQ4E41956wkSiYjnX/7m3yDw==
    SOURCE
    
    head *.{h,cpp}
    
    CXXFLAGS=" -Wall -Wswitch -Wno-deprecated-declarations -Wempty-body -Wconversion -Wreturn-type -Wparentheses -Wuninitialized -Wunreachable-code -Wunused-function -Wunused-value -Wunused-variable"
    #CXXFLAGS+=" -Wno-format " # leads to security error on my version of GCC
    CXXFLAGS+=" -O3 -fno-strict-aliasing -fomit-frame-pointer"
    CXXFLAGS+=" -g1 -DNDEBUG"
    CXXFLAGS+=" -DBOOST_ASIO_HAS_STD_COROUTINE -DBOOST_ASIO_HAS_CO_AWAIT"
    CXXFLAGS+=" -fthreadsafe-statics -fexceptions -frtti -std=c++20 -fno-inline"
    #to show some validation of the working executable
    CXXFLAGS+=" -DBOOST_ASIO_ENABLE_HANDLER_TRACKING=1"
    
    for a in ctx main test_link{,a}; do
      g++ -c -x c++ "$a.cpp" -o "$a.o" $CXXFLAGS &
    done
    wait
    
    LDFLAGS=" -Wl,--no-undefined -Wl,-Lsk-server-base/lib/boost/release -Wl,-Lsk-server-base/lib/tclog/release -Wl,-Lsk-server-base/lib/log4cplus/release"
    LDFLAGS+=" -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack"
    #LDFLAGS+=" -llog4cplus -ltclog " # missing and unrelated
    LDFLAGS+=" -lboost_system -lboost_thread -lboost_date_time -lboost_regex -lboost_serialization -lboost_context"
    LDFLAGS+=" -lpthread" # should be `-pthread` really?
    g++ -o "asio.out" ctx.o main.o test_link.o test_linka.o $LDFLAGS
    
    time ./asio.out
    

    Which works fine on my Linux box (replaced head with bat for prettier output):

    Also Live On Coliru

    Suggestions

    I’d simplify and remove unneeded flags. If you can still reproduce it, please mention exact dependency versions.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search