From: Jules Maselbas <jmaselbas@zdiv.net>
To: musl@lists.openwall.com
Cc: Jules Maselbas <jmaselbas@zdiv.net>
Subject: [musl] [PATCH] modify dladdr to add dladdr1 support
Date: Thu, 25 Jan 2024 13:10:04 +0100 [thread overview]
Message-ID: <20240125121004.13629-1-jmaselbas@zdiv.net> (raw)
The dladdr1() function is very much like dladdr(), but also returns
additional information depending on the value of the flags argument,
which can be one of the following values:
- RTLD_DL_LINKMAP, returns a pointer to the link map for the matched
file, same as dlinfo() with the RTLD_DI_LINKMAP request.
- RTLD_DL_SYMENT, returns a pointer to the ELF symbole structure that
matched for the given addr argument.
---
Implemented this because it is used by plthook (a dependency of renderdoc),
I have not tested this.
include/dlfcn.h | 3 +++
ldso/dynlink.c | 12 +++++++++++-
src/ldso/dladdr1.c | 9 +++++++++
3 files changed, 23 insertions(+), 1 deletion(-)
create mode 100644 src/ldso/dladdr1.c
diff --git a/include/dlfcn.h b/include/dlfcn.h
index 13ab71dd..8d09767a 100644
--- a/include/dlfcn.h
+++ b/include/dlfcn.h
@@ -32,6 +32,9 @@ typedef struct {
void *dli_saddr;
} Dl_info;
int dladdr(const void *, Dl_info *);
+int dladdr1(const void *, Dl_info *, void **, int);
+#define RTLD_DL_SYMENT 1
+#define RTLD_DL_LINKMAP 2
int dlinfo(void *, int, void *);
#endif
diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 324aa859..5cc550d6 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -2291,7 +2291,7 @@ static void *do_dlsym(struct dso *p, const char *s, void *ra)
return laddr(def.dso, def.sym->st_value);
}
-int dladdr(const void *addr_arg, Dl_info *info)
+int dladdr1(const void *addr_arg, Dl_info *info, void **extra_info, int flags)
{
size_t addr = (size_t)addr_arg;
struct dso *p;
@@ -2355,9 +2355,19 @@ int dladdr(const void *addr_arg, Dl_info *info)
info->dli_sname = strings + bestsym->st_name;
info->dli_saddr = (void *)best;
+ if (flags == RTLD_DL_LINKMAP)
+ *(struct link_map **)extra_info = (void *)p;
+ if (flags == RTLD_DL_SYMENT)
+ *(const Sym **)extra_info = bestsym;
+
return 1;
}
+int dladdr(const void *addr_arg, Dl_info *info)
+{
+ return dladdr1(addr_arg, info, NULL, 0);
+}
+
hidden void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)
{
void *res;
diff --git a/src/ldso/dladdr1.c b/src/ldso/dladdr1.c
new file mode 100644
index 00000000..b1e51379
--- /dev/null
+++ b/src/ldso/dladdr1.c
@@ -0,0 +1,9 @@
+#define _GNU_SOURCE
+#include <dlfcn.h>
+
+static int stub_dladdr1(const void *addr, Dl_info *info, void **extra_info, int flags)
+{
+ return 0;
+}
+
+weak_alias(stub_dladdr1, dladdr1);
--
2.43.0
reply other threads:[~2024-01-25 12:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20240125121004.13629-1-jmaselbas@zdiv.net \
--to=jmaselbas@zdiv.net \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).