Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Ability to set dlopen flags used to load .node modules #436

Closed
springmeyer opened this issue Nov 18, 2010 · 4 comments
Closed

Ability to set dlopen flags used to load .node modules #436

springmeyer opened this issue Nov 18, 2010 · 4 comments

Comments

@springmeyer
Copy link

No description provided.

@springmeyer
Copy link
Author

The dlopen call in node.cc uses RTLD_LAZY:

https://github.com/ry/node/blob/master/src/node.cc#L1257

Would it be possible to expose the ability to customize those flags? I've found I need to be able to pass RTLD_NOW in a specific circumstance (see explanation below). If this is acceptable I will then start work on a patch to node.cc.

The background on needing to pass RTLD_NOW is this:

I am writing a node addon in C++, wrapping Mapnik (http://mapnik.org) and mapnik has, itself, a plugin system that uses dlopen. Calls inside of Mapnik to dlopen on linux fail because the symbols of the mapnik library are not visible within the node process that mapnik.node has been loaded into. My sense is that this fails because RTLD_LAZY does not make the mapnik symbols available to mapnik's plugins. If I change RTLD_LAZY to RTLD_NOW in node.cc#L1257 the loading of mapnik plugins immediately starts working.

My workaround right now is suboptimal, basically I've found I can "preload" the necessary mapnik symbols by manually calling dlopen with the RTLD flag from the node module:

mapnik/node-mapnik@58ece58

Instead I would love to do something more like this in index.js:

var sys = require('sys');
if (process.platform == "linux")
    sys.set_dlopen_flags(sys.RTLD_NOW|sys.RTLD_GLOBAL);

This would be similar to python:

http://docs.python.org/library/sys.html#sys.setdlopenflags

Any feedback greatly appreciated!

@volkmuth
Copy link

I ran into the same problem you describe. I made the change you suggested, though instead of putting the dlopen flags in sys I put them in process. I also added the relevant constants from dlfcn.h to node_constants.h. E.g.,
var c = require('constants');
var oldFlags = process.dlOpenFlags;
process.dlOpenFlags = c.RTLD_LAZY | c.RTLD_GLOBAL;
var x = require('some_dynamically_loaded_node_extension');
process.dlOpenFlags = oldFlags;

If you have a chance test it with your mapnik extension and see if it works ok for you.

https://github.com/volkmuth/node/commit/a77a3394713b03a2298192d4a40956a22555d6d1

@TooTallNate
Copy link

I've encountered the need to call dlopen in a native module I'm creating as well, so +1 from me.

@bnoordhuis
Copy link
Member

I'm going to close this. If someone still has problems loading shared objects from modules, please open a libuv issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants