Skip to content

Commit 0a81ad4

Browse files
committed
dynamically search with base nix store path
1 parent dffff3d commit 0a81ad4

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/rtld_loader.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ char* la_objsearch(const char* name, uintptr_t* cookie, unsigned int flag) {
3939
log_debug(", ");
4040
log_debug_int(flag);
4141
log_debug(")\n");
42-
if (flag == LA_SER_DEFAULT && strncmp(name, "/nix/store", 10) != 0) {
42+
if (flag == LA_SER_DEFAULT) {
4343
char* libname = my_strrchr(name, '/');
4444
if (libname != NULL) {
4545
libname++; // advance past the /
@@ -48,7 +48,21 @@ char* la_objsearch(const char* name, uintptr_t* cookie, unsigned int flag) {
4848
log_info("\n searching...\n");
4949
const char* result = NULL;
5050
if (result == NULL) {
51-
result = dynamic_lookup(libname, replit_ld_library_path);
51+
if (strstartswith("/nix/store/", name)) {
52+
// Count slashes to find the 5th one (after /nix/store/hash-name/lib/)
53+
int slash_count = 0;
54+
int i;
55+
for (i = 0; name[i] && slash_count < 5; i++) {
56+
if (name[i] == '/') slash_count++;
57+
}
58+
char extended_path[MAX_LD_LIBRARY_PATH_LENGTH];
59+
my_strncpy(extended_path, name, i);
60+
extended_path[i - 1] = ':';
61+
my_strncpy(extended_path + i, replit_ld_library_path, MAX_LD_LIBRARY_PATH_LENGTH - i - 1);
62+
result = dynamic_lookup(libname, extended_path);
63+
} else {
64+
result = dynamic_lookup(libname, replit_ld_library_path);
65+
}
5266
if (result != NULL) {
5367
log_info(" found dynamically: ");
5468
log_info(result);

0 commit comments

Comments
 (0)