The tracepoint header declares pointer global variables meant to be
placed contiguously within the __tracepoints_ptrs section, and then used
as an array of pointers when loading an executable or shared object.
Clang Address Sanitizer adds redzones around each variable, thus leading to
detection of a global buffer overflow.
Those redzones should not be placed within this section, because it
defeats its purpose. Therefore, teach asan not to add redzones
around those variables with an attribute.
Note that there does not appear to be any issue with gcc (tested with
gcc-8 with address sanitization enabled), and gcc ignores the
no_sanitize_address attribute when applied to a global variable.
Fixes: #1238
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
}; \
static struct lttng_ust_tracepoint * \
__tracepoint_ptr_##_provider##___##_name \
- __attribute__((used, section("__tracepoints_ptrs"))) = \
+ __attribute__((section("__tracepoints_ptrs"), used)) \
+ __lttng_ust_variable_attribute_no_sanitize_address = \
&__tracepoint_##_provider##___##_name;
static void lttng_ust_notrace __attribute__((constructor))
#define lttng_ust_notrace __attribute__((no_instrument_function))
#define LTTNG_PACKED __attribute__((__packed__))
+/*
+ * Clang supports the no_sanitize variable attribute on global variables.
+ * GCC only supports the no_sanitize_address function attribute, which is
+ * not what we need.
+ */
+#if defined(__clang__)
+# if __has_feature(address_sanitizer)
+# define __lttng_ust_variable_attribute_no_sanitize_address \
+ __attribute__((no_sanitize("address")))
+# else
+# define __lttng_ust_variable_attribute_no_sanitize_address
+# endif
+#else
+# define __lttng_ust_variable_attribute_no_sanitize_address
+#endif
+
#endif /* _LTTNG_UST_COMPILER_H */