From 54157251d30d586e8f97fb594f22bf18e9ac4bbe Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 12 Jun 2013 16:16:51 -0700 Subject: [PATCH] dlwrap: Don't resolve libfips_handle on every call to dlopen. Instead, call dladdr and the real dlopen on the first call to dlopen then save the libfips_handle result for all future calls. --- dlwrap.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/dlwrap.c b/dlwrap.c index aac06f6..9f623da 100644 --- a/dlwrap.c +++ b/dlwrap.c @@ -46,17 +46,23 @@ dlopen (const char *filename, int flag) if (STRNCMP_LITERAL (filename, "libGL.so")) return dlwrap_real_dlopen (filename, flag); - /* Redirect all dlopens to libGL to our own wrapper library. - * We find our own filename by looking up this very function - * (that is, this "dlopen"), with dladdr).*/ - if (dladdr (dlopen, &info)) { - libfips_handle = dlwrap_real_dlopen (info.dli_fname, flag); + /* Otherwise, for all libGL lookups we redirectl dlopens to + * our own library. If we've resolved libfips_handle before, + * our work is done. */ + if (libfips_handle) return libfips_handle; - } else { + + /* We find our own filename by looking up this very function + * (that is, this "dlopen"), with dladdr).*/ + if (dladdr (dlopen, &info) == 0) { fprintf (stderr, "Error: Failed to redirect dlopen of %s:\n", filename); exit (1); } + + libfips_handle = dlwrap_real_dlopen (info.dli_fname, flag); + + return libfips_handle; } void * -- 2.43.0