Skip to content

Commit

Permalink
Merge pull request ofiwg#13 from ngusev/dlsym
Browse files Browse the repository at this point in the history
util_mem_monitor.c: fix call of getauxval when glibc < 2.16 for memhooks
  • Loading branch information
ddurnov authored and GitHub Enterprise committed Oct 7, 2019
2 parents a05debe + 52e49fd commit f773997
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
14 changes: 13 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,19 @@ AC_DEFINE_UNQUOTED([HAVE_UFFD_UNMAP], [$have_uffd],
[Define to 1 if platform supports userfault fd unmap])

dnl Check support to intercept syscalls
# AC_CHECK_HEADERS_ONCE(elf.h sys/auxv.h)
AC_CHECK_HEADERS_ONCE(elf.h)
AC_DEFINE_UNQUOTED([HAVE_SYS_AUXV_H], 1,
[Define HAVE_SYS_AUXV_H to 1])

AC_ARG_ENABLE([impi],
[AS_HELP_STRING([--enable-impi],
[Enable atomics support @<:@default=no@:>@])
],
[AC_DEFINE_UNQUOTED([I_MPI], 1,
[Define I_MPI to 1])
],
[])


dnl Provider-specific checks
FI_PROVIDER_INIT
Expand Down
31 changes: 31 additions & 0 deletions prov/util/src/util_mem_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ enum {
OFI_INTERCEPT_MAX
};

typedef unsigned long getauxval_func_t(unsigned long);
getauxval_func_t* func = NULL;

static void *ofi_intercept_dlopen(const char *filename, int flag);
static void *ofi_intercept_mmap(void *start, size_t length,
int prot, int flags, int fd, off_t offset);
Expand Down Expand Up @@ -231,7 +234,11 @@ static int ofi_intercept_phdr_handler(struct dl_phdr_info *info,
struct ofi_intercept *intercept = data;
int phent, ret;

#ifdef I_MPI
phent = (int)(*func)(AT_PHENT);
#else /* I_MPI */
phent = getauxval(AT_PHENT);
#endif /* I_MPI */
if (phent <= 0) {
FI_DBG(&core_prov, FI_LOG_MR, "failed to read phent size");
return -FI_EINVAL;
Expand Down Expand Up @@ -305,7 +312,11 @@ static int ofi_restore_phdr_handler(struct dl_phdr_info *info,
struct ofi_intercept *intercept = data;
int phent, ret;

#ifdef I_MPI
phent = (int)(*func)(AT_PHENT);
#else /* I_MPI */
phent = getauxval(AT_PHENT);
#endif /* I_MPI */
if (phent <= 0) {
FI_DBG(&core_prov, FI_LOG_MR, "failed to read phent size");
return -FI_EINVAL;
Expand Down Expand Up @@ -479,6 +490,26 @@ int ofi_memhooks_init(void)
memhooks_monitor->unsubscribe = ofi_memhooks_unsubscribe;
dlist_init(&memhooks.intercept_list);

#ifdef I_MPI
void* libc_handle = NULL;
dlerror();

libc_handle = dlopen("libc.so.6", RTLD_LAZY);
if (!libc_handle) {
FI_DBG(&core_prov, FI_LOG_MR,
"Could not dlopen() C library: %s\n", dlerror());
return -FI_ENOMEM;
}

func = (getauxval_func_t*)dlsym(libc_handle, "getauxval");
if (!func){
FI_DBG(&core_prov, FI_LOG_MR,
"Could not find getauxval() in C library\n");
return -FI_ENOMEM;
}
dlclose(libc_handle);
#endif /* I_MPI */

for (i = 0; i < OFI_INTERCEPT_MAX; ++i)
dlist_init(&intercepts[i].dl_intercept_list);

Expand Down

0 comments on commit f773997

Please sign in to comment.