libobjc2 icon indicating copy to clipboard operation
libobjc2 copied to clipboard

OpenBSD build fails - undefined symbols - Unwind

Open rmottola opened this issue 2 years ago • 14 comments

a standard OpenBSD build with system clang and configured OOB,

[ 13%] Linking C executable ExceptionTest
ld: error: undefined symbol: _Unwind_Resume
>>> referenced by ExceptionTest.m
>>>               CMakeFiles/ExceptionTest.dir/ExceptionTest.m.o:(finally)
>>> referenced by ExceptionTest.m
>>>               CMakeFiles/ExceptionTest.dir/ExceptionTest.m.o:(rethrow_id)
>>> referenced by ExceptionTest.m
>>>               CMakeFiles/ExceptionTest.dir/ExceptionTest.m.o:(rethrow_test)
>>> referenced by ExceptionTest.m
>>>               CMakeFiles/ExceptionTest.dir/ExceptionTest.m.o:(rethrow_catchall)
>>> referenced by ExceptionTest.m
>>>               CMakeFiles/ExceptionTest.dir/ExceptionTest.m.o:(main)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error 1 in . (Test/CMakeFiles/ExceptionTest.dir/build.make:107 'Test/ExceptionTest')
*** Error 2 in . (CMakeFiles/Makefile2:5324 'Test/CMakeFiles/ExceptionTest.dir/all')

rmottola avatar Jul 27 '21 23:07 rmottola

Hi,

You're either running -stable or an old -current version, i'm right?

These issues have been fixed in -current by adding libexecinfo into base (https://github.com/openbsd/src/commit/771fbea0148a7fe458cf2c657edb98b32659f150). I can build the current HEAD (646c142f3c459e47aea6cb7b10cca5905750e0d7) without issues on OpenBSD/amd64.

If you're still wanting to not use -current, by experience (https://github.com/openbsd/ports/commit/025717b78e04dc6d3754adb7160cde803687274f), you may want to drop -fexceptions, but i'm not sure it would solve the issue.

julianaito avatar Jul 28 '21 22:07 julianaito

I'm running release, which a normal user is supposed to do: in this case 6.9

rmottola avatar Oct 10 '21 22:10 rmottola

Sorry, I didn't see this when it was reported. This symbol is part of the generic unwinder. This is normally provided by libgcc_s and should be added to the link step by the compiler automatically. It might be in a separate libUnwind on OpenBSD, so you can try adding -lunwind or -lUnwind to the CMake EXE linker flags and see if that fixes it.

Is the same undefined symbol in libobjc.so or only in the tests? If it's in only the tests, you should be able to just build without tests.

Dropping -fexceptions will give you compile failures instead of link failures (you can't throw and catch exceptions without it).

davidchisnall avatar Oct 11 '21 08:10 davidchisnall

I just upgraded to OpenBSD 7.0 - and I still have that issue, so I am unsure @julianaito spotted commit was the fix?

ld: error: unable to find library -lUnwind

Tells us -lUnwind is not present and -lunwind gives me the same error

ld: error: unable to find library -lunwind

Now on 7.0 the full error actually is:

ld: error: undefined symbol: _Unwind_RaiseException
>>> referenced by BoxedForeignException.m
>>>               CMakeFiles/BoxedForeignException_optimised.dir/BoxedForeignException.m.o:(throw)
>>> referenced by BoxedForeignException.m
>>>               CMakeFiles/BoxedForeignException_optimised.dir/BoxedForeignException.m.o:(finally)

ld: error: undefined symbol: _Unwind_Resume
>>> referenced by BoxedForeignException.m
>>>               CMakeFiles/BoxedForeignException_optimised.dir/BoxedForeignException.m.o:(finally)
>>> referenced by BoxedForeignException.m
>>>               CMakeFiles/BoxedForeignException_optimised.dir/BoxedForeignException.m.o:(main)

ld: error: undefined symbol: _Unwind_Resume_or_Rethrow
>>> referenced by BoxedForeignException.m
>>>               CMakeFiles/BoxedForeignException_optimised.dir/BoxedForeignException.m.o:(_i_BoxedException__rethrow)

rmottola avatar Oct 18 '21 16:10 rmottola

I am having this same issue with OpenBSD 7.1. I tried to build libunwind from source but it requires getcontext and OpenBSD does not provide getcontext from POSIX (see here).

Some folks have created a libucontext implementation but, I am trying to compile on ppc which these implementations do not support without having getcontext already available. I may be stuck.

adderthorn avatar Jul 31 '22 15:07 adderthorn

Can you see what OpenBSD's C++ runtime (libcxxrt, libsupc++, or libc++abi) links to? It might be statically linked into the C++ standard library (libc++ or libstdc++).

davidchisnall avatar Jul 31 '22 16:07 davidchisnall

Some folks have created a libucontext implementation but, I am trying to compile on ppc which these implementations do not support without having getcontext already available. I may be stuck.

Even if you manage to build libobjc2 with OpenBSD getcontext patches, there is currently no PowerPC (32bit big-endian, 64bit big/little-endian) support for libobjc2. The required msgSend trampoline assembly is missing.

hmelder avatar Jul 31 '22 16:07 hmelder

It should still work with the C fallback (clang won't generate objc_msgSend calls on PowerPC, it will generate calls to the slower C paths).

davidchisnall avatar Jul 31 '22 16:07 davidchisnall

Can you see what OpenBSD's C++ runtime (libcxxrt, libsupc++, or libc++abi) links to?

I'd be happy to, but I must admit, I'm pretty novice to C on unix/linux world so I'm not exactly sure how to figure this out.

adderthorn avatar Jul 31 '22 16:07 adderthorn

Just updated to OpenBSD 7.2 - still fails

[ 21%] Linking C executable BlockImpTest
ld: error: undefined symbol: _Unwind_Resume
>>> referenced by BlockImpTest.m
>>>               CMakeFiles/BlockImpTest.dir/BlockImpTest.m.o:(main)

rmottola avatar Oct 26 '22 16:10 rmottola

Checking libc++abi.so.6.0

ldd doesn't say much:

libc++abi.so.6.0:
        Start    End      Type  Open Ref GrpRef Name
        0d0dd000 2d0e1000 dlib  1    0   0      /usr/lib/libc++abi.so.6.0

however, I find this symbol using nm:

00015a00 W unw_resume Could it be related to _Unwind_Resume ?

rmottola avatar Oct 26 '22 16:10 rmottola

unw_resume is an internal symbol used by the unwinder. I believe that it's only present in the nongnu / GCC implementation of libunwind, not the LLVM one. I'm not sure what OpenBSD's stack looks like here. We aren't using that symbol directly but you might see an error like that if you statically link against the GCC unwinder and then dynamically link against the LLVM one? _Unwind_Resume is one of the symbols defined by the language-agnostic portion of the ABI, so should be present everywhere.

davidchisnall avatar Oct 27 '22 08:10 davidchisnall

On OpenBSD 7.5 / i386:

[ 16%] Built target AssociatedObject2_legacy_optimised
ld: error: undefined symbol: _Unwind_Resume
>>> referenced by BlockImpTest.m
>>>               CMakeFiles/BlockImpTest.dir/BlockImpTest.m.o:(main)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
[ 17%] Building OBJC object Test/CMakeFiles/BlockImpTest_optimised.dir/BlockImpTest.m.o

this happens if TESTS are enabled

rmottola avatar May 02 '24 13:05 rmottola

If I build without TESTS, I can build & install, but later building of gnustep base will fail:

ld: error: undefined symbol: _Unwind_Resume
>>> referenced by cvtenc.m:0
>>>               ./obj/cvtenc.obj/cvtenc.m.o:(gnustep_base_user_main)

rmottola avatar May 02 '24 13:05 rmottola