aboutsummaryrefslogtreecommitdiff
path: root/src/include/c.h
diff options
context:
space:
mode:
authorJohn Naylor <john.naylor@postgresql.org>2024-04-06 12:14:38 +0700
committerJohn Naylor <john.naylor@postgresql.org>2024-04-06 12:20:40 +0700
commitdb17594ad73a871a176a9bf96e0589c2cf57052c (patch)
treec7aea52bc45f0308819b436389557d0d6a07ccd7 /src/include/c.h
parent4b968e2027ba46b31be0a648486f86a2cadc707d (diff)
downloadpostgresql-db17594ad73a871a176a9bf96e0589c2cf57052c.tar.gz
postgresql-db17594ad73a871a176a9bf96e0589c2cf57052c.zip
Add macro to disable address safety instrumentation
fasthash_accum_cstring_aligned() uses a technique, found in various strlen() implementations, to detect a string's NUL terminator by reading a word at at time. That triggers failures when testing with "-fsanitize=address", at least with frontend code. To enable using this function anywhere, add a function attribute macro to disable such testing. Reviewed by Jeff Davis Discussion: https://postgr.es/m/CANWCAZbwvp7oUEkbw-xP4L0_S_WNKq-J-ucP4RCNDPJnrakUPw%40mail.gmail.com
Diffstat (limited to 'src/include/c.h')
-rw-r--r--src/include/c.h13
1 files changed, 13 insertions, 0 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"