This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 2 problems with sprof


On Thu, Sep 20, 2001 at 08:07:57AM -0700, H . J . Lu wrote:
> On Thu, Sep 20, 2001 at 12:20:51AM -0700, Ulrich Drepper wrote:
> > "H . J . Lu" <hjl@lucon.org> writes:
> > 
> > > I think it is wrong for sprof to call dlopen with RTLD_LAZY. I think
> > > we should add RTLD_PROF for sprof. It should treat undefined symbols
> > > as weak if we have to resolve them and also it shouldn't call init/fini
> > > functions.
> > 
> > Well, I'd like something more general.  The same flag might be useful
> > in certain situations.  So it would be rather something like
> > RTLD_UNDEF_OK or so.
> 
> How about not calling init/fini? It is not clear if RTLD_UNDEF_OK
> covers it. Should we have another one, RTLD_NO_INIT_FINI? Also do
> we need another one, not to check DT_NEEDED? I think we need a list
> for new options. I can implement them. It shouldn't be too hard.
> 
> 

sprof is a very special case. I don't think RTLD_UNDEF_OK is appropriate
here. Also it doesn't have to deal with DT_INIT/DT_FINI/DT_NEEDED. This
patch has minimum impact on performance.


H.J.
----
2001-09-20  H.J. Lu  <hjl@gnu.org>

	* sysdeps/generic/bits/dlfcn.h (RTLD_PROFILE): New.

	* elf/dl-open.c (dl_open_worker): Return immediately after
	loading for RTLD_PROFILE.

	* elf/sprof.c (main): Default to the filename if soname
	doesn't exist.
	(load_shobj): Call dlopen with `RTLD_LAZY | RTLD_PROFILE'.

--- libc/elf/dl-open.c.prof	Wed Sep 19 17:19:58 2001
+++ libc/elf/dl-open.c	Thu Sep 20 16:58:44 2001
@@ -225,6 +225,9 @@ dl_open_worker (void *a)
       return;
     }
 
+  if (mode & RTLD_PROFILE)
+    return;
+
   /* It was already open.  */
   if (new->l_searchlist.r_list != NULL)
     {
--- libc/elf/sprof.c.prof	Sat Jul  7 16:44:45 2001
+++ libc/elf/sprof.c	Thu Sep 20 16:38:57 2001
@@ -264,19 +264,11 @@ main (int argc, char *argv[])
   if (profdata == NULL)
     {
       char *newp;
+      const char *soname;
 
-      if (shobj_handle->soname == NULL)
-	{
-	  unload_shobj (shobj_handle);
-
-	  error (EXIT_FAILURE, 0, _("\
-no filename for profiling data given and shared object `%s' has no soname"),
-		 shobj);
-	}
-
-      newp = (char *) alloca (strlen (shobj_handle->soname)
-			      + sizeof ".profile");
-      stpcpy (stpcpy (newp, shobj_handle->soname), ".profile");
+      soname = shobj_handle->soname ?: basename (shobj);
+      newp = (char *) alloca (strlen (soname) + sizeof ".profile");
+      stpcpy (stpcpy (newp, soname), ".profile");
       profdata = newp;
     }
 
@@ -389,16 +381,19 @@ load_shobj (const char *name)
      line (without specifying a directory) we should load the file in the
      current directory even if a normal dlopen() call would read the other
      file.  We do this by adding a directory portion to the name.  */
+
+#define RTLD_PROF	(RTLD_LAZY | RTLD_PROFILE)
+
   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);
+      map = (struct link_map *) dlopen (load_name, RTLD_PROF);
     }
   if (map == NULL)
     {
-      map = (struct link_map *) dlopen (name, RTLD_LAZY);
+      map = (struct link_map *) dlopen (name, RTLD_PROF);
       if (map == NULL)
 	{
 	  error (0, errno, _("failed to load shared object `%s'"), name);
--- libc/sysdeps/generic/bits/dlfcn.h.prof	Sat Jul  7 16:45:54 2001
+++ libc/sysdeps/generic/bits/dlfcn.h	Thu Sep 20 16:39:36 2001
@@ -40,6 +40,9 @@
 /* Do not delete object when closed.  */
 #define RTLD_NODELETE	0x01000
 
+/* Used by sprof.  */
+#define RTLD_PROFILE	0x02000
+
 #ifdef __USE_GNU
 /* To support profiling of shared objects it is a good idea to call
    the function found using `dlsym' using the following macro since


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]