test,static-destruct: Use retain attribute to prevent linker garbage collection

Fixes: #21847
This commit is contained in:
Jan Janssen
2021-12-22 12:14:08 +09:00
committed by Yu Watanabe
parent 8470a16d6f
commit a3aff1c47f
4 changed files with 8 additions and 2 deletions
+4
View File
@@ -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_ \