summaryrefslogtreecommitdiff
path: root/include/common.h
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2018-06-21 08:39:30 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-06-28 07:06:46 -0700
commit6c6888037c8d82228b480eeba0eaf1b0aa83e9f8 (patch)
tree5ccd44915959fa98d811bb4e53f71b295ec41317 /include/common.h
parentdcfbe0be69d3445edfd45fb036bfae2581b6fdd5 (diff)
downloadchrome-ec-6c6888037c8d82228b480eeba0eaf1b0aa83e9f8.tar.gz
ec: Make it possible to run tests with AddressSanitizer enabled
Automatically use CC=clang if TEST_ASAN is specified. Also, add a __no_sanitize_address attribute macro to prevent ASan from adding guards around host_command, mkbp_event, and hook "arrays" that are generated at link-time. Also, set ASAN_OPTIONS env variable in run_host_test. BRANCH=none BUG=chromium:854924 TEST=make TEST_ASAN=y runtests -j Change-Id: Iaf0ec405022760d757a8a9d62a5022460d1b16e1 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1109661 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'include/common.h')
-rw-r--r--include/common.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h
index 555f91a953..dac0bf2f00 100644
--- a/include/common.h
+++ b/include/common.h
@@ -96,6 +96,23 @@
#define __bss_slow __attribute__((section(".bss.slow")))
#endif
+/* gcc does not support __has_feature */
+#ifndef __has_feature
+#define __has_feature(x) 0
+#endif
+
+/*
+ * Use this to prevent AddressSanitizer from putting guards around some global
+ * variables (e.g. hook/commands "arrays" that are put together at link time).
+ */
+#ifndef __no_sanitize_address
+#if __has_feature(address_sanitizer)
+#define __no_sanitize_address __attribute__((no_sanitize("address")))
+#else
+#define __no_sanitize_address
+#endif
+#endif
+
/* There isn't really a better place for this */
#define C_TO_K(temp_c) ((temp_c) + 273)
#define K_TO_C(temp_c) ((temp_c) - 273)