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