[PATCH 25/28] elf: Implement tail merging of strings in ldconfig

Florian Weimer fweimer@redhat.com
Fri Oct 30 17:36:53 GMT 2020


* Adhemerval Zanella via Libc-alpha:

>> diff --git a/elf/cache.c b/elf/cache.c
>> index 3a02a4070a..eda3da98a7 100644
>> --- a/elf/cache.c
>> +++ b/elf/cache.c
>> @@ -35,11 +35,15 @@
>>  #include <ldconfig.h>
>>  #include <dl-cache.h>
>>  #include <version.h>
>> +#include <stringtable.h>
>> +
>> +/* Used to store library names, paths, and other strings.  */
>> +struct stringtable strings;
>
> Maybe static here?

Right, added.

>> @@ -596,14 +591,27 @@ void
>>  add_to_cache (const char *path, const char *lib, int flags,
>>  	      unsigned int osversion, uint64_t hwcap)
>>  {
>> +  struct cache_entry *new_entry = xmalloc (sizeof (*new_entry));
>> +
>> +  struct stringtable_entry *path_interned;
>> +  {
>> +    /* Use a small, on-stack buffer in most cases.  */
>> +    char buf[200];
>> +    int ret = snprintf (buf, sizeof (buf), "%s/%s", path, lib);
>> +    if (ret < 0 || ret >= sizeof (buf) - 1)
>> +      {
>> +	char *p;
>> +	if (asprintf (&p, "%s/%s", path, lib) < 0)
>> +	  error (EXIT_FAILURE, errno, _("Could not create library path"));
>> +	path_interned = stringtable_intern (&strings, p);
>> +	free (p);
>> +      }
>> +    else
>> +      path_interned = stringtable_intern (&strings, buf);
>> +  }
>> +
>> +  new_entry->lib = stringtable_intern (&strings, lib);
>> +  new_entry->path = path_interned;
>>    new_entry->flags = flags;
>>    new_entry->osversion = osversion;
>>    new_entry->hwcap = hwcap;
>> 
>
> Ok. Is this small string optimization really worth instead of just using
> asprintf?

Probably not, due to the tcache.  I'm going to remove it.

Thanks,
Florian
-- 
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill



More information about the Libc-alpha mailing list