diff options
| author | Paul Eggert | 2018-06-13 13:30:29 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-06-13 13:31:34 -0700 |
| commit | 967d2c55ef3908fd378e05b2a0070663ae45f6de (patch) | |
| tree | b49c5abdec3a63b16cf339268afdc8db729d6fe7 /src/lisp.h | |
| parent | b8478b2ab7ad19c629da9c6b0dfd9a6544a6acee (diff) | |
| download | emacs-967d2c55ef3908fd378e05b2a0070663ae45f6de.tar.gz emacs-967d2c55ef3908fd378e05b2a0070663ae45f6de.zip | |
Remove some wrong 8-byte alignment assumptions
Do not assume that 8-byte alignment suffices for all C objects,
as some platforms require 16-byte alignment for some objects,
and this will start to bite us as time goes on (e.g., if an
Emacs module ever uses an object containing a long
double, which requires 16-byte alignment on x86-64).
Conversely, on !USE_LSB_TAG platforms, do not insist on
aligning Lisp objects to a multiple of 8, as this is not
needed for high-order tag bits.
* src/alloc.c (LISP_ALIGNMENT, MALLOC_IS_LISP_ALIGNED):
New constants.
(XMALLOC_BASE_ALIGNMENT, XMALLOC_HEADER_ALIGNMENT):
Removed. All uses replaced by LISP_ALIGNMENT.
(aligned_alloc, laligned, lmalloc, lrealloc, union aligned_Lisp_Misc)
(maybe_lisp_pointer, pure_alloc):
Use LISP_ALIGNMENT rather than GCALIGNMENT.
(aligned_alloc): Do not worry about an alignment of
LISP_ALIGNMENT when MALLOC_IS_LISP_ALIGNED, as the code never
uses aligned_alloc with alignment == LISP_ALIGNMENT in that case.
(__alignof__): Remove. All uses removed.
(MALLOC_IS_GC_ALIGNED): Remove.
All uses replaced with MALLOC_IS_LISP_ALIGNED.
(vector_alignment): Remove.
All uses replaced with LISP_ALIGNMENT.
* src/alloc.c (mark_maybe_pointer):
* src/emacs-module.c (value_to_lisp_bits):
Do not assume GCALIGNMENT == 1 << GCTYPEBITS, as GCALIGNMENT
is 1 on !USE_LSB_TAG platforms now.
* src/lisp.h (GCALIGNMENT) [!USE_LSB_TAG]: Now 1.
(struct Lisp_Symbol, union vectorlike_header, struct Lisp_Cons)
(struct Lisp_String): Simplify test for verifying alignment.
Diffstat (limited to 'src/lisp.h')
| -rw-r--r-- | src/lisp.h | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/lisp.h b/src/lisp.h index d4499846053..aaad90b2dad 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -233,10 +233,6 @@ extern bool suppress_checking EXTERNALLY_VISIBLE; | |||
| 233 | 233 | ||
| 234 | enum Lisp_Bits | 234 | enum Lisp_Bits |
| 235 | { | 235 | { |
| 236 | /* 2**GCTYPEBITS. This must be a macro that expands to a literal | ||
| 237 | integer constant, for older versions of GCC (through at least 4.9). */ | ||
| 238 | #define GCALIGNMENT 8 | ||
| 239 | |||
| 240 | /* Number of bits in a Lisp_Object value, not counting the tag. */ | 236 | /* Number of bits in a Lisp_Object value, not counting the tag. */ |
| 241 | VALBITS = EMACS_INT_WIDTH - GCTYPEBITS, | 237 | VALBITS = EMACS_INT_WIDTH - GCTYPEBITS, |
| 242 | 238 | ||
| @@ -247,10 +243,6 @@ enum Lisp_Bits | |||
| 247 | FIXNUM_BITS = VALBITS + 1 | 243 | FIXNUM_BITS = VALBITS + 1 |
| 248 | }; | 244 | }; |
| 249 | 245 | ||
| 250 | #if GCALIGNMENT != 1 << GCTYPEBITS | ||
| 251 | # error "GCALIGNMENT and GCTYPEBITS are inconsistent" | ||
| 252 | #endif | ||
| 253 | |||
| 254 | /* The maximum value that can be stored in a EMACS_INT, assuming all | 246 | /* The maximum value that can be stored in a EMACS_INT, assuming all |
| 255 | bits other than the type bits contribute to a nonnegative signed value. | 247 | bits other than the type bits contribute to a nonnegative signed value. |
| 256 | This can be used in #if, e.g., '#if USE_LSB_TAG' below expands to an | 248 | This can be used in #if, e.g., '#if USE_LSB_TAG' below expands to an |
| @@ -277,12 +269,21 @@ DEFINE_GDB_SYMBOL_END (VALMASK) | |||
| 277 | error !; | 269 | error !; |
| 278 | #endif | 270 | #endif |
| 279 | 271 | ||
| 272 | /* Minimum alignment requirement for Lisp objects, imposed by the | ||
| 273 | internal representation of tagged pointers. It is 2**GCTYPEBITS if | ||
| 274 | USE_LSB_TAG, 1 otherwise. It must be a literal integer constant, | ||
| 275 | for older versions of GCC (through at least 4.9). */ | ||
| 280 | #if USE_LSB_TAG | 276 | #if USE_LSB_TAG |
| 281 | # define GCALIGNED_UNION char alignas (GCALIGNMENT) gcaligned; | 277 | # define GCALIGNMENT 8 |
| 278 | # if GCALIGNMENT != 1 << GCTYPEBITS | ||
| 279 | # error "GCALIGNMENT and GCTYPEBITS are inconsistent" | ||
| 280 | # endif | ||
| 282 | #else | 281 | #else |
| 283 | # define GCALIGNED_UNION | 282 | # define GCALIGNMENT 1 |
| 284 | #endif | 283 | #endif |
| 285 | 284 | ||
| 285 | #define GCALIGNED_UNION char alignas (GCALIGNMENT) gcaligned; | ||
| 286 | |||
| 286 | /* Lisp_Word is a scalar word suitable for holding a tagged pointer or | 287 | /* Lisp_Word is a scalar word suitable for holding a tagged pointer or |
| 287 | integer. Usually it is a pointer to a deliberately-incomplete type | 288 | integer. Usually it is a pointer to a deliberately-incomplete type |
| 288 | 'union Lisp_X'. However, it is EMACS_INT when Lisp_Objects and | 289 | 'union Lisp_X'. However, it is EMACS_INT when Lisp_Objects and |
| @@ -774,7 +775,7 @@ struct Lisp_Symbol | |||
| 774 | GCALIGNED_UNION | 775 | GCALIGNED_UNION |
| 775 | } u; | 776 | } u; |
| 776 | }; | 777 | }; |
| 777 | verify (!USE_LSB_TAG || alignof (struct Lisp_Symbol) % GCALIGNMENT == 0); | 778 | verify (alignof (struct Lisp_Symbol) % GCALIGNMENT == 0); |
| 778 | 779 | ||
| 779 | /* Declare a Lisp-callable function. The MAXARGS parameter has the same | 780 | /* Declare a Lisp-callable function. The MAXARGS parameter has the same |
| 780 | meaning as in the DEFUN macro, and is used to construct a prototype. */ | 781 | meaning as in the DEFUN macro, and is used to construct a prototype. */ |
| @@ -888,7 +889,7 @@ union vectorlike_header | |||
| 888 | ptrdiff_t size; | 889 | ptrdiff_t size; |
| 889 | GCALIGNED_UNION | 890 | GCALIGNED_UNION |
| 890 | }; | 891 | }; |
| 891 | verify (!USE_LSB_TAG || alignof (union vectorlike_header) % GCALIGNMENT == 0); | 892 | verify (alignof (union vectorlike_header) % GCALIGNMENT == 0); |
| 892 | 893 | ||
| 893 | INLINE bool | 894 | INLINE bool |
| 894 | (SYMBOLP) (Lisp_Object x) | 895 | (SYMBOLP) (Lisp_Object x) |
| @@ -1249,7 +1250,7 @@ struct Lisp_Cons | |||
| 1249 | GCALIGNED_UNION | 1250 | GCALIGNED_UNION |
| 1250 | } u; | 1251 | } u; |
| 1251 | }; | 1252 | }; |
| 1252 | verify (!USE_LSB_TAG || alignof (struct Lisp_Cons) % GCALIGNMENT == 0); | 1253 | verify (alignof (struct Lisp_Cons) % GCALIGNMENT == 0); |
| 1253 | 1254 | ||
| 1254 | INLINE bool | 1255 | INLINE bool |
| 1255 | (NILP) (Lisp_Object x) | 1256 | (NILP) (Lisp_Object x) |
| @@ -1371,7 +1372,7 @@ struct Lisp_String | |||
| 1371 | GCALIGNED_UNION | 1372 | GCALIGNED_UNION |
| 1372 | } u; | 1373 | } u; |
| 1373 | }; | 1374 | }; |
| 1374 | verify (!USE_LSB_TAG || alignof (struct Lisp_String) % GCALIGNMENT == 0); | 1375 | verify (alignof (struct Lisp_String) % GCALIGNMENT == 0); |
| 1375 | 1376 | ||
| 1376 | INLINE bool | 1377 | INLINE bool |
| 1377 | STRINGP (Lisp_Object x) | 1378 | STRINGP (Lisp_Object x) |