coroutine icon indicating copy to clipboard operation
coroutine copied to clipboard

Coroutine does not build cleanly on OS-X in universal mode (arm+x86)

Open clusty opened this issue 3 years ago • 8 comments

I checked out the 1.80 release branch of boost and ran the following commands: ./bootstrap.sh ./b2 architecture="arm+x86" cxxflags="-arch x86_64 -arch arm64"

everything seems to have compiled correctly apart from an error at the end: ...updating 4 targets... clang-darwin.link.dll bin.v2/libs/coroutine/build/clang-darwin-13/release/architecture-arm+x86/threading-multi/visibility-hidden/libboost_coroutine.dylib Undefined symbols for architecture arm64: "_jump_fcontext", referenced from: boost::coroutines::detail::coroutine_context::jump(boost::coroutines::detail::coroutine_context&, void*) in coroutine_context.o "_make_fcontext", referenced from: boost::coroutines::detail::coroutine_context::coroutine_context(void ()(boost::context::detail::transfer_t), boost::coroutines::detail::preallocated const&) in coroutine_context.o boost::coroutines::detail::coroutine_context::coroutine_context(void ()(boost::context::detail::transfer_t), boost::coroutines::detail::preallocated const&) in coroutine_context.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

"clang++"   -o "bin.v2/libs/coroutine/build/clang-darwin-13/release/architecture-arm+x86/threading-multi/visibility-hidden/libboost_coroutine.dylib" -single_module -dynamiclib -install_name "@rpath/libboost_coroutine.dylib" "bin.v2/libs/coroutine/build/clang-darwin-13/release/architecture-arm+x86/threading-multi/visibility-hidden/detail/coroutine_context.o" "bin.v2/libs/coroutine/build/clang-darwin-13/release/architecture-arm+x86/threading-multi/visibility-hidden/exceptions.o" "bin.v2/libs/coroutine/build/clang-darwin-13/release/architecture-arm+x86/threading-multi/visibility-hidden/posix/stack_traits.o" "bin.v2/libs/context/build/clang-darwin-13/release/architecture-arm+x86/threading-multi/visibility-hidden/libboost_context.dylib"         -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -arch arm64 -arch x86_64

...failed clang-darwin.link.dll bin.v2/libs/coroutine/build/clang-darwin-13/release/architecture-arm+x86/threading-multi/visibility-hidden/libboost_coroutine.dylib... ...skipped <p/opt/UnitySrc/git/com.unity.recorder/Native/External/boost/stage/lib>libboost_coroutine.dylib for lack of <pbin.v2/libs/coroutine/build/clang-darwin-13/release/architecture-arm+x86/threading-multi/visibility-hidden>libboost_coroutine.dylib... ...skipped <pbin.v2/libs/coroutine/build/clang-darwin-13/release/architecture-arm+x86/threading-multi/visibility-hidden>libboost_coroutine-variant-shared.cmake for lack of <pbin.v2/libs/coroutine/build/clang-darwin-13/release/architecture-arm+x86/threading-multi/visibility-hidden>libboost_coroutine.dylib... ...skipped <p/opt/UnitySrc/git/com.unity.recorder/Native/External/boost/stage/lib/cmake/boost_coroutine-1.80.0>libboost_coroutine-variant-shared.cmake for lack of <pbin.v2/libs/coroutine/build/clang-darwin-13/release/architecture-arm+x86/threading-multi/visibility-hidden>libboost_coroutine-variant-shared.cmake... ...failed updating 1 target... ...skipped 3 targets...

clusty avatar Sep 13 '22 15:09 clusty

Sorry - I've no access to an machine with OS-X...

olk avatar Sep 14 '22 16:09 olk

Sorry - I've no access to an machine with OS-X...

Is there a way I can help you with that ? :) I do have an OSX, but do not know much about the boost build system or coroutine libs

clusty avatar Sep 14 '22 17:09 clusty

