From 22a78a75eeb5e19ed3a70e90ed4d80e06a60fe90 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Sun, 22 Aug 2021 02:21:23 +0800 Subject: [PATCH] build: preserves symbols during LTO with macOS linker man ld -export_dynamic: ``` Preserves all global symbols in main executables during LTO. Without this option, Link Time Optimization is allowed to inline and remove global functions. This option is used when a main executable may load a plug-in which requires certain symbols from the main executable. ``` Bug: vercel/pkg#1155 Signed-off-by: Jesse Chan PR-URL: https://github.com/nodejs/node/pull/39839 Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- node.gyp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/node.gyp b/node.gyp index 0c11797baa2197..faf50d86bcad64 100644 --- a/node.gyp +++ b/node.gyp @@ -236,6 +236,19 @@ 'OTHER_LDFLAGS': [ '-Wl,-rpath,@loader_path', ], }, }], + [ 'enable_lto=="true"', { + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + # man ld -export_dynamic: + # Preserves all global symbols in main executables during LTO. + # Without this option, Link Time Optimization is allowed to + # inline and remove global functions. This option is used when + # a main executable may load a plug-in which requires certain + # symbols from the main executable. + '-Wl,-export_dynamic', + ], + }, + }], ['OS=="win"', { 'libraries': [ 'Dbghelp.lib',