public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: Add the soname to the libname_list eagerly on loading a library
@ 2023-04-28  6:26 Fangrui Song
  2023-04-28  8:42 ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Fangrui Song @ 2023-04-28  6:26 UTC (permalink / raw)
  To: libc-alpha; +Cc: Fangrui Song

Original author is Ambrose Feinstein while working at Google.

_dl_map_object iterates over loaded objects and calls _dl_name_match_p.
If l->l_soname_added is 0, we incur two costs.

First, loading l->l_info[DT_SONAME]->d_un.d_val has TLB pressure as
every library's string table is in a different page.  The cost will be
avoided if the string is on the heap.

Second, add_name_to_object repeats the l_libname comparison already done
by the _dl_name_match_p call.

To remove these costs, we eagerly add the SONAME to the libname_list.
l_soname_added is typically 1, so laziness doesn't provide savings.
---
 elf/dl-load.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 9a0e40c0e9..1b17410ce0 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1451,10 +1451,11 @@ cannot enable executable stack as shared object requires");
 
   /* When we profile the SONAME might be needed for something else but
      loading.  Add it right away.  */
-  if (__glibc_unlikely (GLRO(dl_profile) != NULL)
-      && l->l_info[DT_SONAME] != NULL)
+  if (l->l_info[DT_SONAME] != NULL) {
     add_name_to_object (l, ((const char *) D_PTR (l, l_info[DT_STRTAB])
 			    + l->l_info[DT_SONAME]->d_un.d_val));
+    l->l_soname_added = 1;
+  }
 
   /* If we have newly loaded libc.so, update the namespace
      description.  */
-- 
2.40.1.495.gc816e09b53d-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-05 18:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-28  6:26 [PATCH] elf: Add the soname to the libname_list eagerly on loading a library Fangrui Song
2023-04-28  8:42 ` Florian Weimer
2023-05-02 23:08   ` Fangrui Song
2023-07-05  6:17   ` Florian Weimer
2023-07-05 18:22     ` Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).