Commit ed3099c9 authored by Kevin Harms's avatar Kevin Harms

Rework how the ldpreload code is initialized. Each function checks to

see if the function is resolved and if not, resolves it at that time.
The other method failed when constructors were called for libraries that
were not linked in so the dlsym lookup failed.


git-svn-id: https://svn.mcs.anl.gov/repos/darshan/trunk@369 3b7491f3-a168-0410-bf4b-c445ed680a29
parent 85a1981a
...@@ -111,7 +111,7 @@ lib/libdarshan-posix.a: lib/darshan-posix.o lib/lookup3.o lib/lookup8.o ...@@ -111,7 +111,7 @@ lib/libdarshan-posix.a: lib/darshan-posix.o lib/lookup3.o lib/lookup8.o
ar rcs $@ $^ ar rcs $@ $^
lib/libdarshan.so: lib/darshan-mpi-io.po lib/darshan-pnetcdf.po lib/darshan-hdf5.po lib/darshan-posix.po lib/lookup3.po lib/lookup8.po lib/libdarshan.so: lib/darshan-mpi-io.po lib/darshan-pnetcdf.po lib/darshan-hdf5.po lib/darshan-posix.po lib/lookup3.po lib/lookup8.po
$(CC) $(CFLAGS_MPI_SHARED) -ldl -o $@ $^ gcc $(CFLAGS_MPI_SHARED) -ldl -o $@ $^ -lpthread -lrt
install:: all install:: all
install -d $(libdir) install -d $(libdir)
......
...@@ -16,11 +16,25 @@ typedef int herr_t; ...@@ -16,11 +16,25 @@ typedef int herr_t;
#ifdef DARSHAN_PRELOAD #ifdef DARSHAN_PRELOAD
#define __USE_GNU
#include <dlfcn.h>
#include <stdlib.h>
#define DARSHAN_FORWARD_DECL(name,ret,args) \ #define DARSHAN_FORWARD_DECL(name,ret,args) \
ret (*__real_ ## name)args = NULL; ret (*__real_ ## name)args = NULL;
#define DARSHAN_DECL(__name) __name #define DARSHAN_DECL(__name) __name
#define MAP_OR_FAIL(func) \
if (!(__real_ ## func)) \
{ \
__real_ ## func = dlsym(RTLD_NEXT, #func); \
if(!(__real_ ## func)) { \
fprintf(stderr, "Darshan failed to map symbol: %s\n", #func); \
exit(1); \
} \
}
#else #else
#define DARSHAN_FORWARD_DECL(name,ret,args) \ #define DARSHAN_FORWARD_DECL(name,ret,args) \
...@@ -28,33 +42,14 @@ typedef int herr_t; ...@@ -28,33 +42,14 @@ typedef int herr_t;
#define DARSHAN_DECL(__name) __wrap_ ## __name #define DARSHAN_DECL(__name) __wrap_ ## __name
#define MAP_OR_FAIL(func)
#endif #endif
DARSHAN_FORWARD_DECL(H5Fcreate, hid_t, (const char *filename, unsigned flags, hid_t create_plist, hid_t access_plist)); DARSHAN_FORWARD_DECL(H5Fcreate, hid_t, (const char *filename, unsigned flags, hid_t create_plist, hid_t access_plist));
DARSHAN_FORWARD_DECL(H5Fopen, hid_t, (const char *filename, unsigned flags, hid_t access_plist)); DARSHAN_FORWARD_DECL(H5Fopen, hid_t, (const char *filename, unsigned flags, hid_t access_plist));
DARSHAN_FORWARD_DECL(H5Fclose, herr_t, (hid_t file_id)); DARSHAN_FORWARD_DECL(H5Fclose, herr_t, (hid_t file_id));
#ifdef DARSHAN_PRELOAD
#define __USE_GNU
#include <dlfcn.h>
#include <stdlib.h>
static void __attribute__ ((constructor)) darshan_ldpreload_init(void)
{
#define MAP_OR_FAIL(func) \
__real_ ## func = dlsym(RTLD_NEXT, #func); \
if(!(__real_ ## func)) { \
fprintf(stderr, "Darshan failed to map symbol: %s\n", #func); \
exit(1); \
}
MAP_OR_FAIL(H5Fcreate);
MAP_OR_FAIL(H5Fopen);
MAP_OR_FAIL(H5Fclose);
return;
}
#endif
static struct darshan_file_runtime* darshan_file_by_hid(int hid); static struct darshan_file_runtime* darshan_file_by_hid(int hid);
hid_t DARSHAN_DECL(H5Fcreate)(const char *filename, unsigned flags, hid_t DARSHAN_DECL(H5Fcreate)(const char *filename, unsigned flags,
...@@ -65,6 +60,8 @@ hid_t DARSHAN_DECL(H5Fcreate)(const char *filename, unsigned flags, ...@@ -65,6 +60,8 @@ hid_t DARSHAN_DECL(H5Fcreate)(const char *filename, unsigned flags,
char* tmp; char* tmp;
int hash_index; int hash_index;
MAP_OR_FAIL(H5Fcreate);
ret = __real_H5Fcreate(filename, flags, create_plist, access_plist); ret = __real_H5Fcreate(filename, flags, create_plist, access_plist);
if(ret >= 0) if(ret >= 0)
{ {
...@@ -106,6 +103,8 @@ hid_t DARSHAN_DECL(H5Fopen)(const char *filename, unsigned flags, ...@@ -106,6 +103,8 @@ hid_t DARSHAN_DECL(H5Fopen)(const char *filename, unsigned flags,
char* tmp; char* tmp;
int hash_index; int hash_index;
MAP_OR_FAIL(H5Fopen);
ret = __real_H5Fopen(filename, flags, access_plist); ret = __real_H5Fopen(filename, flags, access_plist);
if(ret >= 0) if(ret >= 0)
{ {
...@@ -148,6 +147,8 @@ herr_t DARSHAN_DECL(H5Fclose)(hid_t file_id) ...@@ -148,6 +147,8 @@ herr_t DARSHAN_DECL(H5Fclose)(hid_t file_id)
int tmp_hid = file_id; int tmp_hid = file_id;
int ret; int ret;
MAP_OR_FAIL(H5Fclose);
ret = __real_H5Fclose(file_id); ret = __real_H5Fclose(file_id);
CP_LOCK(); CP_LOCK();
......
This diff is collapsed.
...@@ -11,12 +11,25 @@ ...@@ -11,12 +11,25 @@
#include "darshan-config.h" #include "darshan-config.h"
#ifdef DARSHAN_PRELOAD #ifdef DARSHAN_PRELOAD
#define __USE_GNU
#include <dlfcn.h>
#include <stdlib.h>
#define DARSHAN_FORWARD_DECL(name,ret,args) \ #define DARSHAN_FORWARD_DECL(name,ret,args) \
ret (*__real_ ## name)args = NULL; ret (*__real_ ## name)args = NULL;
#define DARSHAN_DECL(__name) __name #define DARSHAN_DECL(__name) __name
#define MAP_OR_FAIL(func) \
if (!(__real_ ## func)) \
{ \
__real_ ## func = dlsym(RTLD_NEXT, #func); \
if(!(__real_ ## func)) { \
fprintf(stderr, "Darshan failed to map symbol: %s\n", #func); \
exit(1); \
} \
}
#else #else
#define DARSHAN_FORWARD_DECL(name,ret,args) \ #define DARSHAN_FORWARD_DECL(name,ret,args) \
...@@ -24,33 +37,14 @@ ...@@ -24,33 +37,14 @@
#define DARSHAN_DECL(__name) __wrap_ ## __name #define DARSHAN_DECL(__name) __wrap_ ## __name
#define MAP_OR_FAIL(func)
#endif #endif
DARSHAN_FORWARD_DECL(ncmpi_create, int, (MPI_Comm comm, const char *path, int cmode, MPI_Info info, int *ncidp)); DARSHAN_FORWARD_DECL(ncmpi_create, int, (MPI_Comm comm, const char *path, int cmode, MPI_Info info, int *ncidp));
DARSHAN_FORWARD_DECL(ncmpi_open, int, (MPI_Comm comm, const char *path, int omode, MPI_Info info, int *ncidp)); DARSHAN_FORWARD_DECL(ncmpi_open, int, (MPI_Comm comm, const char *path, int omode, MPI_Info info, int *ncidp));
DARSHAN_FORWARD_DECL(ncmpi_close, int, (int ncid)); DARSHAN_FORWARD_DECL(ncmpi_close, int, (int ncid));
#ifdef DARSHAN_PRELOAD
#define __USE_GNU
#include <dlfcn.h>
#include <stdlib.h>
static void __attribute__ ((constructor)) darshan_ldpreload_init(void)
{
#define MAP_OR_FAIL(func) \
__real_ ## func = dlsym(RTLD_NEXT, #func); \
if(!(__real_ ## func)) { \
fprintf(stderr, "Darshan failed to map symbol: %s\n", #func); \
exit(1); \
}
MAP_OR_FAIL(ncmpi_create);
MAP_OR_FAIL(ncmpi_open);
MAP_OR_FAIL(ncmpi_close);
return;
}
#endif
static struct darshan_file_runtime* darshan_file_by_ncid(int ncid); static struct darshan_file_runtime* darshan_file_by_ncid(int ncid);
int DARSHAN_DECL(ncmpi_create)(MPI_Comm comm, const char *path, int DARSHAN_DECL(ncmpi_create)(MPI_Comm comm, const char *path,
...@@ -62,6 +56,8 @@ int DARSHAN_DECL(ncmpi_create)(MPI_Comm comm, const char *path, ...@@ -62,6 +56,8 @@ int DARSHAN_DECL(ncmpi_create)(MPI_Comm comm, const char *path,
int comm_size; int comm_size;
int hash_index; int hash_index;
MAP_OR_FAIL(ncmpi_create);
ret = __real_ncmpi_create(comm, path, cmode, info, ncidp); ret = __real_ncmpi_create(comm, path, cmode, info, ncidp);
if(ret == 0) if(ret == 0)
{ {
...@@ -114,6 +110,8 @@ int DARSHAN_DECL(ncmpi_open)(MPI_Comm comm, const char *path, ...@@ -114,6 +110,8 @@ int DARSHAN_DECL(ncmpi_open)(MPI_Comm comm, const char *path,
int comm_size; int comm_size;
int hash_index; int hash_index;
MAP_OR_FAIL(ncmpi_open);
ret = __real_ncmpi_open(comm, path, omode, info, ncidp); ret = __real_ncmpi_open(comm, path, omode, info, ncidp);
if(ret == 0) if(ret == 0)
{ {
...@@ -165,6 +163,8 @@ int DARSHAN_DECL(ncmpi_close)(int ncid) ...@@ -165,6 +163,8 @@ int DARSHAN_DECL(ncmpi_close)(int ncid)
int tmp_ncid = ncid; int tmp_ncid = ncid;
int ret; int ret;
MAP_OR_FAIL(ncmpi_close);
ret = __real_ncmpi_close(ncid); ret = __real_ncmpi_close(ncid);
CP_LOCK(); CP_LOCK();
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment