You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
4.9 KiB
88 lines
4.9 KiB
From 8d45c6b730d7c56e970708767301700397756b52 Mon Sep 17 00:00:00 2001
|
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
Date: Sun, 7 May 2023 18:37:13 +0900
|
|
Subject: [PATCH] static-destruct: several cleanups
|
|
|
|
No functional changes, preparation for later commits.
|
|
|
|
(cherry picked from commit 555ead898539183a435e18c6e1e4d5fb89499231)
|
|
|
|
Related: #2190226
|
|
---
|
|
src/basic/static-destruct.h | 42 ++++++++++++++++++-------------------
|
|
1 file changed, 21 insertions(+), 21 deletions(-)
|
|
|
|
diff --git a/src/basic/static-destruct.h b/src/basic/static-destruct.h
|
|
index 97baac7abb..4bc82889be 100644
|
|
--- a/src/basic/static-destruct.h
|
|
+++ b/src/basic/static-destruct.h
|
|
@@ -10,6 +10,21 @@
|
|
* feel a bit like the gcc cleanup attribute, but for static variables. Note that this does not work for static
|
|
* variables declared in .so's, as the list is private to the same linking unit. But maybe that's a good thing. */
|
|
|
|
+#define _common_static_destruct_attrs_ \
|
|
+ /* 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") \
|
|
+ /* Use pointer alignment, since that is apparently what gcc does for static variables. */ \
|
|
+ _alignptr_ \
|
|
+ /* Make sure this is not dropped from the image despite not being explicitly referenced. */ \
|
|
+ _used_ \
|
|
+ /* Prevent garbage collection by the linker. */ \
|
|
+ _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_
|
|
+
|
|
typedef struct StaticDestructor {
|
|
void *data;
|
|
free_func_t destroy;
|
|
@@ -24,19 +39,7 @@ 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") \
|
|
- /* Use pointer alignment, since that is apparently what gcc does for static variables. */ \
|
|
- _alignptr_ \
|
|
- /* Make sure this is not dropped from the image despite not being explicitly referenced. */ \
|
|
- _used_ \
|
|
- /* Prevent garbage collection by the linker. */ \
|
|
- _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_ \
|
|
+ _common_static_destruct_attrs_ \
|
|
static const StaticDestructor UNIQ_T(static_destructor_entry, uq) = { \
|
|
.data = &(variable), \
|
|
.destroy = UNIQ_T(static_destructor_wrapper, uq), \
|
|
@@ -44,20 +47,17 @@ typedef struct StaticDestructor {
|
|
|
|
/* Beginning and end of our section listing the destructors. We define these as weak as we want this to work
|
|
* even if no destructors are defined and the section is missing. */
|
|
-extern const struct StaticDestructor _weak_ __start_SYSTEMD_STATIC_DESTRUCT[];
|
|
-extern const struct StaticDestructor _weak_ __stop_SYSTEMD_STATIC_DESTRUCT[];
|
|
+extern const StaticDestructor _weak_ __start_SYSTEMD_STATIC_DESTRUCT[];
|
|
+extern const StaticDestructor _weak_ __stop_SYSTEMD_STATIC_DESTRUCT[];
|
|
|
|
/* The function to destroy everything. (Note that this must be static inline, as it's key that it remains in
|
|
* the same linking unit as the variables we want to destroy.) */
|
|
static inline void static_destruct(void) {
|
|
- const StaticDestructor *d;
|
|
-
|
|
if (!__start_SYSTEMD_STATIC_DESTRUCT)
|
|
return;
|
|
|
|
- d = ALIGN_PTR(__start_SYSTEMD_STATIC_DESTRUCT);
|
|
- while (d < __stop_SYSTEMD_STATIC_DESTRUCT) {
|
|
+ for (const StaticDestructor *d = ALIGN_PTR(__start_SYSTEMD_STATIC_DESTRUCT);
|
|
+ d < __stop_SYSTEMD_STATIC_DESTRUCT;
|
|
+ d = ALIGN_PTR(d + 1))
|
|
d->destroy(d->data);
|
|
- d = ALIGN_PTR(d + 1);
|
|
- }
|
|
}
|