]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: debug: mark the __start_mem_stats/__stop_mem_stats symbols as weak
authorWilly Tarreau <w@1wt.eu>
Wed, 13 Apr 2022 15:09:45 +0000 (17:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 13 Apr 2022 17:13:49 +0000 (19:13 +0200)
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

index 71b37eda6974c5cf08e34ce1c84ae6f7d777aa1a..997a114600fbc28cb465b9f197ae102e52a1851d 100644 (file)
@@ -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);                                                    \