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

[Linux] Half-Life can't load compiled libraries #33

Closed
MegaBrutal opened this issue Aug 26, 2021 · 8 comments
Closed

[Linux] Half-Life can't load compiled libraries #33

MegaBrutal opened this issue Aug 26, 2021 · 8 comments

Comments

@MegaBrutal
Copy link
Contributor

I've built the SO files following this tutorial:
https://twhl.info/wiki/page/Half-Life_Programming_-_Getting_Started

For some reason, Half-Life (up-to-date Steam for Linux version) can't load the libraries and it doesn't give much info why. For the client library, I only get the following message:
could not load library .../client.so
(In the place of "...", it writes the full path.)

When I try to go only with the server library, the following messages appear in the developer console.

LoadLibrary failed on /home/megabrutal/.steam/steam/steamapps/common/Half-Life/deltasection/dlls/hl.so: /home/megabrutal/.steam/steam/steamapps/common/Half-Life/deltasection/dlls/hl.so: undefined symbol: _ZdlPvj
Last 32 messages parsed.
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
0 0000 svc_bad
BAD:   -1:svc_bad
Wrote erroneous message to buffer.dat
Host_Error: Couldn't get DLL API from /home/megabrutal/.steam/steam/steamapps/common/Half-Life/deltasection/dlls/hl.so!

Contents of the mentioned buffer.dat:

00000000  00 00 00 00 ff ff ff ff                           |........|

So... the libraries are built but then just don't work. What am I doing wrong?

What's also strange is that my SOs have significant size differences to the originals (might be because of debug info, though neither of the binaries are stripped).

-rwxr-xr-x 1 megabrutal megabrutal 1036632 aug   26 00:23 deltasection/cl_dlls/client.so
-rwxr-xr-x 1 megabrutal megabrutal 4000283 márc  22  2020 valve/cl_dlls/client.so
-rwxr-xr-x 1 megabrutal megabrutal 2261332 aug   26 00:23 deltasection/dlls/hl.so
-rwxrwxr-x 1 megabrutal megabrutal 6773862 jún   21 00:06 valve/dlls/hl.so

Various other differences:

megabrutal@thinkpad:~/.steam/steam/steamapps/common/Half-Life$ file */dlls/hl.so
deltasection/dlls/hl.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=217a8c162def419cdbb4b028cccff1e105c7fea8, not stripped
valve/dlls/hl.so:        ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, with debug_info, not stripped
megabrutal@thinkpad:~/.steam/steam/steamapps/common/Half-Life$ ldd valve/dlls/hl.so
	linux-gate.so.1 (0xf7f3d000)
	libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xf7c2a000)
	libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xf7a4b000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf7854000)
	/lib/ld-linux.so.2 (0xf7f3f000)
	libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xf7835000)
megabrutal@thinkpad:~/.steam/steam/steamapps/common/Half-Life$ ldd deltasection/dlls/hl.so
	linux-gate.so.1 (0xf7fbc000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf7b9a000)
	/lib/ld-linux.so.2 (0xf7fbe000)

As of now I have no modifications to the code, I'm compiling from d872ad0.

@SamVanheer
Copy link
Collaborator

I don't know about the client loading problems. You can try running Half-Life through a debugger like gdb to try to get more info. This article explains how to debug this kind of problem: https://twhl.info/wiki/page/Half-Life_Programming_-_Debugging

For the server dll the error means it can't find the global operator delete. On my end this works, probably because my distribution (Ubuntu) does something special.

Operator delete is a C++ function defined in libstdc++.so.

To make it link with that you'll need to switch it to use g++ instead of gcc. I'm updating the Makefiles to do this since all of the code is C++ code so g++ is supposed to be used everywhere anyway.

I'll get these changes committed tomorrow. You can test it locally to see if it solves your problem.

@MegaBrutal
Copy link
Contributor Author

Thanks for the tip, I tried g++. It seemed to help, because the library now links to libstdc++.so.

megabrutal@thinkpad:~/.steam/steam/steamapps/common/Half-Life$ ldd deltasection/dlls/hl.so
	linux-gate.so.1 (0xf7f5c000)
	libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xf7b52000)
	libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xf7a4b000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf7854000)
	/lib/ld-linux.so.2 (0xf7f5e000)
	libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xf7835000)

But it still doesn't work, albeit the LoadLibrary error message has changed:

LoadLibrary failed on /home/megabrutal/.steam/steam/steamapps/common/Half-Life/deltasection/dlls/hl.so: /home/megabrutal/.steam/steam/steamapps/common/Half-Life/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /home/megabrutal/.steam/steam/steamapps/common/Half-Life/deltasection/dlls/hl.so)

I build the libraries in a minimalistic LXC container that only has the tools to compile various programs (Ubuntu 18.04.5 LTS). Then I try to run them on Ubuntu 20.10. Maybe that's the problem? That the build system and the target system have different versions of libstdc++?

Wait, I just see that the Steam Half-Life installation ships its own version of libstdc++ (~/.steam/steam/steamapps/common/Half-Life/libstdc++.so.6). I suppose Steam or the Half-Life executable forces the use of this library instead of whatever being installed by the OS distribution. And it doesn't have CXXABI_1.3.9.

megabrutal@thinkpad:~/.steam/steam/steamapps/common/Half-Life$ strings libstdc++.so.6 | grep CXXABI
CXXABI_1.3
CXXABI_1.3.1
CXXABI_1.3.2
CXXABI_1.3.3
CXXABI_1.3.4
CXXABI_1.3.5
CXXABI_1.3
CXXABI_1.3.2
CXXABI_1.3.1
CXXABI_1.3.5
CXXABI_1.3.4
CXXABI_1.3.3

So can we somehow force g++ to link the libraries against an older CXXABI, e.g. 1.3.5?
And why does it work for you without problems? What Ubuntu / libstdc++ versions do you have?

@SamVanheer
Copy link
Collaborator

I'm using Ubuntu 20.04.2 LTS. The GCC version is 9.3.0, you may need to install that or a newer version to make the program work.

ABI version 1.3.9 matches GCC 5.1.0 so you should have an up-to-date version installed already.

I don't know why there's a libstdc++ library in the Half-Life Directory, it's not there for me. SteamDB doesn't list the file as being part of the game's Linux depot and validating game files doesn't put it there, so i'd recommend reinstalling the game to see if it's supposed to be there.

Steam passes the Half-Life directory as a path in LD_LIBRARY_PATH which is probably why it's using that one. ldd won't know about that which is why it reports linking to the one in /lib.

@SamVanheer
Copy link
Collaborator

I've updated the makefiles to use g++. Once you've double checked the presence of libstdc++ we can see if there's anything else that needs fixing.

@MegaBrutal
Copy link
Contributor Author

Sorry for the late answer, meanwhile my attention was diverted by HLDS.

I've tried your modified Makefile and it works, so that's good.

I don't understand why do I have a libstdc++ and libgcc_s in my Half-Life installation. I also didn't find it on SteamDB. What's even more confusing is that I renamed these files by adding the .bak extension to their names, then run a validation that didn't put the files back. At that point I assumed the presence of these files has historical reasons, because I installed the game on this computer many years ago, maybe in 2014 or even earlier; probably the SO files were part of the installation at that time, but later they got removed and Steam didn't care to delete them when they disappeared from the Steam repository. But I checked now and the files are there again! Steam put them back on September 18.

megabrutal@thinkpad:~/.steam/steam/steamapps/common/Half-Life$ LD_LIBRARY_PATH=~/.steam/steam/steamapps/common/Half-Life:${LD_LIBRARY_PATH} ldd deltasection/dlls/hl.so
deltasection/dlls/hl.so: /home/megabrutal/.steam/steam/steamapps/common/Half-Life/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by deltasection/dlls/hl.so)
	linux-gate.so.1 (0xf7f8c000)
	libstdc++.so.6 => /home/megabrutal/.steam/steam/steamapps/common/Half-Life/libstdc++.so.6 (0xf7cbc000)
	libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xf7b96000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf7999000)
	/lib/ld-linux.so.2 (0xf7f8e000)
	libgcc_s.so.1 => /home/megabrutal/.steam/steam/steamapps/common/Half-Life/libgcc_s.so.1 (0xf7984000)

Just as I was typing this comment, I found that these files are part of the Half-Life Dedicated Server that I also have installed.
https://steamdb.info/depot/4/
(SteamDB doesn't find this depot when I search for the filename, I had to manually browse the HLDS app, which makes me think whether I'm the idiot unable to use the SteamDB search properly or SteamDB search is flawed.)

Strange because I don't think I had HLDS installed on August 26 when I reported this issue, though I don't know exactly when did I install it. The original (now *.bak) files' modification dates are August 11, so it's not impossible that I installed it then. Anyway, I don't need HLDS here, I have only installed it for testing purposes; my legit HLDS is running on a VPS, so I might as well delete it.

@SamVanheer
Copy link
Collaborator

You're not supposed to install that app. The dedicated server software should be installed through SteamCMD using app id 90: https://developer.valvesoftware.com/wiki/SteamCMD#Downloading_an_app

There are other HLDS apps on Steam that are out of date and not supported, that seems to be one of them.

You also shouldn't install the dedicated server software in the same directory as a client installation since it can mess things up.

Is everything working now?

@SamVanheer
Copy link
Collaborator

Do you still need help with this?

@SamVanheer
Copy link
Collaborator

Closing due to inactivity.

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

No branches or pull requests

2 participants