From 7021192af5af6b6a65a2a708da0a88bb968898e6 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 16 Dec 2024 22:10:24 +0100 Subject: [PATCH] build: build v8 with -fvisibility=hidden V8 should be built with -fvisibility=hidden, otherwise the resulting binary would contain unnecessary symbols. In particular, on macOS, this leads to 5000+ weak symbols resolved at runtime, leading to a startup regression. On macOS this also reduces the binary size about ~10MB. On Linux the size reduction is around 8MB. --- tools/v8_gypfiles/v8.gyp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp index 9acad07d966a35..19e490167fc0dc 100644 --- a/tools/v8_gypfiles/v8.gyp +++ b/tools/v8_gypfiles/v8.gyp @@ -41,6 +41,14 @@ 'AdditionalOptions': ['/utf-8'] } }, + # Hide symbols that are not explicitly exported with V8_EXPORT. + 'cflags': ['-fvisibility=hidden'], + 'xcode_settings': { + 'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden + }, + 'defines': [ + 'BUILDING_V8_SHARED', # Make V8_EXPORT visible. + ], }, 'targets': [ {