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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id EF0D93858D32 for ; Wed, 5 Jul 2023 06:17:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EF0D93858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688537865; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bjByUOxoDmag/4+4v3LIaqSZloQcJohVYGqzC4iz5PY=; b=DzFJa8WcyNiXKK9TIiMw16c8ta+ZbylsKu++6+s+k3jUoOC/isZqXEt9e7XdZEgQqsploX vY36ibKURMSEaFdOQ5nkRme4H4TNsUIFAXYLAGd9/jzNAUO4k8Gk92nAfe/SP7d6/Gn4cN 3pFVAtWcKhY/ur/J9GR+GrN1J3A+7Fk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-594-0dtkhYk2MiaJUdA7UFOEyw-1; Wed, 05 Jul 2023 02:17:44 -0400 X-MC-Unique: 0dtkhYk2MiaJUdA7UFOEyw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 351FF104458E; Wed, 5 Jul 2023 06:17:44 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 78FD4F41C9; Wed, 5 Jul 2023 06:17:43 +0000 (UTC) From: Florian Weimer To: Fangrui Song via Libc-alpha Cc: Fangrui Song Subject: Re: [PATCH] elf: Add the soname to the libname_list eagerly on loading a library References: <20230428062634.2152615-1-maskray@google.com> <87o7n89z3n.fsf@oldenburg.str.redhat.com> Date: Wed, 05 Jul 2023 08:17:41 +0200 In-Reply-To: <87o7n89z3n.fsf@oldenburg.str.redhat.com> (Florian Weimer's message of "Fri, 28 Apr 2023 10:42:52 +0200") Message-ID: <87v8eyhofu.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-10.5 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_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: * 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"); >> =20 >> /* When we profile the SONAME might be needed for something else but >> loading. Add it right away. */ >> - if (__glibc_unlikely (GLRO(dl_profile) !=3D NULL) >> - && l->l_info[DT_SONAME] !=3D NULL) >> + if (l->l_info[DT_SONAME] !=3D NULL) { >> add_name_to_object (l, ((const char *) D_PTR (l, l_info[DT_STRTAB]) >> =09=09=09 + l->l_info[DT_SONAME]->d_un.d_val)); >> + l->l_soname_added =3D 1; >> + } >> =20 >> /* 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 =E2=80=A6 The hash table is implemented here: [PATCH 32/33] elf: Add hash tables to speed up DT_NEEDED, dlopen lookups Thanks, Florian