From 871a0633d1e59289832249a4b814cf73d8f8d6cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20A=C3=A7acak?= Date: Tue, 14 Jan 2025 09:57:32 +0300 Subject: [PATCH 1/4] win,build: add option to enable Control Flow Guard --- common.gypi | 11 +++++++++++ configure.py | 7 +++++++ vcbuild.bat | 3 +++ 3 files changed, 21 insertions(+) diff --git a/common.gypi b/common.gypi index 0ce17772cf5e25..0df6e6f9bb463e 100644 --- a/common.gypi +++ b/common.gypi @@ -28,6 +28,7 @@ 'clang%': 0, 'error_on_warn%': 'false', 'suppress_all_error_on_warn%': 'false', + 'cfg%': 'false', 'openssl_product': '<(STATIC_LIB_PREFIX)openssl<(STATIC_LIB_SUFFIX)', 'openssl_no_asm%': 0, @@ -310,6 +311,11 @@ '/Zm2000', ], }], + ['cfg=="true"', { + 'AdditionalOptions': [ + '/guard:cf', # Control Flow Guard + ], + }], ], 'BufferSecurityCheck': 'true', 'DebugInformationFormat': 1, # /Z7 embed info in .obj files @@ -336,6 +342,11 @@ ['target_arch=="arm64"', { 'TargetMachine' : 0, # NotSet. MACHINE:ARM64 is inferred from the input files. }], + ['cfg=="true"', { + 'AdditionalOptions': [ + '/guard:cf', # Control Flow Guard + ], + }], ], 'GenerateDebugInformation': 'true', 'SuppressStartupBanner': 'true', diff --git a/configure.py b/configure.py index 8e140ac6d67c66..0cf55b5d66645a 100755 --- a/configure.py +++ b/configure.py @@ -819,6 +819,12 @@ default=None, help='do not install the bundled Corepack') +parser.add_argument('--cfg', + action='store_true', + dest='enable_cfg', + default=None, + help='enable Control Flow Guard (CFG)') + # Dummy option for backwards compatibility parser.add_argument('--without-report', action='store_true', @@ -1443,6 +1449,7 @@ def configure_node(o): o['variables']['node_prefix'] = options.prefix o['variables']['node_install_npm'] = b(not options.without_npm) o['variables']['node_install_corepack'] = b(not options.without_corepack) + o['variables']['cfg'] = b(options.enable_cfg) o['variables']['node_use_amaro'] = b(not options.without_amaro) o['variables']['debug_node'] = b(options.debug_node) o['default_configuration'] = 'Debug' if options.debug else 'Release' diff --git a/vcbuild.bat b/vcbuild.bat index eb8e5194f0fb8a..9a42f498107562 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -72,6 +72,7 @@ set no_shared_roheap= set doc= set extra_msbuild_args= set compile_commands= +set cfg= set exit_code=0 :next-arg @@ -150,6 +151,7 @@ if /i "%1"=="no-shared-roheap" set no_shared_roheap=1&goto arg-ok if /i "%1"=="doc" set doc=1&goto arg-ok if /i "%1"=="binlog" set extra_msbuild_args=/binaryLogger:out\%config%\node.binlog&goto arg-ok if /i "%1"=="compile-commands" set compile_commands=1&goto arg-ok +if /i "%1"=="cfg" set cfg=1&goto arg-ok echo Error: invalid command line option `%1`. exit /b 1 @@ -210,6 +212,7 @@ if defined no_shared_roheap set configure_flags=%configure_flags% --disable-shar if defined DEBUG_HELPER set configure_flags=%configure_flags% --verbose if defined ccache_path set configure_flags=%configure_flags% --use-ccache-win if defined compile_commands set configure_flags=%configure_flags% -C +if defined cfg set configure_flags=%configure_flags% --cfg if "%target_arch%"=="x86" ( echo "32-bit Windows builds are not supported anymore." From aaaa57dcdfadd23ddc09d11b0fc83547104a18fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20A=C3=A7acak?= <110401522+huseyinacacak-janea@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:19:38 +0300 Subject: [PATCH 2/4] Update common.gypi Co-authored-by: Richard Lau --- common.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.gypi b/common.gypi index 0df6e6f9bb463e..41ce5208b3ba3f 100644 --- a/common.gypi +++ b/common.gypi @@ -28,7 +28,7 @@ 'clang%': 0, 'error_on_warn%': 'false', 'suppress_all_error_on_warn%': 'false', - 'cfg%': 'false', + 'control_flow_guard%': 'false', 'openssl_product': '<(STATIC_LIB_PREFIX)openssl<(STATIC_LIB_SUFFIX)', 'openssl_no_asm%': 0, From b372083d3bf382e1c5b562162477c08735d6e22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20A=C3=A7acak?= <110401522+huseyinacacak-janea@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:19:45 +0300 Subject: [PATCH 3/4] Update configure.py Co-authored-by: Richard Lau --- configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.py b/configure.py index 0cf55b5d66645a..69b8fc2ae6f48f 100755 --- a/configure.py +++ b/configure.py @@ -819,7 +819,7 @@ default=None, help='do not install the bundled Corepack') -parser.add_argument('--cfg', +parser.add_argument('--control-flow-guard', action='store_true', dest='enable_cfg', default=None, From fd6368b4027e813da229e63c8c7e0db5fbe4807b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20A=C3=A7acak?= Date: Tue, 21 Jan 2025 13:47:26 +0300 Subject: [PATCH 4/4] fix inconsistency in variables --- common.gypi | 4 ++-- configure.py | 2 +- vcbuild.bat | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common.gypi b/common.gypi index 41ce5208b3ba3f..43cbd973fdfd38 100644 --- a/common.gypi +++ b/common.gypi @@ -311,7 +311,7 @@ '/Zm2000', ], }], - ['cfg=="true"', { + ['control_flow_guard=="true"', { 'AdditionalOptions': [ '/guard:cf', # Control Flow Guard ], @@ -342,7 +342,7 @@ ['target_arch=="arm64"', { 'TargetMachine' : 0, # NotSet. MACHINE:ARM64 is inferred from the input files. }], - ['cfg=="true"', { + ['control_flow_guard=="true"', { 'AdditionalOptions': [ '/guard:cf', # Control Flow Guard ], diff --git a/configure.py b/configure.py index 69b8fc2ae6f48f..6b91212c7bcd4c 100755 --- a/configure.py +++ b/configure.py @@ -1449,7 +1449,7 @@ def configure_node(o): o['variables']['node_prefix'] = options.prefix o['variables']['node_install_npm'] = b(not options.without_npm) o['variables']['node_install_corepack'] = b(not options.without_corepack) - o['variables']['cfg'] = b(options.enable_cfg) + o['variables']['control_flow_guard'] = b(options.enable_cfg) o['variables']['node_use_amaro'] = b(not options.without_amaro) o['variables']['debug_node'] = b(options.debug_node) o['default_configuration'] = 'Debug' if options.debug else 'Release' diff --git a/vcbuild.bat b/vcbuild.bat index 9a42f498107562..d2dbf423e5a9b6 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -212,7 +212,7 @@ if defined no_shared_roheap set configure_flags=%configure_flags% --disable-shar if defined DEBUG_HELPER set configure_flags=%configure_flags% --verbose if defined ccache_path set configure_flags=%configure_flags% --use-ccache-win if defined compile_commands set configure_flags=%configure_flags% -C -if defined cfg set configure_flags=%configure_flags% --cfg +if defined cfg set configure_flags=%configure_flags% --control-flow-guard if "%target_arch%"=="x86" ( echo "32-bit Windows builds are not supported anymore."