From b12966af1006be8d4438ee1ca39c2541a1f2a4f9 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 13 Apr 2022 17:09:45 +0200 Subject: [PATCH] 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. --- include/haproxy/bug.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) 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); \ -- 2.39.5