From 6a1ed32789eaec6e1cd4345552e7342b5b18da5f Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Thu, 3 Jun 2021 08:26:04 +0200 Subject: dlfcn: Move dlmopen into libc The symbol was moved using scripts/move-symbol-to-libc.py. Reviewed-by: Adhemerval Zanella --- dlfcn/Makefile | 3 ++- dlfcn/Versions | 6 ++++- dlfcn/dlfcn.c | 19 ++++++++++++++- dlfcn/dlmopen.c | 73 +++++++++++++++++++++++++++++++------------------------- dlfcn/sdlmopen.c | 1 - 5 files changed, 65 insertions(+), 37 deletions(-) delete mode 100644 dlfcn/sdlmopen.c (limited to 'dlfcn') diff --git a/dlfcn/Makefile b/dlfcn/Makefile index b0f2e8a..f7ffd24 100644 --- a/dlfcn/Makefile +++ b/dlfcn/Makefile @@ -22,13 +22,14 @@ include ../Makeconfig headers := bits/dlfcn.h dlfcn.h extra-libs := libdl libdl-routines := dlopen dlvsym dladdr1 dlinfo \ - dlmopen dlfcn + dlfcn routines := $(patsubst %,s%,$(filter-out dlfcn,$(libdl-routines))) elide-routines.os := $(routines) routines += \ dladdr \ dlclose \ dlerror \ + dlmopen \ dlsym \ libc_dlerror_result \ diff --git a/dlfcn/Versions b/dlfcn/Versions index 7d6b51a..584035e 100644 --- a/dlfcn/Versions +++ b/dlfcn/Versions @@ -5,10 +5,14 @@ libc { dlerror; dlsym; } + GLIBC_2.3.4 { + dlmopen; + } GLIBC_2.34 { dladdr; dlclose; dlerror; + dlmopen; dlsym; } GLIBC_PRIVATE { @@ -28,6 +32,6 @@ libdl { dladdr1; dlinfo; } GLIBC_2.3.4 { - dlmopen; + __libdl_version_placeholder; } } diff --git a/dlfcn/dlfcn.c b/dlfcn/dlfcn.c index 8f85308..90cdee0 100644 --- a/dlfcn/dlfcn.c +++ b/dlfcn/dlfcn.c @@ -17,7 +17,7 @@ . */ #include - +#include int __dlfcn_argc attribute_hidden; char **__dlfcn_argv attribute_hidden; @@ -36,3 +36,20 @@ static void (*const init_array []) (int argc, char *argv[]) { init }; + +/* The remainder of this file is used to keep specific symbol versions + occupied, so that ld does not generate weak symbol version + definitions. */ + +void +attribute_compat_text_section +__attribute_used__ +__libdl_version_placeholder_1 (void) +{ +} + +#if SHLIB_COMPAT (libdl, GLIBC_2_3_4, GLIBC_2_34) \ + && ABI_libdl_GLIBC_2_3_4 != ABI_libdl_GLIBC_2_1 +compat_symbol (libdl, __libdl_version_placeholder_1, + __libdl_version_placeholder, GLIBC_2_3_4); +#endif diff --git a/dlfcn/dlmopen.c b/dlfcn/dlmopen.c index 6c6e98c..ae42814 100644 --- a/dlfcn/dlmopen.c +++ b/dlfcn/dlmopen.c @@ -22,17 +22,7 @@ #include #include #include - -#if !defined SHARED && IS_IN (libdl) - -void * -dlmopen (Lmid_t nsid, const char *file, int mode) -{ - return __dlmopen (nsid, file, mode, RETURN_ADDRESS (0)); -} -static_link_warning (dlmopen) - -#else +#include struct dlmopen_args { @@ -70,38 +60,55 @@ dlmopen_doit (void *a) args->new = GLRO(dl_open) (args->file ?: "", args->mode | __RTLD_DLOPEN, args->caller, - args->nsid, __dlfcn_argc, __dlfcn_argv, - __environ); + args->nsid, __libc_argc, __libc_argv, __environ); } - -void * -__dlmopen (Lmid_t nsid, const char *file, int mode DL_CALLER_DECL) +static void * +dlmopen_implementation (Lmid_t nsid, const char *file, int mode, + void *dl_caller) { -# ifdef SHARED - if (!rtld_active ()) - return _dlfcn_hook->dlmopen (nsid, file, mode, RETURN_ADDRESS (0)); -# endif - struct dlmopen_args args; args.nsid = nsid; args.file = file; args.mode = mode; - args.caller = DL_CALLER; + args.caller = dl_caller; -# ifdef SHARED return _dlerror_run (dlmopen_doit, &args) ? NULL : args.new; -# else - if (_dlerror_run (dlmopen_doit, &args)) - return NULL; +} - __libc_register_dl_open_hook ((struct link_map *) args.new); - __libc_register_dlfcn_hook ((struct link_map *) args.new); +#ifdef SHARED +void * +___dlmopen (Lmid_t nsid, const char *file, int mode) +{ + if (!rtld_active ()) + return _dlfcn_hook->dlmopen (nsid, file, mode, RETURN_ADDRESS (0)); + else + return dlmopen_implementation (nsid, file, mode, RETURN_ADDRESS (0)); +} +versioned_symbol (libc, ___dlmopen, dlmopen, GLIBC_2_34); - return args.new; +# if OTHER_SHLIB_COMPAT (libdl, GLIBC_2_3_4, GLIBC_2_34) +compat_symbol (libdl, ___dlmopen, dlmopen, GLIBC_2_3_4); # endif +#else /* !SHARED */ +/* Also used with _dlfcn_hook. */ +void * +__dlmopen (Lmid_t nsid, const char *file, int mode, void *dl_caller) +{ + return dlmopen_implementation (nsid, file, mode, RETURN_ADDRESS (0)); } -# ifdef SHARED -strong_alias (__dlmopen, dlmopen) -# endif -#endif + +void * +___dlmopen (Lmid_t nsid, const char *file, int mode) +{ + struct link_map *l = __dlmopen (nsid, file, mode, RETURN_ADDRESS (0)); + if (l != NULL) + { + __libc_register_dl_open_hook (l); + __libc_register_dlfcn_hook (l); + } + return l; +} +weak_alias (___dlmopen, dlmopen) +static_link_warning (dlmopen) +#endif /* !SHARED */ diff --git a/dlfcn/sdlmopen.c b/dlfcn/sdlmopen.c deleted file mode 100644 index 9630c89..0000000 --- a/dlfcn/sdlmopen.c +++ /dev/null @@ -1 +0,0 @@ -#include "dlmopen.c" -- cgit v1.1