gnustep / libobjc2

Objective-C runtime library intended for use with Clang.
http://www.gnustep.org/
MIT License
426 stars 116 forks source link

failed to compile with clang, libc++ and musl libc on aarch64 #235

Closed alepi closed 6 months ago

alepi commented 1 year ago

Hi all,

I am trying to compile libobjc2 with clang on aarch64 and I get a weird error:

[ 94%] Linking C executable CXXExceptions ld.lld: error: ../libobjc.so.4.6: undefined reference to cxx_throw() ld.lld: error: ../libobjc.so.4.6: undefined reference to test_eh_personality

I checked the file where cxx_throw is defined and it is marked as PRIVATE.

I tried removing PRIVATE but still it gives me the exact same error. The weird thing is that if I build using clang with glibc on x86_64 I get no error at all.

Can anyone help? Thanks :-)

davidchisnall commented 1 year ago

PRIVATE just expands to hidden visibility on ELF platforms: it won't be visible outside of the library, but is visible across compilation units.

Can you build with ninja -v to get the linker command line and see what's happening?

alepi commented 1 year ago

I am building with cmake, not ninja. Does that make a difference?

Below is the output of linking that program. I don't see anything special there. Notice that if I search for cxx_throw in the built libobjc I find it. Also, I added the output of readelf -d and of nm -gDC below.

What I can see is that cxx_throw is marked as 'U', but as far as I can tell, it should not be called explicitly by CXXExceptions...

Apologies for the lack of newlines. I thought that the code tag in the github editor was able to pick them.

EDIT: I remember vaguely that there are differences between lld and gnu ld but I am not an expert in this.

output of linker

