From 026c2677fc9ad6baf32dadc640c58a11dfc09bf1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 3 Dec 2018 17:30:43 +0100 Subject: [PATCH] macro: add macro for llvm no_sanitize_address attribute 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 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/basic/macro.h b/src/basic/macro.h index 2213d4b9ac9..05956a50bff 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -73,6 +73,16 @@ # 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"); \ -- 2.39.5