]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
macro: add macro for llvm no_sanitize_address attribute
authorLennart Poettering <lennart@poettering.net>
Mon, 3 Dec 2018 16:30:43 +0000 (17:30 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 3 Dec 2018 16:35:50 +0000 (17:35 +0100)
We want it for global variables, which LLVM supports and GCC currently
does not (GCC does support it for functions, but we care about global
variables here).

Why is this relevant? When asan is used global variables are padded with
hotzones before and after. But we can't have that for the registration
variables we place in special ELF sections: we want them tightly packed
so that we can iterate through them.

Note that for gcc this isn't an issue, as it will pack stuff in
non-standard sections anyway, even if asan is used.

src/basic/macro.h

index 2213d4b9ac9d56ed8e6ad050a4d0f2f0d81123cf..05956a50bff33110c26a113ee82b0d85ad531ad2 100644 (file)
 #  endif
 #endif
 
+/* Note: on GCC "no_sanitize_address" is a function attribute only, on llvm it may also be applied to global
+ * variables. We define a specific macro which knows this. Note that on GCC we don't need this decorator so much, since
+ * our primary usecase for this attribute is registration structures placed in named ELF sections which shall not be
+ * padded, but GCC doesn't pad those anyway if AddressSanitizer is enabled. */
+#if HAS_FEATURE_ADDRESS_SANITIZER && defined(__clang__)
+#define _variable_no_sanitize_address_ __attribute__((__no_sanitize_address__))
+#else
+#define _variable_no_sanitize_address_
+#endif
+
 /* Temporarily disable some warnings */
 #define DISABLE_WARNING_FORMAT_NONLITERAL                               \
         _Pragma("GCC diagnostic push");                                 \