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

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

Comments

Projects
None yet
4 participants

No description provided.

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!

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

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

Owner

bnoordhuis commented Mar 27, 2012

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

bnoordhuis closed this Mar 27, 2012

ezequielgarcia referenced this issue in nodejs/node May 2, 2017

Open

Add process.dlopenFlags #12794

3 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment