Commit 85a1981a authored by Kevin Harms's avatar Kevin Harms

Changes to allow creating both a static and dynamic version of darshan.

The dynamic version can be used with LD_PRELOAD to instrument dynamicly
linked executables.


git-svn-id: https://svn.mcs.anl.gov/repos/darshan/trunk@368 3b7491f3-a168-0410-bf4b-c445ed680a29
parent 3b978fa9
all: checkpath lib/libdarshan-posix.a lib/libdarshan-mpi-io.a darshan-parser darshan-diff darshan-analyzer darshan-log-params
all: checkpath lib/libdarshan-posix.a lib/libdarshan-mpi-io.a lib/libdarshan.so darshan-parser darshan-diff darshan-analyzer darshan-log-params
DESTDIR =
srcdir = @srcdir@
......@@ -22,6 +22,9 @@ cp_zlib_include_flags = @__CP_ZLIB_INCLUDE_FLAGS@
CFLAGS = -I . -I $(srcdir) @CFLAGS@ @CPPFLAGS@ -Wall
CFLAGS_MPI = -I . -I $(srcdir) @CFLAGS@ @CPPFLAGS@ -D_LARGEFILE64_SOURCE -Wall
CFLAGS_MPI_SHARED = -I . -I $(srcdir) @CFLAGS@ @CPPFLAGS@ -D_LARGEFILE64_SOURCE -Wall -shared -fpic -DPIC -DDARSHAN_PRELOAD
CC=@MPICC@
LD=@MPICC@
......@@ -65,23 +68,41 @@ test/gz-bench: test/gz-bench.c mktestdir
lib/darshan-mpi-io.o: lib/darshan-mpi-io.c darshan.h darshan-log-format.h | lib
$(CC) $(cp_zlib_include_flags) $(CFLAGS_MPI) -c $< -o $@
lib/darshan-mpi-io.po: lib/darshan-mpi-io.c darshan.h darshan-log-format.h | lib
$(CC) $(cp_zlib_include_flags) $(CFLAGS_MPI_SHARED) -c $< -o $@
lib/darshan-pnetcdf.o: lib/darshan-pnetcdf.c darshan.h darshan-log-format.h | lib
$(CC) $(cp_zlib_include_flags) $(CFLAGS_MPI) -c $< -o $@
lib/darshan-pnetcdf.po: lib/darshan-pnetcdf.c darshan.h darshan-log-format.h | lib
$(CC) $(cp_zlib_include_flags) $(CFLAGS_MPI_SHARED) -c $< -o $@
lib/darshan-hdf5.o: lib/darshan-hdf5.c darshan.h darshan-log-format.h | lib
$(CC) $(cp_zlib_include_flags) $(CFLAGS_MPI) -c $< -o $@
lib/darshan-hdf5.po: lib/darshan-hdf5.c darshan.h darshan-log-format.h | lib
$(CC) $(cp_zlib_include_flags) $(CFLAGS_MPI_SHARED) -c $< -o $@
lib/darshan-posix.o: lib/darshan-posix.c darshan.h darshan-log-format.h | lib
$(CC) $(cp_zlib_include_flags) $(CFLAGS_MPI) -c $< -o $@
lib/darshan-posix.po: lib/darshan-posix.c darshan.h darshan-log-format.h | lib
$(CC) $(cp_zlib_include_flags) $(CFLAGS_MPI_SHARED) -c $< -o $@
lib/lookup3.o: lib/lookup3.c
$(CC) $(CFLAGS_MPI) -c $< -o $@
lib/lookup3.po: lib/lookup3.c
$(CC) $(CFLAGS_MPI_SHARED) -c $< -o $@
lib/lookup8.o: lib/lookup8.c
$(CC) $(CFLAGS_MPI) -c $< -o $@
lib/lookup8.po: lib/lookup8.c
$(CC) $(CFLAGS_MPI_SHARED) -c $< -o $@
%.i: %.c
$(CC) -E $(CFLAGS_MPI) -c $< o $@
$(CC) -E $(CFLAGS_MPI) -c $< -o $@
lib/libdarshan-mpi-io.a: lib/darshan-mpi-io.o lib/darshan-pnetcdf.o lib/darshan-hdf5.o
ar rcs $@ $^
......@@ -89,10 +110,14 @@ lib/libdarshan-mpi-io.a: lib/darshan-mpi-io.o lib/darshan-pnetcdf.o lib/darshan-
lib/libdarshan-posix.a: lib/darshan-posix.o lib/lookup3.o lib/lookup8.o
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
$(CC) $(CFLAGS_MPI_SHARED) -ldl -o $@ $^
install:: all
install -d $(libdir)
install -m 755 lib/libdarshan-posix.a $(libdir)
install -m 755 lib/libdarshan-mpi-io.a $(libdir)
install -m 755 lib/libdarshan.so $(libdir)
install -d $(bindir)
install -m 755 darshan-parser $(bindir)
install -m 755 darshan-diff $(bindir)
......@@ -112,7 +137,7 @@ install:: all
clean::
rm -f *.o *.a lib/*.o lib/*.a darshan-parser darshan-diff darshan-analyzer darshan-log-params
rm -f *.o *.a lib/*.o lib/*.po lib/*.a lib/*.so darshan-parser darshan-diff darshan-analyzer darshan-log-params
distclean:: clean
rm -f darshan-config.h darshan-gen-cxx.pl darshan-gen-fortran.pl darshan-gen-cc.pl darshan-mk-log-dirs.pl aclocal.m4 autom4te.cache/* config.status config.log Makefile util/bin/darshan-job-summary.pl
......
......@@ -14,15 +14,50 @@
typedef int hid_t;
typedef int herr_t;
extern hid_t __real_H5Fcreate(const char *filename, unsigned flags,
hid_t create_plist, hid_t access_plist);
extern hid_t __real_H5Fopen(const char *filename, unsigned flags,
hid_t access_plist);
extern herr_t __real_H5Fclose(hid_t file_id);
#ifdef DARSHAN_PRELOAD
#define DARSHAN_FORWARD_DECL(name,ret,args) \
ret (*__real_ ## name)args = NULL;
#define DARSHAN_DECL(__name) __name
#else
#define DARSHAN_FORWARD_DECL(name,ret,args) \
extern ret __real_ ## name args;
#define DARSHAN_DECL(__name) __wrap_ ## __name
#endif
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(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);
hid_t __wrap_H5Fcreate(const char *filename, unsigned flags,
hid_t DARSHAN_DECL(H5Fcreate)(const char *filename, unsigned flags,
hid_t create_plist, hid_t access_plist)
{
int ret;
......@@ -63,7 +98,7 @@ hid_t __wrap_H5Fcreate(const char *filename, unsigned flags,
return(ret);
}
hid_t __wrap_H5Fopen(const char *filename, unsigned flags,
hid_t DARSHAN_DECL(H5Fopen)(const char *filename, unsigned flags,
hid_t access_plist)
{
int ret;
......@@ -106,7 +141,7 @@ hid_t __wrap_H5Fopen(const char *filename, unsigned flags,
}
herr_t __wrap_H5Fclose(hid_t file_id)
herr_t DARSHAN_DECL(H5Fclose)(hid_t file_id)
{
struct darshan_file_runtime* file;
int hash_index;
......
......@@ -10,15 +10,50 @@
#include "darshan.h"
#include "darshan-config.h"
extern int __real_ncmpi_create(MPI_Comm comm, const char *path,
int cmode, MPI_Info info, int *ncidp);
extern int __real_ncmpi_open(MPI_Comm comm, const char *path,
int omode, MPI_Info info, int *ncidp);
extern int __real_ncmpi_close(int ncid);
#ifdef DARSHAN_PRELOAD
#define DARSHAN_FORWARD_DECL(name,ret,args) \
ret (*__real_ ## name)args = NULL;
#define DARSHAN_DECL(__name) __name
#else
#define DARSHAN_FORWARD_DECL(name,ret,args) \
extern ret __real_ ## name args;
#define DARSHAN_DECL(__name) __wrap_ ## __name
#endif
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_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);
int __wrap_ncmpi_create(MPI_Comm comm, const char *path,
int DARSHAN_DECL(ncmpi_create)(MPI_Comm comm, const char *path,
int cmode, MPI_Info info, int *ncidp)
{
int ret;
......@@ -70,7 +105,7 @@ int __wrap_ncmpi_create(MPI_Comm comm, const char *path,
return(ret);
}
int __wrap_ncmpi_open(MPI_Comm comm, const char *path,
int DARSHAN_DECL(ncmpi_open)(MPI_Comm comm, const char *path,
int omode, MPI_Info info, int *ncidp)
{
int ret;
......@@ -123,7 +158,7 @@ int __wrap_ncmpi_open(MPI_Comm comm, const char *path,
}
int __wrap_ncmpi_close(int ncid)
int DARSHAN_DECL(ncmpi_close)(int ncid)
{
struct darshan_file_runtime* file;
int hash_index;
......
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