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

Building with GCC on Linux #1017

Closed
lexzor opened this issue Feb 7, 2024 · 2 comments
Closed

Building with GCC on Linux #1017

lexzor opened this issue Feb 7, 2024 · 2 comments

Comments

@lexzor
Copy link

lexzor commented Feb 7, 2024

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
Copy link
Contributor

anzz1 commented Feb 7, 2024

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

lexzor commented Feb 17, 2024

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

@lexzor lexzor closed this as completed Feb 17, 2024
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