Skip to content

Commit b5f9779

Browse files
orangemochatjfontaine
authored andcommitted
windows: fix module registration
The linker was optimizing the static variables that were supposed to trigger module initialization. I am making them non-static, and dllexport so that they don't get optimized away. Fixes #7116
1 parent 2ca4d9d commit b5f9779

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/node.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,16 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
332332
#pragma section(".CRT$XCU", read)
333333
#define NODE_C_CTOR(fn) \
334334
static void __cdecl fn(void); \
335-
__declspec(allocate(".CRT$XCU")) static void (__cdecl*fn ## _)(void) = fn; \
335+
__declspec(dllexport, allocate(".CRT$XCU")) \
336+
void (__cdecl*fn ## _)(void) = fn; \
336337
static void __cdecl fn(void)
337338
#else
338339
#define NODE_C_CTOR(fn) \
339340
static void fn(void) __attribute__((constructor)); \
340341
static void fn(void)
341342
#endif
342343

343-
#define NODE_MODULE_X(modstr, regfunc, priv, flags) \
344+
#define NODE_MODULE_X(modname, regfunc, priv, flags) \
344345
extern "C" { \
345346
static node::node_module _module = \
346347
{ \
@@ -350,16 +351,16 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
350351
__FILE__, \
351352
(node::addon_register_func) (regfunc), \
352353
NULL, \
353-
modstr, \
354+
NODE_STRINGIFY(modname), \
354355
priv, \
355356
NULL \
356357
}; \
357-
NODE_C_CTOR(_register) { \
358+
NODE_C_CTOR(_register_ ## modname) { \
358359
node_module_register(&_module); \
359360
} \
360361
}
361362

362-
#define NODE_MODULE_CONTEXT_AWARE_X(modstr, regfunc, priv, flags) \
363+
#define NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, priv, flags) \
363364
extern "C" { \
364365
static node::node_module _module = \
365366
{ \
@@ -369,24 +370,23 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
369370
__FILE__, \
370371
NULL, \
371372
(node::addon_context_register_func) (regfunc), \
372-
modstr, \
373+
NODE_STRINGIFY(modname), \
373374
priv, \
374375
NULL \
375376
}; \
376-
NODE_C_CTOR(_register) { \
377+
NODE_C_CTOR(_register_ ## modname) { \
377378
node_module_register(&_module); \
378379
} \
379380
}
380381

381382
#define NODE_MODULE(modname, regfunc) \
382-
NODE_MODULE_X(NODE_STRINGIFY(modname), regfunc, NULL, 0)
383+
NODE_MODULE_X(modname, regfunc, NULL, 0)
383384

384385
#define NODE_MODULE_CONTEXT_AWARE(modname, regfunc) \
385-
NODE_MODULE_CONTEXT_AWARE_X(NODE_STRINGIFY(modname), regfunc, NULL, 0)
386+
NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, 0)
386387

387388
#define NODE_MODULE_CONTEXT_AWARE_BUILTIN(modname, regfunc) \
388-
NODE_MODULE_CONTEXT_AWARE_X(NODE_STRINGIFY(modname), \
389-
regfunc, NULL, NM_F_BUILTIN)
389+
NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, NM_F_BUILTIN) \
390390

391391
/*
392392
* For backward compatibility in add-on modules.

0 commit comments

Comments
 (0)