-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: explicitly register built-in modules #16565
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me. The commit message should start with src:
rather than lib:
for C++ file changes. :)
src/node.h
Outdated
@@ -200,6 +200,7 @@ NODE_EXTERN extern bool force_fips_crypto; | |||
# endif | |||
#endif | |||
|
|||
NODE_EXTERN void RegisterBuiltinModules(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a short doc comment for this method, in particular that embedders need to call it on startup?
I know a lot in this file isn’t very well-documented, but at least new code should come with something. :)
src/node.h
Outdated
V(inspector) \ | ||
V(crypto) \ | ||
V(tls_wrap) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node_internals.h might be a better place?
src/node.h
Outdated
#else | ||
#define NODE_C_CTOR(fn) \ | ||
NODE_CTOR_PREFIX void fn(void) __attribute__((constructor)); \ | ||
NODE_CTOR_PREFIX void fn(void) | ||
#define NODE_C_CTOR_BUILTIN(fn) \ | ||
void fn(void); \ | ||
void fn(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto re: node_internals.h
src/node.h
Outdated
@@ -502,14 +551,40 @@ extern "C" NODE_EXTERN void node_module_register(void* mod); | |||
} \ | |||
} | |||
|
|||
/* for nodejs built-in modules only */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very good sign that this, too, would be nicer to have in node_internals.h
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addaleax thanks, actually @bnoordhuis had the same comments. I got 2-3 working servers, seems I didn't pick the right one to push the change. let me do it now. Thanks for the comments.
1616f7a
to
5d48b68
Compare
I pushed an updated version. It should address the |
src/node.h
Outdated
@@ -508,8 +508,6 @@ extern "C" NODE_EXTERN void node_module_register(void* mod); | |||
#define NODE_MODULE_CONTEXT_AWARE(modname, regfunc) \ | |||
NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, 0) | |||
|
|||
#define NODE_MODULE_CONTEXT_AWARE_BUILTIN(modname, regfunc) \ | |||
NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, NM_F_BUILTIN) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a good idea but this is definitely semver-major
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fishrock123 What here is semver-major?
I’m on the fence myself but if it is semver-major, then that is the case because embedders need to make an extra function call – not because of the other changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I was attempting to build node through xlC compiler once, and could not proceed further due to this semantics that was not possible with xlC.
Does this cover all the instances of attribute constructs, or only the ones that are associated with built-in modules?
src/node_internals.h
Outdated
* use the __attribute__((constructor)). Need to | ||
* explicitly call the _register* functions. | ||
*/ | ||
void RegisterBuiltinModules(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was unclear, but this is part of the embedder API so it should be in the public header – right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @addaleax and @gireeshpunathil, actually, this change is for built-in modules. It only removes the __attribute__((constructos))
for build-in modules. So, I moved this to the node_internals.h
and it needs to be invoked inside the node::Start()
.
For third-party modules, they are built as shared library in most case and __attribute__((constructor))
works properly in dlopen()
. I left that part as-is. I was not aware of that xIc compiler doesn't support it. If we want to remove the __attribute__((constructor))
for third-party modules, we also need to change the module initialization process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yhwang Yes, but not all embedders use node::Start(int argc, char** argv)
, right? So they need a definition of this function to be available.
src/node.cc
Outdated
* function for each built-in modules explicitly in | ||
* node::RegisterBuiltinModules(). This is only forward declaration. | ||
* The definitions are in each module's implementation when calling | ||
* the NODE_MODULE_CONTEXT_AWARE_BUILTIN. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nit: can you use //
comments? C-style comments aren't exactly wrong but they look incongruous because we use C++-style comments everywhere else.
src/node_internals.h
Outdated
priv, \ | ||
flags) \ | ||
static node::node_module _module = \ | ||
{ \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nit: {
should go on the previous line and since you're here, can you replace NULL
with nullptr
?
src/node_internals.h
Outdated
V(uv, MODREG_WITH_DEF) \ | ||
V(inspector, MODREG_WITH_DEF) \ | ||
V(crypto, OPENSSL_MODREG_DEF) \ | ||
V(tls_wrap, OPENSSL_MODREG_DEF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not wrong but I'd approach it a little differently.
#define NODE_BUILTIN_STANDARD_MODULES(V) \
V(async_wrap) \
V(cares_wrap) \
// ...
#if HAVE_OPENSSL
#define NODE_BUILTIN_OPENSSL_MODULES(V) V(crypto) V(tls_wrap)
#else
#define NODE_BUILTIN_OPENSSL_MODULES(V)
#endif
#if NODE_HAVE_I18N_SUPPORT
#define NODE_BUILTIN_ICU_MODULES(V) V(icu)
#else
#define NODE_BUILTIN_ICU_MODULES(V)
#endif
#define NODE_BUILTIN_MODULES(V) \
NODE_BUILTIN_STANDARD_MODULES(V) \
NODE_BUILTIN_OPENSSL_MODULES(V) \
NODE_BUILTIN_ICU_MODULES(V)
It's arguably a little easier to comprehend because the V macro takes only one argument this way.
src/node_internals.h
Outdated
NULL, \ | ||
__FILE__, \ | ||
NULL, \ | ||
(node::addon_context_register_func) (regfunc), \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something for a future cleanup PR: getting rid of this cast.
src/node_internals.h
Outdated
NULL \ | ||
}; \ | ||
NODE_C_CTOR_BUILTIN(_register_ ## modname) { \ | ||
node_module_register(&_module); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another something for a future cleanup PR: export the struct and call node_module_register()
directly in node.cc, instead of first going through _register_foo()
.
Performance-wise it's unlikely to matter but it should make it a little easier to understand for future maintainers.
Also, I think you can get rid of NODE_C_CTOR_BUILTIN
now, you don't need to special-case for Windows anymore.
src/node.cc
Outdated
* The definitions are in each module's implementation when calling | ||
* the NODE_MODULE_CONTEXT_AWARE_BUILTIN. | ||
*/ | ||
#define DECLAREFUN(modname, impl) void _register_##modname(void) impl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nit: void _register_##modname()
(no void argument list, that's a C-ism) and perhaps you can call the macro simply V? Also applies to line 4999.
5762a40
to
5c33fe4
Compare
@bnoordhuis I updated the commit to address all your comments. @addaleax you're right. So I moved the invocation of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo style nits.
src/node_internals.h
Outdated
priv, \ | ||
nullptr \ | ||
}; \ | ||
void _register_ ## modname() { \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\
is not aligned with its surroundings.
src/node_internals.h
Outdated
NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, NM_F_INTERNAL) \ | ||
NODE_MODULE_CONTEXT_AWARE_X_BUILTIN(modname, \ | ||
regfunc, \ | ||
NULL, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're here: nullptr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure and done!
5c33fe4
to
9d5676b
Compare
src/node_internals.h
Outdated
V(tty_wrap) \ | ||
V(udp_wrap) \ | ||
V(uv) \ | ||
V(inspector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: alphabetical order please :)
test/cctest/node_module_reg.cc
Outdated
void _register_fs_event_wrap() {} | ||
void _register_js_stream() {} | ||
void _register_module_wrap() {} | ||
void _register_config() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: alphabetical order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
6c15dbd
to
5d4200a
Compare
d9b5438
to
d0f06d3
Compare
Hi @Fishrock123 , @addaleax and @bnoordhuis I removed the change in |
d0f06d3
to
074e201
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -20,6 +20,7 @@ | |||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
|
|||
#include "node.h" | |||
#include "node_internals.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this include and the one in uv.cc necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. need to add node_internals.h
for node_v8.cc and uv.cc
@bnoordhuis thanks for the review. would you remove the |
I created a PR for it and please kick off a CI for it. Thanks |
Previously, built-in modules are registered before main() via __attribute__((constructor)) mechanism in GCC and similiar mechanism in MSVC. This causes some issues when node is built as static library. Calling module registration function for built-in modules in node::Init() helps to avoid the issues. Signed-off-by: Yihong Wang <yh.wang@ibm.com> Refs: #14986 (comment) Backport-PR-URL: #17625 PR-URL: #16565 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Previously, built-in modules are registered before main() via __attribute__((constructor)) mechanism in GCC and similiar mechanism in MSVC. This causes some issues when node is built as static library. Calling module registration function for built-in modules in node::Init() helps to avoid the issues. Signed-off-by: Yihong Wang <yh.wang@ibm.com> Refs: #14986 (comment) Backport-PR-URL: #17625 PR-URL: #16565 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
* update submodule refs for node v9.3.0 * Define "llvm_version" for Node.js build * NODE_MODULE_CONTEXT_AWARE_BUILTIN -> NODE_BUILTIN_MODULE_CONTEXT_AWARE * update NodePlatform to MultiIsolatePlatform * fix linting error * update node ref * REVIEW: Explicitly register builtin modules nodejs/node#16565 * update libcc ref * switch libcc to c62 * REVIEW: Address node api changes - Always start the inspector agent for nodejs/node#17085 - Set the tracing controller for node nodejs/node#15538 - Isolate data creation now requires plaform nodejs/node#16700
Previously, built-in modules are registered before main() via __attribute__((constructor)) mechanism in GCC and similiar mechanism in MSVC. This causes some issues when node is built as static library. Calling module registration function for built-in modules in node::Init() helps to avoid the issues. Signed-off-by: Yihong Wang <yh.wang@ibm.com> PR-URL: nodejs#16565 Backport-PR-URL: nodejs#18179 Refs: nodejs#14986 (comment) Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Previously, built-in modules are registered before main() via __attribute__((constructor)) mechanism in GCC and similiar mechanism in MSVC. This causes some issues when node is built as static library. Calling module registration function for built-in modules in node::Init() helps to avoid the issues. Signed-off-by: Yihong Wang <yh.wang@ibm.com> Backport-PR-URL: #18179 PR-URL: #16565 Refs: #14986 (comment) Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
* update submodule refs for node v9.3.0 * Define "llvm_version" for Node.js build * NODE_MODULE_CONTEXT_AWARE_BUILTIN -> NODE_BUILTIN_MODULE_CONTEXT_AWARE * update NodePlatform to MultiIsolatePlatform * fix linting error * update node ref * REVIEW: Explicitly register builtin modules nodejs/node#16565 * update libcc ref * switch libcc to c62 * REVIEW: Address node api changes - Always start the inspector agent for nodejs/node#17085 - Set the tracing controller for node nodejs/node#15538 - Isolate data creation now requires plaform nodejs/node#16700
* update submodule refs for node v9.3.0 * Define "llvm_version" for Node.js build * NODE_MODULE_CONTEXT_AWARE_BUILTIN -> NODE_BUILTIN_MODULE_CONTEXT_AWARE * update NodePlatform to MultiIsolatePlatform * fix linting error * update node ref * REVIEW: Explicitly register builtin modules nodejs/node#16565 * update libcc ref * switch libcc to c62 * REVIEW: Address node api changes - Always start the inspector agent for nodejs/node#17085 - Set the tracing controller for node nodejs/node#15538 - Isolate data creation now requires plaform nodejs/node#16700
* update submodule refs for node v9.3.0 * Define "llvm_version" for Node.js build * NODE_MODULE_CONTEXT_AWARE_BUILTIN -> NODE_BUILTIN_MODULE_CONTEXT_AWARE * update NodePlatform to MultiIsolatePlatform * fix linting error * update node ref * REVIEW: Explicitly register builtin modules nodejs/node#16565 * update libcc ref * switch libcc to c62 * REVIEW: Address node api changes - Always start the inspector agent for nodejs/node#17085 - Set the tracing controller for node nodejs/node#15538 - Isolate data creation now requires plaform nodejs/node#16700
* update submodule refs for node v9.3.0 * Define "llvm_version" for Node.js build * NODE_MODULE_CONTEXT_AWARE_BUILTIN -> NODE_BUILTIN_MODULE_CONTEXT_AWARE * update NodePlatform to MultiIsolatePlatform * fix linting error * update node ref * REVIEW: Explicitly register builtin modules nodejs/node#16565 * update libcc ref * switch libcc to c62 * REVIEW: Address node api changes - Always start the inspector agent for nodejs/node#17085 - Set the tracing controller for node nodejs/node#15538 - Isolate data creation now requires plaform nodejs/node#16700
* update submodule refs for node v9.3.0 * Define "llvm_version" for Node.js build * NODE_MODULE_CONTEXT_AWARE_BUILTIN -> NODE_BUILTIN_MODULE_CONTEXT_AWARE * update NodePlatform to MultiIsolatePlatform * fix linting error * update node ref * REVIEW: Explicitly register builtin modules nodejs/node#16565 * update libcc ref * switch libcc to c62 * REVIEW: Address node api changes - Always start the inspector agent for nodejs/node#17085 - Set the tracing controller for node nodejs/node#15538 - Isolate data creation now requires plaform nodejs/node#16700
* update submodule refs for node v9.3.0 * Define "llvm_version" for Node.js build * NODE_MODULE_CONTEXT_AWARE_BUILTIN -> NODE_BUILTIN_MODULE_CONTEXT_AWARE * update NodePlatform to MultiIsolatePlatform * fix linting error * update node ref * REVIEW: Explicitly register builtin modules nodejs/node#16565 * update libcc ref * switch libcc to c62 * REVIEW: Address node api changes - Always start the inspector agent for nodejs/node#17085 - Set the tracing controller for node nodejs/node#15538 - Isolate data creation now requires plaform nodejs/node#16700
Previously, built-in modules are registered before main() via
__attribute__((constructor))
mechanism in GCC and similiarmechanism in MSVC. This causes some issues when node is built as
static library. Calling module registration function for built-in
modules in node::Init() helps to avoid the issues.
Refs: #14986 (comment)
Signed-off-by: Yihong Wang yh.wang@ibm.com
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)