mirror of
https://github.com/nodejs/node.git
synced 2025-05-22 17:53:49 +00:00

On Windows, when node or io.js attempts to dynamically load a compiled addon, the compiled addon tries to load node.exe or iojs.exe again - depending on which import library the module used when it was linked. This causes many compiled addons to break when node.exe or iojs.exe are renamed, because when the binary has been renamed the addon DLL can't find the (right) .exe file to load its imports from. This patch gives compiled addon developers an option to overcome this restriction by compiling a delay-load hook into their binary. The delay-load hook ensures that whenever a module tries to load imports from node.exe/iojs.exe, it'll just look at the process image, thereby making the addon work regardless of what name the node/iojs binary has. To enable this feature, the addon developer must set the 'win_delay_load_hook' option to 'true' in their binding.gyp file, like this: ``` { 'targets': [ { 'target_name': 'ernie', 'win_delay_load_hook': 'true', ... ``` Bug: https://github.com/iojs/io.js/issues/751 Bug: https://github.com/iojs/io.js/issues/965 Upstream PR: https://github.com/TooTallNate/node-gyp/pull/599 PR-URL: https://github.com/iojs/io.js/pull/1251 Reviewed-By: Rod Vagg <rod@vagg.org> PR-URL: https://github.com/iojs/io.js/pull/1266 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
85 lines
2.6 KiB
Python
85 lines
2.6 KiB
Python
{
|
|
'target_defaults': {
|
|
'type': 'loadable_module',
|
|
'win_delay_load_hook': 'false',
|
|
'product_prefix': '',
|
|
|
|
'include_dirs': [
|
|
'<(node_root_dir)/src',
|
|
'<(node_root_dir)/deps/uv/include',
|
|
'<(node_root_dir)/deps/v8/include'
|
|
],
|
|
|
|
'target_conditions': [
|
|
['_type=="loadable_module"', {
|
|
'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 addon specifies `'win_delay_load_hook': 'true'` in its
|
|
# binding.gyp, link a delay-load hook into the DLL. This 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': [
|
|
[ 'OS=="mac"', {
|
|
'defines': [ '_DARWIN_USE_64_BIT_INODE=1' ],
|
|
'libraries': [ '-undefined dynamic_lookup' ],
|
|
'xcode_settings': {
|
|
'DYLIB_INSTALL_NAME_BASE': '@rpath'
|
|
},
|
|
}],
|
|
[ 'OS=="win"', {
|
|
'libraries': [
|
|
'-lkernel32.lib',
|
|
'-luser32.lib',
|
|
'-lgdi32.lib',
|
|
'-lwinspool.lib',
|
|
'-lcomdlg32.lib',
|
|
'-ladvapi32.lib',
|
|
'-lshell32.lib',
|
|
'-lole32.lib',
|
|
'-loleaut32.lib',
|
|
'-luuid.lib',
|
|
'-lodbc32.lib',
|
|
'-lDelayImp.lib',
|
|
'-l"<(node_root_dir)/$(ConfigurationName)/iojs.lib"'
|
|
],
|
|
# warning C4251: 'node::ObjectWrap::handle_' : class 'v8::Persistent<T>'
|
|
# needs to have dll-interface to be used by clients of class 'node::ObjectWrap'
|
|
'msvs_disabled_warnings': [ 4251 ],
|
|
}, {
|
|
# OS!="win"
|
|
'defines': [ '_LARGEFILE_SOURCE', '_FILE_OFFSET_BITS=64' ],
|
|
}],
|
|
[ 'OS=="freebsd" or OS=="openbsd" or OS=="solaris" or (OS=="linux" and target_arch!="ia32")', {
|
|
'cflags': [ '-fPIC' ],
|
|
}]
|
|
]
|
|
}
|
|
}
|