changeset 16:2623ca084473

Better loading for libhost_.so
author Gregor Richards <Richards@codu.org>
date Mon, 14 Dec 2009 16:36:53 -0500
parents d30b0a07f3e1
children c474880f5c85
files gelfload/README gelfload/src/elfload.c
diffstat 2 files changed, 21 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/gelfload/README	Mon Dec 14 16:23:49 2009 -0500
+++ b/gelfload/README	Mon Dec 14 16:36:53 2009 -0500
@@ -10,7 +10,10 @@
    or they may use symbolic names to refer to host libraries:
    * libhost_<name> refers to the library <name> on the host, e.g.
      libhost_libc.so.6 or libhost_msvcrt.dll
-   * libhost_.so refers to libc or its nearest equivalent
+   * libhost_.so refers to:
+     * if possible, all libraries loaded by gelfload in the host, including
+       certainly at least libc
+     * otherwise, libc or the nearest equivalent, e.g. msvcrt.dll
    * libloader_dl.0 refers to the loader's builtin library providing dlopen()
      and dlsym()
 
--- a/gelfload/src/elfload.c	Mon Dec 14 16:23:49 2009 -0500
+++ b/gelfload/src/elfload.c	Mon Dec 14 16:36:53 2009 -0500
@@ -1,3 +1,7 @@
+#ifndef _GNU_SOURCE /* for RTLD_DEFAULT */
+#define _GNU_SOURCE 1
+#endif
+
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -60,22 +64,25 @@
 #if defined(HAVE_DLFCN_H)
         if (strcmp(nm, "libhost_.so") == 0) {
             /* the entire host */
-            f->prog = dlopen(
-#ifdef __APPLE__
-                    "libc.dylib"
+#ifdef RTLD_DEFAULT
+            f->prog = RTLD_DEFAULT;
 #else
-                    NULL
+            f->prog = dlopen(NULL, RTLD_NOW|RTLD_GLOBAL);
 #endif
-                    , RTLD_NOW|RTLD_GLOBAL);
         } else {
             f->prog = dlopen(nm + 8, RTLD_NOW|RTLD_GLOBAL);
-        }
-        if (f->prog == NULL) {
-            fprintf(stderr, "Could not resolve host library %s.\n", nm + 8);
-            exit(1);
+
+            if (f->prog == NULL) {
+                fprintf(stderr, "Could not resolve host library %s.\n", nm + 8);
+                exit(1);
+            }
         }
 #elif defined(__WIN32)
-        f->prog = LoadLibrary(nm + 8);
+        if (strcmp(nm, "libhost_.so") == 0) {
+            f->prog = LoadLibrary("msvcrt.dll");
+        } else {
+            f->prog = LoadLibrary(nm + 8);
+        }
         if (f->prog == NULL) {
             fprintf(stderr, "Could not resolve host library %s.\n", nm + 8);
             exit(1);