From: Willy Tarreau Date: Wed, 13 Apr 2022 15:09:45 +0000 (+0200) Subject: BUILD: debug: mark the __start_mem_stats/__stop_mem_stats symbols as weak X-Git-Tag: v2.6-dev6~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b12966af1;p=thirdparty%2Fhaproxy.git BUILD: debug: mark the __start_mem_stats/__stop_mem_stats symbols as weak Building with clang and DEBUG_MEM_STATS shows the following warnings: warning: __start_mem_stats changed binding to STB_WEAK [-Wsource-mgr] warning: __stop_mem_stats changed binding to STB_WEAK [-Wsource-mgr] The reason is that the symbols are declared using ".globl" while they are also referenced as __attribute__((weak)) elsewhere. It turns out that a weak symbol is implicitly a global one and that the two classes are exclusive, thus it may confuse the linker. Better fix this. This may be backported where the patch applies. --- diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index 71b37eda69..997a114600 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -234,8 +234,8 @@ struct mem_stats { .file = __FILE__, .line = __LINE__, \ .type = MEM_STATS_TYPE_CALLOC, \ }; \ - __asm__(".globl __start_mem_stats"); \ - __asm__(".globl __stop_mem_stats"); \ + __asm__(".weak __start_mem_stats"); \ + __asm__(".weak __stop_mem_stats"); \ _HA_ATOMIC_INC(&_.calls); \ _HA_ATOMIC_ADD(&_.size, __x * __y); \ calloc(__x,__y); \ @@ -251,8 +251,8 @@ struct mem_stats { .file = __FILE__, .line = __LINE__, \ .type = MEM_STATS_TYPE_FREE, \ }; \ - __asm__(".globl __start_mem_stats"); \ - __asm__(".globl __stop_mem_stats"); \ + __asm__(".weak __start_mem_stats"); \ + __asm__(".weak __stop_mem_stats"); \ if (__x) \ _HA_ATOMIC_INC(&_.calls); \ free(__x); \ @@ -265,8 +265,8 @@ struct mem_stats { .file = __FILE__, .line = __LINE__, \ .type = MEM_STATS_TYPE_FREE, \ }; \ - __asm__(".globl __start_mem_stats"); \ - __asm__(".globl __stop_mem_stats"); \ + __asm__(".weak __start_mem_stats"); \ + __asm__(".weak __stop_mem_stats"); \ if (__builtin_constant_p((x)) || __builtin_constant_p(*(x))) { \ HA_LINK_ERROR(call_to_ha_free_attempts_to_free_a_constant); \ } \ @@ -283,8 +283,8 @@ struct mem_stats { .file = __FILE__, .line = __LINE__, \ .type = MEM_STATS_TYPE_MALLOC, \ }; \ - __asm__(".globl __start_mem_stats"); \ - __asm__(".globl __stop_mem_stats"); \ + __asm__(".weak __start_mem_stats"); \ + __asm__(".weak __stop_mem_stats"); \ _HA_ATOMIC_INC(&_.calls); \ _HA_ATOMIC_ADD(&_.size, __x); \ malloc(__x); \ @@ -297,8 +297,8 @@ struct mem_stats { .file = __FILE__, .line = __LINE__, \ .type = MEM_STATS_TYPE_REALLOC, \ }; \ - __asm__(".globl __start_mem_stats"); \ - __asm__(".globl __stop_mem_stats"); \ + __asm__(".weak __start_mem_stats"); \ + __asm__(".weak __stop_mem_stats"); \ _HA_ATOMIC_INC(&_.calls); \ _HA_ATOMIC_ADD(&_.size, __y); \ realloc(__x,__y); \ @@ -311,8 +311,8 @@ struct mem_stats { .file = __FILE__, .line = __LINE__, \ .type = MEM_STATS_TYPE_STRDUP, \ }; \ - __asm__(".globl __start_mem_stats"); \ - __asm__(".globl __stop_mem_stats"); \ + __asm__(".weak __start_mem_stats"); \ + __asm__(".weak __stop_mem_stats"); \ _HA_ATOMIC_INC(&_.calls); \ _HA_ATOMIC_ADD(&_.size, __y); \ strdup(__x); \