From patchwork Mon May 2 14:51:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Guriev X-Patchwork-Id: 1625215 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=guriev.su header.i=@guriev.su header.a=rsa-sha256 header.s=bvj00itehu6icf4 header.b=DvKiDVHE; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KsVVB0q7Fz9sFr for ; Tue, 3 May 2022 03:30:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A0623857345 for ; Mon, 2 May 2022 17:30:23 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from dandelion.mymedia.su (dandelion.mymedia.su [107.191.98.137]) by sourceware.org (Postfix) with ESMTPS id 3C23B3858C51 for ; Mon, 2 May 2022 17:30:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3C23B3858C51 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=guriev.su Authentication-Results: sourceware.org; spf=none smtp.mailfrom=dandelion.mymedia.su Received: by dandelion.mymedia.su (Postfix, from userid 1000) id 9F415C00B3; Mon, 2 May 2022 20:30:13 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=guriev.su; s=bvj00itehu6icf4; t=1651512613; bh=oR93JR4ixWehNE0rkGtHiucTSbrftl2iBtkQUJii1gU=; h=Message-Id:From:Date:Subject:To:From; b=DvKiDVHEkygPRXhcwf3+DDx1I56sGNe3jnW2M0q4Cfay0yStUa5MuWR6OpXV1JMlO 4O2hY+xFv6BqU+OdHQC202AdLCtq2iEimyetQ9djWdMqCR4nNxNELnmS/ZEnZUn5eG BjXimgKJoqyMofTTxg3p1s26Ivm+2M1y/ZTIKYMauVH9PgiNlbv2T2fDNQM8w8FnOx C8UYd2xMY2nqDBOQgx37MyBkVAdY89dvtFdFJvv4Cou3FiMHIS2N8FH/iSq+K2/1VJ pQ6O+TUgNV3E4q8YoX60CRevYpnfGzfJfxxciXiudmcMglSfLhoQ/mWDbQ/QqIlRSn PeIpjZ5gL3A5A== Message-Id: From: Nicholas Guriev Date: Mon, 2 May 2022 17:51:17 +0300 Subject: [PATCH] elf: Rewrite long RESOLVE_MAP macro to a debug friendly function To: libc-alpha@sourceware.org X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" A static function that may be inlined is way better to find where exactly a crash happens. So one can step into the function with GDB. The macro still remains for compatibility with other code. Signed-off-by: Nicholas Guriev --- I was playing with the DT_AUXILIARY flag and run into a crash in the RESOLVE_MAP macro. Alas, GDB is unable to see what is going on in a multi-line macro, so I turned it to a static function. Hope this is useful. elf/dl-reloc.c | 55 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c index 771a34bd14..88d7fee041 100644 --- a/elf/dl-reloc.c +++ b/elf/dl-reloc.c @@ -162,29 +162,40 @@ _dl_nothread_init_static_tls (struct link_map *map) } #endif /* !PTHREAD_IN_LIBC */ +static lookup_t +_dl_resolve_map (lookup_t l, struct r_scope_elem *scope[], const ElfW(Sym) **ref, + const struct r_found_version *version, unsigned long r_type) +{ + if (ELFW(ST_BIND) ((*ref)->st_info) == STB_LOCAL + || __glibc_unlikely (dl_symbol_visibility_binds_local_p (*ref))) + return l; + + if (__glibc_unlikely (*ref == l->l_lookup_cache.sym) + && elf_machine_type_class (r_type) == l->l_lookup_cache.type_class) + { + bump_num_cache_relocations (); + *ref = l->l_lookup_cache.ret; + } + else + { + lookup_t _lr; + int _tc = elf_machine_type_class (r_type); + l->l_lookup_cache.type_class = _tc; + l->l_lookup_cache.sym = *ref; + const struct r_found_version *v = NULL; + if (version != NULL && version->hash != 0) + v = version; + _lr = _dl_lookup_symbol_x ((const char *) D_PTR (l, l_info[DT_STRTAB]) + (*ref)->st_name, + l, ref, scope, v, _tc, + DL_LOOKUP_ADD_DEPENDENCY | DL_LOOKUP_FOR_RELOCATE, NULL); + l->l_lookup_cache.ret = *ref; + l->l_lookup_cache.value = _lr; + } + return l->l_lookup_cache.value; +} + /* This macro is used as a callback from the ELF_DYNAMIC_RELOCATE code. */ -#define RESOLVE_MAP(l, scope, ref, version, r_type) \ - ((ELFW(ST_BIND) ((*ref)->st_info) != STB_LOCAL \ - && __glibc_likely (!dl_symbol_visibility_binds_local_p (*ref))) \ - ? ((__glibc_unlikely ((*ref) == l->l_lookup_cache.sym) \ - && elf_machine_type_class (r_type) == l->l_lookup_cache.type_class) \ - ? (bump_num_cache_relocations (), \ - (*ref) = l->l_lookup_cache.ret, \ - l->l_lookup_cache.value) \ - : ({ lookup_t _lr; \ - int _tc = elf_machine_type_class (r_type); \ - l->l_lookup_cache.type_class = _tc; \ - l->l_lookup_cache.sym = (*ref); \ - const struct r_found_version *v = NULL; \ - if ((version) != NULL && (version)->hash != 0) \ - v = (version); \ - _lr = _dl_lookup_symbol_x ((const char *) D_PTR (l, l_info[DT_STRTAB]) + (*ref)->st_name, \ - l, (ref), scope, v, _tc, \ - DL_LOOKUP_ADD_DEPENDENCY \ - | DL_LOOKUP_FOR_RELOCATE, NULL); \ - l->l_lookup_cache.ret = (*ref); \ - l->l_lookup_cache.value = _lr; })) \ - : l) +#define RESOLVE_MAP _dl_resolve_map #include "dynamic-link.h"