Skip to content

Commit

Permalink
eliminate internal SONAME mapping
Browse files Browse the repository at this point in the history
This is now handled more reliably by our build-system and external packages.
  • Loading branch information
vtjnash committed Dec 4, 2017
1 parent b8ee561 commit 0cdec63
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 140 deletions.
1 change: 0 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6620,7 +6620,6 @@ extern "C" void *jl_init_llvm(void)
jl_page_size = jl_getpagesize();
imaging_mode = jl_generating_output();
jl_init_debuginfo();
jl_init_runtime_ccall();

#ifdef USE_POLLY
PassRegistry &Registry = *PassRegistry::getPassRegistry();
Expand Down
9 changes: 0 additions & 9 deletions src/dlload.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,6 @@ static void *jl_load_dynamic_library_(const char *modname, unsigned flags, int t
goto done;
}

#if defined(__linux__) || defined(__FreeBSD__)
// check map of versioned libs from "libX" to full soname "libX.so.ver"
if (!abspath && n_extensions > 1) { // soname map only works for libX
handle = jl_dlopen_soname(modname, strlen(modname), flags);
if (handle)
goto done;
}
#endif

notfound:
if (throw_err)
jl_dlerror("could not load library \"%s\"\n%s", modname);
Expand Down
4 changes: 0 additions & 4 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1419,10 +1419,6 @@ JL_DLLEXPORT int jl_dlclose(jl_uv_libhandle handle);
JL_DLLEXPORT void *jl_dlsym_e(jl_uv_libhandle handle, const char *symbol);
JL_DLLEXPORT void *jl_dlsym(jl_uv_libhandle handle, const char *symbol);

#if defined(__linux__) || defined(__FreeBSD__)
JL_DLLEXPORT const char *jl_lookup_soname(const char *pfx, size_t n);
#endif

// compiler
JL_DLLEXPORT jl_value_t *jl_toplevel_eval(jl_module_t *m, jl_value_t *v);
JL_DLLEXPORT jl_value_t *jl_toplevel_eval_in(jl_module_t *m, jl_value_t *ex);
Expand Down
2 changes: 0 additions & 2 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ void jl_init_serializer(void);
void jl_gc_init(void);
void jl_init_signal_async(void);
void jl_init_debuginfo(void);
void jl_init_runtime_ccall(void);
void jl_init_thread_heap(jl_ptls_t ptls);

void _julia_init(JL_IMAGE_SEARCH rel);
Expand Down Expand Up @@ -745,7 +744,6 @@ JL_DLLEXPORT void *jl_load_and_lookup(const char *f_lib, const char *f_name,
#define JL_EXE_LIBNAME ((const char*)1)
#define JL_DL_LIBNAME ((const char*)2)
const char *jl_dlfind_win32(const char *name);
void *jl_dlopen_soname(const char *pfx, size_t n, unsigned flags);

// libuv wrappers:
JL_DLLEXPORT int jl_fs_rename(const char *src_path, const char *dst_path);
Expand Down
120 changes: 0 additions & 120 deletions src/runtime_ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,126 +14,6 @@ using namespace llvm;

// --- library symbol lookup ---

// map from "libX" to full soname "libX.so.ver"
#if defined(__linux__) || defined(__FreeBSD__)
static uv_rwlock_t soname_lock;
static std::map<std::string, std::string> sonameMap;
static bool got_sonames = false;

extern "C" void jl_init_runtime_ccall(void)
{
uv_rwlock_init(&soname_lock);
}

// This reloads the sonames, necessary after system upgrade.
// Keep this DLLEXPORTed, this is used by `BinDeps.jl` to make sure
// newly installed libraries can be found.
extern "C" JL_DLLEXPORT void jl_read_sonames(void)
{
char *line=NULL;
size_t sz=0;
#if defined(__linux__)
FILE *ldc = popen("/sbin/ldconfig -p", "r");
#else
FILE *ldc = popen("/sbin/ldconfig -r", "r");
#endif
if (ldc == NULL) return; // ignore errors in running ldconfig (other than whatever might have been printed to stderr)

// This loop is not allowed to call julia GC while holding the lock
uv_rwlock_wrlock(&soname_lock);
sonameMap.clear();
while (!feof(ldc)) {
ssize_t n = getline(&line, &sz, ldc);
if (n == -1)
break;
if (n > 2 && isspace((unsigned char)line[0])) {
#ifdef __linux__
int i = 0;
while (isspace((unsigned char)line[++i])) ;
char *name = &line[i];
char *dot = strstr(name, ".so");
i = 0;
#else
char *name = strstr(line, ":-l");
if (name == NULL) continue;
strncpy(name, "lib", 3);
char *dot = strchr(name, '.');
#endif

if (NULL == dot)
continue;

#ifdef __linux__
// Detect if this entry is for the current architecture
while (!isspace((unsigned char)dot[++i])) ;
while (isspace((unsigned char)dot[++i])) ;
int j = i;
while (!isspace((unsigned char)dot[++j])) ;
char *arch = strstr(dot+i,"x86-64");
if (arch != NULL && arch < dot + j) {
#ifdef _P32
continue;
#endif
}
else {
#ifdef _P64
continue;
#endif
}
#endif // __linux__

char *abslibpath = strrchr(line, ' ');
if (dot != NULL && abslibpath != NULL) {
std::string pfx(name, dot - name);
// Do not include ' ' in front and '\n' at the end
std::string soname(abslibpath+1, line+n-(abslibpath+1)-1);
sonameMap[pfx] = soname;
}
}
}

free(line);
pclose(ldc);
uv_rwlock_wrunlock(&soname_lock);
}

// This API is not thread safe. The return value can be free'd if
// `jl_read_sonames()` is called on another thread.
extern "C" JL_DLLEXPORT const char *jl_lookup_soname(const char *pfx, size_t n)
{
if (!got_sonames) {
jl_read_sonames();
got_sonames = true;
}
const char *res = nullptr;
uv_rwlock_rdlock(&soname_lock);
auto search = sonameMap.find(std::string(pfx, n));
if (search != sonameMap.end())
res = search->second.c_str();
uv_rwlock_rdunlock(&soname_lock);
return res;
}

extern "C" void *jl_dlopen_soname(const char *pfx, size_t n, unsigned flags)
{
if (!got_sonames) {
jl_read_sonames();
got_sonames = true;
}
void *res = nullptr;
uv_rwlock_rdlock(&soname_lock);
auto search = sonameMap.find(std::string(pfx, n));
if (search != sonameMap.end())
res = jl_dlopen(search->second.c_str(), flags);
uv_rwlock_rdunlock(&soname_lock);
return res;
}
#else
extern "C" void jl_init_runtime_ccall(void)
{
}
#endif

// map from user-specified lib names to handles
static std::map<std::string, void*> libMap;
static jl_mutex_t libmap_lock;
Expand Down
4 changes: 0 additions & 4 deletions test/libdl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,4 @@ let dl = C_NULL
end
end

if Sys.KERNEL in (:Linux, :FreeBSD)
ccall(:jl_read_sonames, Void, ())
end

end

0 comments on commit 0cdec63

Please sign in to comment.