The arm64 assembler tool doesn't find symbol _jump_fcontext which is the label/function name of jump functionality. I don't know the requirements for labels in the universal mode on OS-X.

olk avatar Oct 04 '22 05:10 olk

relates to https://github.com/boostorg/context/issues/203

olk avatar Oct 04 '22 05:10 olk

faced the same issue using macports to build boost 1.81.0 (issue) on a mac M1 (arm)

I would like to help too, as boost is required on other universal packages like poppler and I need it^^. Any chance we can fix it simply or does it imply big changes ? A location where we can send you a mac M1 😄 ?

Don't know if it can help, but a similar issue was reported some years ago for i386 architecture => https://lists.boost.org/boost-bugs/2014/03/35459.php

What do you think of the "[removal of] Untested.cpp from libs\context\build\Jamfile.v2" as a workaround ? Is it reliable ?

edit : Sounds like the related commits that were pushed at the time to fix the issue on i386 were these ones

edit2 : other informations that could help you can be found in this issue reported on macports, where a third symbol was undefined (_ontop_fcontext). Also, this issue was reported with boost171, so maybe it was working before.

kaamui avatar Feb 03 '23 11:02 kaamui

Sorry, I need to debug the code but unfortunately I have no OSX ...

maybe this issue of boost.context https://github.com/boostorg/context/issues/214 fixes your problem?

olk avatar Feb 03 '23 14:02 olk

No, it didn't.

But I found this SO thread and the following script worked :

#!/bin/sh

rm -rf arm64 x86_64 universal stage bin.v2
rm -f b2 project-config*
./bootstrap.sh cxxflags="-arch x86_64 -arch arm64" cflags="-arch x86_64 -arch arm64" linkflags="-arch x86_64 -arch arm64"
./b2 toolset=clang-darwin target-os=darwin architecture=arm abi=aapcs cxxflags="-arch arm64" cflags="-arch arm64" linkflags="-arch arm64" -a
mkdir -p arm64 && cp stage/lib/*.dylib arm64
./b2 toolset=clang-darwin target-os=darwin architecture=x86 cxxflags="-arch x86_64" cflags="-arch x86_64" linkflags="-arch x86_64" abi=sysv binary-format=mach-o -a
mkdir x86_64 && cp stage/lib/*.dylib x86_64
mkdir universal
for dylib in arm64/*; do 
  lipo -create -arch arm64 $dylib -arch x86_64 x86_64/$(basename $dylib) -output universal/$(basename $dylib); 
done
for dylib in universal/*; do
  lipo $dylib -info;
done

I'll try to dig more into it, to find if a specific option is making it working for my config, but I suspect that the default options make it impossible to find the correct flags (abi, archs, linkflags) when passing arm+x86, so it sounds more like a configuration issue than a technical/low-level issue with symbols, etc

Note that I didn't need to apply the patch you suggested to make it work... maybe because the patch is targeting sysv abi where an equivalent patch is needed when compilation is launched from an ARM-based machine ? Something like :

# COMBINED
alias asm_sources
   : asm/make_combined_sysv_macho_gas.S
     asm/jump_combined_sysv_macho_gas.S
     asm/ontop_combined_sysv_macho_gas.S
   : <abi>sysv
     <architecture>arm+x86
     <binary-format>mach-o
   ;

alias asm_sources
   : asm/make_combined_sysv_macho_gas.S
     asm/jump_combined_sysv_macho_gas.S
     asm/ontop_combined_sysv_macho_gas.S
   : <abi>aapcs
     <address-model>64
     <architecture>arm+x86
     <binary-format>mach-o
   ;

Maybe ?

kaamui avatar Feb 07 '23 13:02 kaamui

https://github.com/boostorg/context/pull/228 should've fixed this (if clang -arch x86_64 -arch arm64 asm.S is actually able to produce an universal binary).

Kojoley avatar Jul 06 '23 22:07 Kojoley