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

musl libc support #1725

Open
ii8 opened this issue Dec 29, 2024 · 6 comments · May be fixed by #1727
Open

musl libc support #1725

ii8 opened this issue Dec 29, 2024 · 6 comments · May be fixed by #1727

Comments

@ii8
Copy link
Contributor

ii8 commented Dec 29, 2024

[  3%] Built target translations
[  3%] Built target glad
[  3%] Built target endian_static
[  5%] Built target s25util_common
[ 12%] Built target siedler2
[ 13%] Built target s25util_log
[ 15%] Built target s25util_network
[ 16%] Built target mygettext
[ 17%] Built target s25Common
[ 18%] Built target rttrConfig
[ 19%] Built target SGE
[ 21%] Built target gamedata
[ 21%] Linking CXX executable ../../bin/s25edit
/usr/bin/ld: /home/murray/c/s25client/external/dev-tools/lua/linux/lib/liblua52.a(ldo.o): in function `luaD_throw':
ldo.c:(.text+0xad): undefined reference to `__longjmp_chk'
/usr/bin/ld: /home/murray/c/s25client/external/dev-tools/lua/linux/lib/liblua52.a(lobject.o): in function `luaO_pushvfstring':
lobject.c:(.text+0x49f): undefined reference to `__sprintf_chk'
/usr/bin/ld: /home/murray/c/s25client/external/dev-tools/lua/linux/lib/liblua52.a(lvm.o): in function `luaV_tostring':
lvm.c:(.text+0x34e): undefined reference to `__sprintf_chk'
/usr/bin/ld: /home/murray/c/s25client/external/dev-tools/lua/linux/lib/liblua52.a(lauxlib.o): in function `panic':
lauxlib.c:(.text+0x49): undefined reference to `__fprintf_chk'
/usr/bin/ld: /home/murray/c/s25client/external/dev-tools/lua/linux/lib/liblua52.a(lstrlib.o): in function `str_format':
lstrlib.c:(.text+0xa1f): undefined reference to `__memcpy_chk'
/usr/bin/ld: lstrlib.c:(.text+0xb76): undefined reference to `__sprintf_chk'
/usr/bin/ld: lstrlib.c:(.text+0xc5c): undefined reference to `__sprintf_chk'
/usr/bin/ld: lstrlib.c:(.text+0xd53): undefined reference to `__sprintf_chk'
/usr/bin/ld: lstrlib.c:(.text+0xd8e): undefined reference to `__sprintf_chk'
/usr/bin/ld: lstrlib.c:(.text+0xe40): undefined reference to `__sprintf_chk'
collect2: error: ld returned 1 exit status
make[2]: *** [external/s25edit/CMakeFiles/s25edit.dir/build.make:388: bin/s25edit] Error 1
make[1]: *** [CMakeFiles/Makefile2:1397: external/s25edit/CMakeFiles/s25edit.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

System is voidlinux, libc is musl
I don't know what library these _chk versions of functions come from but cmake doesn't seem to be configured right because it doesn't check that it's installed during configure.

@Flamefire
Copy link
Member

The message indicates the functions are referenced by the vendored liblua.a. As that was built against glibc and musl libc doesn't support all features of glibc it cannot be used in this case.

You can set -DRTTR_INCLUDE_DEVTOOLS=OFF to avoid using any of those vendored dependencies

@ii8
Copy link
Contributor Author

ii8 commented Dec 30, 2024

I see, I think the way this is typically done to avoid portability issues is to add the lua source code instead of a pre-compiled binary for each OS.

I tried this:

cmake -DCMAKE_BUILD_TYPE=Release -DRTTR_INCLUDE_DEVTOOLS=OFF ..
make

But the same thing still happens

@Flamefire
Copy link
Member

I see, I think the way this is typically done to avoid portability issues is to add the lua source code instead of a pre-compiled binary for each OS.

The pre-compiled library is just a convenience for developers and our build infrastructure.
You are supposed to have the libraries installed on the system as per the documentation. Maybe we shouldn't add them by default and enable it explicitly in the build servers.

I tried this:

cmake -DCMAKE_BUILD_TYPE=Release -DRTTR_INCLUDE_DEVTOOLS=OFF ..
make

Did you forgot to delete your CMake cache or the build folder? CMake caches the found libraries and hence will continue to use the (wrong) one it found before.
You might also remove the LUA* entries from the CMake cache before rerunning CMake if you don't want to delete everything.

@ii8
Copy link
Contributor Author

ii8 commented Dec 31, 2024

Did you forgot to delete your CMake cache or the build folder? CMake caches the found libraries and hence will continue to use the (wrong) one it found before.

Does not seem to make a difference, still the same error. I have zero knowledge of cmake so not sure but this time it did try to link s25client first, before s25edit. I was able to get it to successfully link s25client by adding libexecinfo to the linked libraries. The build still fails but only after creating s25client so I'm able to start the game.

So if you care to support musl it looks like: link execinfo library into any binary that uses the backtrace function. And don't link any binaries that were built with glibc.

And if you don't care to support musl feel free to close this issue.

@ii8 ii8 changed the title s25client fails to compile musl libc support Dec 31, 2024
@Flamefire
Copy link
Member

Does not seem to make a difference, still the same error.

To be clear: You did a clean configure by deleting the whole build folder or at least the CMakeCache.txt and did a configure with -DRTTR_INCLUDE_DEVTOOLS=OFF and it still shows an error in external/dev-tools/lua/linux/lib/liblua52.a? I don't see how that could happen as it won't be able to find that library during configure.

it did try to link s25client first, before s25edit

So linking s25client did work but s25edit did not showing the lua error? Again I can't see how as they both use the same dependency.

link execinfo library into any binary that uses the backtrace function.

That seems to make sense

And don't link any binaries that were built with glibc.

As mentioned this only happens when using the prebuilds which are fully optional. However I do agree to make this opt-in rather than opt-out.

@ii8
Copy link
Contributor Author

ii8 commented Dec 31, 2024

To be clear: You did a clean configure by deleting the whole build folder or at least the CMakeCache.txt and did a configure with -DRTTR_INCLUDE_DEVTOOLS=OFF

I thought I did exactly this, but I must have messed something up because I just did it again and this time it worked, my bad then excuse me.

So linking s25client did work but s25edit did not showing the lua error? Again I can't see how as they both use the same dependency.

This was definitely the case. Because I got the error but also a working s25client. I guess my messing with the CMakeLists.txt files to add libexecinfo made the difference somehow.

@Flamefire Flamefire linked a pull request Jan 1, 2025 that will close this issue
1 task
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.

2 participants