Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NODE_RTLD_GLOBAL to control library loading #4105

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/uv/docs/src/dll.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ N/A
API
---

.. c:function:: int uv_dlopen(const char* filename, uv_lib_t* lib)
.. c:function:: int uv_dlopen(const char* filename, uv_lib_t* lib, int glob)

Opens a shared library. The filename is in utf-8. Returns 0 on success and
-1 on error. Call :c:func:`uv_dlerror` to get the error message.
Expand Down
2 changes: 1 addition & 1 deletion deps/uv/include/uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ UV_EXTERN extern uint64_t uv_hrtime(void);

UV_EXTERN void uv_disable_stdio_inheritance(void);

UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib);
UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib, int glob);
UV_EXTERN void uv_dlclose(uv_lib_t* lib);
UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr);
UV_EXTERN const char* uv_dlerror(const uv_lib_t* lib);
Expand Down
12 changes: 10 additions & 2 deletions deps/uv/src/unix/dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@
static int uv__dlerror(uv_lib_t* lib);


int uv_dlopen(const char* filename, uv_lib_t* lib) {
int uv_dlopen(const char* filename, uv_lib_t* lib, int glob) {
int flag;

dlerror(); /* Reset error status. */
lib->errmsg = NULL;
lib->handle = dlopen(filename, RTLD_LAZY);

flag = RTLD_LAZY;
if (glob) {
flag |= RTLD_GLOBAL;
}

lib->handle = dlopen(filename, flag);
return lib->handle ? 0 : uv__dlerror(lib);
}

Expand Down
2 changes: 1 addition & 1 deletion deps/uv/src/win/dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
static int uv__dlerror(uv_lib_t* lib, int errorno);


int uv_dlopen(const char* filename, uv_lib_t* lib) {
int uv_dlopen(const char* filename, uv_lib_t* lib, int glob) {
WCHAR filename_w[32768];

lib->handle = NULL;
Expand Down
2 changes: 1 addition & 1 deletion deps/uv/test/test-dlerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ TEST_IMPL(dlerror) {
ASSERT(msg != NULL);
ASSERT(strstr(msg, dlerror_no_error) != NULL);

r = uv_dlopen(path, &lib);
r = uv_dlopen(path, &lib, false);
ASSERT(r == -1);

msg = uv_dlerror(&lib);
Expand Down
3 changes: 2 additions & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ Module._extensions['.json'] = function(module, filename) {

//Native extension for .node
Module._extensions['.node'] = function(module, filename) {
return process.dlopen(module, path._makeLong(filename));
const dlOpenFlag = process.env.NODE_RTLD_GLOBAL === "true";
return process.dlopen(module, path._makeLong(filename), dlOpenFlag);
};


Expand Down
9 changes: 5 additions & 4 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,7 @@ struct node_module* get_linked_module(const char* name) {

typedef void (UV_DYNAMIC* extInit)(Local<Object> exports);

// DLOpen is process.dlopen(module, filename).
// DLOpen is process.dlopen(module, filename, [glob=false]).
// Used to load 'module.node' dynamically shared objects.
//
// FIXME(bnoordhuis) Not multi-context ready. TBD how to resolve the conflict
Expand All @@ -2165,14 +2165,15 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {

CHECK_EQ(modpending, nullptr);

if (args.Length() != 2) {
env->ThrowError("process.dlopen takes exactly 2 arguments.");
if (args.Length() < 2 || args.Length() > 3) {
env->ThrowError("process.dlopen takes at least 2 arguments.");
return;
}

Local<Object> module = args[0]->ToObject(env->isolate()); // Cast
node::Utf8Value filename(env->isolate(), args[1]); // Cast
const bool is_dlopen_error = uv_dlopen(*filename, &lib);
const bool dl_open_flag = args.Length() == 3 && args[2]->IsBoolean() && args[2]->BooleanValue();
const bool is_dlopen_error = uv_dlopen(*filename, &lib, dl_open_flag);

// Objects containing v14 or later modules will have registered themselves
// on the pending list. Activate all of them now. At present, only one
Expand Down