From d42a6ac39a27e3674dff618284fac88c2c764f03 Mon Sep 17 00:00:00 2001 From: Fergus Dall Date: Sat, 10 Jul 2021 04:04:47 +1000 Subject: [PATCH] test-runner: Disable address sanitization on .test_section Clang inserts red-zones around allocations in user defined section, which break the common assumption that objects are densely packed. The test runner uses this trick to construct an array of test objects, which causes asan violations when iterating over the array. This can be disabled by adding __attribute__((no_sanitize("address"))) to each object in the section. See https://github.com/google/sanitizers/issues/1028 for more discussion of this issue. Signed-off-by: Fergus Dall --- tests/test-runner.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test-runner.h b/tests/test-runner.h index d0734009..f0f2a4a7 100644 --- a/tests/test-runner.h +++ b/tests/test-runner.h @@ -37,11 +37,18 @@ struct test { int must_fail; } __attribute__ ((aligned (16))); +#if defined(__clang__) +#define SUPPRESS_ASAN __attribute__ ((no_sanitize("address"))) +#else +#define SUPPRESS_ASAN +#endif + #define TEST(name) \ static void name(void); \ \ const struct test test##name \ - __attribute__ ((used, section ("test_section"))) = { \ + SUPPRESS_ASAN \ + __attribute__ ((used, section ("test_section"))) = { \ #name, name, 0 \ }; \ \ @@ -51,7 +58,8 @@ struct test { static void name(void); \ \ const struct test test##name \ - __attribute__ ((used, section ("test_section"))) = { \ + SUPPRESS_ASAN \ + __attribute__ ((used, section ("test_section"))) = { \ #name, name, 1 \ }; \ \