diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2013-12-26 00:57:28 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2013-12-26 00:57:28 -0800 |
commit | e76119d7542b19eb03f8d725480cbf98f7fa03d9 (patch) | |
tree | bdc730dbcd0f54ca25623960feb8df4dfce073b7 /src/conf_post.h | |
parent | 2200a8c91de23f9749d1b3c961c4f8bb3145ddfa (diff) | |
download | emacs-e76119d7542b19eb03f8d725480cbf98f7fa03d9.tar.gz |
Fix core dumps with gcc -fsanitize=address and GNU/Linux.
On my Fedora 19 platform the core dumps were so big that
my desktop became nearly catatonic.
* configure.ac: Check whether addresses are sanitized.
(CANNOT_DUMP): Warn if addresses are sanitized and not CANNOT_DUMP.
(DOUG_LEA_MALLOC): Do not define if addresses are sanitized.
(SYSTEM_MALLOC): Define if addresses are sanitized.
* src/alloc.c (no_sanitize_memcpy) [MAX_SAVE_STACK > 0]: New function.
(Fgarbage_collect) [MAX_SAVE_STACK > 0]: Use it.
(USE_ALIGNED_MALLOC): Do not define if addresses are sanitized.
(mark_memory): Use ATTRIBUTE_NO_SANITIZE_ADDRESS rather than
a clang-only syntax.
* src/conf_post.h (__has_feature): New macro, if not already defined.
(ADDRESS_SANITIZER, ADDRESS_SANITIZER_WORKAROUND)
(ATTRIBUTE_NO_SANITIZE_ADDRESS): New macros.
Diffstat (limited to 'src/conf_post.h')
-rw-r--r-- | src/conf_post.h | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/conf_post.h b/src/conf_post.h index 66dd9a36f00..04c4f4f5f15 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -50,8 +50,19 @@ typedef bool bool_bf; #endif #endif +/* When not using Clang, assume its attributes and features are absent. */ #ifndef __has_attribute -# define __has_attribute(a) false /* non-clang */ +# define __has_attribute(a) false +#endif +#ifndef __has_feature +# define __has_feature(a) false +#endif + +/* True if addresses are being sanitized. */ +#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) +# define ADDRESS_SANITIZER true +#else +# define ADDRESS_SANITIZER false #endif #ifdef DARWIN_OS @@ -204,6 +215,32 @@ extern void _DebPrint (const char *fmt, ...); #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST +/* Work around GCC bug 59600: when a function is inlined, the inlined + code may have its addresses sanitized even if the function has the + no_sanitize_address attribute. This bug is present in GCC 4.8.2 + and clang 3.3, the latest releases as of December 2013, and the + only platforms known to support address sanitization. When the bug + is fixed the #if can be updated accordingly. */ +#if ADDRESS_SANITIZER +# define ADDRESS_SANITIZER_WORKAROUND NO_INLINE +#else +# define ADDRESS_SANITIZER_WORKAROUND +#endif + +/* Attribute of functions whose code should not have addresses + sanitized. */ + +#if (__has_attribute (no_sanitize_address) \ + || 4 < __GNUC__ + (8 <= __GNUC_MINOR__)) +# define ATTRIBUTE_NO_SANITIZE_ADDRESS \ + __attribute__ ((no_sanitize_address)) ADDRESS_SANITIZER_WORKAROUND +#elif __has_attribute (no_address_safety_analysis) +# define ATTRIBUTE_NO_SANITIZE_ADDRESS \ + __attribute__ ((no_address_safety_analysis)) ADDRESS_SANITIZER_WORKAROUND +#else +# define ATTRIBUTE_NO_SANITIZE_ADDRESS +#endif + /* Some versions of GNU/Linux define noinline in their headers. */ #ifdef noinline #undef noinline |