diff options
| author | Paul Eggert | 2016-01-17 14:10:26 -0800 |
|---|---|---|
| committer | Paul Eggert | 2016-01-17 14:11:09 -0800 |
| commit | fabb1fa31d1fd60764c025925e6c76c9145e5a59 (patch) | |
| tree | 9bb5e66cb3fac71c258e37954210e2be056a44b2 | |
| parent | 05e8148a24ebe51fbe758dd16265e8fb81f85953 (diff) | |
| download | emacs-fabb1fa31d1fd60764c025925e6c76c9145e5a59.tar.gz emacs-fabb1fa31d1fd60764c025925e6c76c9145e5a59.zip | |
Port cleanup attribute to OpenBSD
The OpenBSD C compiler issues false alarms about strcpy, strcat, and
sprintf, and this messes up 'configure' when it tests for the cleanup
attribute. Work around the problem by using __has_attribute directly.
Problem reported by Joakim Jalap (Bug#22385).
* configure.ac: Don’t use AX_GCC_VAR_ATTRIBUTE.
* m4/ax_gcc_var_attribute.m4: Remove.
* src/conf_post.h (__has_attribute): Provide a substitute, for
non-GCC or older GCC compilers. All uses changed to assume
the substitute. Check for the cleanup attribute.
* src/emacs-module.c (module_has_cleanup): Just use __has_attribute.
| -rw-r--r-- | configure.ac | 1 | ||||
| -rw-r--r-- | m4/ax_gcc_var_attribute.m4 | 141 | ||||
| -rw-r--r-- | src/conf_post.h | 28 | ||||
| -rw-r--r-- | src/emacs-module.c | 3 |
4 files changed, 18 insertions, 155 deletions
diff --git a/configure.ac b/configure.ac index 8c01abac9c6..3aeba22ec47 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -3327,7 +3327,6 @@ if test "${HAVE_MODULES}" = yes; then | |||
| 3327 | fi | 3327 | fi |
| 3328 | AC_SUBST(MODULES_OBJ) | 3328 | AC_SUBST(MODULES_OBJ) |
| 3329 | AC_SUBST(LIBMODULES) | 3329 | AC_SUBST(LIBMODULES) |
| 3330 | AX_GCC_VAR_ATTRIBUTE(cleanup) | ||
| 3331 | AC_CHECK_FUNCS(dladdr) | 3330 | AC_CHECK_FUNCS(dladdr) |
| 3332 | 3331 | ||
| 3333 | ### Use -lpng if available, unless '--with-png=no'. | 3332 | ### Use -lpng if available, unless '--with-png=no'. |
diff --git a/m4/ax_gcc_var_attribute.m4 b/m4/ax_gcc_var_attribute.m4 deleted file mode 100644 index d12fce8934e..00000000000 --- a/m4/ax_gcc_var_attribute.m4 +++ /dev/null | |||
| @@ -1,141 +0,0 @@ | |||
| 1 | # =========================================================================== | ||
| 2 | # http://www.gnu.org/software/autoconf-archive/ax_gcc_var_attribute.html | ||
| 3 | # =========================================================================== | ||
| 4 | # | ||
| 5 | # SYNOPSIS | ||
| 6 | # | ||
| 7 | # AX_GCC_VAR_ATTRIBUTE(ATTRIBUTE) | ||
| 8 | # | ||
| 9 | # DESCRIPTION | ||
| 10 | # | ||
| 11 | # This macro checks if the compiler supports one of GCC's variable | ||
| 12 | # attributes; many other compilers also provide variable attributes with | ||
| 13 | # the same syntax. Compiler warnings are used to detect supported | ||
| 14 | # attributes as unsupported ones are ignored by default so quieting | ||
| 15 | # warnings when using this macro will yield false positives. | ||
| 16 | # | ||
| 17 | # The ATTRIBUTE parameter holds the name of the attribute to be checked. | ||
| 18 | # | ||
| 19 | # If ATTRIBUTE is supported define HAVE_VAR_ATTRIBUTE_<ATTRIBUTE>. | ||
| 20 | # | ||
| 21 | # The macro caches its result in the ax_cv_have_var_attribute_<attribute> | ||
| 22 | # variable. | ||
| 23 | # | ||
| 24 | # The macro currently supports the following variable attributes: | ||
| 25 | # | ||
| 26 | # aligned | ||
| 27 | # cleanup | ||
| 28 | # common | ||
| 29 | # nocommon | ||
| 30 | # deprecated | ||
| 31 | # mode | ||
| 32 | # packed | ||
| 33 | # tls_model | ||
| 34 | # unused | ||
| 35 | # used | ||
| 36 | # vector_size | ||
| 37 | # weak | ||
| 38 | # dllimport | ||
| 39 | # dllexport | ||
| 40 | # init_priority | ||
| 41 | # | ||
| 42 | # Unsupported variable attributes will be tested against a global integer | ||
| 43 | # variable and without any arguments given to the attribute itself; the | ||
| 44 | # result of this check might be wrong or meaningless so use with care. | ||
| 45 | # | ||
| 46 | # LICENSE | ||
| 47 | # | ||
| 48 | # Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com> | ||
| 49 | # | ||
| 50 | # Copying and distribution of this file, with or without modification, are | ||
| 51 | # permitted in any medium without royalty provided the copyright notice | ||
| 52 | # and this notice are preserved. This file is offered as-is, without any | ||
| 53 | # warranty. | ||
| 54 | |||
| 55 | #serial 3 | ||
| 56 | |||
| 57 | AC_DEFUN([AX_GCC_VAR_ATTRIBUTE], [ | ||
| 58 | AS_VAR_PUSHDEF([ac_var], [ax_cv_have_var_attribute_$1]) | ||
| 59 | |||
| 60 | AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [ | ||
| 61 | AC_LINK_IFELSE([AC_LANG_PROGRAM([ | ||
| 62 | m4_case([$1], | ||
| 63 | [aligned], [ | ||
| 64 | int foo __attribute__(($1(32))); | ||
| 65 | ], | ||
| 66 | [cleanup], [ | ||
| 67 | int bar(int *t) { return *t; }; | ||
| 68 | ], | ||
| 69 | [common], [ | ||
| 70 | int foo __attribute__(($1)); | ||
| 71 | ], | ||
| 72 | [nocommon], [ | ||
| 73 | int foo __attribute__(($1)); | ||
| 74 | ], | ||
| 75 | [deprecated], [ | ||
| 76 | int foo __attribute__(($1)) = 0; | ||
| 77 | ], | ||
| 78 | [mode], [ | ||
| 79 | long foo __attribute__(($1(word))); | ||
| 80 | ], | ||
| 81 | [packed], [ | ||
| 82 | struct bar { | ||
| 83 | int baz __attribute__(($1)); | ||
| 84 | }; | ||
| 85 | ], | ||
| 86 | [tls_model], [ | ||
| 87 | __thread int bar1 __attribute__(($1("global-dynamic"))); | ||
| 88 | __thread int bar2 __attribute__(($1("local-dynamic"))); | ||
| 89 | __thread int bar3 __attribute__(($1("initial-exec"))); | ||
| 90 | __thread int bar4 __attribute__(($1("local-exec"))); | ||
| 91 | ], | ||
| 92 | [unused], [ | ||
| 93 | int foo __attribute__(($1)); | ||
| 94 | ], | ||
| 95 | [used], [ | ||
| 96 | int foo __attribute__(($1)); | ||
| 97 | ], | ||
| 98 | [vector_size], [ | ||
| 99 | int foo __attribute__(($1(16))); | ||
| 100 | ], | ||
| 101 | [weak], [ | ||
| 102 | int foo __attribute__(($1)); | ||
| 103 | ], | ||
| 104 | [dllimport], [ | ||
| 105 | int foo __attribute__(($1)); | ||
| 106 | ], | ||
| 107 | [dllexport], [ | ||
| 108 | int foo __attribute__(($1)); | ||
| 109 | ], | ||
| 110 | [init_priority], [ | ||
| 111 | struct bar { bar() {} ~bar() {} }; | ||
| 112 | bar b __attribute__(($1(65535/2))); | ||
| 113 | ], | ||
| 114 | [ | ||
| 115 | m4_warn([syntax], [Unsupported attribute $1, the test may fail]) | ||
| 116 | int foo __attribute__(($1)); | ||
| 117 | ] | ||
| 118 | )], [ | ||
| 119 | m4_case([$1], | ||
| 120 | [cleanup], [ | ||
| 121 | int foo __attribute__(($1(bar))) = 0; | ||
| 122 | foo = foo + 1; | ||
| 123 | ], | ||
| 124 | [] | ||
| 125 | )]) | ||
| 126 | ], | ||
| 127 | dnl GCC doesn't exit with an error if an unknown attribute is | ||
| 128 | dnl provided but only outputs a warning, so accept the attribute | ||
| 129 | dnl only if no warning were issued. | ||
| 130 | [AS_IF([test -s conftest.err], | ||
| 131 | [AS_VAR_SET([ac_var], [no])], | ||
| 132 | [AS_VAR_SET([ac_var], [yes])])], | ||
| 133 | [AS_VAR_SET([ac_var], [no])]) | ||
| 134 | ]) | ||
| 135 | |||
| 136 | AS_IF([test yes = AS_VAR_GET([ac_var])], | ||
| 137 | [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_VAR_ATTRIBUTE_$1), 1, | ||
| 138 | [Define to 1 if the system has the `$1' variable attribute])], []) | ||
| 139 | |||
| 140 | AS_VAR_POPDEF([ac_var]) | ||
| 141 | ]) | ||
diff --git a/src/conf_post.h b/src/conf_post.h index 98ff12e5a53..5c332a05a5c 100644 --- a/src/conf_post.h +++ b/src/conf_post.h | |||
| @@ -51,10 +51,21 @@ typedef bool bool_bf; | |||
| 51 | #endif | 51 | #endif |
| 52 | #endif | 52 | #endif |
| 53 | 53 | ||
| 54 | /* When not using Clang, assume its attributes and features are absent. */ | 54 | /* Simulate __has_attribute on compilers that lack it. It is used only |
| 55 | on arguments like alloc_size that are handled in this simulation. */ | ||
| 55 | #ifndef __has_attribute | 56 | #ifndef __has_attribute |
| 56 | # define __has_attribute(a) false | 57 | # define __has_attribute(a) __has_attribute_##a |
| 57 | #endif | 58 | # define __has_attribute_alloc_size (4 < __GNUC__ + (3 <= __GNUC_MINOR__)) |
| 59 | # define __has_attribute_cleanup (3 < __GNUC__ + (4 <= __GNUC_MINOR__)) | ||
| 60 | # define __has_attribute_externally_visible \ | ||
| 61 | (4 < __GNUC__ + (1 <= __GNUC_MINOR__)) | ||
| 62 | # define __has_attribute_no_address_safety_analysis false | ||
| 63 | # define __has_attribute_no_sanitize_address \ | ||
| 64 | (4 < __GNUC__ + (8 <= __GNUC_MINOR__)) | ||
| 65 | #endif | ||
| 66 | |||
| 67 | /* Simulate __has_feature on compilers that lack it. It is used only | ||
| 68 | to define ADDRESS_SANITIZER below. */ | ||
| 58 | #ifndef __has_feature | 69 | #ifndef __has_feature |
| 59 | # define __has_feature(a) false | 70 | # define __has_feature(a) false |
| 60 | #endif | 71 | #endif |
| @@ -222,9 +233,7 @@ extern int emacs_setenv_TZ (char const *); | |||
| 222 | #define NO_INLINE | 233 | #define NO_INLINE |
| 223 | #endif | 234 | #endif |
| 224 | 235 | ||
| 225 | #if (__clang__ \ | 236 | #if __has_attribute (externally_visible) |
| 226 | ? __has_attribute (externally_visible) \ | ||
| 227 | : (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))) | ||
| 228 | #define EXTERNALLY_VISIBLE __attribute__((externally_visible)) | 237 | #define EXTERNALLY_VISIBLE __attribute__((externally_visible)) |
| 229 | #else | 238 | #else |
| 230 | #define EXTERNALLY_VISIBLE | 239 | #define EXTERNALLY_VISIBLE |
| @@ -253,9 +262,7 @@ extern int emacs_setenv_TZ (char const *); | |||
| 253 | # define ATTRIBUTE_MALLOC | 262 | # define ATTRIBUTE_MALLOC |
| 254 | #endif | 263 | #endif |
| 255 | 264 | ||
| 256 | #if (__clang__ \ | 265 | #if __has_attribute (alloc_size) |
| 257 | ? __has_attribute (alloc_size) \ | ||
| 258 | : 4 < __GNUC__ + (3 <= __GNUC_MINOR__)) | ||
| 259 | # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args)) | 266 | # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args)) |
| 260 | #else | 267 | #else |
| 261 | # define ATTRIBUTE_ALLOC_SIZE(args) | 268 | # define ATTRIBUTE_ALLOC_SIZE(args) |
| @@ -278,8 +285,7 @@ extern int emacs_setenv_TZ (char const *); | |||
| 278 | /* Attribute of functions whose code should not have addresses | 285 | /* Attribute of functions whose code should not have addresses |
| 279 | sanitized. */ | 286 | sanitized. */ |
| 280 | 287 | ||
| 281 | #if (__has_attribute (no_sanitize_address) \ | 288 | #if __has_attribute (no_sanitize_address) |
| 282 | || 4 < __GNUC__ + (8 <= __GNUC_MINOR__)) | ||
| 283 | # define ATTRIBUTE_NO_SANITIZE_ADDRESS \ | 289 | # define ATTRIBUTE_NO_SANITIZE_ADDRESS \ |
| 284 | __attribute__ ((no_sanitize_address)) ADDRESS_SANITIZER_WORKAROUND | 290 | __attribute__ ((no_sanitize_address)) ADDRESS_SANITIZER_WORKAROUND |
| 285 | #elif __has_attribute (no_address_safety_analysis) | 291 | #elif __has_attribute (no_address_safety_analysis) |
diff --git a/src/emacs-module.c b/src/emacs-module.c index b5e044e758f..79a077b3cb4 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -35,8 +35,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 35 | 35 | ||
| 36 | /* Feature tests. */ | 36 | /* Feature tests. */ |
| 37 | 37 | ||
| 38 | /* True if __attribute__ ((cleanup (...))) works, false otherwise. */ | 38 | #if __has_attribute (cleanup) |
| 39 | #ifdef HAVE_VAR_ATTRIBUTE_CLEANUP | ||
| 40 | enum { module_has_cleanup = true }; | 39 | enum { module_has_cleanup = true }; |
| 41 | #else | 40 | #else |
| 42 | enum { module_has_cleanup = false }; | 41 | enum { module_has_cleanup = false }; |