Linux: Allow building with GCC > 8, only GCC 6/7 trigger the Object::cast_to optimization issue

And likewise, prevent building with mingw-gcc for Windows if it's GCC 6/7.

The check for the Server platform was unnecessary as its `release` template
doesn't use `-O3`/`-Ofast`.
This commit is contained in:
Rémi Verschelde 2025-01-02 23:16:09 +01:00
parent df4d769f99
commit a87391d256
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 24 additions and 20 deletions

View file

@ -326,6 +326,18 @@ def configure(env):
if (env["bits"] == "64"):
env.Append(CCFLAGS=['-O3'])
if (os.system(mingw_prefix + "gcc --version > /dev/null 2>&1") == 0): # GCC
# Hack to prevent segfaults due to UB when dereferencing NULL `this` in `Object::cast_to` with `-O3`.
# This is fixed in 3.0, for 2.1 we just prevent using the known affected GCC versions (6 and 7).
# GCC 5 or GCC 8 and later seem to be fine.
import subprocess
gcc_major = int(subprocess.check_output([mingw_prefix + 'gcc', '-dumpversion']).decode('ascii').split('.')[0])
if (gcc_major == 6 or gcc_major == 7):
print("Your configured compiler appears to be GCC %d, which triggers issues in release builds for this version of Godot (fixed in Godot 3.0+)." % gcc_major)
print("You can use the Clang compiler instead with the `use_llvm=yes` option, or configure another compiler such as GCC 5 using the CC, CXX and LD flags.")
print("Aborting..")
sys.exit(255)
else:
env.Append(CCFLAGS=['-O2'])