From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by sourceware.org (Postfix) with ESMTPS id 431353858D37 for ; Fri, 28 Apr 2023 06:26:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 431353858D37 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=flex--maskray.bounces.google.com Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b8f46dc51bdso18322744276.3 for ; Thu, 27 Apr 2023 23:26:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682663205; x=1685255205; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=FS3fUl9eD76YRjtgWToeRAm3NM7B9FPwJCA4XiXQfJw=; b=R+xFfWNHu7kJIJfGRGtEqZAsBzna7O6bKKw8yOjEz+5ZyWbCrnbR2f9TeFs6/QGSpF TBsGS3Ga3KZmOW0aY8mNc8mPpMAeg4OUoYy3fEaOwuF4Abycxu1KLD2PcZvO30/ZFyV4 ldhM3cwDQFeASYNnv45xPU8PIPohwayPRwPCMACCor2o7Md+dyo49jpv8gMemHSixx4e 2gmFYj0kq/ZMI7uU1z6RDpvZsCoCH1czZpeqp6iUmDVDUz3kQTT03g3rNqhrFXeZZibi RMxxebbW+J8MzMaVD7IGCN1Rc/dlnmw9M/BLZI6or/AX8aMmcqB9EDKk5/D5wFK6aIDW /iFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682663205; x=1685255205; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=FS3fUl9eD76YRjtgWToeRAm3NM7B9FPwJCA4XiXQfJw=; b=VBhUQ+AiPn1D+ct7SNMkrfXc9AR7gNG+SPZKL8PM5ubEWQI781er+pmUOGbdCoykNL uuRNNJvuHsFRfyL+0ilIwmBo3DOTX9/5FMHpxr4zt8JdWlcSMveFVk2sC1Q8JRfuH8H/ qdIWXZptvcPFxnHIbeZUD0VCC58q2IhEvi+PvC2z0Wu+gRimJge1Sg07CzE8ued7+eUC /3xAuDGmivawJ/gmK7fQ9ofYr9qgN9qLCNqabWm0H9olQJFJfgXXwiLFNQUBnWh51vnP dBoe9lGyDAxDw33GJa9kp2t2P14aBzXGepatA+ldJfsDY5FCzspZqVNjF8qNziMBd0OZ O3jg== X-Gm-Message-State: AC+VfDwsQHheVhgZnYUknT9HLBG9M8Ipao+SRHO9RhFNd11HQU4LNZY9 /1w2cKdSEEitR6sTPiz2MmCkBszv7uCJhpj6fm1Z1Dfoj21O0zr6y8w61HYLM/CZ8cKhSy2x9MK 9Uj+sal1060p4Xa2jYRZS9Aqsf7xVdxs9oIZTJ757FV4b2jpWMngTBGtkVBWMWGbjfvec X-Google-Smtp-Source: ACHHUZ6o5DX1LA49RPz/uHeeqjpsf67+xwv0tKs4RVQK5Ld4R0OERKfS6K1X6dWWrUYesoe+M0UTxjTqUKv2 X-Received: from maskray.svl.corp.google.com ([2620:15c:2d3:205:f300:c7e9:1369:c3a5]) (user=maskray job=sendgmr) by 2002:a25:abd3:0:b0:b99:f228:37fe with SMTP id v77-20020a25abd3000000b00b99f22837femr2328239ybi.5.1682663205582; Thu, 27 Apr 2023 23:26:45 -0700 (PDT) Date: Thu, 27 Apr 2023 23:26:34 -0700 Mime-Version: 1.0 Message-ID: <20230428062634.2152615-1-maskray@google.com> Subject: [PATCH] elf: Add the soname to the libname_list eagerly on loading a library From: Fangrui Song To: libc-alpha@sourceware.org Cc: Fangrui Song Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_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: 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. */ -- 2.40.1.495.gc816e09b53d-goog