2 problems with sprof

H . J . Lu hjl@lucon.org
Wed Sep 19 19:02:00 GMT 2001


There are 2 problems with sprof. First, we don't store the canonical
filename so that LD_PROFILE=dynfunc.so won't work with

dlopen ("./dynfunc.so,...);

The patch enclosed here seems to fix it. But the more serious problem
is we do dlopen on dynfunc.so in sprof. If dynfunc.so has some
unresolved symbols, sprof will fail to output the profil data with

# sprof dynfunc.so
sprof: failed to load shared object `dynfunc.so': No such file or directory

The message is misleading since we do

  if (strchr (name, '/') == NULL) 
    {
      char *load_name = (char *) alloca (strlen (name) + 3);
      stpcpy (stpcpy (load_name, "./"), name);

      map = (struct link_map *) dlopen (load_name, RTLD_LAZY);
    }
  if (map == NULL)
    {
      map = (struct link_map *) dlopen (name, RTLD_LAZY);
      if (map == NULL)
        {     
          error (0, errno, _("failed to load shared object `%s'"), name);
          return NULL;
        }
    }

If we do

# LD_LIBRARY_PATH=. sprof dynfunc.so
sprof: failed to load shared object `dynfunc.so'

It doesn't tell me why it failed. Shouldn't we have a mode for dlopen
just to load DSO for sprof?


----
--- elf/dl-object.c.prof	Tue Sep 11 07:42:41 2001
+++ elf/dl-object.c	Wed Sep 19 18:20:28 2001
@@ -36,10 +36,15 @@ _dl_new_object (char *realname, const ch
 {
   struct link_map *l;
   int idx;
-  size_t libname_len = strlen (libname) + 1;
+  size_t libname_len;
   struct link_map *new;
   struct libname_list *newname;
+  const char *base;
 
+  base = strrchr (libname, '/');
+  if (base)
+    libname = base + 1;
+  libname_len = strlen (libname) + 1;
   new = (struct link_map *) calloc (sizeof (*new) + sizeof (*newname)
 				    + libname_len, 1);
   if (new == NULL)



More information about the Libc-alpha mailing list