diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2018-05-18 15:45:42 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2018-05-18 15:49:48 -0700 |
commit | a1c925fd41818cb8ad209762739b220efb919d1e (patch) | |
tree | 4d3c95a065057114a49a9a3435d26479a086d8a1 /src/conf_post.h | |
parent | f4d9fd3dd45f767eca33fbf1beee40da790fa74e (diff) | |
download | emacs-a1c925fd41818cb8ad209762739b220efb919d1e.tar.gz |
Port to GCC 8 -fsanitize=undefined
In GCC 8, gcc -fsanitize=undefined flags the undefined behavior
that Emacs relies on in its XPNTR and XSYMBOL low-level functions.
Disable undefined sanitization in these functions. Although this
disabling doesn’t suffice if DEFINE_KEY_OPS_AS_MACROS is true, it
works for -fsanitize=undefined -DINLINING=0, which is good enough.
* src/alloc.c (macro_PNTR_ADD): New macro.
(PNTR_ADD): New function and macro.
The function disables -fsanitize=undefined.
(macro_XPNTR): Use it.
* src/conf_post.h (ATTRIBUTE_NO_SANITIZE_UNDEFINED): New macro.
* src/lisp.h (XSYMBOL): Disable -fsanitize=undefined.
Diffstat (limited to 'src/conf_post.h')
-rw-r--r-- | src/conf_post.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/conf_post.h b/src/conf_post.h index 00e283d289c..bf2cfc4f05f 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -67,6 +67,7 @@ typedef bool bool_bf; # define __has_attribute_externally_visible GNUC_PREREQ (4, 1, 0) # define __has_attribute_no_address_safety_analysis false # define __has_attribute_no_sanitize_address GNUC_PREREQ (4, 8, 0) +# define __has_attribute_no_sanitize_undefined GNUC_PREREQ (4, 9, 0) #endif /* Simulate __has_builtin on compilers that lack it. It is used only @@ -338,6 +339,17 @@ extern int emacs_setenv_TZ (char const *); # define ATTRIBUTE_NO_SANITIZE_ADDRESS #endif +/* Attribute of functions whose undefined behavior should not be sanitized. */ + +#if __has_attribute (no_sanitize_undefined) +# define ATTRIBUTE_NO_SANITIZE_UNDEFINED __attribute__ ((no_sanitize_undefined)) +#elif __has_attribute (no_sanitize) +# define ATTRIBUTE_NO_SANITIZE_UNDEFINED \ + __attribute__ ((no_sanitize ("undefined"))) +#else +# define ATTRIBUTE_NO_SANITIZE_UNDEFINED +#endif + /* gcc -fsanitize=address does not work with vfork in Fedora 25 x86-64. For now, assume that this problem occurs on all platforms. */ #if ADDRESS_SANITIZER && !defined vfork |