clang version 11.0.0 (https://github.com/llvm/llvm-project.git 498e37e786ea2632b1c8596ad2512c306b3c8f58) Target: aarch64-unknown-linux-musl Thread model: posix InstalledDir: /home/ale/Scrivania/lola_games/crosstools/bin Found CUDA installation: /opt/cuda, version 7.0 "/home/ale/Scrivania/lola_games/crosstools/bin/ld.lld" --sysroot=/home/ale/Scrivania/lola_games/rootfs -pie -export-dynamic -EL --eh-frame-hdr -m aarch64linux -export-dynamic -dynamic-linker /lib/ld-musl-aarch64.so.1 -o CXXExceptions /home/ale/Scrivania/lola_games/rootfs/usr/lib/Scrt1.o /home/ale/Scrivania/lola_games/rootfs/usr/lib/crti.o /home/ale/Scrivania/lola_games/crosstools/lib/clang/11.0.0/lib/linux/clang_rt.crtbegin-aarch64.o -L/run/media/ale/fe38056b-09dc-4e4a-96f2-520883d97d2a/usr/lib -L/home/ale/Scrivania/lola_games/rootfs/lib -L/home/ale/Scrivania/lola_games/rootfs/usr/lib -lunwind CMakeFiles/CXXExceptions.dir/CXXException.m.o CMakeFiles/CXXExceptions.dir/CXXException.cc.o CMakeFiles/test_runtime.dir/Test.m.o -rpath /home/ale/Scrivania/objc/libobjc2/build ../libobjc.so.4.6 -lm -lc++ -lm /home/ale/Scrivania/lola_games/crosstools/lib/clang/11.0.0/lib/linux/libclang_rt.builtins-aarch64.a -lc /home/ale/Scrivania/lola_games/crosstools/lib/clang/11.0.0/lib/linux/libclang_rt.builtins-aarch64.a /home/ale/Scrivania/lola_games/crosstools/lib/clang/11.0.0/lib/linux/clang_rt.crtend-aarch64.o /home/ale/Scrivania/lola_games/rootfs/usr/lib/crtn.o ld.lld: error: ../libobjc.so.4.6: undefined reference to cxx_throw() ld.lld: error: ../libobjc.so.4.6: undefined reference to test_eh_personality clang-11: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [Test/CMakeFiles/CXXExceptions.dir/build.make:117: Test/CXXExceptions] Errore 1 make[1]: *** [CMakeFiles/Makefile2:5386: Test/CMakeFiles/CXXExceptions.dir/all] Errore 2 make: *** [Makefile:166: all] Errore 2

output of readelf

readelf -d libobjc.so.4.6 Dynamic section at offset 0x33b00 contains 24 entries: Tag Tipo Nome/Valore 0x0000000000000001 (NEEDED) Libreria condivisa: [libc++.so.1] 0x0000000000000001 (NEEDED) Libreria condivisa: [libc.so] 0x000000000000000e (SONAME) soname della libreria: [libobjc.so.4.6] 0x0000000000000007 (RELA) 0x5850 0x0000000000000008 (RELASZ) 26328 (byte) 0x0000000000000009 (RELAENT) 24 (byte) 0x000000006ffffff9 (RELACOUNT) 1033 0x0000000000000017 (JMPREL) 0xbf28 0x0000000000000002 (PLTRELSZ) 2928 (byte) 0x0000000000000003 (PLTGOT) 0x64a08 0x0000000000000014 (PLTREL) RELA 0x0000000000000006 (SYMTAB) 0x270 0x000000000000000b (SYMENT) 24 (byte) 0x0000000000000005 (STRTAB) 0x392c 0x000000000000000a (STRSZ) 7968 (byte) 0x000000006ffffef5 (GNU_HASH) 0x2550 0x0000000000000004 (HASH) 0x2d84 0x0000000000000019 (INIT_ARRAY) 0x51df8 0x000000000000001b (INIT_ARRAYSZ) 16 (byte) 0x000000000000001a (FINI_ARRAY) 0x51e08 0x000000000000001c (FINI_ARRAYSZ) 8 (byte) 0x000000000000000c (INIT) 0x415c4 0x000000000000000d (FINI) 0x415d4 0x0000000000000000 (NULL) 0x0

output of nm

nm -gDC libobjc.so.4.6 U abort 0000000000024868 T alias_getClass 00000000000666f8 B ARCThreadKey U __assert_fail U atexit 000000000003bed8 T _Block_copy 0000000000025364 T block_copyIMPTypeEncoding_np 000000000003bc44 T block_getType_np 000000000003bc08 T _Block_has_signature 000000000003bc70 T _Block_object_assign 000000000003bfbc T _Block_object_dispose 000000000003c140 T _Block_release 000000000003bc18 T _Block_signature U calloc 000000000003235c T class_addIvar 0000000000032578 T class_addMethod 000000000003d7a4 T class_addProperty 0000000000032740 T class_addProtocol 0000000000030bc8 T class_conformsToProtocol 00000000000327b4 T class_copyIvarList 00000000000328e8 T class_copyMethodList 000000000003ce10 T class_copyPropertyList 0000000000032a5c T class_copyProtocolList 0000000000032b0c T class_createInstance 0000000000032ed8 T class_getClassMethod 0000000000032f0c T class_getClassVariable 0000000000032dd8 T class_getInstanceMethod 0000000000032d34 T class_getInstanceSize 00000000000324dc T class_getInstanceVariable 0000000000032fc8 T class_getIvarLayout 0000000000037ed0 T class_getMethodImplementation 0000000000037f30 T class_getMethodImplementation_stret 0000000000032fd4 T class_getName 000000000003cd50 T class_getProperty 000000000002cb20 T class_getSuperclass 0000000000032fec T class_getVersion 0000000000032ff8 T class_getWeakIvarLayout 0000000000033000 T class_isMetaClass 000000000002cd7c T class_pose_as 0000000000024e84 T class_registerAlias_np 0000000000033010 T class_replaceMethod 000000000003d8d8 T class_replaceProperty 0000000000037e9c T class_respondsToSelector 00000000000330dc T class_setIvarLayout 000000000003313c T class_setSuperclass 00000000000332fc T class_setVersion 000000000003330c T class_setWeakIvarLayout U __cxa_atexit U __cxa_begin_catch w __cxa_end_catch w __cxa_finalize U __cxa_guard_abort U __cxa_guard_acquire U __cxa_guard_release 0000000000039628 T __deregister_frame w __deregister_frame_info 0000000000065b78 V _dispatch_begin_NSAutoReleasePool 0000000000065b68 V dispatch_begin_thread_4GC 0000000000065b80 V _dispatch_end_NSAutoReleasePool 0000000000065b70 V dispatch_end_thread_4GC U dladdr U dl_iterate_phdr U fflush 00000000000415d4 T _fini U fprintf U free U fwrite U getenv 0000000000010178 R gnu_cxx_exception_class 000000000003841c T __gnu_objc_personality_v0 000000000003870c T __gnustep_objc_personality_v0 0000000000038714 T __gnustep_objcxx_personality_v0 w __gxx_personality_v0 00000000000250f0 T imp_getBlock 0000000000024f44 T imp_implementationWithBlock 00000000000251cc T imp_removeBlock 00000000000415c4 T _init 0000000000033310 T ivar_getName 000000000003331c T ivar_getOffset 000000000003332c T ivar_getTypeEncoding 0000000000010180 R llvm_cxx_exception_class 0000000000066850 B loadSel U malloc U memchr U memcpy U memmove U memset 000000000002f28c T method_copyArgumentType 000000000002f334 T method_copyReturnType 0000000000033338 T method_exchangeImplementations 000000000002f0b0 T method_getArgumentType 0000000000033354 T method_getImplementation 0000000000033360 T method_getName 000000000002f204 T method_get_number_of_arguments 000000000002f17c T method_getNumberOfArguments 000000000002f004 T method_getReturnType 000000000002f0a0 T method_getTypeEncoding 000000000003336c T method_setImplementation U mmap U mprotect 0000000000066900 B _NSConcreteGlobalBlock 0000000000066988 B _NSConcreteMallocBlock 0000000000066a10 B _NSConcreteStackBlock 000000000002ef74 T objc_aligned_size 000000000002ec30 T objc_alignof_type 0000000000033708 T objc_allocateClassPair 000000000003dc70 T objc_allocate_object 0000000000031834 T objc_allocateProtocol 000000000003e1e4 T objc_arc_autorelease_count_for_object_np 000000000003e15c T objc_arc_autorelease_count_np 000000000003dad8 T objc_assertRegisteredThreadWithCollector 000000000003dc4c T objc_assign_global 000000000003dc54 T objc_assign_ivar 000000000003dc44 T objc_assign_strongCast 000000000003dc68 T objc_assign_weak 000000000003dba4 T objc_atomicCompareAndSwapGlobal 000000000003dbcc T objc_atomicCompareAndSwapGlobalBarrier 000000000003dbf4 T objc_atomicCompareAndSwapInstanceVariable 000000000003dc1c T objc_atomicCompareAndSwapInstanceVariableBarrier 000000000003db54 T objc_atomicCompareAndSwapPtr 000000000003db7c T objc_atomicCompareAndSwapPtrBarrier 000000000003e9cc T objc_autorelease 000000000003e5d8 T objc_autoreleasePoolPop 000000000003e2a4 T objc_autoreleasePoolPush 000000000003e9d8 T objc_autoreleaseReturnValue 0000000000038728 T objc_begin_catch 000000000003a7d4 T __objc_block_trampoline 000000000003a7e4 T __objc_block_trampoline_end 000000000003a7f4 T __objc_block_trampoline_end_sret 000000000003a7e4 T __objc_block_trampoline_sret 0000000000066890 B _objc_class_for_boxing_foreign_exception 0000000000064298 D ._OBJC_CLASS___IncompleteProtocol 00000000000643d8 D ._OBJC_CLASS___ObjC_Protocol_Holder_Ugly_Hack 0000000000064518 D ._OBJC_CLASS_Object 0000000000064188 D ._OBJC_CLASS_Protocol 0000000000064628 D ._OBJC_CLASS_ProtocolGCC 0000000000064738 D ._OBJC_CLASS_ProtocolGSv1 000000000003dc84 T objc_clear_stack 000000000003db48 T objc_collect 000000000003dc78 T objc_collecting_enabled 000000000003db4c T objc_collectingEnabled 000000000002ca80 T objc_copyClassList 000000000003c6f4 T objc_copyCppObjectAtomic 000000000003c9d8 T objc_copyPropertyStruct 000000000003168c T objc_copyProtocolList 0000000000040150 T objc_copyWeak 000000000003a92c T objc_create_block_classes_as_subclasses_of 000000000003dd9c T objc_delete_weak_refs 0000000000040244 T objc_destroyWeak 00000000000334a0 T objc_disposeClassPair 00000000000388b0 T objc_end_catch 000000000002fef0 W objc_enumerationMutation 000000000003833c T objc_exception_from_header 00000000000389f4 T objc_exception_rethrow 0000000000038344 T objc_exception_throw 000000000002fd38 T __objc_exec_class 000000000003dc90 T objc_finalizeOnMainThread 000000000003b220 T objc_getAssociatedObject 000000000002cbfc T objc_get_class 000000000002c3e8 T objc_getClass 000000000002c9f0 T objc_getClassList 000000000003c848 T objc_getCppObjectAtomic 000000000002ccec T objc_get_meta_class 000000000002cb80 T objc_getMetaClass 000000000003c210 T objc_getProperty 000000000003cb60 T objc_getPropertyStruct 0000000000030aa4 T objc_getProtocol 0000000000033380 T objc_getRequiredClass 0000000000037e28 T objc_get_slot 0000000000037ba0 T objc_get_slot2 000000000002f3b4 T objc_get_type_qualifiers 0000000000064910 D ._OBJC_INIT_CLASS___IncompleteProtocol 0000000000064918 D ._OBJC_INIT_CLASS___ObjC_Protocol_Holder_Ugly_Hack 0000000000064920 D ._OBJC_INIT_CLASS_Object 0000000000064908 D ._OBJC_INIT_CLASS_Protocol 0000000000064928 D ._OBJC_INIT_CLASS_ProtocolGCC 0000000000064930 D ._OBJC_INIT_CLASS_ProtocolGSv1 000000000004050c T objc_initWeak 000000000003dc88 T objc_is_finalized 00000000000666d8 B __objc_ivar_offset___ObjC_Protocol_Holder_Ugly_Hack.isa. 00000000000666dc B __objc_ivar_offset_Object.isa. 000000000002f428 T objc_layout_structure 000000000002f540 T objc_layout_structure_get_info 000000000002f430 T objc_layout_structure_next_member 000000000002f9a8 T __objc_load 0000000000066840 B _objc_load_callback 0000000000040130 T objc_loadWeak 000000000003fd08 T objc_loadWeakRetained 0000000000066848 B _objc_lookup_class 000000000002cc74 T objc_lookup_class 000000000002cb54 T objc_lookUpClass 000000000003dc5c T objc_memmove_collectable 0000000000066888 B objc_method_cache_version 00000000000401e8 T objc_moveWeak 0000000000063e88 D __objc_msg_forward2 0000000000063e80 D __objc_msg_forward3 0000000000037f90 T objc_msg_lookup 0000000000037400 T objc_msg_lookup2 0000000000036bd4 T objc_msg_lookup_sender 0000000000038308 T objc_msg_lookup_super 000000000003a7f4 T objc_msgSend 000000000003a7f4 T objc_msgSend_fpret 000000000003a7f4 T objc_msgSend_stret 000000000002cd68 T objc_next_class 000000000002efd0 T objc_promoted_size 0000000000063e78 D objc_proxy_lookup 000000000003dc60 T objc_read_weak 0000000000064950 D ._OBJC_REF_CLASS___IncompleteProtocol 0000000000064958 D ._OBJC_REF_CLASS___ObjC_Protocol_Holder_Ugly_Hack 0000000000064960 D ._OBJC_REF_CLASS_Object 0000000000064948 D ._OBJC_REF_CLASS_Protocol 0000000000064968 D ._OBJC_REF_CLASS_ProtocolGCC 0000000000064970 D ._OBJC_REF_CLASS_ProtocolGSv1 00000000000338c8 T objc_registerClassPair 00000000000318e4 T objc_registerProtocol 000000000002c874 T objc_registerSmallObjectClass_np 000000000003dad0 T objc_registerThreadWithCollector 000000000002d21c T objc_registerTracingHook 000000000003ef08 T objc_release 000000000003dd08 T objc_release_fast_no_destroy_np 000000000003e094 T objc_release_fast_np 000000000003b46c T objc_removeAssociatedObjects 000000000003ebe0 T objc_retain 000000000003ecb8 T objc_retainAutorelease 000000000003ea70 T objc_retainAutoreleasedReturnValue 000000000003eda4 T objc_retainAutoreleaseReturnValue 000000000003ef04 T objc_retainBlock 000000000003dcb8 T objc_retain_fast_np 0000000000063e68 D __objc_runtime_threads_alive 00000000000668f8 B _objc_selector_type_mismatch 0000000000063e90 D _objc_selector_type_mismatch2 000000000003ac14 T objc_setAssociatedObject 000000000003db44 T objc_set_collection_ratio 000000000003db40 T objc_set_collection_threshold 000000000003c910 T objc_setCppObjectAtomic 000000000002bb54 T objc_setDeveloperMode_np 000000000003c310 T objc_setProperty 000000000003c4a4 T objc_setProperty_atomic 000000000003c56c T objc_setProperty_atomic_copy 000000000003c658 T objc_setProperty_nonatomic 000000000003c68c T objc_setProperty_nonatomic_copy 000000000003cc58 T objc_setPropertyStruct 000000000002ec04 T objc_sizeof_type 000000000002eb80 T objc_skip_argspec 000000000002e6a0 T objc_skip_type_qualifiers 000000000002e6ec T objc_skip_typespec 0000000000037a08 T objc_slot_lookup_super 00000000000377d4 T objc_slot_lookup_super2 0000000000036fe0 T objc_slot_lookup_version 000000000003dc80 T objc_startCollectorThread 000000000003f020 T objc_storeStrong 000000000003f42c T objc_storeWeak 000000000003b6a8 T objc_sync_enter 000000000003b6e0 T objc_sync_exit 000000000002b0e8 T objc_test_capability 0000000000066898 B _objc_unexpected_exception 000000000003dad4 T objc_unregisterThreadWithCollector 00000000000668a0 B _objc_weak_load 000000000003b76c T object_addMethod_np 000000000003b938 T object_clone_np 0000000000032be4 T object_copy 0000000000032d40 T object_dispose 0000000000032d00 T object_getClass 0000000000033878 T object_getClassName 0000000000033808 T object_getIndexedIvars 000000000002f950 T object_getInstanceVariable 000000000002f8e4 T object_getIvar 000000000003babc T object_getPrototype_np 000000000003dc94 T object_getRetainCount_np 000000000003b8fc T object_replaceMethod_np 000000000003384c T object_setClass 000000000002f81c T object_setInstanceVariable 000000000002f798 T object_setIvar 000000000003cfb4 T property_copyAttributeList 000000000003da08 T property_copyAttributeValue 000000000003cfa8 T property_getAttributes 000000000003cdec T property_getName 0000000000031b24 T protocol_addMethodDescription 0000000000031d1c T protocol_addProperty 0000000000031c5c T protocol_addProtocol 0000000000030b08 T protocol_conformsToProtocol 0000000000030c64 T protocol_copyMethodDescriptionList 0000000000031110 T protocol_copyPropertyList 0000000000030e84 T protocol_copyPropertyList2 0000000000030e20 T protocol_copyProtocolList 000000000002ffc0 T protocol_for_name 000000000003143c T protocol_getMethodDescription 0000000000031614 T _protocol_getMethodTypeEncoding 0000000000031630 T protocol_getName 00000000000312a0 T protocol_getProperty 000000000003163c T protocol_isEqual 00000000000668a8 B protocol_table_lock U pthread_getspecific U pthread_key_create U pthread_mutexattr_destroy U pthread_mutexattr_init U pthread_mutexattr_settype U pthread_mutex_destroy U pthread_mutex_init U pthread_mutex_lock U pthread_mutex_unlock U pthread_rwlock_rdlock U pthread_rwlock_unlock U pthread_rwlock_wrlock U pthread_setspecific U realloc 00000000000395d4 T __register_frame w __register_frame_info 0000000000036100 T sel_copyTypedSelectors_np 0000000000036028 T sel_copyTypes_np 00000000000668d0 B selector_table_lock 0000000000035894 T sel_getName 0000000000035b70 T sel_getType_np 0000000000035964 T sel_getUid 00000000000359bc T sel_isEqual 0000000000035990 T sel_registerName 0000000000035ffc T sel_registerTypedName_np U sleep U snprintf U stderr U strchr U strcmp U strdup U strlen U strstr U strtol U test_eh_personality 0000000000000000 D uncacheable_slot 0000000000000018 D uncacheable_slot_v1 0000000000026db0 T __unw_add_dynamic_fde 000000000002b050 W unw_getcontext 0000000000026644 W unw_get_fpreg 000000000002689c W unw_get_proc_info 00000000000269e4 W unw_get_proc_name 0000000000026414 W unw_get_reg 000000000003932c T _Unwind_Backtrace 0000000000025e80 T _Unwind_DeleteException 00000000000392a4 T _Unwind_FindEnclosingFunction 0000000000039470 T _Unwind_Find_FDE 0000000000025cf4 T _Unwind_ForcedUnwind 0000000000039510 T _Unwind_GetCFA 00000000000391c4 T _Unwind_GetDataRelBase 0000000000025ee4 T _Unwind_GetGR 0000000000025fb0 T _Unwind_GetIP 0000000000039574 T _Unwind_GetIPInfo 0000000000025d7c T _Unwind_GetLanguageSpecificData 0000000000025e18 T _Unwind_GetRegionStart 0000000000039234 T _Unwind_GetTextRelBase 0000000000025400 T _Unwind_RaiseException 0000000000025998 T _Unwind_Resume 0000000000039120 T _Unwind_Resume_or_Rethrow 0000000000025f48 T _Unwind_SetGR 0000000000026014 T _Unwind_SetIP 0000000000026298 W unw_init_local 0000000000026aac W unw_is_fpreg 0000000000026bec W unw_is_signal_frame 0000000000026c84 W unw_iterate_dwarf_unwind_cache 0000000000063e38 D unw_local_addr_space 0000000000026b50 W unw_regname 0000000000026e1c T __unw_remove_dynamic_fde 000000000002694c W unw_resume 0000000000026728 W unw_set_fpreg 00000000000264fc W unw_set_reg 000000000002680c W unw_step U cxx_throw() U operator delete(void*) 000000000002606c T libunwind::findUnwindSectionsByPhdr(dl_phdr_info*, unsigned long, void*) 000000000004124c W std::__1::__vector_base_common<true>::__throw_length_error() const 0000000000041258 W std::__1::__vector_base_common<true>::__throw_out_of_range() const U operator new(unsigned long) U std::terminate()

davidchisnall commented 1 year ago

I am building with cmake, not ninja. Does that make a difference?

CMake doesn't build, it configures (it produces a build system from a build configuration). Normally it's used to generate Ninja files, though it does have some other options for people that like slow builds.

Below is the output of linking that program

That's not the line I need. I need the line that produces libobjc.so.4.6, because that's the line that will tell me how it's trying to link the thing that is missing the symbol.

alepi commented 1 year ago

CMake doesn't build, it configures (it produces a build system from a build configuration). Normally it's used to generate Ninja files, though it does have some other options for people that like slow builds.

What I mean is, I am generating the build files with cmake and doing the build with "cmake --build .". I haven't specified a build system so it would use its default. I assume this is using make under the hood.

By the way, building is quite fast. Maybe ninja is faster but I really don't care. Most of the build time is taken by tests anyway.

Below is the linker verbose output for libobjc2.

Thanks :-)

