BUILD: tools: fix build with static only toolchains
authorBaruch Siach <baruch@tkos.co.il>
Fri, 24 Jul 2020 04:52:20 +0000 (07:52 +0300)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 27 Jul 2020 07:49:20 +0000 (09:49 +0200)
uClibc toolchains built with no dynamic library support don't provide
the dlfcn.h header. That leads to build failure:

CC src/tools.o
src/tools.c:15:10: fatal error: dlfcn.h: No such file or directory
 #include <dlfcn.h>
          ^~~~~~~~~
Enable dladdr on Linux platforms only when USE_DL is defined.

This should be backported wherever 109201fc5 ("BUILD: tools: rely on
__ELF__ not USE_DL to enable use of dladdr()") is backported (currently
only 2.2 and 2.1).

(cherry picked from commit e1651b2970a699c517e185115e8f866dd5a04c92)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit c28833ecacd3cc315527003dca5b1ee7ac06a1c3)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/standard.c

index 1291461..33ab309 100644 (file)
@@ -10,7 +10,7 @@
  *
  */
 
-#ifdef __ELF__
+#if (defined(__ELF__) && !defined(__linux__)) || defined(USE_DL)
 #define _GNU_SOURCE
 #include <dlfcn.h>
 #include <link.h>
@@ -4343,7 +4343,7 @@ void debug_hexdump(FILE *out, const char *pfx, const char *buf,
        }
 }
 
-#ifdef __ELF__
+#if (defined(__ELF__) && !defined(__linux__)) || defined(USE_DL)
 /* calls dladdr() or dladdr1() on <addr> and <dli>. If dladdr1 is available,
  * also returns the symbol size in <size>, otherwise returns 0 there.
  */
@@ -4377,7 +4377,7 @@ static int dladdr_and_size(const void *addr, Dl_info *dli, size_t *size)
  * The file name (lib or executable) is limited to what lies between the last
  * '/' and the first following '.'. An optional prefix <pfx> is prepended before
  * the output if not null. The file is not dumped when it's the same as the one
- * that contains the "main" symbol, or when __ELF__ is not set.
+ * that contains the "main" symbol, or when __ELF__ && USE_DL are not set.
  *
  * The symbol's base address is returned, or NULL when unresolved, in order to
  * allow the caller to match it against known ones.
@@ -4405,7 +4405,7 @@ void *resolve_sym_name(struct buffer *buf, const char *pfx, void *addr)
 #endif
        };
 
-#ifdef __ELF__
+#if (defined(__ELF__) && !defined(__linux__)) || defined(USE_DL)
        Dl_info dli, dli_main;
        size_t size;
        const char *fname, *p;
@@ -4422,7 +4422,7 @@ void *resolve_sym_name(struct buffer *buf, const char *pfx, void *addr)
                }
        }
 
-#ifdef __ELF__
+#if (defined(__ELF__) && !defined(__linux__)) || defined(USE_DL)
        /* Now let's try to be smarter */
        if (!dladdr_and_size(addr, &dli, &size))
                goto unknown;
@@ -4462,7 +4462,7 @@ void *resolve_sym_name(struct buffer *buf, const char *pfx, void *addr)
                chunk_appendf(buf, "+%#lx", (long)(addr - dli.dli_fbase));
                return NULL;
        }
-#endif /* __ELF__ */
+#endif /* __ELF__ && !__linux__ || USE_DL */
  unknown:
        /* unresolved symbol from the main file, report relative offset to main */
        if ((void*)addr < (void*)main)