[PATCH] elf: Add the soname to the libname_list eagerly on loading a library

Fangrui Song maskray@google.com
Fri Apr 28 06:26:34 GMT 2023


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



More information about the Libc-alpha mailing list