From: "Wangbing(wangbing,RTOS/Poincare Lab)" <wangbing6@huawei.com>
To: "libc-alpha@sourceware.org" <libc-alpha@sourceware.org>
Cc: Nixiaoming <nixiaoming@huawei.com>
Subject: [PATCH] dlsym: Add RTLD_PROBE for situation when dlsym only wants to probe a symbol but not use it
Date: Tue, 27 Sep 2022 09:21:04 +0000 [thread overview]
Message-ID: <efbc56f827194b87878392540b88fa12@huawei.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2470 bytes --]
dlsym with RTLD_DEFAULT add dependency for target symbol, if program use dlsym only to detect if a symbol exist, and will not use it.
this operation will make unable to dlclose so file containing target symbol, add RTLD_PROBE to support symbol probe.
commit f769328dba5351107097c3a3ad7e1192604318d0
Author: Wang Bing <wangbing6@huawei.com<mailto:wangbing6@huawei.com>>
Date: Tue Sep 27 14:58:43 2022 +0800
dlsym: Add RTLD_PROBE for situation when dlsym only wants to probe a symbol but not use it
diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h
index fe181085..7ac0d5f1 100644
--- a/dlfcn/dlfcn.h
+++ b/dlfcn/dlfcn.h
@@ -39,6 +39,9 @@
is returned. */
# define RTLD_DEFAULT ((void *) 0)
+/* If only find sym in the global scope, but will not use it, do not
+ set sym dependency. */
+# define RTLD_PROBE ((void *) -2l)
/* Type for namespace indices. */
typedef long int Lmid_t;
diff --git a/elf/dl-sym.c b/elf/dl-sym.c
index de5769f9..970f2028 100644
--- a/elf/dl-sym.c
+++ b/elf/dl-sym.c
@@ -92,10 +92,15 @@ do_sym (void *handle, const char *name, void *who,
/* Link map of the caller if needed. */
struct link_map *match = NULL;
- if (handle == RTLD_DEFAULT)
+ if (handle == RTLD_DEFAULT || handle == RTLD_PROBE)
{
match = _dl_sym_find_caller_link_map (caller);
+ int def_flags = flags;
+ if (handle == RTLD_DEFAULT)
+ {
+ def_flags |= DL_LOOKUP_ADD_DEPENDENCY;
+ }
/* 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
@@ -104,7 +109,7 @@ do_sym (void *handle, const char *name, void *who,
if (RTLD_SINGLE_THREAD_P)
result = GLRO(dl_lookup_symbol_x) (name, match, &ref,
match->l_scope, vers, 0,
- flags | DL_LOOKUP_ADD_DEPENDENCY,
+ def_flags,
NULL);
else
{
@@ -113,7 +118,7 @@ do_sym (void *handle, const char *name, void *who,
args.map = match;
args.vers = vers;
args.flags
- = flags | DL_LOOKUP_ADD_DEPENDENCY | DL_LOOKUP_GSCOPE_LOCK;
+ = def_flags | DL_LOOKUP_GSCOPE_LOCK;
args.refp = &ref;
THREAD_GSCOPE_SET_FLAG ();
next reply other threads:[~2022-09-27 9:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-27 9:21 Wangbing(wangbing,RTOS/Poincare Lab) [this message]
2022-09-27 10:40 ` Florian Weimer
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=efbc56f827194b87878392540b88fa12@huawei.com \
--to=wangbing6@huawei.com \
--cc=libc-alpha@sourceware.org \
--cc=nixiaoming@huawei.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).