glibc/dlfcn/dlinfo.c

122 lines
3.0 KiB
C
Raw Permalink Normal View History

/* dlinfo -- Get information from the dynamic linker.
Copyright (C) 2003-2022 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
Prefer https to http for gnu.org and fsf.org URLs Also, change sources.redhat.com to sourceware.org. This patch was automatically generated by running the following shell script, which uses GNU sed, and which avoids modifying files imported from upstream: sed -ri ' s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g ' \ $(find $(git ls-files) -prune -type f \ ! -name '*.po' \ ! -name 'ChangeLog*' \ ! -path COPYING ! -path COPYING.LIB \ ! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \ ! -path manual/texinfo.tex ! -path scripts/config.guess \ ! -path scripts/config.sub ! -path scripts/install-sh \ ! -path scripts/mkinstalldirs ! -path scripts/move-if-change \ ! -path INSTALL ! -path locale/programs/charmap-kw.h \ ! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \ ! '(' -name configure \ -execdir test -f configure.ac -o -f configure.in ';' ')' \ ! '(' -name preconfigure \ -execdir test -f preconfigure.ac ';' ')' \ -print) and then by running 'make dist-prepare' to regenerate files built from the altered files, and then executing the following to cleanup: chmod a+x sysdeps/unix/sysv/linux/riscv/configure # Omit irrelevant whitespace and comment-only changes, # perhaps from a slightly-different Autoconf version. git checkout -f \ sysdeps/csky/configure \ sysdeps/hppa/configure \ sysdeps/riscv/configure \ sysdeps/unix/sysv/linux/csky/configure # Omit changes that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines git checkout -f \ sysdeps/powerpc/powerpc64/ppc-mcount.S \ sysdeps/unix/sysv/linux/s390/s390-64/syscall.S # Omit change that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 07:40:42 +02:00
<https://www.gnu.org/licenses/>. */
#include <dlfcn.h>
#include <link.h>
#include <ldsodefs.h>
#include <libintl.h>
#include <dl-tls.h>
#include <shlib-compat.h>
struct dlinfo_args
{
void *handle;
int request;
void *arg;
/* This is the value that is returned from dlinfo if no error is
signaled. */
int result;
};
static void
dlinfo_doit (void *argsblock)
{
struct dlinfo_args *const args = argsblock;
struct link_map *l = args->handle;
switch (args->request)
{
case RTLD_DI_CONFIGADDR:
default:
args->result = -1;
_dl_signal_error (0, NULL, NULL, N_("unsupported dlinfo request"));
break;
[BZ #77] Update. Add support for namespaces in the dynamic linker. * dlfcn/Makefile (libdl-routines): Add dlmopen. * dlfcn/Versions [libdl, GLIBC_2.3.4]: Add dlmopen. * dlfcn/dlfcn.h: Define Lmid_t, LM_ID_BASE, and LM_ID_NEWLM. Declare dlmopen. Document RTLD_DI_LMID. * dlfcn/dlinfo.c: Handle RTLD_DI_LMID. * dlfcn/dlmopen.c: New file. * dlfcn/dlopen.c: Pass new parameter to _dl_open. * dlfcn/dlopenold.c: Likewise. * elf/dl-addr.c: Adjust for removal of GL(dl_loaded). * elf/dl-caller.c: Likewise. * elf/dl-close.c: Likewise. * elf/dl-conflict.c: Likewise. * elf/dl-debug.c: Likewise. * elf/dl-lookup.c: Likewise. * elf/dl-sym.c: Likewise. * elf/dl-version.c: Likewise. * elf/do-lookup.h: Likewise. * elf/rtld.c: Likewise. * sysdeps/unix/sysv/linux/i386/dl-librecon.h: Likewise. * elf/dl-depsc: Likewise. Add new parameter to _dl_map_object. * elf/dl-fini.c: Call destructors in all namespaces. * elf/dl-iteratephdr.c: Compute total nloaded. Adjust for removal of GL(dl_loaded). * elf/dl-libc.c: Pass new parameter to _dl_open. Adjust for removal of GL(dl_loaded). * elf/dl-load.c (_dl_map_object_from_fd): Don't load ld.so a second time. Reuse the one from the main namespace in all others. Pass new parameter to _dl_new_object. Adjust for removal of GL(dl_loaded). * elf/dl-object.c: Take new parameter. Use it to initialize l_ns. Adjust for removal of GL(dl_loaded). * elf/dl-open.c (_dl_open): Take new parameter. Adjust for removal of GL(dl_loaded). * elf/dl-support.c: Replace global _dl_loaded etc variables with _dl_ns variable. * include/dlfcn.h: Adjust prototype of _dl_open. Define __LM_ID_CALLER. * include/link.h: Add l_real, l_ns, and l_direct_opencount elements. * sysdeps/generic/dl-tls.c: Bump TLS_STATIC_SURPLUS. Since libc is using TLS we need memory appropriate to the number of namespaces. * sysdeps/generic/ldsodefs.h (struct rtld_global): Replace _dl_loaded, _dl_nloaded, _dl_global_scope, _dl_main_searchlist, and _dl_global_scope_alloc with _dl_ns element. Define DL_NNS. Adjust prototypes of _dl_map_object and member in rtld_global_ro. * malloc/malloc.c: Include <dlfcn.h>. * malloc/arena.c (ptmalloc_init): If libc is not in primary namespace, never use brk. * elf/Makefile: Add rules to build and run tst-dlmopen1 and tst-dlmopen2. * elf/tst-dlmopen1.c: New file. * elf/tst-dlmopen1mod.c: New file. * elf/tst-dlmopen2.c: New file. * elf/dl-close.c: Improve reference counting by tracking direct loads. * elf/dl-lookup.c (add_dependency): Likewise. * elf/dl-open.c (dl_open_worker): Likewise. * elf/rtld.c (dl_main): Likewise. 2004-09-09 GOTO Masanori <gotom@debian.or.jp> [BZ #77] * elf/dl-close.c: Count down l_opencount to check not only for l_reldeps, but also l_initfini. 2004-10-13 Ulrich Drepper <drepper@redhat.com>
2004-10-14 04:08:23 +02:00
case RTLD_DI_LMID:
*(Lmid_t *) args->arg = l->l_ns;
break;
case RTLD_DI_LINKMAP:
*(struct link_map **) args->arg = l;
break;
case RTLD_DI_SERINFO:
_dl_rtld_di_serinfo (l, args->arg, false);
break;
case RTLD_DI_SERINFOSIZE:
_dl_rtld_di_serinfo (l, args->arg, true);
break;
case RTLD_DI_ORIGIN:
strcpy (args->arg, l->l_origin);
break;
case RTLD_DI_TLS_MODID:
*(size_t *) args->arg = 0;
*(size_t *) args->arg = l->l_tls_modid;
break;
case RTLD_DI_TLS_DATA:
{
void *data = NULL;
if (l->l_tls_modid != 0)
data = GLRO(dl_tls_get_addr_soft) (l);
*(void **) args->arg = data;
break;
}
case RTLD_DI_PHDR:
*(const ElfW(Phdr) **) args->arg = l->l_phdr;
args->result = l->l_phnum;
break;
}
}
static int
dlinfo_implementation (void *handle, int request, void *arg)
{
struct dlinfo_args args = { handle, request, arg };
_dlerror_run (&dlinfo_doit, &args);
return args.result;
}
#ifdef SHARED
int
___dlinfo (void *handle, int request, void *arg)
{
if (GLRO (dl_dlfcn_hook) != NULL)
return GLRO (dl_dlfcn_hook)->dlinfo (handle, request, arg);
else
return dlinfo_implementation (handle, request, arg);
}
versioned_symbol (libc, ___dlinfo, dlinfo, GLIBC_2_34);
# if OTHER_SHLIB_COMPAT (libdl, GLIBC_2_3_3, GLIBC_2_34)
compat_symbol (libc, ___dlinfo, dlinfo, GLIBC_2_3_3);
Update. 2004-10-18 Jakub Jelinek <jakub@redhat.com> * elf/dl-libc.c (__libc_dlsym_private, __libc_register_dl_open_hook): New functions. (__libc_dlopen_mode): Call __libc_register_dl_open_hook and __libc_register_dlfcn_hook. * dlfcn/Makefile (routines, elide-routines.os): Set. Add rules to build and test tststatic2. * dlfcn/tststatic2.c: New test. * dlfcn/modstatic2.c: New test module. * dlfcn/dladdr.c: Call _dlfcn_hook from libdl.so if not NULL. Define __ prefixed routine in libc.a and in libdl.a just call it. * dlfcn/dladdr1.c: Likewise. * dlfcn/dlclose.c: Likewise. * dlfcn/dlerror.c: Likewise. * dlfcn/dlinfo.c: Likewise. * dlfcn/dlmopen.c: Likewise. * dlfcn/dlopen.c: Likewise. * dlfcn/dlopenold.c: Likewise. * dlfcn/dlsym.c: Likewise. * dlfcn/dlvsym.c: Likewise. * dlfcn/sdladdr.c: New file. * dlfcn/sdladdr1.c: New file. * dlfcn/sdlclose.c: New file. * dlfcn/sdlerror.c: New file. * dlfcn/sdlinfo.c: New file. * dlfcn/sdlopen.c: New file. * dlfcn/sdlsym.c: New file. * dlfcn/sdlvsym.c: New file. * dlfcn/Versions (libdl): Export _dlfcn_hook@GLIBC_PRIVATE. * include/dlfcn.h (DL_CALLER_DECL, DL_CALLER RETURN_ADDRESS): Define. (struct dlfcn_hook): New type. (_dlfcn_hook): New extern decl. (__dlopen, __dlclose, __dlsym, __dlerror, __dladdr, __dladdr1, __dlinfo, __dlmopen, __libc_dlsym_private, __libc_register_dl_open_hook, __libc_register_dlfcn_hook): New prototypes. (__dlvsym): Use DL_CALLER_DECL. * include/libc-symbols.h: Define libdl_hidden_proto and friends. * malloc/arena.c (_dl_open_hook): Extern decl. (ptmalloc_init): Don't call _dl_addr when dlopened from statically linked programs but don't use brk for them either.
2004-10-19 01:17:46 +02:00
# endif
#else /* !SHARED */
/* Also used with _dlfcn_hook. */
int
__dlinfo (void *handle, int request, void *arg)
{
return dlinfo_implementation (handle, request, arg);
}
weak_alias (__dlinfo, dlinfo)
Update. 2004-10-18 Jakub Jelinek <jakub@redhat.com> * elf/dl-libc.c (__libc_dlsym_private, __libc_register_dl_open_hook): New functions. (__libc_dlopen_mode): Call __libc_register_dl_open_hook and __libc_register_dlfcn_hook. * dlfcn/Makefile (routines, elide-routines.os): Set. Add rules to build and test tststatic2. * dlfcn/tststatic2.c: New test. * dlfcn/modstatic2.c: New test module. * dlfcn/dladdr.c: Call _dlfcn_hook from libdl.so if not NULL. Define __ prefixed routine in libc.a and in libdl.a just call it. * dlfcn/dladdr1.c: Likewise. * dlfcn/dlclose.c: Likewise. * dlfcn/dlerror.c: Likewise. * dlfcn/dlinfo.c: Likewise. * dlfcn/dlmopen.c: Likewise. * dlfcn/dlopen.c: Likewise. * dlfcn/dlopenold.c: Likewise. * dlfcn/dlsym.c: Likewise. * dlfcn/dlvsym.c: Likewise. * dlfcn/sdladdr.c: New file. * dlfcn/sdladdr1.c: New file. * dlfcn/sdlclose.c: New file. * dlfcn/sdlerror.c: New file. * dlfcn/sdlinfo.c: New file. * dlfcn/sdlopen.c: New file. * dlfcn/sdlsym.c: New file. * dlfcn/sdlvsym.c: New file. * dlfcn/Versions (libdl): Export _dlfcn_hook@GLIBC_PRIVATE. * include/dlfcn.h (DL_CALLER_DECL, DL_CALLER RETURN_ADDRESS): Define. (struct dlfcn_hook): New type. (_dlfcn_hook): New extern decl. (__dlopen, __dlclose, __dlsym, __dlerror, __dladdr, __dladdr1, __dlinfo, __dlmopen, __libc_dlsym_private, __libc_register_dl_open_hook, __libc_register_dlfcn_hook): New prototypes. (__dlvsym): Use DL_CALLER_DECL. * include/libc-symbols.h: Define libdl_hidden_proto and friends. * malloc/arena.c (_dl_open_hook): Extern decl. (ptmalloc_init): Don't call _dl_addr when dlopened from statically linked programs but don't use brk for them either.
2004-10-19 01:17:46 +02:00
#endif