Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Harden Linux executables with `PIE` and `RELRO`.

Lukas Tenbrink73396e9add99
diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py
index ca04f9b039f..4d1dc04818d 100644
--- a/platform/linuxbsd/detect.py
+++ b/platform/linuxbsd/detect.py
@@ -127,6 +127,11 @@ def configure(env: "SConsEnvironment"):
env["CXX"] = "clang++"
env.extra_suffix = ".llvm" + env.extra_suffix
+ if env["library_type"] == "executable" and env["arch"] not in ["x86_32", "arm32"]:
+ # PIE has a performance cost on 32-bit, and it's a niche target. Not worth the tradeoff.
+ env.Append(CCFLAGS=["-fPIE"], LINKFLAGS=["-pie"])
+ env.Append(LINKFLAGS=["-Wl,-z,relro", "-Wl,-z,now"])
+
if env["linker"] != "default":
print("Using linker program: " + env["linker"])
if env["linker"] == "mold" and using_gcc(env): # GCC < 12.1 doesn't support -fuse-ld=mold.