From e4f79b7167312dab649218b53b84c0829ea0c103 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Mon, 10 May 2021 11:38:48 -0400 Subject: [PATCH] [CLI] ensure error on not finding symbol (#40748) This sanity check was attempted in #38994, but dlsym is often also okay with finding the trampoline, so we want to also check that it does not use that to resolve the trampoline ad infinitum. --- cli/jl_exports.h | 14 ++++++++++---- cli/loader_lib.c | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cli/jl_exports.h b/cli/jl_exports.h index 0d467a6528b75..35d2767726865 100644 --- a/cli/jl_exports.h +++ b/cli/jl_exports.h @@ -10,13 +10,19 @@ JL_EXPORTED_DATA_POINTERS(XX) #undef XX -// Define symbol data as `$type) $(name);` +// Define symbol data as `$(type) $(name);` #define XX(name, type) JL_DLLEXPORT type name; JL_EXPORTED_DATA_SYMBOLS(XX) #undef XX -// Define holder locations for function addresses as `const void * $(name)_addr` -#define XX(name) JL_HIDDEN const void * name##_addr; +// Declare list of exported functions (sans type) +#define XX(name) JL_DLLEXPORT void name(void); +typedef void (anonfunc)(void); +JL_EXPORTED_FUNCS(XX) +#undef XX + +// Define holder locations for function addresses as `const void * $(name)_addr = & $(name);` +#define XX(name) JL_HIDDEN anonfunc * name##_addr = (anonfunc*)&name; JL_EXPORTED_FUNCS(XX) #undef XX @@ -29,7 +35,7 @@ static const char *const jl_exported_func_names[] = { #undef XX #define XX(name) &name##_addr, -static const void ** jl_exported_func_addrs[] = { +static anonfunc **const jl_exported_func_addrs[] = { JL_EXPORTED_FUNCS(XX) NULL }; diff --git a/cli/loader_lib.c b/cli/loader_lib.c index 2f596ac27202d..f7858d9bc909f 100644 --- a/cli/loader_lib.c +++ b/cli/loader_lib.c @@ -161,7 +161,7 @@ __attribute__((constructor)) void jl_load_libjulia_internal(void) { // Once we have libjulia-internal loaded, re-export its symbols: for (unsigned int symbol_idx=0; jl_exported_func_names[symbol_idx] != NULL; ++symbol_idx) { void *addr = lookup_symbol(libjulia_internal, jl_exported_func_names[symbol_idx]); - if (addr == NULL) { + if (addr == NULL || addr == *jl_exported_func_addrs[symbol_idx]) { jl_loader_print_stderr3("ERROR: Unable to load ", jl_exported_func_names[symbol_idx], " from libjulia-internal"); exit(1); }