Skip to content

Commit 1c95c8b

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

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

src/rtld_loader.c

Lines changed: 21 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,26 @@ 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+
char extended_path[MAX_LD_LIBRARY_PATH_LENGTH];
52+
const char* search_path = replit_ld_library_path;
53+
54+
if (strstartswith("/nix/store/", name)) {
55+
// Count slashes to find the 5th one (after /nix/store/hash-name/lib/)
56+
int slash_count = 0;
57+
int i;
58+
for (i = 0; name[i] && slash_count < 5; i++) {
59+
if (name[i] == '/') slash_count++;
60+
}
61+
// Check if it's actually a /lib/ directory
62+
if (i >= 5 && strneql(name + i - 5, "/lib/", 5)) {
63+
my_strncpy(extended_path, name, i);
64+
extended_path[i - 1] = ':';
65+
my_strncpy(extended_path + i, replit_ld_library_path, MAX_LD_LIBRARY_PATH_LENGTH - i - 1);
66+
search_path = extended_path;
67+
}
68+
}
69+
70+
result = dynamic_lookup(libname, search_path);
5271
if (result != NULL) {
5372
log_info(" found dynamically: ");
5473
log_info(result);

0 commit comments

Comments
 (0)