@@ -16,7 +16,7 @@ extern "C" {
16
16
#endif
17
17
18
18
// Save DEP_LIBS to a variable that is explicitly sized for expansion
19
- static char dep_libs [512 ] = DEP_LIBS ;
19
+ static char dep_libs [1024 ] = DEP_LIBS ;
20
20
21
21
JL_DLLEXPORT void jl_loader_print_stderr (const char * msg )
22
22
{
@@ -31,7 +31,7 @@ void jl_loader_print_stderr3(const char * msg1, const char * msg2, const char *
31
31
}
32
32
33
33
/* Wrapper around dlopen(), with extra relative pathing thrown in*/
34
- static void * load_library (const char * rel_path , const char * src_dir ) {
34
+ static void * load_library (const char * rel_path , const char * src_dir , int err ) {
35
35
void * handle = NULL ;
36
36
37
37
// See if a handle is already open to the basename
@@ -65,6 +65,8 @@ static void * load_library(const char * rel_path, const char * src_dir) {
65
65
#endif
66
66
67
67
if (handle == NULL ) {
68
+ if (!err )
69
+ return NULL ;
68
70
jl_loader_print_stderr3 ("ERROR: Unable to load dependent library " , path , "\n" );
69
71
#if defined(_OS_WINDOWS_ )
70
72
LPWSTR wmsg = TEXT ("" );
@@ -157,31 +159,75 @@ __attribute__((constructor)) void jl_load_libjulia_internal(void) {
157
159
// Pre-load libraries that libjulia-internal needs.
158
160
int deps_len = strlen (dep_libs );
159
161
char * curr_dep = & dep_libs [0 ];
162
+
163
+ // We keep track of "special" libraries names (ones whose name is prefixed with `@`)
164
+ // which are libraries that we want to load in some special, custom way, such as
165
+ // `libjulia-internal` or `libjulia-codegen`.
166
+ int special_idx = 0 ;
167
+ char * special_library_names [2 ] = {NULL };
160
168
while (1 ) {
161
- // try to find next colon character, if we can't, escape out.
169
+ // try to find next colon character; if we can't, break out
162
170
char * colon = strchr (curr_dep , ':' );
163
171
if (colon == NULL )
164
172
break ;
165
173
166
- // Chop the string at the colon, load this library.
174
+ // Chop the string at the colon so it's a valid-ending-string
167
175
* colon = '\0' ;
168
- load_library (curr_dep , lib_dir );
176
+
177
+ // If this library name starts with `@`, don't open it here (but mark it as special)
178
+ if (curr_dep [0 ] == '@' ) {
179
+ if (special_idx > sizeof (special_library_names )/sizeof (char * )) {
180
+ jl_loader_print_stderr ("ERROR: Too many special library names specified, check LOADER_BUILD_DEP_LIBS and friends!\n" );
181
+ exit (1 );
182
+ }
183
+ special_library_names [special_idx ] = curr_dep + 1 ;
184
+ special_idx += 1 ;
185
+ } else {
186
+ load_library (curr_dep , lib_dir , 1 );
187
+ }
169
188
170
189
// Skip ahead to next dependency
171
190
curr_dep = colon + 1 ;
172
191
}
173
192
174
- // Last dependency is `libjulia-internal`, so load that and we're done with `dep_libs`!
175
- libjulia_internal = load_library (curr_dep , lib_dir );
193
+ if (special_idx != sizeof (special_library_names )/sizeof (char * )) {
194
+ jl_loader_print_stderr ("ERROR: Too few special library names specified, check LOADER_BUILD_DEP_LIBS and friends!\n" );
195
+ exit (1 );
196
+ }
197
+
198
+ // Unpack our special library names. This is why ordering of library names matters.
199
+ libjulia_internal = load_library (special_library_names [0 ], lib_dir , 1 );
200
+ void * libjulia_codegen = load_library (special_library_names [1 ], lib_dir , 0 );
201
+ const char * const * codegen_func_names ;
202
+ if (libjulia_codegen == NULL ) {
203
+ // if codegen is not available, use fallback implementation in libjulia-internal
204
+ libjulia_codegen = libjulia_internal ;
205
+ codegen_func_names = jl_codegen_fallback_func_names ;
206
+ }
207
+ else {
208
+ codegen_func_names = jl_codegen_exported_func_names ;
209
+ }
176
210
177
211
// Once we have libjulia-internal loaded, re-export its symbols:
178
- for (unsigned int symbol_idx = 0 ; jl_exported_func_names [symbol_idx ] != NULL ; ++ symbol_idx ) {
179
- void * addr = lookup_symbol (libjulia_internal , jl_exported_func_names [symbol_idx ]);
212
+ for (unsigned int symbol_idx = 0 ; jl_runtime_exported_func_names [symbol_idx ] != NULL ; ++ symbol_idx ) {
213
+ void * addr = lookup_symbol (libjulia_internal , jl_runtime_exported_func_names [symbol_idx ]);
214
+ if (addr == NULL ) {
215
+ jl_loader_print_stderr3 ("ERROR: Unable to load " , jl_runtime_exported_func_names [symbol_idx ], " from libjulia-internal\n" );
216
+ exit (1 );
217
+ }
218
+ (* jl_runtime_exported_func_addrs [symbol_idx ]) = addr ;
219
+ }
220
+ // jl_options must be initialized very early, in case an embedder sets some
221
+ // values there before calling jl_init
222
+ ((void (* )())jl_init_options_addr )();
223
+
224
+ for (unsigned int symbol_idx = 0 ; codegen_func_names [symbol_idx ] != NULL ; ++ symbol_idx ) {
225
+ void * addr = lookup_symbol (libjulia_codegen , codegen_func_names [symbol_idx ]);
180
226
if (addr == NULL ) {
181
- jl_loader_print_stderr3 ("ERROR: Unable to load " , jl_exported_func_names [symbol_idx ], " from libjulia-internal \n" );
227
+ jl_loader_print_stderr3 ("ERROR: Unable to load " , codegen_func_names [symbol_idx ], " from libjulia-codegen \n" );
182
228
exit (1 );
183
229
}
184
- (* jl_exported_func_addrs [symbol_idx ]) = addr ;
230
+ (* jl_codegen_exported_func_addrs [symbol_idx ]) = addr ;
185
231
}
186
232
187
233
// jl_options must be initialized very early, in case an embedder sets some
0 commit comments