mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-23 06:41:32 +02:00
BUILD: compiler: properly distinguish weak and global symbols
While weak symbols were finally fixed with commit fb1b6f5bc ("BUILD: compiler: use a more portable set of asm(".weak") statements"), it was an error to think that initcall symbols were also weak. They must not be and they're only global. The reason is that any externally linked code loaded as a .so would drop its weak symbols when being loaded, hence its initcalls that may contain various function registration calls. The ambiguity came from the fact that we initially reused the initcall's HA_GLOBL macro for OSX then generalized it, then turned it to a choice between .globl and .weak based on the OS, while in fact we needed a macro to define weak symbols. Let's rename the macro to HA_WEAK() to make it clear it's only for weak symbols, and redefine HA_GLOBL() that initcall needs. This will need to be backported wherever the commit above is backported (at least 2.5 for now).
This commit is contained in:
parent
03a32e5dd2
commit
65d9f83794
@ -234,8 +234,8 @@ struct mem_stats {
|
|||||||
.file = __FILE__, .line = __LINE__, \
|
.file = __FILE__, .line = __LINE__, \
|
||||||
.type = MEM_STATS_TYPE_CALLOC, \
|
.type = MEM_STATS_TYPE_CALLOC, \
|
||||||
}; \
|
}; \
|
||||||
HA_GLOBL("__start_mem_stats"); \
|
HA_WEAK("__start_mem_stats"); \
|
||||||
HA_GLOBL("__stop_mem_stats"); \
|
HA_WEAK("__stop_mem_stats"); \
|
||||||
_HA_ATOMIC_INC(&_.calls); \
|
_HA_ATOMIC_INC(&_.calls); \
|
||||||
_HA_ATOMIC_ADD(&_.size, __x * __y); \
|
_HA_ATOMIC_ADD(&_.size, __x * __y); \
|
||||||
calloc(__x,__y); \
|
calloc(__x,__y); \
|
||||||
@ -251,8 +251,8 @@ struct mem_stats {
|
|||||||
.file = __FILE__, .line = __LINE__, \
|
.file = __FILE__, .line = __LINE__, \
|
||||||
.type = MEM_STATS_TYPE_FREE, \
|
.type = MEM_STATS_TYPE_FREE, \
|
||||||
}; \
|
}; \
|
||||||
HA_GLOBL("__start_mem_stats"); \
|
HA_WEAK("__start_mem_stats"); \
|
||||||
HA_GLOBL("__stop_mem_stats"); \
|
HA_WEAK("__stop_mem_stats"); \
|
||||||
if (__x) \
|
if (__x) \
|
||||||
_HA_ATOMIC_INC(&_.calls); \
|
_HA_ATOMIC_INC(&_.calls); \
|
||||||
free(__x); \
|
free(__x); \
|
||||||
@ -265,8 +265,8 @@ struct mem_stats {
|
|||||||
.file = __FILE__, .line = __LINE__, \
|
.file = __FILE__, .line = __LINE__, \
|
||||||
.type = MEM_STATS_TYPE_FREE, \
|
.type = MEM_STATS_TYPE_FREE, \
|
||||||
}; \
|
}; \
|
||||||
HA_GLOBL("__start_mem_stats"); \
|
HA_WEAK("__start_mem_stats"); \
|
||||||
HA_GLOBL("__stop_mem_stats"); \
|
HA_WEAK("__stop_mem_stats"); \
|
||||||
if (__builtin_constant_p((x)) || __builtin_constant_p(*(x))) { \
|
if (__builtin_constant_p((x)) || __builtin_constant_p(*(x))) { \
|
||||||
HA_LINK_ERROR(call_to_ha_free_attempts_to_free_a_constant); \
|
HA_LINK_ERROR(call_to_ha_free_attempts_to_free_a_constant); \
|
||||||
} \
|
} \
|
||||||
@ -283,8 +283,8 @@ struct mem_stats {
|
|||||||
.file = __FILE__, .line = __LINE__, \
|
.file = __FILE__, .line = __LINE__, \
|
||||||
.type = MEM_STATS_TYPE_MALLOC, \
|
.type = MEM_STATS_TYPE_MALLOC, \
|
||||||
}; \
|
}; \
|
||||||
HA_GLOBL("__start_mem_stats"); \
|
HA_WEAK("__start_mem_stats"); \
|
||||||
HA_GLOBL("__stop_mem_stats"); \
|
HA_WEAK("__stop_mem_stats"); \
|
||||||
_HA_ATOMIC_INC(&_.calls); \
|
_HA_ATOMIC_INC(&_.calls); \
|
||||||
_HA_ATOMIC_ADD(&_.size, __x); \
|
_HA_ATOMIC_ADD(&_.size, __x); \
|
||||||
malloc(__x); \
|
malloc(__x); \
|
||||||
@ -297,8 +297,8 @@ struct mem_stats {
|
|||||||
.file = __FILE__, .line = __LINE__, \
|
.file = __FILE__, .line = __LINE__, \
|
||||||
.type = MEM_STATS_TYPE_REALLOC, \
|
.type = MEM_STATS_TYPE_REALLOC, \
|
||||||
}; \
|
}; \
|
||||||
HA_GLOBL("__start_mem_stats"); \
|
HA_WEAK("__start_mem_stats"); \
|
||||||
HA_GLOBL("__stop_mem_stats"); \
|
HA_WEAK("__stop_mem_stats"); \
|
||||||
_HA_ATOMIC_INC(&_.calls); \
|
_HA_ATOMIC_INC(&_.calls); \
|
||||||
_HA_ATOMIC_ADD(&_.size, __y); \
|
_HA_ATOMIC_ADD(&_.size, __y); \
|
||||||
realloc(__x,__y); \
|
realloc(__x,__y); \
|
||||||
@ -311,8 +311,8 @@ struct mem_stats {
|
|||||||
.file = __FILE__, .line = __LINE__, \
|
.file = __FILE__, .line = __LINE__, \
|
||||||
.type = MEM_STATS_TYPE_STRDUP, \
|
.type = MEM_STATS_TYPE_STRDUP, \
|
||||||
}; \
|
}; \
|
||||||
HA_GLOBL("__start_mem_stats"); \
|
HA_WEAK("__start_mem_stats"); \
|
||||||
HA_GLOBL("__stop_mem_stats"); \
|
HA_WEAK("__stop_mem_stats"); \
|
||||||
_HA_ATOMIC_INC(&_.calls); \
|
_HA_ATOMIC_INC(&_.calls); \
|
||||||
_HA_ATOMIC_ADD(&_.size, __y); \
|
_HA_ATOMIC_ADD(&_.size, __y); \
|
||||||
strdup(__x); \
|
strdup(__x); \
|
||||||
|
@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
#endif // USE_OBSOLETE_LINKER
|
#endif // USE_OBSOLETE_LINKER
|
||||||
|
|
||||||
/* Declare a symbol as global and if possible, as weak. Since we don't want to
|
/* Declare a symbol as weak if possible, otherwise global. Since we don't want to
|
||||||
* error on multiple definitions, the symbol is declared weak. On MacOS ".weak"
|
* error on multiple definitions, the symbol is declared weak. On MacOS ".weak"
|
||||||
* does not exist and we must continue to use ".globl" instead. Note that
|
* does not exist and we must continue to use ".globl" instead. Note that
|
||||||
* ".global" is to be avoided on other platforms as llvm complains about it
|
* ".global" is to be avoided on other platforms as llvm complains about it
|
||||||
@ -97,11 +97,15 @@
|
|||||||
* anyway (and most likely it will only work with !USE_OBSOLETE_LINKER).
|
* anyway (and most likely it will only work with !USE_OBSOLETE_LINKER).
|
||||||
*/
|
*/
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
# define __HA_GLOBL(sym) __asm__(".globl " #sym)
|
# define __HA_WEAK(sym) __asm__(".globl " #sym)
|
||||||
#else
|
#else
|
||||||
# define __HA_GLOBL(sym) __asm__(".weak " #sym)
|
# define __HA_WEAK(sym) __asm__(".weak " #sym)
|
||||||
#endif
|
#endif
|
||||||
#define HA_GLOBL(sym) __HA_GLOBL(sym)
|
#define HA_WEAK(sym) __HA_WEAK(sym)
|
||||||
|
|
||||||
|
/* declare a symbol as global */
|
||||||
|
#define __HA_GLOBL(sym) __asm__(".globl " #sym)
|
||||||
|
#define HA_GLOBL(sym) __HA_GLOBL(sym)
|
||||||
|
|
||||||
/* use this attribute on a variable to move it to the read_mostly section */
|
/* use this attribute on a variable to move it to the read_mostly section */
|
||||||
#if !defined(__read_mostly)
|
#if !defined(__read_mostly)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user