nodejs / nodejs/node

Support loading dynamic addon modules (`.node` files) when embedding the Node.js shared library without needing to link with `node.def`

Open
#52,282 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

What is the problem this feature will solve?

Node.js addon modules on Windows current import from the node.exe executable, when you build Node.js as a shared library, it reexports all the needed symbols from the node shared library from the executable using a generated node.def file.

If you embed the Node.js shared library into a different executable/program, for loading such addon modules to work, that executable will need to be linked with node.def to reexport the needed symbols.

node-gyp also adds win_delay_load_hook.cc to addons on Windows to make them work when the Node.js executable is renamed.

What is the feature you are proposing to solve the problem?

Maybe we can support loading such addon modules without this requirement?

For example, what if the delay load hook looked for an env var (e.g. NODE_LIBRARY) that it would then pass to GetModuleHandle instead of NULL if it is set, and when Node.js is built as a shared library, it would set this env var before dynamically loading a module?

Though I'm not sure what security implications such a mechanism may have...

What alternatives have you considered?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with node-gyp's win_delay_load_hook.cc and the Node.js shared-library loading path described in the issue, including node.def and GetModuleHandle. Determine a supported mechanism for embedded programs to load .node modules without linking node.def, and define the security behavior; done means this works for embedded Node.js on Windows without breaking renamed executables.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.