[ 8%] Linking C shared library libobjc.so clang version 11.0.0 (https://github.com/llvm/llvm-project.git 498e37e786ea2632b1c8596ad2512c306b3c8f58) Target: aarch64-unknown-linux-musl Thread model: posix InstalledDir: /home/ale/Scrivania/lola_games/crosstools/bin Found CUDA installation: /opt/cuda, version 7.0 "/home/ale/Scrivania/lola_games/crosstools/bin/ld.lld" --sysroot=/home/ale/Scrivania/lola_games/rootfs -EL --eh-frame-hdr -m aarch64linux -shared -o libobjc.so.4.6 /home/ale/Scrivania/lola_games/rootfs/usr/lib/crti.o /home/ale/Scrivania/lola_games/crosstools/lib/clang/11.0.0/lib/linux/clang_rt.crtbegin-aarch64.o -L/run/media/ale/fe38056b-09dc-4e4a-96f2-520883d97d2a/usr/lib -L/home/ale/Scrivania/lola_games/rootfs/lib -L/home/ale/Scrivania/lola_games/rootfs/usr/lib -lunwind -soname libobjc.so.4.6 CMakeFiles/objc.dir/alias_table.c.o CMakeFiles/objc.dir/block_to_imp.c.o CMakeFiles/objc.dir/caps.c.o CMakeFiles/objc.dir/category_loader.c.o CMakeFiles/objc.dir/class_table.c.o CMakeFiles/objc.dir/dtable.c.o CMakeFiles/objc.dir/encoding2.c.o CMakeFiles/objc.dir/hooks.c.o CMakeFiles/objc.dir/ivar.c.o CMakeFiles/objc.dir/loader.c.o CMakeFiles/objc.dir/mutation.m.o CMakeFiles/objc.dir/protocol.c.o CMakeFiles/objc.dir/runtime.c.o CMakeFiles/objc.dir/sarray2.c.o CMakeFiles/objc.dir/selector_table.c.o CMakeFiles/objc.dir/sendmsg2.c.o CMakeFiles/objc.dir/eh_personality.c.o CMakeFiles/objc.dir/legacy.c.o CMakeFiles/objc.dir/abi_version.c.o CMakeFiles/objc.dir/statics_loader.c.o CMakeFiles/objc.dir/block_trampolines.S.o CMakeFiles/objc.dir/objc_msgSend.S.o CMakeFiles/objc.dir/eh_trampoline.s.o CMakeFiles/objc.dir/NSBlocks.m.o CMakeFiles/objc.dir/Protocol2.m.o CMakeFiles/objc.dir/associate.m.o CMakeFiles/objc.dir/blocks_runtime.m.o CMakeFiles/objc.dir/properties.m.o CMakeFiles/objc.dir/gc_none.c.o CMakeFiles/objc.dir/arc.mm.o -lm -lc++ -lm /home/ale/Scrivania/lola_games/crosstools/lib/clang/11.0.0/lib/linux/libclang_rt.builtins-aarch64.a -lc /home/ale/Scrivania/lola_games/crosstools/lib/clang/11.0.0/lib/linux/libclang_rt.builtins-aarch64.a /home/ale/Scrivania/lola_games/crosstools/lib/clang/11.0.0/lib/linux/clang_rt.crtend-aarch64.o /home/ale/Scrivania/lola_games/rootfs/usr/lib/crtn.o [ 8%] Built target objc

davidchisnall commented 1 year ago

It looks as if objcxx_eh.cc is not being linked into your final output. Can you show me the output from your initial cmake run? My guess is that we're not detecting a working C++ install.

alepi commented 1 year ago

This is the output from the cmake command.

You may be very right: I see a suspicious "-- No useable C++ runtime found"

If it can help, I am cross compiling from linux x86_64 to linux aarch64.

LDFLAGS="-lunwind -L /run/media/ale/fe38056b-09dc-4e4a-96f2-520883d97d2a/usr/lib" cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="--sysroot /home/ale/Scrivania/lola_games/rootfs -I /run/media/ale/fe38056b-09dc-4e4a-96f2-520883d97d2a/usr/include/LIBDRM -I /home/ale/Scrivania/lola_games/rootfs/usr/include/libevdev-1.0 -I /home/ale/Scrivania/lola_games/rootfs/usr/include -v" -DCMAKE_CXX_FLAGS="--sysroot /home/ale/Scrivania/lola_games/rootfs -I /run/media/ale/fe38056b-09dc-4e4a-96f2-520883d97d2a/usr/include/LIBDRM -I /home/ale/Scrivania/lola_games/rootfs/usr/include/libevdev-1.0 -I /home/ale/Scrivania/lola_games/rootfs/usr/include -v" -DCMAKE_INSTALL_PREFIX=/run/media/ale/fe38056b-09dc-4e4a-96f2-520883d97d2a ..
-- The C compiler identification is Clang 11.0.0
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: /home/ale/Scrivania/lola_games/crosstools/bin/clang
-- The CXX compiler identification is Clang 11.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/ale/Scrivania/lola_games/crosstools/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/ale/Scrivania/lola_games/crosstools/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Testing C++ interop
-- Testing /usr/lib/libsupc++.a as the C++ runtime library
-- Testing C++ standard library
-- Using /home/ale/Scrivania/lola_games/crosstools/bin/clang
-- No useable C++ runtime found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- GNUstep install type set to NONE
-- Performing Test CXA_ALLOCATE_EXCEPTION_NOEXCEPT_COMPILES
-- Performing Test CXA_ALLOCATE_EXCEPTION_NOEXCEPT_COMPILES - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ale/Scrivania/objc/libobjc2/build
davidchisnall commented 1 year ago

-- Testing C++ standard library

This is surprising. Can you look in the log and see why that fails? Building without a C++ runtime is not supported anymore, but I haven't updated the CMake to fail when it happens.

alepi commented 1 year ago

Ok, I think I found the cause of the c++ runtime missing.

I don't have libcxxrt nor libsupc++.

I am using libc++abi from llvm project. At present, it is linked together with libc++ in a single dynamic library.

That means that the functionality is there when compiling, but cmake is not finding the runtime.

Another thing I noticed is that it prints:

Testing /usr/lib/libsupc++.a as the C++ runtime library

I am cross compiling and specifying a --sysroot for the compiler. Why is it checking /usr/lib at all? That version of libsupc++ is for x86_64, not aarch64...

I am getting a successful build by doing the following:

  1. have a symbolic link to libc++.so called libc++abi.so
  2. commenting out the test_cxx for libsupc++ and libcxxrt in CMakeLists.txt
  3. add set(CXX_RUNTIME c++abi) after all the test_cxx so that it has the same effect as if it found it correctly

Of course it's hacky, I will probably need some guidance on how to make it work fine

davidchisnall commented 1 year ago

The CMake has now been reworked and doesn't try to link directly against a C++ runtime. Can you try again?

dh-harald commented 1 year ago

I had similar problem with musl and x86_64, and using master branch solved my issue