Skip to content
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

[clang] Undefined references some reason. Possible code generation issues. #11942

Closed
gcasa opened this issue Jun 27, 2022 · 3 comments · Fixed by #19948
Closed

[clang] Undefined references some reason. Possible code generation issues. #11942

gcasa opened this issue Jun 27, 2022 · 3 comments · Fixed by #19948

Comments

@gcasa
Copy link

gcasa commented Jun 27, 2022

On the branch

[gregc@mother-win-vm libobjc2] % git status                                                     [0]
On branch msys2_experimental
Your branch is up to date with 'origin/msys2_experimental'.

I am seeing the following undefined references when trying to build with the script build-windows-libobjc2

[email protected]:gnustep/tools-scripts.git

The repo for libobjc2 is here....

[email protected]:gnustep/libobjc2

The errors are below...

[ 81%] Building C object CMakeFiles/objc.dir/blocks_runtime.m.obj
[ 85%] Building C object CMakeFiles/objc.dir/properties.m.obj
[ 88%] Building C object CMakeFiles/objc.dir/gc_none.c.obj
[ 92%] Building CXX object CMakeFiles/objc.dir/arc.mm.obj
[ 96%] Building CXX object CMakeFiles/objc.dir/eh_win32_msys2.cc.obj
[100%] Linking C shared library libobjc.dll
Warning: corrupt .drectve at end of def file
C:/tools/msys64/mingw64/bin/ld: cannot export objc_enumerationMutation: symbol wrong type (2 vs 3)
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(objc_msgSend.S.obj):C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/objc_msgSend.x86-64.S:292: undefined reference to `__guard_dispatch_icall_fptr'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(objc_msgSend.S.obj):C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/objc_msgSend.x86-64.S:296: undefined reference to `__guard_dispatch_icall_fptr'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(NSBlocks.m.obj):NSBlocks.m:(.xdata+0x10): undefined reference to `__gnustep_objc_personality_v0'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(Protocol2.m.obj):Protocol2.m:(.data+0xd0): undefined reference to `.objc_selector_conformsTo:_i240:816'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(Protocol2.m.obj):Protocol2.m:(.data+0xe8): undefined reference to `.objc_selector_retain_160:8'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(Protocol2.m.obj):Protocol2.m:(.data+0x100): undefined reference to `.objc_selector_release_v160:8'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(Protocol2.m.obj):Protocol2.m:(.data+0x118): undefined reference to `.objc_selector_self_160:8'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(associate.m.obj):C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/associate.m:134: undefined reference to `.objc_selector_copy_160:8'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(associate.m.obj): in function `setReference':
C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/associate.m:177: undefined reference to `objc_begin_catch'
C:/tools/msys64/mingw64/bin/ld: C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/associate.m:182: undefined reference to `objc_end_catch'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(associate.m.obj):associate.m:(.xdata+0x20): undefined reference to `__gnustep_objc_personality_v0'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(associate.m.obj):associate.m:(.xdata+0x108): undefined reference to `__gnustep_objc_personality_v0'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(associate.m.obj):associate.m:(.xdata+0x140): undefined reference to `__gnustep_objc_personality_v0'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(properties.m.obj):C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/properties.m:59: undefined reference to `.objc_selector_copy_160:8'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(properties.m.obj): in function `objc_setProperty':
C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/properties.m:66: undefined reference to `.objc_selector_copy_160:8'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(properties.m.obj):C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/properties.m:109: undefined reference to `.objc_selector_copy_160:8'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(properties.m.obj):C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/properties.m:135: undefined reference to `.objc_selector_copy_160:8'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(properties.m.obj):properties.m:(.xdata+0xd0): undefined reference to `__gnustep_objc_personality_v0'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(properties.m.obj):properties.m:(.xdata+0x110): undefined reference to `__gnustep_objc_personality_v0'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj):C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/arc.mm:366: undefined reference to `.objc_selector_dealloc_v160:8'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj): in function `retain(objc_object*, int)':
C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/arc.mm:322: undefined reference to `.objc_selector_retain_160:8'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj): in function `release(objc_object*)':
C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/arc.mm:388: undefined reference to `.objc_selector_release_v160:8'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj): in function `weakRefRelease((anonymous namespace)::WeakRef*)':
C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/arc.mm:753: undefined reference to `operator delete(void*)'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj): in function `incrementWeakRefCount(objc_object*)':
C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/arc.mm:811: undefined reference to `operator new(unsigned long long)'
C:/tools/msys64/mingw64/bin/ld: C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/arc.mm:811: undefined reference to `operator delete(void*)'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj): in function `(anonymous namespace)::weakRefs()':
C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/arc.mm:703: undefined reference to `__cxa_guard_acquire'
C:/tools/msys64/mingw64/bin/ld: C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/arc.mm:703: undefined reference to `__cxa_guard_release'
C:/tools/msys64/mingw64/bin/ld: C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/arc.mm:703: undefined reference to `__cxa_guard_abort'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj): in function `weakRefRelease((anonymous namespace)::WeakRef*)':
C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/arc.mm:753: undefined reference to `operator delete(void*)'
C:/tools/msys64/mingw64/bin/ld: C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/arc.mm:753: undefined reference to `operator delete(void*)'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj): in function `operator()':
C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/third_party/robin-map/include/tsl/robin_hash.h:510: undefined reference to `std::terminate()'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj): in function `tsl::detail_robin_hash::robin_hash<std::pair<void const*, (anonymous namespace)::WeakRef*>, tsl::robin_map<void const*, (anonymous namespace)::WeakRef*, std::hash<void const*>, std::equal_to<void const*>, (anonymous namespace)::malloc_allocator<std::pair<void const*, (anonymous namespace)::WeakRef*> >, false, tsl::rh::prime_growth_policy>::KeySelect, tsl::robin_map<void const*, (anonymous namespace)::WeakRef*, std::hash<void const*>, std::equal_to<void const*>, (anonymous namespace)::malloc_allocator<std::pair<void const*, (anonymous namespace)::WeakRef*> >, false, tsl::rh::prime_growth_policy>::ValueSelect, std::hash<void const*>, std::equal_to<void const*>, (anonymous namespace)::malloc_allocator<std::pair<void const*, (anonymous namespace)::WeakRef*> >, false, tsl::rh::prime_growth_policy>::static_empty_bucket_ptr()':
C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/third_party/robin-map/include/tsl/robin_hash.h:1371: undefined reference to `__cxa_guard_acquire'
C:/tools/msys64/mingw64/bin/ld: C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/third_party/robin-map/include/tsl/robin_hash.h:1371: undefined reference to `__cxa_guard_release'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj): in function `std::vector<tsl::detail_robin_hash::bucket_entry<std::pair<void const*, (anonymous namespace)::WeakRef*>, false>, (anonymous namespace)::malloc_allocator<tsl::detail_robin_hash::bucket_entry<std::pair<void const*, (anonymous namespace)::WeakRef*>, false> > >::_S_check_init_len(unsigned long long, (anonymous namespace)::malloc_allocator<tsl::detail_robin_hash::bucket_entry<std::pair<void const*, (anonymous namespace)::WeakRef*>, false> > const&)':
C:/tools/msys64/mingw64/include/c++/12.1.0/bits/stl_vector.h:1905: undefined reference to `std::__throw_length_error(char const*)'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj):arc.mm:(.xdata+0x28): undefined reference to `__gnustep_objcxx_personality_v0'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj):arc.mm:(.xdata+0xfc): undefined reference to `__gnustep_objcxx_personality_v0'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj):arc.mm:(.xdata+0x140): undefined reference to `__gnustep_objcxx_personality_v0'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj):arc.mm:(.xdata+0x168): undefined reference to `__gnustep_objcxx_personality_v0'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj):arc.mm:(.xdata+0x1a8): undefined reference to `__gnustep_objcxx_personality_v0'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj):arc.mm:(.xdata+0x1e4): more undefined references to `__gnustep_objcxx_personality_v0' follow
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj):arc.mm:(.text$__clang_call_terminate[__clang_call_terminate]+0x5): undefined reference to `__cxa_begin_catch'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj):arc.mm:(.text$__clang_call_terminate[__clang_call_terminate]+0xa): undefined reference to `std::terminate()'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj):arc.mm:(.xdata$_ZNK3tsl2rh19prime_growth_policy15bucket_for_hashEy+0x8): undefined reference to `__gnustep_objcxx_personality_v0'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj): in function `tsl::rh::prime_growth_policy::next_bucket_count() const':
C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/third_party/robin-map/include/tsl/robin_growth_policy.h:300: undefined reference to `std::terminate()'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj): in function `prime_growth_policy':
C:/tools/msys64/home/gregc/Development/gnustep/libobjc2/third_party/robin-map/include/tsl/robin_growth_policy.h:282: undefined reference to `std::terminate()'
C:/tools/msys64/mingw64/bin/ld: CMakeFiles/objc.dir/objects.a(arc.mm.obj):arc.mm:(.xdata$_ZNSt5tupleIJOPKvEEC2IJS1_ELb1ELb1EEEDpOT_+0x8): undefined reference to `__gnustep_objcxx_personality_v0'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/objc.dir/build.make:496: libobjc.dll] Error 1
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/objc.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
.... done ....
[gregc@mother-win-vm libobjc2] %                                                                                                                        [0]

