dreamstalker / rehlds

Reverse-engineered HLDS
GNU General Public License v3.0
625 stars 165 forks source link

Building with GCC on Linux #1017

Closed lexzor closed 4 months ago

lexzor commented 4 months ago

Hello,

Building on Linux cause a engine corrupt image after I follow building instructions for Linux. It can be seen below:

image

OS: Linux, package Ubuntu 22.04.3 LTS CMake Version: 3.22.1 GCC Version: 11.4.0

What i am missing?

anzz1 commented 4 months ago

It seems you have this ./libstdc++.so.6 in the rehlds folder brought in from somewhere which doesn't mach the GLIBCXX version installed on your system and used by GCC. Removing this file or removing the export LD_LIBRARY_PATH=".:$LD_LIBRARY_PATH" from top of your hlds run script should do the trick.

There is another problem in the GCC build the way it currently is however, CMake is pretty crap and the GCC build flags are all over the place because of multiple CMakeLists.txt strewn around everywhere in the project.

Some of the problems because of this is that different parts of the projects end up being compiled with different sets of optimization flags, and also that the project configuration does not take into account the stupid decisions made by distro administrators like changing GCC default flags to use crap like ASLR and stack canaries by default.

So while the CMakeLists.txt does have this portion commented as trying to avoid -fPIC: https://github.com/dreamstalker/rehlds/blob/master/rehlds/CMakeLists.txt#L29-L31 This isn't actually enough and you have to explicitly state gcc: -fno-pic for all libraries and gcc: -fno-pic -fno-pie ld: -no-pie for all executables which currently isn't done. The rehlds main executable ends up being compiled as PIE code since only -no-pie LD flag is specified but no -fno-pie GCC flag which is also required.

Also CMake being CMake you can't actually set these globally from the command line since the options are set in the CMakeLists.txt without bringing in any flags from the command line. So in my personal build I've copy-pasted the ASLR disablings -fno-stack-protector -fno-pic -fno-pie -no-pie and additional compiler flags (for example, you'd want to use -march=native to properly optimize the build for your processor capabilities) to each CMakeLists.txt separately but this is a fucking mess.

To address this correctly would be to scrap CMake and use something simpler and more robust like a good ol' Makefile or even better: a simple shell script.

For the time being, I'd advise to use the latest release version which is properly compiled without stack protectors and other ASLR crap. Building it yourself without changes to the compiler flags will not yield the same result in most of the popular distros. Using the precompiled version does lose you the additional optimizations allowed by -march=native though.

lexzor commented 4 months ago

Thanks, worked by deleting the export from build.sh file.