From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Subject: [PATCH 28/33] elf: Determine the caller link map in _dl_open
Date: Tue, 04 Jul 2023 22:04:19 +0200 [thread overview]
Message-ID: <21b73a41f677870a7a8e20a3313e4887ef470416.1688499219.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1688499219.git.fweimer@redhat.com>
No functional change expected.
This is in preparation of adding a fast path to dlopen in case
no link map changes are required.
---
elf/dl-open.c | 47 +++++++++++++++++++----------------------------
1 file changed, 19 insertions(+), 28 deletions(-)
diff --git a/elf/dl-open.c b/elf/dl-open.c
index c2560f7eae..78c43a630c 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -49,8 +49,7 @@ struct dl_open_args
{
const char *file;
int mode;
- /* This is the caller of the dlopen() function. */
- const void *caller_dlopen;
+ struct link_map_private *caller_map; /* Derived from the caller address. */
struct link_map_private *map;
/* Namespace ID. */
Lmid_t nsid;
@@ -496,30 +495,6 @@ dl_open_worker_begin (void *a)
struct dl_open_args *args = a;
const char *file = args->file;
int mode = args->mode;
- struct link_map_private *call_map = NULL;
-
- /* Determine the caller's map if necessary. This is needed in case
- we have a DST, when we don't know the namespace ID we have to put
- the new object in, or when the file name has no path in which
- case we need to look along the RUNPATH/RPATH of the caller. */
- const char *dst = strchr (file, '$');
- if (dst != NULL || args->nsid == __LM_ID_CALLER
- || strchr (file, '/') == NULL)
- {
- const void *caller_dlopen = args->caller_dlopen;
-
- /* We have to find out from which object the caller is calling.
- By default we assume this is the main application. */
- call_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
-
- struct link_map_private *l = _dl_find_dso_for_object ((ElfW(Addr)) caller_dlopen);
-
- if (l)
- call_map = l;
-
- if (args->nsid == __LM_ID_CALLER)
- args->nsid = call_map->l_ns;
- }
/* Prepare for link map updates. If dl_open_worker below returns
normally, a matching _dl_protmem_end call is performed there. On
@@ -541,7 +516,7 @@ dl_open_worker_begin (void *a)
/* Load the named object. */
struct link_map_private *new;
- args->map = new = _dl_map_object (call_map, file, lt_loaded, 0,
+ args->map = new = _dl_map_object (args->caller_map, file, lt_loaded, 0,
mode | __RTLD_CALLMAP, args->nsid);
/* If the pointer returned is NULL this means the RTLD_NOLOAD flag is
@@ -887,7 +862,6 @@ no more namespaces available for dlmopen()"));
struct dl_open_args args;
args.file = file;
args.mode = mode;
- args.caller_dlopen = caller_dlopen;
args.map = NULL;
args.nsid = nsid;
/* args.libc_already_loaded is always assigned by dl_open_worker
@@ -896,6 +870,23 @@ no more namespaces available for dlmopen()"));
args.argv = argv;
args.env = env;
+ /* Determine the caller's map if necessary. This is needed when we
+ don't know the namespace ID in which we have to put the new object,
+ in case we have a DST, or when the file name has no path in
+ which case we need to look along the RUNPATH/RPATH of the caller. */
+ if (nsid == __LM_ID_CALLER || strchr (file, '$') != NULL
+ || strchr (file, '/') == NULL)
+ {
+ args.caller_map = _dl_find_dso_for_object ((ElfW(Addr)) caller_dlopen);
+ if (args.caller_map == NULL)
+ /* By default we assume this is the main application. */
+ args.caller_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
+ if (args.nsid == __LM_ID_CALLER)
+ args.nsid = args.caller_map->l_ns;
+ }
+ else
+ args.caller_map = NULL;
+
struct dl_exception exception;
int errcode = _dl_catch_exception (&exception, dl_open_worker, &args);
--
2.41.0
next prev parent reply other threads:[~2023-07-04 20:04 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-04 20:02 [PATCH 00/33] RFC: RELRO link maps Florian Weimer
2023-07-04 20:02 ` [PATCH 01/33] support: Add <support/memprobe.h> for protection flags probing Florian Weimer
2023-07-04 20:02 ` [PATCH 02/33] misc: Enable internal use of memory protection keys Florian Weimer
2023-07-04 20:02 ` [PATCH 03/33] elf: Remove _dl_sysdep_open_object hook function Florian Weimer
2023-07-04 20:02 ` [PATCH 04/33] elf: Eliminate second loop in find_version in dl-version.c Florian Weimer
2023-07-04 20:02 ` [PATCH 05/33] elf: In rtld_setup_main_map, assume ld.so has a DYNAMIC segment Florian Weimer
2023-07-04 20:02 ` [PATCH 06/33] elf: Remove version assert in check_match in elf/dl-lookup.c Florian Weimer
2023-07-04 20:02 ` [PATCH 07/33] elf: Disambiguate some failures in _dl_load_cache_lookup Florian Weimer
2023-07-04 20:02 ` [PATCH 08/33] elf: Eliminate alloca in open_verify Florian Weimer
2023-07-04 20:02 ` [PATCH 09/33] Do not export <alloc_buffer.h> functions from libc Florian Weimer
2023-07-04 20:02 ` [PATCH 10/33] elf: Make <alloc_buffer.h> usable in ld.so Florian Weimer
2023-07-04 20:03 ` [PATCH 11/33] elf: Merge the three implementations of _dl_dst_substitute Florian Weimer
2023-07-04 20:03 ` [PATCH 12/33] elf: _dl_find_object may return 1 during early startup (bug 30515) Florian Weimer
2023-07-04 20:03 ` [PATCH 13/33] elf: Move __rtld_malloc_init_stubs call into _dl_start_final Florian Weimer
2023-07-04 20:03 ` [PATCH 14/33] elf: Merge __dl_libc_freemem into __rtld_libc_freeres Florian Weimer
2023-07-04 20:03 ` [PATCH 15/33] elf: Use struct link_map_private for the internal link map Florian Weimer
2023-07-04 20:03 ` [PATCH 16/33] elf: Remove run-time-writable fields from struct link_map_private Florian Weimer
2023-07-04 20:03 ` [PATCH 17/33] elf: Move l_tls_offset into read-write part of link map Florian Weimer
2023-07-04 20:03 ` [PATCH 18/33] elf: Allocate auditor state after read-write " Florian Weimer
2023-07-04 20:03 ` [PATCH 19/33] elf: Move link map fields used by dependency sorting to writable part Florian Weimer
2023-07-04 20:03 ` [PATCH 20/33] elf: Split _dl_lookup_map, _dl_map_new_object from _dl_map_object Florian Weimer
2023-07-04 20:03 ` [PATCH 21/33] elf: Add l_soname accessor function for DT_SONAME values Florian Weimer
2023-07-04 20:03 ` [PATCH 22/33] elf: _dl_rtld_map should not exist in static builds Florian Weimer
2023-07-04 20:03 ` [PATCH 23/33] elf: Introduce GLPM accessor for the protected memory area Florian Weimer
2023-07-04 20:04 ` [PATCH 24/33] elf: Bootstrap allocation for future protected memory allocator Florian Weimer
2023-07-04 20:04 ` [PATCH 25/33] elf: Implement a basic " Florian Weimer
2023-07-04 20:04 ` [PATCH 26/33] elf: Move most of the _dl_find_object data to the protected heap Florian Weimer
2023-07-04 20:04 ` [PATCH 27/33] elf: Switch to a region-based protected memory allocator Florian Weimer
2023-07-04 20:04 ` Florian Weimer [this message]
2023-07-04 20:04 ` [PATCH 29/33] elf: Add fast path to dlopen for fully-opened maps Florian Weimer
2023-07-04 20:04 ` [PATCH 30/33] elf: Use _dl_find_object instead of _dl_find_dso_for_object in dlopen Florian Weimer
2023-07-04 20:04 ` [PATCH 31/33] elf: Put critical _dl_find_object pointers into protected memory area Florian Weimer
2023-07-04 20:04 ` [PATCH 32/33] elf: Add hash tables to speed up DT_NEEDED, dlopen lookups Florian Weimer
2023-07-04 20:04 ` [PATCH 33/33] elf: Use memory protection keys for the protected memory allocator Florian Weimer
2023-07-04 20:07 ` [PATCH 00/33] RFC: RELRO link maps Florian Weimer
2023-07-05 15:54 ` Carlos O'Donell
2023-07-05 15:57 ` Florian Weimer
2023-07-05 17:48 ` Carlos O'Donell
2023-07-05 17:58 ` Adhemerval Zanella Netto
2023-07-07 11:10 ` Florian Weimer
2023-07-07 12:42 ` Florian Weimer
2023-07-07 12:48 ` Adhemerval Zanella Netto
2023-07-07 13:18 ` Florian Weimer
2023-07-07 13:58 ` Adhemerval Zanella Netto
2023-07-07 14:55 ` 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=21b73a41f677870a7a8e20a3313e4887ef470416.1688499219.git.fweimer@redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/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).