From patchwork Fri Apr 28 06:26:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 68442 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C74023858C66 for ; Fri, 28 Apr 2023 06:27:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C74023858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682663227; bh=FS3fUl9eD76YRjtgWToeRAm3NM7B9FPwJCA4XiXQfJw=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=rBqLKU+CNMD0+MVqVAfzaHmGoiNOSYDYW9MwnLCK9AZzLAPswmwzIQG8lxYdPWdlR VDgXlwx0T609oaRVIuZ20YhBV4/TIPTAvg9fJLg3pBFK+Klp9TsstT2wnwUSZHY77m GTvAaEp3Zh8/x3db08hk+Fnjv0Zx0gKB8pvbRx30= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b8f46dc51bdso18322744276.3 for ; Thu, 27 Apr 2023 23:26:46 -0700 (PDT) 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 To: libc-alpha@sourceware.org Cc: Fangrui Song 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 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-Patchwork-Original-From: Fangrui Song via Libc-alpha From: Fangrui Song Reply-To: Fangrui Song Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "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"); /* 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. */