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

dlopen missing shared lib twice returns nonzero result in non-debug builds #22887

Open
hoodmane opened this issue Nov 8, 2024 · 0 comments
Open

Comments

@hoodmane
Copy link
Contributor

hoodmane commented Nov 8, 2024

Source file:

#include <dlfcn.h>
#include <stdio.h>

int main() {
    void* res = dlopen("a", RTLD_NOW);
    printf("res: %p\n", res);
    res = dlopen("a", RTLD_NOW);
    printf("res: %p\n", res);
    return 0;
}

Compile and run:

emcc a.c -sMAIN_MODULE=2
node a.out.js

behaves sort of as expected:

Error in loading dynamic library a: Error: ENOENT: no such file or directory, open '/home/rchatham/Documents/programming/emscripten/a'
res: 0
Aborted(Assertion failed: Attempt to load 'a' twice before the first load completed)
Error in loading dynamic library a: RuntimeError: Aborted(Assertion failed: Attempt to load 'a' twice before the first load completed)
res: 0

Even here I am concerned that if I later created a file called "a" which was a valid shared library, it would not succeed in opening it. Whereas native dlopen would work. But this isn't causing trouble.

The problem is if we compile with -O1, then it does not fail on the second call:

$ emcc a.c -sMAIN_MODULE=2 -O1
$ node a.out.js
res: 0
res: 0x10ef0

This is troublesome.

Version of emscripten/emsdk:

$ emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.72-git (b2ced9de42ea8028233d7d3588c45ce837b61185)
clang version 20.0.0git (https:/github.com/llvm/llvm-project 50866e84d1da8462aeb96607bf6d9e5bbd5869c5)
Target: wasm32-unknown-emscripten
Thread model: posix
@hoodmane hoodmane changed the title Attempting to load missing shared library twice returns a nonzero result in non-debug builds dlopen missing shared library twice returns nonzero result in non-debug builds Nov 8, 2024
@hoodmane hoodmane changed the title dlopen missing shared library twice returns nonzero result in non-debug builds dlopen missing shared lib twice returns nonzero result in non-debug builds Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant