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.
Also use the real name of the libatomic1 library (which includes the SONAME and extension).
  • Loading branch information
vtjnash committed Jan 22, 2018
1 parent dee5219 commit 28f3c06
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 143 deletions.
1 change: 0 additions & 1 deletion src/codegen.cpp
Expand Up @@ -6624,7 +6624,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
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
6 changes: 3 additions & 3 deletions src/jitlayers.cpp
Expand Up @@ -336,14 +336,14 @@ void NotifyDebugger(jit_code_entry *JITCodeEntry)
// ------------------------ END OF TEMPORARY COPY FROM LLVM -----------------

#if defined(_OS_LINUX_) || defined(_OS_WINDOWS_) || defined(_OS_FREEBSD_)
// Resolve non-lock free atomic functions in the libatomic library.
// Resolve non-lock free atomic functions in the libatomic1 library.
// This is the library that provides support for c11/c++11 atomic operations.
static uint64_t resolve_atomic(const char *name)
{
#if defined(_OS_LINUX_) || defined(_OS_FREEBSD_)
static const char *const libatomic = "libatomic";
static const char *const libatomic = "libatomic.so.1";
#elif defined(_OS_WINDOWS_)
static const char *const libatomic = "libatomic-1";
static const char *const libatomic = "libatomic-1.dll";
#endif
static void *atomic_hdl = jl_load_dynamic_library_e(libatomic,
JL_RTLD_LOCAL);
Expand Down
4 changes: 0 additions & 4 deletions src/julia.h
Expand Up @@ -1427,10 +1427,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
Expand Up @@ -555,7 +555,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 @@ -746,7 +745,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
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 stdlib/Libdl/test/runtests.jl
Expand Up @@ -199,8 +199,4 @@ let dl = C_NULL
@test_skip !Libdl.dlclose(dl) # Syscall doesn't fail on Win32
end

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

end

0 comments on commit 28f3c06

Please sign in to comment.