public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Fangrui Song via Libc-alpha <libc-alpha@sourceware.org>
Cc: Fangrui Song <maskray@google.com>
Subject: Re: [PATCH] elf: Add the soname to the libname_list eagerly on loading a library
Date: Wed, 05 Jul 2023 08:17:41 +0200	[thread overview]
Message-ID: <87v8eyhofu.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <87o7n89z3n.fsf@oldenburg.str.redhat.com> (Florian Weimer's message of "Fri, 28 Apr 2023 10:42:52 +0200")

* Florian Weimer:

> * Fangrui Song via Libc-alpha:
>
>> 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.  */
>
> The comment is now outdated.
>
> Not sure if this kind of micro-optimization makes sense.  Maybe until we
> add a hash table here …

The hash table is implemented here:

  [PATCH 32/33] elf: Add hash tables to speed up DT_NEEDED, dlopen lookups
  <https://sourceware.org/pipermail/libc-alpha/2023-July/149669.html>

Thanks,
Florian


  parent reply	other threads:[~2023-07-05  6:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28  6:26 Fangrui Song
2023-04-28  8:42 ` Florian Weimer
2023-05-02 23:08   ` Fangrui Song
2023-07-05  6:17   ` Florian Weimer [this message]
2023-07-05 18:22     ` Fangrui Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v8eyhofu.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=maskray@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).