From 791b8ff681abd1c371d132699987c3732106b7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 7 May 2024 13:55:58 +0200 Subject: [PATCH 1/2] build: harmonize Clang checks - Set the clang variable in `config.gypi` so it depends on compiler checks made by the configure script. - Replace gyp conditions with `llvm_version` and "0.0" with conditions that use the `clang` variable. - Always use `clang==1` or `clang==0` in gyp conditions --- common.gypi | 7 +++---- configure.py | 2 ++ deps/openssl/openssl_common.gypi | 2 +- deps/zlib/zlib.gyp | 7 +++---- node.gyp | 2 +- tools/v8_gypfiles/toolchain.gypi | 4 ++-- tools/v8_gypfiles/v8.gyp | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/common.gypi b/common.gypi index b5a1bcad695ff7..3c73151315d9ff 100644 --- a/common.gypi +++ b/common.gypi @@ -107,7 +107,6 @@ 'v8_base': '<(PRODUCT_DIR)/obj.target/tools/v8_gypfiles/libv8_snapshot.a', }], ['OS=="mac"', { - 'clang%': 1, 'obj_dir%': '<(PRODUCT_DIR)/obj.target', 'v8_base': '<(PRODUCT_DIR)/libv8_snapshot.a', }], @@ -182,10 +181,10 @@ }, { 'MSVC_runtimeType': 2 # MultiThreadedDLL (/MD) }], - ['llvm_version=="0.0"', { - 'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', # GCC - }, { + ['clang==1', { 'lto': ' -flto ', # Clang + }, { + 'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', # GCC }], ], }, diff --git a/configure.py b/configure.py index 1d7c095d03dbc2..a8e48d08bc083b 100755 --- a/configure.py +++ b/configure.py @@ -1042,6 +1042,7 @@ def get_gas_version(cc): # quite prepared to go that far yet. def check_compiler(o): if sys.platform == 'win32': + o['variables']['clang'] = 0 o['variables']['llvm_version'] = '0.0' if not options.openssl_no_asm and options.dest_cpu in ('x86', 'x64'): nasm_version = get_nasm_version('nasm') @@ -1051,6 +1052,7 @@ def check_compiler(o): return ok, is_clang, clang_version, gcc_version = try_check_compiler(CXX, 'c++') + o['variables']['clang'] = B(is_clang) version_str = ".".join(map(str, clang_version if is_clang else gcc_version)) print_verbose(f"Detected {'clang ' if is_clang else ''}C++ compiler (CXX={CXX}) version: {version_str}") if not ok: diff --git a/deps/openssl/openssl_common.gypi b/deps/openssl/openssl_common.gypi index 8745ec130ab878..4312359e947643 100644 --- a/deps/openssl/openssl_common.gypi +++ b/deps/openssl/openssl_common.gypi @@ -67,7 +67,7 @@ 'TERMIOS', ], 'conditions': [ - [ 'llvm_version=="0.0"', { + [ 'clang==0', { 'cflags': ['-Wno-old-style-declaration',], }], ], diff --git a/deps/zlib/zlib.gyp b/deps/zlib/zlib.gyp index 26ceed9fbe6825..25f570fbe7bdb6 100644 --- a/deps/zlib/zlib.gyp +++ b/deps/zlib/zlib.gyp @@ -7,7 +7,6 @@ 'ZLIB_ROOT': '.', 'use_system_zlib%': 0, 'arm_fpu%': '', - 'llvm_version%': '0.0', }, 'conditions': [ ['use_system_zlib==0', { @@ -24,7 +23,7 @@ },{ 'defines': [ 'X86_NOT_WINDOWS' ], }], - ['OS!="win" or llvm_version!="0.0"', { + ['OS!="win" or clang==1', { 'cflags': [ '-mssse3' ], 'xcode_settings': { 'OTHER_CFLAGS': [ '-mssse3' ], @@ -65,7 +64,7 @@ 'conditions': [ ['OS!="ios"', { 'conditions': [ - ['OS!="win" and llvm_version=="0.0"', { + ['OS!="win" and clang==0', { 'cflags': [ '-march=armv8-a+aes+crc' ], }], ['OS=="android"', { @@ -111,7 +110,7 @@ # 'target_name': 'zlib_crc32_simd', # 'type': 'static_library', # 'conditions': [ - # ['OS!="win" or llvm_version!="0.0"', { + # ['OS!="win" or clang==1', { # 'cflags': [ # '-msse4.2', # '-mpclmul', diff --git a/node.gyp b/node.gyp index 6244369405ecce..a994c3d3ee3329 100644 --- a/node.gyp +++ b/node.gyp @@ -504,7 +504,7 @@ '-Wl,-bnoerrmsg', ], }], - ['OS == "linux" and llvm_version != "0.0"', { + ['OS=="linux" and clang==1', { 'libraries': ['-latomic'], }], ], diff --git a/tools/v8_gypfiles/toolchain.gypi b/tools/v8_gypfiles/toolchain.gypi index cc97adfbc30974..e4dd387014eb79 100644 --- a/tools/v8_gypfiles/toolchain.gypi +++ b/tools/v8_gypfiles/toolchain.gypi @@ -134,7 +134,7 @@ '<(V8_ROOT)/include', ], 'conditions': [ - ['clang', { + ['clang==1', { 'cflags': [ '-Werror', '-Wno-unknown-pragmas' ], },{ 'cflags!': [ '-Wall', '-Wextra' ], @@ -144,7 +144,7 @@ '-flax-vector-conversions', ], }], - ['clang or OS!="win"', { + ['clang==1 or OS!="win"', { 'cflags': [ '-Wno-invalid-offsetof' ], 'xcode_settings': { 'WARNING_CFLAGS': ['-Wno-invalid-offsetof'] diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp index 1e2b3645132aab..fa84690ba79be7 100644 --- a/tools/v8_gypfiles/v8.gyp +++ b/tools/v8_gypfiles/v8.gyp @@ -1879,7 +1879,7 @@ ['enable_lto=="true"', { 'cflags_cc': [ '-fno-lto' ], }], - ['clang or OS!="win"', { + ['clang==1 or OS!="win"', { 'conditions': [ ['_toolset == "host" and host_arch == "x64" or _toolset == "target" and target_arch=="x64"', { 'sources': [ From 3c2feaac907962ccc7242486329f549f5ba7bf63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 7 May 2024 15:17:08 +0200 Subject: [PATCH 2/2] build: sync V8 warning cflags with BUILD.gn --- common.gypi | 1 - tools/v8_gypfiles/toolchain.gypi | 28 ++++++++++++++++++---------- tools/v8_gypfiles/v8.gyp | 6 ------ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/common.gypi b/common.gypi index 3c73151315d9ff..d3e13508e09e72 100644 --- a/common.gypi +++ b/common.gypi @@ -3,7 +3,6 @@ 'configuring_node%': 0, 'asan%': 0, 'ubsan%': 0, - 'werror': '', # Turn off -Werror in V8 build. 'visibility%': 'hidden', # V8's visibility setting 'target_arch%': 'ia32', # set v8's target architecture 'host_arch%': 'ia32', # set v8's host architecture diff --git a/tools/v8_gypfiles/toolchain.gypi b/tools/v8_gypfiles/toolchain.gypi index e4dd387014eb79..c48338d343a5c2 100644 --- a/tools/v8_gypfiles/toolchain.gypi +++ b/tools/v8_gypfiles/toolchain.gypi @@ -82,7 +82,6 @@ 'v8_toolset_for_shell%': 'target', 'host_os%': '<(OS)', - 'werror%': '-Werror', # For a shared library build, results in "libv8-<(soname_version).so". 'soname_version%': '', @@ -133,21 +132,33 @@ '<(V8_ROOT)', '<(V8_ROOT)/include', ], + 'cflags!': ['-Wall', '-Wextra'], 'conditions': [ - ['clang==1', { - 'cflags': [ '-Werror', '-Wno-unknown-pragmas' ], - },{ - 'cflags!': [ '-Wall', '-Wextra' ], + ['clang==0 and OS!="win"', { 'cflags': [ + # In deps/v8/BUILD.gn: if (!is_clang && !is_win) { cflags += [...] } + '-Wno-strict-overflow', '-Wno-return-type', + '-Wno-int-in-bool-context', + '-Wno-deprecated', + '-Wno-stringop-overflow', + '-Wno-stringop-overread', + '-Wno-restrict', + '-Wno-array-bounds', + '-Wno-nonnull', + '-Wno-dangling-pointer', # On by default in Clang and V8 requires it at least for arm64. '-flax-vector-conversions', ], }], ['clang==1 or OS!="win"', { - 'cflags': [ '-Wno-invalid-offsetof' ], + 'cflags_cc': [ + # In deps/v8/BUILD.gn: if (is_clang || !is_win) { cflags += [...] } + '-Wno-invalid-offsetof', + ], 'xcode_settings': { - 'WARNING_CFLAGS': ['-Wno-invalid-offsetof'] + # -Wno-invalid-offsetof + 'GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO': 'NO', }, }], ['v8_target_arch=="arm"', { @@ -434,9 +445,6 @@ ['_toolset=="target"', { 'conditions': [ ['v8_target_arch==target_arch', { - 'cflags': [ - '-Wno-error=array-bounds', # Workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56273 - ], 'conditions': [ ['v8_target_arch=="mips64el"', { 'cflags': ['-EL'], diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp index fa84690ba79be7..bf21265ca88b5a 100644 --- a/tools/v8_gypfiles/v8.gyp +++ b/tools/v8_gypfiles/v8.gyp @@ -2132,12 +2132,6 @@ ] }], ], - # -Wno-invalid-offsetof flag is not valid for C. - # The flag is initially set in `toolchain.gypi` for all targets. - 'cflags!': [ '-Wno-invalid-offsetof' ], - 'xcode_settings': { - 'WARNING_CFLAGS!': ['-Wno-invalid-offsetof'] - }, 'direct_dependent_settings': { 'include_dirs': [ '<(V8_ROOT)/third_party/zlib',