aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/c.h13
-rw-r--r--src/include/common/hashfn_unstable.h5
2 files changed, 17 insertions, 1 deletions
diff --git a/src/include/c.h b/src/include/c.h
index cf37e02fe1f..dc1841346cd 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -136,6 +136,19 @@
#endif
/*
+ * This macro will disable address safety instrumentation for a function
+ * when running with "-fsanitize=address". Think twice before using this!
+ */
+#if defined(__clang__) || __GNUC__ >= 8
+#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize("address")))
+#elif __has_attribute(no_sanitize_address)
+/* This would work for clang, but it's deprecated. */
+#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize_address))
+#else
+#define pg_attribute_no_sanitize_address()
+#endif
+
+/*
* Place this macro before functions that should be allowed to make misaligned
* accesses. Think twice before using it on non-x86-specific code!
* Testing can be done with "-fsanitize=alignment -fsanitize-trap=alignment"
diff --git a/src/include/common/hashfn_unstable.h b/src/include/common/hashfn_unstable.h
index 1c782179cd6..d7ab6eeefe7 100644
--- a/src/include/common/hashfn_unstable.h
+++ b/src/include/common/hashfn_unstable.h
@@ -213,8 +213,11 @@ fasthash_accum_cstring_unaligned(fasthash_state *hs, const char *str)
*
* With an aligned pointer, we consume the string a word at a time.
* Loading the word containing the NUL terminator cannot segfault since
- * allocation boundaries are suitably aligned.
+ * allocation boundaries are suitably aligned. To keep from setting
+ * off alarms with address sanitizers, exclude this function from
+ * such testing.
*/
+pg_attribute_no_sanitize_address()
static inline size_t
fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
{