AC_SUBST([dl_LIBS], [$LIBS])
LIBS="$saved_LIBS"
+# Check RTLD_DI_ORIGIN (not decalred by musl. glibc has it as an enum so cannot use ifdef)
+AC_CHECK_DECL([RTLD_DI_ORIGIN], [AC_DEFINE([HAVE_RTLD_DI_ORIGIN], 1,
+ [define when RTLD_DI_ORIGIN is declared])], ,[[#include <dlfcn.h>]])
+
# OS detection
AC_MSG_CHECKING([for os in ${host_os}])
#include <fcntl.h>
#include <dlfcn.h>
#include <errno.h>
+#include <libgen.h>
+#include <link.h>
#include <string.h>
#include <sys/param.h>
#include <sys/types.h>
return 0;
}
+static int get_lib_dir(void *lib_handle, char dir[MAXPATHLEN])
+{
+ int res;
+#ifndef HAVE_RTLD_DI_ORIGIN
+ struct link_map *lm;
+ char l_name[MAXPATHLEN];
+#endif
+
+#ifdef HAVE_RTLD_DI_ORIGIN
+ res = dlinfo(lib_handle, RTLD_DI_ORIGIN, dir);
+#else
+ /*
+ * musl libc doesn't support RTLD_DI_ORIGIN
+ */
+ res = dlinfo(lib_handle, RTLD_DI_LINKMAP, &lm);
+ if (res == 0) {
+ snprintf(l_name, sizeof(l_name), "%s", lm->l_name);
+ snprintf(dir, MAXPATHLEN, "%s", dirname(l_name));
+ }
+#endif
+
+ return res;
+}
+
static void *open_lib(knet_handle_t knet_h, const char *libname, int extra_flags)
{
void *ret = NULL;
memset(dir, 0, sizeof(dir));
memset(link, 0, sizeof(link));
memset(path, 0, sizeof(path));
- if (dlinfo(ret, RTLD_DI_ORIGIN, &dir) < 0) {
+ if (get_lib_dir(ret, dir) < 0) {
/*
* should we dlclose and return error?
*/