From 94b8874ba55a09b4a07cace7e4cdf6504b254053 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 17 Dec 2024 15:25:36 +0100 Subject: [PATCH] build: build v8 with -fvisibility=hidden -fvisibility-inlines-hidden --- node.gyp | 13 +++++++++++++ tools/v8_gypfiles/v8.gyp | 25 +++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/node.gyp b/node.gyp index 00c9de8a28ed07..2f4934b9a8c8b8 100644 --- a/node.gyp +++ b/node.gyp @@ -491,6 +491,19 @@ ['clang==0 and OS!="win"', { 'cflags': [ '-Wno-restrict', ], }], + # TODO(joyeecheung): investigate if it breaks addons. + # ['OS=="mac"', { + # 'xcode_settings': { + # 'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden + # 'GCC_INLINES_ARE_PRIVATE_EXTERN': 'YES' # -fvisibility-inlines-hidden + # }, + # }], + # ['OS!="win" or clang==1', { + # 'cflags': [ + # '-fvisibility=hidden', + # '-fvisibility-inlines-hidden' + # ], + # }], # Pointer authentication for ARM64. ['target_arch=="arm64"', { 'target_conditions': [ diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp index 2d5e78b338b0cb..5acb8169c692fd 100644 --- a/tools/v8_gypfiles/v8.gyp +++ b/tools/v8_gypfiles/v8.gyp @@ -46,22 +46,31 @@ } }, 'conditions': [ - ['OS=="mac"', { - # Hide symbols that are not explicitly exported with V8_EXPORT. - # TODO(joyeecheung): enable it on other platforms. Currently gcc times out - # or run out of memory with -fvisibility=hidden on some machines in the CI. - 'xcode_settings': { - 'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden - }, + # Build with -fvisibility=hidden and -fvisibility-inlines-hidden to avoid + # including unnecessary internal symbols, which may lead to run-time fixups. + # This is not done on AIX where symbols are exported by tools/create_expfile.sh + # see https://github.com/nodejs/node/pull/56290#issuecomment-2582703109 + ['OS!="aix"', { 'defines': [ 'BUILDING_V8_SHARED', # Make V8_EXPORT visible. - ], + ] }], ['node_shared=="true"', { 'defines': [ 'V8_TLS_USED_IN_LIBRARY', # Enable V8_TLS_LIBRARY_MODE. ], }], + ['OS=="mac"', { + 'xcode_settings': { + 'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden + 'GCC_INLINES_ARE_PRIVATE_EXTERN': 'YES' # -fvisibility-inlines-hidden + }, + }, 'OS!="aix" and (OS!="win" or clang==1)', { + 'cflags': [ + '-fvisibility=hidden', + '-fvisibility-inlines-hidden' + ], + }], # MSVC hides the non-public symbols by default so no need to configure it. ], }, 'targets': [