emscripten-core / emscripten-core/emscripten
`dlopen` missing shared lib twice returns nonzero result in non-debug builds
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Source file:
```C
#include
#include
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:
```sh
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:
```sh
$ 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
```
Contributor guide
Assessment
This issue has not been assessed yet.