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

OpenBSD build fails - undefined symbols - Unwind #210

Open
rmottola opened this issue Jul 27, 2021 · 16 comments
Open

OpenBSD build fails - undefined symbols - Unwind #210

rmottola opened this issue Jul 27, 2021 · 16 comments

Comments

@rmottola
Copy link
Member

rmottola commented Jul 27, 2021

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')
@julianaito
Copy link

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 (openbsd/src@771fbea). I can build the current HEAD (646c142) without issues on OpenBSD/amd64.

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

@rmottola
Copy link
Member Author

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

@davidchisnall
Copy link
Member

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).

@rmottola
Copy link
Member Author

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 rmottola changed the title OpenBSD build fails - undefined symbols OpenBSD build fails - undefined symbols - Unwind Dec 14, 2021
@adderthorn
Copy link

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.

@davidchisnall
Copy link
Member

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++).

@hmelder
Copy link
Collaborator

hmelder commented Jul 31, 2022

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.

@davidchisnall
Copy link
Member

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).

@adderthorn
Copy link

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.

@rmottola
Copy link
Member Author

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
Copy link
Member Author

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 ?

@davidchisnall
Copy link
Member

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.

@rmottola
Copy link
Member Author

rmottola commented May 2, 2024

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
Copy link
Member Author

rmottola commented May 2, 2024

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
Copy link
Member Author

The issue can be solved in OpenBSD 7.6 by adding
CMAKE_EXE_LINKER_FLAGS -lc++abi

That way library builds and I can run tests (thanks to Sebastian Reitenback). Maybe it can be added automatically?

I tested it on i386 32bit. 64bit will follow soon

@hmelder
Copy link
Collaborator

hmelder commented Nov 19, 2024

Maybe it can be added automatically?

As written in https://man.openbsd.org/intro.3 users do not normally have to explicitly link with this library.. Seems like it is a CMake bug (sigh).

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

No branches or pull requests

5 participants