From 08acf1352c48aa867ed304db2ca088b2c95e40a4 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Wed, 25 Mar 2015 20:53:35 -0700 Subject: [PATCH] win,node-gyp: make delay-load hook optional The delay-load hook that was landed in 3d46fef to make compiled addons work on Windows regardless of the iojs.exe/node.exe filename causes issues with a small amount of compiled addons. Therefore this patch makes it an opt-in feature. An addon may set the 'win_delay_load_hook' option to 'true' in its binding.gyp to enable this feature. Example: ``` { 'targets': [ { 'target_name': 'ernie', 'win_delay_load_hook': 'true', ... ``` Refs: https://github.com/iojs/io.js/pull/1251 PR-URL: https://github.com/iojs/io.js/pull/1266 Reviewed-By: Ben Noordhuis --- deps/npm/node_modules/node-gyp/addon.gypi | 37 +++++++++++++++-------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/deps/npm/node_modules/node-gyp/addon.gypi b/deps/npm/node_modules/node-gyp/addon.gypi index fd322cce6de96f..a52f93f278ec66 100644 --- a/deps/npm/node_modules/node-gyp/addon.gypi +++ b/deps/npm/node_modules/node-gyp/addon.gypi @@ -1,7 +1,9 @@ { 'target_defaults': { 'type': 'loadable_module', + 'win_delay_load_hook': 'false', 'product_prefix': '', + 'include_dirs': [ '<(node_root_dir)/src', '<(node_root_dir)/deps/uv/include', @@ -13,11 +15,34 @@ 'product_extension': 'node', 'defines': [ 'BUILDING_NODE_EXTENSION' ], }], + ['_type=="static_library"', { # set to `1` to *disable* the -T thin archive 'ld' flag. # older linkers don't support this flag. 'standalone_static_library': '<(standalone_static_library)' }], + + ['_win_delay_load_hook=="true"', { + # If the has the 'win_delay_load_hook' option set to 'true', link a + # delay-load hook into the DLL. That hook ensures that the addon + # will work regardless of whether the node/iojs binary is named + # node.exe, iojs.exe, or something else. + 'conditions': [ + [ 'OS=="win"', { + 'sources': [ + 'src/win_delay_load_hook.c', + ], + 'msvs_settings': { + 'VCLinkerTool': { + 'DelayLoadDLLs': [ 'iojs.exe', 'node.exe' ], + # Don't print a linker warning when no imports from either .exe + # are used. + 'AdditionalOptions': [ '/ignore:4199' ], + }, + }, + }], + ], + }], ], 'conditions': [ @@ -29,9 +54,6 @@ }, }], [ 'OS=="win"', { - 'sources': [ - 'src/win_delay_load_hook.c', - ], 'libraries': [ '-lkernel32.lib', '-luser32.lib', @@ -50,15 +72,6 @@ # warning C4251: 'node::ObjectWrap::handle_' : class 'v8::Persistent' # needs to have dll-interface to be used by clients of class 'node::ObjectWrap' 'msvs_disabled_warnings': [ 4251 ], - # Set up delay-loading for node.exe/iojs.exe so the loadable module - # will still be able to find it's imports if the binary is renamed. - 'msvs_settings': { - 'VCLinkerTool': { - 'DelayLoadDLLs': [ 'iojs.exe', 'node.exe' ], - # Don't print a linker warning when no imports from either .exe are used. - 'AdditionalOptions': [ '/ignore:4199' ], - } - }, }, { # OS!="win" 'defines': [ '_LARGEFILE_SOURCE', '_FILE_OFFSET_BITS=64' ],