From a87391d2562eaf4fa820df7d211978c6b25dd2c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 2 Jan 2025 23:16:09 +0100 Subject: [PATCH] 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`. --- platform/server/detect.py | 10 ---------- platform/windows/detect.py | 12 ++++++++++++ platform/x11/detect.py | 22 ++++++++++++---------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/platform/server/detect.py b/platform/server/detect.py index 3afbd01133b..28f0956746a 100644 --- a/platform/server/detect.py +++ b/platform/server/detect.py @@ -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 diff --git a/platform/windows/detect.py b/platform/windows/detect.py index a7151235a52..40aa51cac4d 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -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']) diff --git a/platform/x11/detect.py b/platform/x11/detect.py index ab791f357f7..0dfbca11f8b 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -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'])