Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
22620d5
Locate shared libraries using rpath
ryanking13 Mar 9, 2025
dfa80d8
Use rpath to load shared libraries
ryanking13 Mar 9, 2025
3b9d68e
Update test
ryanking13 Mar 9, 2025
39db974
ruff
ryanking13 Mar 9, 2025
1568cfe
Automatic rebaseline of codesize expectations. NFC
ryanking13 Mar 9, 2025
4f3ffe5
Don't run test on pthread
ryanking13 Mar 9, 2025
e49d1a2
Fix wasmfs test
ryanking13 Mar 9, 2025
82b38da
Automatic rebaseline of codesize expectations. NFC
ryanking13 Mar 9, 2025
3689d4e
ruff
ryanking13 Mar 9, 2025
a0732d7
Address comments
ryanking13 Mar 10, 2025
defefc2
Make closure compiler happy
ryanking13 Mar 10, 2025
8a7196d
Automatic rebaseline of codesize expectations. NFC
ryanking13 Mar 10, 2025
5511492
Merge remote-tracking branch 'upstream/main' into dylink-rpath
ryanking13 Mar 11, 2025
abacbf0
Fix tests
ryanking13 Mar 11, 2025
2df17b3
Automatic rebaseline of codesize expectations. NFC
ryanking13 Mar 11, 2025
0603c0a
Merge branch 'main' into dylink-rpath
hoodmane Mar 31, 2025
b23485c
Use C function for path lookup
hoodmane Mar 31, 2025
47f36f4
Revert "Use C function for path lookup"
hoodmane Mar 31, 2025
76d8fc8
Add also_with_wasmfs decorator
hoodmane Mar 31, 2025
17191ba
Revert "Revert "Use C function for path lookup""
hoodmane Mar 31, 2025
820805a
Call wasmExports._emscripten_resolve_path directly
hoodmane Mar 31, 2025
105e771
Tidy up
hoodmane Mar 31, 2025
bbc7be9
Rename test to test_dlopen_rpath
hoodmane Mar 31, 2025
c6c5bdc
Fix tests
hoodmane Apr 1, 2025
d03329b
Revert codesizes
hoodmane Apr 1, 2025
f2a839f
Remove repeat declarations
hoodmane Apr 1, 2025
676e156
Add SUPPORT_RPATH setting
hoodmane Apr 1, 2025
8edc342
Update settings_reference.rst
hoodmane Apr 1, 2025
0895d17
Fix test
hoodmane Apr 1, 2025
0848d77
Fix again
hoodmane Apr 2, 2025
e0b3fba
Merge branch 'main' into dylink-rpath
hoodmane Apr 2, 2025
59875c4
Remove SUPPORT_RPATH
hoodmane Apr 2, 2025
4e4ab33
Update codesize
hoodmane Apr 2, 2025
7e98557
Fix indentation and use withStackSave
hoodmane Apr 2, 2025
6fee8c9
Move RPATH lookup below checks for loadedLibsByName and handle
hoodmane Apr 2, 2025
0af5e3c
Cleanup
hoodmane Apr 2, 2025
4904e56
Move rpath to end of arguments list and remove default
hoodmane Apr 2, 2025
3e1ccce
Merge branch 'main' into dylink-rpath
hoodmane Apr 2, 2025
be22217
Put rpath in flags
hoodmane Apr 2, 2025
e27a006
parentLibPath ==> parentLibName
hoodmane Apr 2, 2025
caf817c
Add comment
hoodmane Apr 2, 2025
97a764d
Merge branch 'main' into dylink-rpath
hoodmane Apr 4, 2025
8763702
Fix wasmfs
hoodmane Apr 4, 2025
bb0240a
Fix in wasmfs
hoodmane Apr 4, 2025
8040eee
Add _emscripten_resolve_path to create_pointer_conversion_wrappers
hoodmane Apr 4, 2025
80b3763
Update codesize
hoodmane Apr 4, 2025
a52f4a8
Rename _emscripten_resolve_path to _emscripten_find_dylib
hoodmane Apr 15, 2025
db81df7
Factor out findLibraryFS
hoodmane Apr 15, 2025
39d91b4
Fix refactor
hoodmane Apr 15, 2025
8e3d3e0
Some test cleanup
hoodmane Apr 15, 2025
fb7ca61
Rename hello1* to hello*
hoodmane Apr 15, 2025
f164ddc
Format fixes
hoodmane Apr 15, 2025
7422fc9
Add comment on why we copy flags rather than mutating.
hoodmane Apr 15, 2025
31ac4ce
Quit out earlier if runtime not initialized and add comment
hoodmane Apr 15, 2025
6c37485
Merge branch 'main' into dylink-rpath
hoodmane Apr 15, 2025
ff9c431
Update codesizes
hoodmane Apr 15, 2025
412fb96
Fix ruff lint
hoodmane Apr 15, 2025
61e93e6
Address some review comments
hoodmane Apr 16, 2025
d5bf161
Simplify path_find
hoodmane Apr 16, 2025
e3a2ff8
Indentation
hoodmane Apr 16, 2025
aa85192
Make `_emscripten_resolve_path` return `NULL` if it didn't resolve th…
hoodmane Apr 16, 2025
5d3620e
adjust test_ld_library_path
hoodmane Apr 16, 2025
e66a372
Revert unneeded change
hoodmane Apr 16, 2025
2e41541
Fix codesize_hello_dylink again
hoodmane Apr 16, 2025
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
Prev Previous commit
Next Next commit
Simplify path_find
  • Loading branch information
