From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by sourceware.org (Postfix) with ESMTPS id D17AD3858423 for ; Wed, 5 Jul 2023 18:22:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D17AD3858423 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=google.com Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-401d1d967beso43141cf.0 for ; Wed, 05 Jul 2023 11:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688581338; x=1691173338; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IxfQ0qCXx453oOvwe9+zp/zXVQSlfn2rGDU3GvSJXsE=; b=xMv8DX6fM4NErDcg5j9hIoxMvu8OYpeZNA0mxxcAuMxp/MGw0NevhOiUv/rzjhMKcu UJDo7y/kDpfObyZ+d0YeN7Wm/ZfYwJ0yEpg+3VdwA2RedxARIox6+6yB4JaadK0+OjxI uSHZs9z0ai8XXl57MLH6iTT9/OF2F4lztqeufZH3j/A+V+RB9Z6ucG0JTcUOU3F5JD+e Fqaa8cryPYZk1cUNoSfGcOmEKL3838gLjxqblcVpmQ0gihk1xUtq3rCTQKbu6VJxqell WM7A3XaG02OxpBZBGM3HRO6fDqq75lV8ucBjGzWUV6yu6tawl+k8mUV/yekmgDQULjGi 5WNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688581338; x=1691173338; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IxfQ0qCXx453oOvwe9+zp/zXVQSlfn2rGDU3GvSJXsE=; b=ZeZ7O3vlDhhz37zX8RgOCMZdCEmJNGA/CwURRCXTepuT6H9j1yAc1+IfdK5vuGNKsh X4pT4Nr6cX0UvQ+1GM8OIT8jfs3+QNFcRrAOzetRIcIQzoi8O6NMPi1h5veFs3tShF4+ TQlByiFE2mJAA9inPBi0CJs0N7QoaA8x55XhxvESByaEp5ki+U8PifYuiA9AfLpljzCV gI2gs0aPq7MiMTQLKtONM3Kv4HM/ruVZ5DKuV+dmkFxfpzzKhH+8Cjv7xN14wcoFeqbK 1Cb17n0tLd9DGrsrg4vCBNPvHwR2j13egGgyBd52G2+IXNF1RLr0DLfpE5pE5U1rp9r1 /7CA== X-Gm-Message-State: ABy/qLZ67hFL3JnnA51D6aAA2LcFvFX0/7lbWQB2sXyGxcgFqFepOa3Z 4Omd/tohqMHKwsy2zZXsU8gQyLEx4GSFeL50G1+IsNc9/Hfy9kIlx/k= X-Google-Smtp-Source: APBJJlFt24D7CU7FdVhEE9g1lejehhQThmFiFg7jMR51gUJFy311Vt3xCTg+lN8vOzjEbosP4YzQujZ2W5XaVIzU02Q= X-Received: by 2002:ac8:5cc7:0:b0:3f9:6930:1308 with SMTP id s7-20020ac85cc7000000b003f969301308mr14881qta.13.1688581337937; Wed, 05 Jul 2023 11:22:17 -0700 (PDT) MIME-Version: 1.0 References: <20230428062634.2152615-1-maskray@google.com> <87o7n89z3n.fsf@oldenburg.str.redhat.com> <87v8eyhofu.fsf@oldenburg.str.redhat.com> In-Reply-To: <87v8eyhofu.fsf@oldenburg.str.redhat.com> From: Fangrui Song Date: Wed, 5 Jul 2023 11:22:06 -0700 Message-ID: Subject: Re: [PATCH] elf: Add the soname to the libname_list eagerly on loading a library To: Florian Weimer Cc: Fangrui Song via Libc-alpha Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-23.4 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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: On Tue, Jul 4, 2023 at 11:17=E2=80=AFPM Florian Weimer = wrote: > > * 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 do= ne > >> 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 objec= t requires"); > >> > >> /* When we profile the SONAME might be needed for something else bu= t > >> 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= ]) > >> + l->l_info[DT_SONAME]->d_un.d_val)); > >> + l->l_soname_added =3D 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 w= e > > 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 lookup= s > > > Thanks, > Florian > Thank you for improving the dynamic loader performance and obsoleting this patch! :) --=20 =E5=AE=8B=E6=96=B9=E7=9D=BF