From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 3535C386F401 for ; Fri, 30 Oct 2020 17:36:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3535C386F401 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-497-X8TSlWE9Nfyux4VsWhCY0w-1; Fri, 30 Oct 2020 13:36:56 -0400 X-MC-Unique: X8TSlWE9Nfyux4VsWhCY0w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 017831006C83; Fri, 30 Oct 2020 17:36:56 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-113-60.ams2.redhat.com [10.36.113.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4DA9A5C1CF; Fri, 30 Oct 2020 17:36:55 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella via Libc-alpha Subject: Re: [PATCH 25/28] elf: Implement tail merging of strings in ldconfig References: Date: Fri, 30 Oct 2020 18:36:53 +0100 In-Reply-To: (Adhemerval Zanella via Libc-alpha's message of "Thu, 22 Oct 2020 18:08:45 -0300") Message-ID: <87d00zk43u.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Oct 2020 17:37:00 -0000 * 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 >> #include >> #include >> +#include >> + >> +/* 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