hoodmane committed Apr 16, 2025
commit d5bf161b77b3a3b28dc6230ece8585b936ae8c44
69 changes: 31 additions & 38 deletions system/lib/libc/dynlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,58 +484,51 @@ static void dlopen_onerror(struct dso* dso, void* user_data) {
}

// Modified version of path_open from musl/ldso/dynlink.c
static int path_find(const char *name, int ncandidates, const char **candidates, char *buf, size_t buf_size) {
static int path_find(const char *name, const char *s, char *buf, size_t buf_size) {
if (s == NULL) {
return -1;
}
size_t l;
int fd;
for (int c = 0; c < ncandidates; c ++) {
const char* s = candidates[c];
if (s == NULL) {
dbg("Candidate %d is null, skipping\n", c);
continue;
}
dbg("Candidate %d...\n", c);
for (;;) {
s += strspn(s, ":\n");
l = strcspn(s, ":\n");
if (l-1 >= INT_MAX) return -1;
if (snprintf(buf, buf_size, "%.*s/%s", (int)l, s, name) < buf_size) {
dbg("dlopen: path_find: %s", buf);
struct stat statbuf;
dbg("Checking file: %s\n", buf);
if (stat(buf, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) {
dbg(" .. found\n");
return 0;
}
dbg(" .. not found\n");
switch (errno) {
case ENOENT:
case ENOTDIR:
case EACCES:
case ENAMETOOLONG:
break;
default:
dbg("dlopen: path_find failed: %s", strerror(errno));
/* Any negative value but -1 will inhibit
* futher path search. */
return -2;
}
for (;;) {
s += strspn(s, ":\n");
l = strcspn(s, ":\n");
if (l-1 >= INT_MAX) return -1;
if (snprintf(buf, buf_size, "%.*s/%s", (int)l, s, name) < buf_size) {
dbg("dlopen: path_find: %s", buf);
struct stat statbuf;
if (stat(buf, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) {
return 0;
}
switch (errno) {
case ENOENT:
case ENOTDIR:
case EACCES:
case ENAMETOOLONG:
break;
default:
dbg("dlopen: path_find failed: %s", strerror(errno));
/* Any negative value but -1 will inhibit
* futher path search. */
return -2;
}
s += l;
}
s += l;
}
return -1;
}

// Resolve filename using LD_LIBRARY_PATH
const char* _emscripten_find_dylib(char* buf, const char* rpath, const char* file, size_t buflen) {
if (!strchr(file, '/')) {
const char* env_path = getenv("LD_LIBRARY_PATH");
int ncandidates = 2;
const char* candidates[2] = {env_path, rpath};
if (path_find(file, ncandidates, candidates, buf, buflen) == 0) {
if (path_find(file, env_path, buf, buflen) == 0) {
dbg("dlopen: found in LD_LIBRARY_PATH: %s", buf);
return buf;
}
if (path_find(file, rpath, buf, buflen) == 0) {
dbg("dlopen: found in RPATH: %s", buf);
return buf;
}
}
return file;
}
Expand Down
Loading