mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-18 06:03:42 +03:00
test,static-destruct: Use retain attribute to prevent linker garbage collection
Fixes: #21847
This commit is contained in:
parent
8470a16d6f
commit
a3aff1c47f
@ -24,12 +24,16 @@ typedef struct StaticDestructor {
|
||||
typeof(variable) *q = p; \
|
||||
func(q); \
|
||||
} \
|
||||
/* Older compilers don't know retain attribute. */ \
|
||||
_Pragma("GCC diagnostic ignored \"-Wattributes\"") \
|
||||
/* The actual destructor structure we place in a special section to find it */ \
|
||||
_section_("SYSTEMD_STATIC_DESTRUCT") \
|
||||
/* We pick pointer alignment, since that is apparently what gcc does for static variables */ \
|
||||
_alignptr_ \
|
||||
/* Make sure this is not dropped from the image because not explicitly referenced */ \
|
||||
_used_ \
|
||||
/* Prevent linker from garbage collection. */ \
|
||||
_retain_ \
|
||||
/* Make sure that AddressSanitizer doesn't pad this variable: we want everything in this section
|
||||
* packed next to each other so that we can enumerate it. */ \
|
||||
_variable_no_sanitize_address_ \
|
||||
|
@ -13,6 +13,7 @@
|
||||
#define _pure_ __attribute__((__pure__))
|
||||
#define _section_(x) __attribute__((__section__(x)))
|
||||
#define _packed_ __attribute__((__packed__))
|
||||
#define _retain_ __attribute__((__retain__))
|
||||
#define _used_ __attribute__((__used__))
|
||||
#define _unused_ __attribute__((__unused__))
|
||||
#define _cleanup_(x) __attribute__((__cleanup__(x)))
|
||||
|
@ -38,7 +38,7 @@ int bus_error_set_errnofv(sd_bus_error *e, int error, const char *format, va_lis
|
||||
_Pragma("GCC diagnostic ignored \"-Wattributes\"") \
|
||||
_section_("SYSTEMD_BUS_ERROR_MAP") \
|
||||
_used_ \
|
||||
__attribute__((retain)) \
|
||||
_retain_ \
|
||||
_alignptr_ \
|
||||
_variable_no_sanitize_address_
|
||||
|
||||
|
@ -57,7 +57,8 @@ typedef struct TestFunc {
|
||||
|
||||
/* See static-destruct.h for an explanation of how this works. */
|
||||
#define REGISTER_TEST(func, ...) \
|
||||
_section_("SYSTEMD_TEST_TABLE") _alignptr_ _used_ _variable_no_sanitize_address_ \
|
||||
_Pragma("GCC diagnostic ignored \"-Wattributes\"") \
|
||||
_section_("SYSTEMD_TEST_TABLE") _alignptr_ _used_ _retain_ _variable_no_sanitize_address_ \
|
||||
static const TestFunc UNIQ_T(static_test_table_entry, UNIQ) = { \
|
||||
.f = (union f) &(func), \
|
||||
.name = STRINGIFY(func), \
|
||||
|
Loading…
x
Reference in New Issue
Block a user