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

@ -40,16 +40,6 @@ def configure(env):
env["CC"] = "clang"
env["CXX"] = "clang++"
env["LD"] = "clang++"
elif (os.system("gcc --version > /dev/null 2>&1") == 0): # GCC
# Hack to prevent building this branch with GCC 6+, which trigger segfaults due to UB when dereferencing pointers in Object::cast_to
# This is fixed in the master branch, for 2.1 we just prevent using too recent GCC versions.
import subprocess
gcc_major = subprocess.check_output(['gcc', '-dumpversion']).decode('ascii').split('.')[0]
if (int(gcc_major) > 5):
print("Your configured compiler appears to be GCC %s, 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)
is64 = sys.maxsize > 2**32

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'])

View file

@ -86,16 +86,6 @@ def configure(env):
env["LD"] = "clang++"
env.Append(CPPFLAGS=['-DTYPED_METHOD_BIND'])
env.extra_suffix = ".llvm"
elif (os.system("gcc --version > /dev/null 2>&1") == 0): # GCC
# Hack to prevent building this branch with GCC 6+, which trigger segfaults due to UB when dereferencing pointers in Object::cast_to
# This is fixed in the master branch, for 2.1 we just prevent using too recent GCC versions.
import subprocess
gcc_major = subprocess.check_output(['gcc', '-dumpversion']).decode('ascii').split('.')[0]
if (int(gcc_major) > 5):
print("Your configured compiler appears to be GCC %s, 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)
if (env["use_sanitizer"] == "yes"):
env.Append(CCFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer'])
@ -125,6 +115,18 @@ def configure(env):
if (env["debug_release"] == "yes"):
env.Prepend(CCFLAGS=['-g2'])
if (os.system("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(['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)
elif (env["target"] == "release_debug"):
env.Prepend(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED'])