From patchwork Wed Nov 27 19:40:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Adhemerval Zanella (Code Review)" X-Patchwork-Id: 1201764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-107454-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gnutoolchain-gerrit.osci.io Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="jlF022VQ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47NWMT3Bbxz9s4Y for ; Thu, 28 Nov 2019 06:40:21 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:in-reply-to:references :reply-to:mime-version:content-transfer-encoding:content-type :message-id; q=dns; s=default; b=AwWYHwzR+3eoIwC8g1AEG1FdFtNOPXo V1KUyauKYiLUfftgECJFiFn+ziEuVWn2W/siHBOteqmE2of/xvQ24eyb1MctSmpc 2tBWZKfO0J8+ZANFfKN9ZWLJByGJhgO7ZAVOc2pWAGTJxvMdt6pvMtRgBb+g9klT V1N3nUMwrQwk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:in-reply-to:references :reply-to:mime-version:content-transfer-encoding:content-type :message-id; s=default; bh=4fJvOlt3gyktXXMfy0SHG7Dj5kc=; b=jlF02 2VQloZvxatxLffmTTon6NqPTPBUV7CJcTOHkldk+vUkxVSkzsIgb+czs+kxTNa/m UvCU8xVGVCnQNGIssdfB7JyVYtcubKQFqul+VIDwzc5dyqWREzYoSqsoesgE8aRV lzgMwCxQ/KH+lcecect0E2Hv2N8bh+pxku6Zl0= Received: (qmail 31362 invoked by alias); 27 Nov 2019 19:40:14 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 31354 invoked by uid 89); 27 Nov 2019 19:40:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io X-Gerrit-PatchSet: 3 Date: Wed, 27 Nov 2019 14:40:09 -0500 From: "Sourceware to Gerrit sync (Code Review)" To: Florian Weimer , libc-alpha@sourceware.org Cc: Carlos O'Donell , Szabolcs Nagy Auto-Submitted: auto-generated X-Gerrit-MessageType: merged Subject: [pushed] dlsym: Do not determine caller link map if not needed X-Gerrit-Change-Id: Ide5d9e2cc7ac25a0ffae8fb4c26def0c898efa29 X-Gerrit-Change-Number: 528 X-Gerrit-ChangeURL: X-Gerrit-Commit: 4a2ab5843a5cc4a5db1b3b79916a520ea8b115dc In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, fweimer@redhat.com, szabolcs.nagy@arm.com, libc-alpha@sourceware.org, carlos@redhat.com MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Message-Id: <20191127194009.415AB20AF6@gnutoolchain-gerrit.osci.io> Sourceware to Gerrit sync has submitted this change. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/528 ...................................................................... dlsym: Do not determine caller link map if not needed Obtaining the link map is potentially very slow because it requires iterating over all loaded objects in the current implementation. If the caller supplied an explicit handle (i.e., not one of the RTLD_* constants), the dlsym implementation does not need the identity of the caller (except in the special case of auditing), so this change avoids computing it in that case. Even in the minimal case (dlsym called from a main program linked with -dl), this shows a small speedup, perhaps around five percent. The performance improvement can be arbitrarily large in principle (if _dl_find_dso_for_object has to iterate over many link maps). Change-Id: Ide5d9e2cc7ac25a0ffae8fb4c26def0c898efa29 --- M elf/dl-sym.c 1 file changed, 21 insertions(+), 4 deletions(-) Approvals: Carlos O'Donell: Looks good to me, approved diff --git a/elf/dl-sym.c b/elf/dl-sym.c index 21e025b..3933194 100644 --- a/elf/dl-sym.c +++ b/elf/dl-sym.c @@ -80,6 +80,18 @@ args->flags, NULL); } +/* Return the link map containing the caller address. */ +static inline struct link_map * +find_caller_link_map (ElfW(Addr) caller) +{ + struct link_map *l = _dl_find_dso_for_object (caller); + if (l != NULL) + return l; + else + /* If the address is not recognized the call comes from the main + program (we hope). */ + return GL(dl_ns)[LM_ID_BASE]._ns_loaded; +} static void * do_sym (void *handle, const char *name, void *who, @@ -89,13 +101,13 @@ lookup_t result; ElfW(Addr) caller = (ElfW(Addr)) who; - struct link_map *l = _dl_find_dso_for_object (caller); - /* If the address is not recognized the call comes from the main - program (we hope). */ - struct link_map *match = l ? l : GL(dl_ns)[LM_ID_BASE]._ns_loaded; + /* Link map of the caller if needed. */ + struct link_map *match = NULL; if (handle == RTLD_DEFAULT) { + match = find_caller_link_map (caller); + /* Search the global scope. We have the simple case where we look up in the scope of an object which was part of the initial binary. And then the more complex part @@ -128,6 +140,8 @@ } else if (handle == RTLD_NEXT) { + match = find_caller_link_map (caller); + if (__glibc_unlikely (match == GL(dl_ns)[LM_ID_BASE]._ns_loaded)) { if (match == NULL @@ -187,6 +201,9 @@ unsigned int ndx = (ref - (ElfW(Sym) *) D_PTR (result, l_info[DT_SYMTAB])); + if (match == NULL) + match = find_caller_link_map (caller); + if ((match->l_audit_any_plt | result->l_audit_any_plt) != 0) { unsigned int altvalue = 0;