The issues with gnustep_objcxx_personality_v0 I understand. The ones confusing me are the .objc_selector_retain... etc. It seems like the error is in the ObjCGNU Code generation code, but I am not sure. These are defined in nsobject.h in libobjc2 and then REDEFINED in NSObject.h in GNUstep. Full disclosure... I am the lead developer of the gnustep project http://www.gnustep.org. The GitHub project is here https://github.com/gnustep.

GC

@gcasa gcasa changed the title [clang] undefined references for no [clang] undefined references some reason. Possible code generation issues. Jun 27, 2022
@gcasa gcasa changed the title [clang] undefined references some reason. Possible code generation issues. [clang] Undefined references some reason. Possible code generation issues. Jun 27, 2022
@mati865
Copy link
Collaborator

mati865 commented Jul 1, 2022

Warning: corrupt .drectve at end of def file

Have you tried using LLD?
Seems like this code is tailored for MSVC so LLD has greater chances to understand it than ld.bfd.

EDIT: Yup, it's in the assembly: https://github.com/gnustep/libobjc2/blob/921e3c338645702b6cacf3e0b220eb7b08bc5bcb/objc_msgSend.x86-64.S#L297
So the problem here is with the code.

@oscarfv
Copy link
Contributor

oscarfv commented Jul 27, 2022

@gcasa: have you fixed the problem? If this issue is no longer applicable, please close it. Thanks.

@gcasa
Copy link
Author

gcasa commented Jul 27, 2022

Hey guys! Great clues as to what is wrong, I haven't had time to get back to this, but I will ASAP. I will keep this item updated. Thanks to you guys I know what to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants