-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using the co_spawn function across multiple modules can trigger linker errors. #1523
Comments
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. |
I think this may be a common issue with the use of template functions, but I have not been able to find out how to disable this compiler optimization. Or perhaps there is something wrong with the way I am using it. |
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
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. |
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
ctx.cpp
test_link.h
test_link.cpp
test_linka.h
test_linka.cpp
main.cpp
My development environment
Compilation
The Boost version is either 1.86.0 or 1.84.0; I have tried both versions.
Link
ErrorInfo
The text was updated successfully, but these errors were encountered: