Skip to content

New dlopen flags API #12848

Closed
Closed
@ezequielgarcia

Description

@ezequielgarcia

Let's discuss how an API for dlopen flags should look like. A proposal has been made on #12794, where it was clear that once we sort out the API, the implementation is fairly straightforward.

As @jasnell and @sam-github pointed out it would be ideal to be able to pass these flags to act locally to a specific addon. On the other hand, this might require more work.

Setting global dlopen flags seems easier, at the cost of being potentially more fragile. Indeed, it would pollute the namespace, breaking if two addons load collisioning symbols. On the other side, this is highly unlikely. In favor of this, note that the global solution is what Python seems to do.

So, I propose two APIs:

(1) Global, using process module. Similar to #12794.

process.setdlopenFlags(os.constants.dlopen.RTLD_NOW | os.constants.dlopen.RTLD_GLOBAL);
var foo = require('foo');
process.setdlopenFlags(0);

(2) Also global (?), putting the setter in the require object:

require.setdlopenFlags(os.constants.dlopen.RTLD_NOW | os.constants.dlopen.RTLD_GLOBAL);
var foo = require('foo');
require.setdlopenFlags(0);

IMO, in this last case, the semantics are misleading. When the require.setdlopenFlags() call is made, the current module has already been loaded. So the dlopen flags are set for a JS script that is already loaded. The Module instance for the addon has to check its parent dlopen flags.

(3) Local to an addon, passing an object as an extra argument to require().

var os = require('os');
var foo = require('foo', {dlopenFlags: os.constants.dlopen.RTLD_NOW | os.constants.dlopen.RTLD_GLOBAL})

As far as I can see, passing an argument to require is the only way of keeping the flag local to a module. The addon to-be-loaded must first create a Module instance, which is created in the context of the require call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    addonsIssues and PRs related to native addons.feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions