summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-open.c4
-rw-r--r--elf/dl-profile.c2
-rw-r--r--elf/sprof.c22
3 files changed, 13 insertions, 15 deletions
diff --git a/elf/dl-open.c b/elf/dl-open.c
index d10ab8ac65..6d07e445d9 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -225,6 +225,10 @@ dl_open_worker (void *a)
       return;
     }
 
+  if (__builtin_expect (mode & __RTLD_SPROF, 0))
+    /* This happens only if we load a DSO for 'sprof'.  */
+    return;
+
   /* It was already open.  */
   if (new->l_searchlist.r_list != NULL)
     {
diff --git a/elf/dl-profile.c b/elf/dl-profile.c
index a29347a369..3165517914 100644
--- a/elf/dl-profile.c
+++ b/elf/dl-profile.c
@@ -507,7 +507,7 @@ _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc)
 	  /* If we still have no entry stop searching and insert.  */
 	  if (*topcindex == 0)
 	    {
-	      uint_fast32_t newarc = 1 + exchange_and_add (narcsp, 1);
+	      uint_fast32_t newarc = exchange_and_add (narcsp, 1);
 
 	      /* In rare cases it could happen that all entries in FROMS are
 		 occupied.  So we cannot count this anymore.  */
diff --git a/elf/sprof.c b/elf/sprof.c
index 37472ab516..ea334f3472 100644
--- a/elf/sprof.c
+++ b/elf/sprof.c
@@ -264,19 +264,13 @@ main (int argc, char *argv[])
   if (profdata == NULL)
     {
       char *newp;
+      const char *soname;
+      size_t soname_len;
 
-      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);
+      soname_len = strlen (soname);
+      newp = (char *) alloca (soname_len + sizeof ".profile");
+      stpcpy (mempcpy (newp, soname, soname_len), ".profile");
       profdata = newp;
     }
 
@@ -394,11 +388,11 @@ load_shobj (const char *name)
       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_LAZY | __RTLD_SPROF);
     }
   if (map == NULL)
     {
-      map = (struct link_map *) dlopen (name, RTLD_LAZY);
+      map = (struct link_map *) dlopen (name, RTLD_LAZY | __RTLD_SPROF);
       if (map == NULL)
 	{
 	  error (0, errno, _("failed to load shared object `%s'"), name);