From patchwork Sat May 7 13:33:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Guriev X-Patchwork-Id: 53573 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 A757138485B6 for ; Sat, 7 May 2022 13:34:09 +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 9DCF73858D33 for ; Sat, 7 May 2022 13:33:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9DCF73858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=guriev.su Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=guriev.su Received: by dandelion.mymedia.su (Postfix, from userid 1000) id AD472BD469; Sat, 7 May 2022 16:33:56 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=guriev.su; s=bvj00itehu6icf4; t=1651930436; bh=xfs2wuPAHI/mRK1e09klDQU+55B404QkUfSZ7z60CIk=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:From; b=JQCY0a3Fx24n8gn7TYhTsKsmAUgOs1ikkJvQ0rhE35WX8F7sMvVWaLR9cXEqNMmAJ 5xIw05CbRHtsErk9VtEX4aObQ8zN6wuG1HwJBO9nz2Uk9aJEw9gUu/jMdCBosNV5hD iE4BWdHmcnb/nGcZWzDeyovekWNcaXgC00UgVSuq+34chFWi59Ka1AIeos7HnvxL+6 RpgdyGeO19TjSBEduupkPV/Aj7KEHngrWFXeNMrdMK/sH1G/zHT1c9RFiIKdDJiKwN d0HtmOV5ggGBHQg1WsTceiG6kUJF9s3gZOU1SvZ2bAV+rsvn/E9dqLQhORTErJGIJa BaOzvcXfn4wpg== Message-ID: Subject: [PATCH v3] elf: Rewrite long RESOLVE_MAP macro to a debug friendly function From: Nicholas Guriev To: =?utf-8?b?RsSBbmctcnXDrCBTw7JuZw==?= Date: Sat, 07 May 2022 16:33:43 +0300 In-Reply-To: References: User-Agent: Evolution 3.40.4-1ubuntu2 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, SPF_HELO_NONE, SPF_PASS, 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: , Cc: libc-alpha@sourceware.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" On Вт, 2022-05-03 at 13:12 -0700, Fāng-ruì Sòng wrote: > The function has internal linkage (static) and it seems that the > prevailing style doesn't use `_dl_` prefix for such functions. Ok, I renamed the function by removing the prefix. I also added keyword `inline` so that GCC could really inline this new function. GCC relies on `--param max-inline-insns-auto` (which defaults to 15) when the compiler decides to inline ordinary function, and `--param max-inline- insns-single` (70 by default) is used for functions with the keyword. -- >8 -- 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 Reviewed-by: Fangrui Song --- elf/dl-reloc.c | 56 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c index 771a34bd14..10affc4d48 100644 --- a/elf/dl-reloc.c +++ b/elf/dl-reloc.c @@ -162,29 +162,41 @@ _dl_nothread_init_static_tls (struct link_map *map) } #endif /* !PTHREAD_IN_LIBC */ +static inline lookup_t +resolve_map (lookup_t l, struct r_scope_elem *scope[], const ElfW(Sym) **ref, + const struct r_found_version *version, unsigned long int 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 + { + int tc = elf_machine_type_class (r_type); + l->l_lookup_cache.type_class = tc; + l->l_lookup_cache.sym = *ref; + const char *undef_name + = (const char *) D_PTR (l, l_info[DT_STRTAB]) + (*ref)->st_name; + const struct r_found_version *v = NULL; + if (version != NULL && version->hash != 0) + v = version; + lookup_t lr = _dl_lookup_symbol_x (undef_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 resolve_map #include "dynamic-link.h"