Skip to content

dlopen ignores RTLD_GLOBAL when reopening an RTLD_LOCAL library #28058

Open

Description

@anutosh491

Reopening an RTLD_LOCAL library with RTLD_GLOBAL succeeds, but its symbols remain unavailable through RTLD_DEFAULT.
Reproduced with Emscripten 6.0.8 on both wasm32 and wasm64.

cat > test.c <<'EOF'
#ifdef BUILD_PROVIDER
int answer_value = 42;
int answer(void) { return answer_value; }
#else
#include <assert.h>
#include <dlfcn.h>
#include <stdio.h>

int main(void) {
  void *handle = dlopen("./provider.so", RTLD_NOW | RTLD_LOCAL);
  assert(handle);
  int (*answer_fn)(void) = dlsym(handle, "answer");
  assert(answer_fn && answer_fn() == 42);
  puts("Handle-specific lookup: 42");

  assert(dlopen("./provider.so", RTLD_NOW | RTLD_GLOBAL) == handle);
  dlerror();
  answer_fn = dlsym(RTLD_DEFAULT, "answer");
  if (!answer_fn) {
    printf("FAIL: %s\n", dlerror());
    return 1;
  }
  printf("Global lookup: %d\n", answer_fn());
  return 0;
}
#endif
EOF

Build the shared library:

emcc test.c -DBUILD_PROVIDER -shared -fPIC -m64 -fwasm-exceptions -O1 \
  -Wl,--export=answer -Wl,--export=answer_value -o provider.so

Build and run the main module:

emcc test.c -m64 -fwasm-exceptions -O1 \
  -sMAIN_MODULE=2 -sENVIRONMENT=node -sEXIT_RUNTIME=1 \
  --embed-file provider.so -o test.js

node test.js

Actual output (exit code 1):

Handle-specific lookup: 42
FAIL: Tried to lookup unknown symbol "answer" in dynamic lib: __main__

Expected: Global lookup: 42.

Replacing both -m64 flags with -m32 produces the same failure.

Activity

  1. anutosh491 commented on Oct 23, 2026

    @anutosh491
    Author

    I tried a fix locally, maybe if someone (cc @sbc100) who confirm the issue is legit i can submit something !

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions