aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2023-08-09 05:07:05 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2023-08-09 05:07:05 +0000
commit21a52f99440c9bec7679f3b0c5c9d888901c3694 (patch)
tree8eebc3e5d109e29898b7a73123bdee394dea2e75
parent0f613ab85e5a5274704d179f39fb15163d46e7c4 (diff)
downloadsrc-21a52f99440c9bec7679f3b0c5c9d888901c3694.tar.gz
src-21a52f99440c9bec7679f3b0c5c9d888901c3694.zip
libc dlfcn.c: make dl_iterate_phdr() from libc more useful
Apparently there are applications that resolve dl_iterate_phdr from libc and try to call the symbol. Our libc only provides stubs for dl* to satisfy static linker or statically linked binaries, and is not prepared to this situation. Add a code to dso libc to find real dl_iterate_phdr and redirect the call to it. Reported by: yuri PR: 272992 Sponsored by: The FreeBSD Foundation MFC after: 1 week
-rw-r--r--lib/libc/gen/dlfcn.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/libc/gen/dlfcn.c b/lib/libc/gen/dlfcn.c
index 61984e2fe86c..f1ee86ec1934 100644
--- a/lib/libc/gen/dlfcn.c
+++ b/lib/libc/gen/dlfcn.c
@@ -169,7 +169,9 @@ _rtld_thread_init(void *li __unused)
#ifndef IN_LIBDL
static pthread_once_t dl_phdr_info_once = PTHREAD_ONCE_INIT;
static struct dl_phdr_info phdr_info;
+#ifndef PIC
static mutex_t dl_phdr_info_lock = MUTEX_INITIALIZER;
+#endif
static void
dl_init_phdr_info(void)
@@ -208,7 +210,16 @@ int
dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *) __unused,
void *data __unused)
{
-#ifndef IN_LIBDL
+#if defined IN_LIBDL
+ return (0);
+#elif defined PIC
+ int (*r)(int (*)(struct dl_phdr_info *, size_t, void *), void *);
+
+ r = dlsym(RTLD_DEFAULT, "dl_iterate_phdr");
+ if (r == NULL)
+ return (0);
+ return (r(callback, data));
+#else
tls_index ti;
int ret;
@@ -223,8 +234,6 @@ dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *) __unused,
ret = callback(&phdr_info, sizeof(phdr_info), data);
mutex_unlock(&dl_phdr_info_lock);
return (ret);
-#else
- return (0);
#endif
}