]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: sym: use the symbol table to resolve a DSO name
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 28 Oct 2026 17:51:13 +0000 (18:51 +0100)
committerOlivier Houchard <cognet@ci0.org>
Thu, 29 Oct 2026 14:18:35 +0000 (15:18 +0100)
resolve_dso_name() only used dladdr() to find the object containing an
address. Our in-process symbol table also knows the owning object, is
lock-free and async-signal-safe, and also works on static builds where
dladdr() may not. Try it first and keep dladdr() as a fallback for
addresses that are not covered by any symbol, or when the table has not
been built yet.

src/sym.c

index a3fe65d48d8a2645d5ad10a3f3e46b2c53567505..412c82caf5a84560b063032d86baff98fcd992ec 100644 (file)
--- a/src/sym.c
+++ b/src/sym.c
@@ -1854,21 +1854,29 @@ const void *resolve_sym_name(struct buffer *buf, const char *pfx, const void *ad
  */
 const void *resolve_dso_name(struct buffer *buf, const char *pfx, const void *addr)
 {
+       struct sym_lookup sl;
+
+       if (sym_resolve(addr, &sl) && sl.file) {
+               if (pfx)
+                       chunk_appendf(buf, "%s", pfx);
+               append_obj_name(buf, sl.file);
+               return addr;
+       }
+
 #if (defined(__ELF__) && !defined(__linux__)) || defined(USE_DL)
-       Dl_info dli;
-       size_t size;
+       {
+               Dl_info dli;
+               size_t size;
 
-       /* Now let's try to be smarter */
-       if (!dladdr_and_size(addr, &dli, &size))
-               goto unknown;
+               /* Now let's try to be smarter */
+               if (!dladdr_and_size(addr, &dli, &size))
+                       goto unknown;
 
-       if (pfx) {
-               chunk_appendf(buf, "%s", pfx);
-               pfx = NULL;
+               if (pfx)
+                       chunk_appendf(buf, "%s", pfx);
+               append_obj_name(buf, dli.dli_fname);
+               return addr;
        }
-
-       append_obj_name(buf, dli.dli_fname);
-       return addr;
  unknown:
 #endif /* __ELF__ && !__linux__ || USE_DL */