From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 17A22395C000; Tue, 10 Aug 2021 13:42:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 17A22395C000 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc/azanella/rtld-shared] elf: Abstract loaded-DSO search code into a helper function X-Act-Checkin: glibc X-Git-Author: Vivek Das Mohapatra X-Git-Refname: refs/heads/azanella/rtld-shared X-Git-Oldrev: 3b233f1ef048eea24b8dbf44fc9c7bac82b8fbd3 X-Git-Newrev: 22b419be4e23df6fead108b7a40ea7b019aa9f13 Message-Id: <20210810134201.17A22395C000@sourceware.org> Date: Tue, 10 Aug 2021 13:42:01 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Aug 2021 13:42:01 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=22b419be4e23df6fead108b7a40ea7b019aa9f13 commit 22b419be4e23df6fead108b7a40ea7b019aa9f13 Author: Vivek Das Mohapatra Date: Thu Jul 8 17:32:49 2021 +0100 elf: Abstract loaded-DSO search code into a helper function Reviewed-by: Adhemerval Zanella Diff: --- elf/dl-load.c | 44 ++++++++++++++++++++++++++++++-------------- sysdeps/generic/ldsodefs.h | 4 ++++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 650e4edc35..fb23ba632b 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -2027,24 +2027,13 @@ open_path (const char *name, size_t namelen, int mode, return -1; } -/* Map in the shared object file NAME. */ - +/* Search for a shared object in a given namespace. */ struct link_map * -_dl_map_object (struct link_map *loader, const char *name, - int type, int trace_mode, int mode, Lmid_t nsid) +_dl_find_dso (const char *name, Lmid_t nsid) { - int fd; - const char *origname = NULL; - char *realname; - char *name_copy; struct link_map *l; - struct filebuf fb; - assert (nsid >= 0); - assert (nsid < GL(dl_nns)); - - /* Look for this name among those already loaded. */ - for (l = GL(dl_ns)[nsid]._ns_loaded; l; l = l->l_next) + for (l = GL(dl_ns)[nsid]._ns_loaded; l != NULL; l = l->l_next) { /* If the requested name matches the soname of a loaded object, use that object. Elide this check for names that have not @@ -2073,6 +2062,33 @@ _dl_map_object (struct link_map *loader, const char *name, return l; } + return NULL; +} + +/* Map in the shared object file NAME. */ + +struct link_map * +_dl_map_object (struct link_map *loader, const char *name, + int type, int trace_mode, int mode, Lmid_t nsid) +{ + int fd; + const char *origname = NULL; + char *realname; + char *name_copy; + struct link_map *l; + struct filebuf fb; + + assert (nsid >= 0); + assert (nsid < GL(dl_nns)); + + /* Look for this name among those already loaded. */ + l = _dl_find_dso (name, nsid); + + if (l != NULL) + { + return l; + } + /* Display information if we are debugging. */ if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES) && loader != NULL) diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 9c15259236..22f3fea436 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1287,6 +1287,10 @@ extern void _dl_show_scope (struct link_map *new, int from) extern struct link_map *_dl_find_dso_for_object (const ElfW(Addr) addr); rtld_hidden_proto (_dl_find_dso_for_object) +extern struct link_map *_dl_find_dso (const char *name, Lmid_t nsid); +rtld_hidden_proto (_dl_find_dso) + + /* Initialization which is normally done by the dynamic linker. */ extern void _dl_non_dynamic_init (void) attribute_hidden;