From: Nicholas Guriev <nicholas@guriev.su>
To: "Fāng-ruì Sòng" <maskray@google.com>
Cc: libc-alpha@sourceware.org
Subject: [PATCH v3] elf: Rewrite long RESOLVE_MAP macro to a debug friendly function
Date: Sat, 07 May 2022 16:33:43 +0300 [thread overview]
Message-ID: <a30afb4ca3c97e16401086e1d8a24ba5714cd2d3.camel@guriev.su> (raw)
In-Reply-To: <CAFP8O3JLS70yTZG81pTW9GjLOPeuqaD_=aAi62EuO_LFmSsbew@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3742 bytes --]
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 <nicholas@guriev.su>
---
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"
--
2.32.0
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2022-05-07 13:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-02 14:51 [PATCH] " Nicholas Guriev
2022-05-02 21:20 ` Fangrui Song
2022-05-03 10:04 ` Nicholas Guriev
2022-05-03 20:12 ` Fāng-ruì Sòng
2022-05-07 13:33 ` Nicholas Guriev [this message]
2022-05-09 13:38 ` [PATCH v3] " Siddhesh Poyarekar
2022-05-14 14:27 ` Nicholas Guriev
2022-05-14 22:48 ` Fangrui Song
2022-05-15 0:58 ` Siddhesh Poyarekar
2022-05-22 22:24 ` Fangrui Song
2022-05-23 7:28 ` Siddhesh Poyarekar
2022-05-23 12:35 ` Adhemerval Zanella
2022-05-23 13:02 ` Siddhesh Poyarekar
2022-05-23 16:22 ` Adhemerval Zanella
2022-05-23 16:33 ` Siddhesh Poyarekar
2022-05-23 16:56 ` Adhemerval Zanella
2022-05-03 19:14 ` [PATCH v2] " Nicholas Guriev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a30afb4ca3c97e16401086e1d8a24ba5714cd2d3.camel@guriev.su \
--to=nicholas@guriev.su \
--cc=libc-alpha@sourceware.org \
--cc=maskray@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).