1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-09 15:50:40 -08:00

Re-port to 32-bit systems without alignment primitives

* configure.ac (ALIGNOF_INT, ALIGNOF_LONG, ALIGNOF_LONG_LONG):
New variables.
(emacs_cv_alignas_unavailable): Define if alignas and structure
alignment primitives are unavailable.  In such an environment,
the MSB tagging scheme must be enabled, as must the GNU malloc.

* msdos/sed2v2.inp: Adjust correspondingly.

* src/alloc.c (union emacs_align_type): Remove types which
contain flexible array members.  The address of a field
subsequent to an aggregate with flexible array members cannot
validly be taken.
(mark_memory) [!USE_LSB_TAG && !WIDE_EMACS_INT]: Strip type bits
before scanning memory.

* src/emacs.c (main):

* src/eval.c (Fautoload_do_load):

* src/fns.c (Frequire): Rename a number of illogically named
fields.

* src/lisp.h (ALIGNOF_EMACS_INT): Define to the natural
alignment of EMACS_INT.
(IDEAL_GCALIGNMENT): New macro.
(USE_LSB_TAG): Disable if no alignment specifiers are available,
WIDE_EMACS_INT is undefined, and the natural alignment of
EMACS_INT falls short of LSB tagging's requirements.
(gflags): Rename illogically named fields and don't define them
as bitfields, which runs afoul of certain compiler issues.
(will_dump_p, will_bootstrap_p, will_dump_with_pdumper_p)
(dumped_with_pdumper_p): Adjust accordingly.

* src/pdumper.c (VM_SUPPORTED): Define to 0 when !USE_LSB_TAG.
It is better to read dump files into the heap by hand than to be
supplied with an address that is not representable.
(_dump_object_start_pseudovector): Rename to
dump_object_start_pseudovector, to avoid encroaching on reserved
names.
(START_DUMP_PVEC): Adjust correspondingly.
(dump_mmap_contiguous_vm): Preserve errno around failure
cleanup.
(dump_bitset_bit_set_p): Work around certain compiler issues.
(pdumper_load) [!USE_LSB_TAG]: Reject dump file allocations
that are not representable as Lisp_Objects.

Tested on i386-unknown-solaris2.10, sparc-sun-solaris2.10.
This commit is contained in:
Po Lu 2025-03-09 23:02:21 +08:00
parent 57cef07710
commit a5f8ce9f1e
8 changed files with 193 additions and 100 deletions

View file

@ -89,18 +89,21 @@ DEFINE_GDB_SYMBOL_END (GCTYPEBITS)
typedef int EMACS_INT;
typedef unsigned int EMACS_UINT;
enum { EMACS_INT_WIDTH = INT_WIDTH, EMACS_UINT_WIDTH = UINT_WIDTH };
# define ALIGNOF_EMACS_INT ALIGNOF_INT
# define EMACS_INT_MAX INT_MAX
# define pI ""
# elif INTPTR_MAX <= LONG_MAX && !defined WIDE_EMACS_INT
typedef long int EMACS_INT;
typedef unsigned long EMACS_UINT;
enum { EMACS_INT_WIDTH = LONG_WIDTH, EMACS_UINT_WIDTH = ULONG_WIDTH };
# define ALIGNOF_EMACS_INT ALIGNOF_LONG
# define EMACS_INT_MAX LONG_MAX
# define pI "l"
# elif INTPTR_MAX <= LLONG_MAX
typedef long long int EMACS_INT;
typedef unsigned long long int EMACS_UINT;
enum { EMACS_INT_WIDTH = LLONG_WIDTH, EMACS_UINT_WIDTH = ULLONG_WIDTH };
# define ALIGNOF_EMACS_INT ALIGNOF_LONG_LONG
# define EMACS_INT_MAX LLONG_MAX
/* MinGW supports %lld only if __USE_MINGW_ANSI_STDIO is non-zero,
which is arranged by config.h, and (for mingw.org) if GCC is 6.0 or
@ -237,13 +240,26 @@ DEFINE_GDB_SYMBOL_END (INTTYPEBITS)
expression involving VAL_MAX. */
#define VAL_MAX (EMACS_INT_MAX >> (GCTYPEBITS - 1))
/* The alignment ideally required of objects subject to garbage
collection. (In the sense that it would be ideal for such an
alignment to be available to enable LSB tagging.) */
#define IDEAL_GCALIGNMENT 8
/* Whether the least-significant bits of an EMACS_INT contain the tag.
On hosts where pointers-as-ints do not exceed VAL_MAX / 2, USE_LSB_TAG is:
a. unnecessary, because the top bits of an EMACS_INT are unused, and
b. slower, because it typically requires extra masking.
So, USE_LSB_TAG is true only on hosts where it might be useful. */
DEFINE_GDB_SYMBOL_BEGIN (bool, USE_LSB_TAG)
#if (ALIGNOF_EMACS_INT < IDEAL_GCALIGNMENT && !defined alignas \
&& !defined WIDE_EMACS_INT \
&& !defined HAVE_STRUCT_ATTRIBUTE_ALIGNED \
&& !defined __alignas_is_defined \
&& __STDC_VERSION__ < 202311 && __cplusplus < 201103)
#define USE_LSB_TAG 0
#else /* EMACS_INT_WIDTH >= GCALIGNMENT || defined alignas ... */
#define USE_LSB_TAG (VAL_MAX / 2 < INTPTR_MAX)
#endif /* EMACS_INT_WIDTH >= GCALIGNMENT || defined alignas ... */
DEFINE_GDB_SYMBOL_END (USE_LSB_TAG)
/* Mask for the value (as opposed to the type bits) of a Lisp object. */
@ -262,7 +278,7 @@ DEFINE_GDB_SYMBOL_END (VALMASK)
USE_LSB_TAG, 1 otherwise. It must be a literal integer constant,
for older versions of GCC (through at least 4.9). */
#if USE_LSB_TAG
# define GCALIGNMENT 8
# define GCALIGNMENT IDEAL_GCALIGNMENT
# if GCALIGNMENT != 1 << GCTYPEBITS
# error "GCALIGNMENT and GCTYPEBITS are inconsistent"
# endif
@ -629,15 +645,15 @@ extern bool initialized;
extern struct gflags
{
/* True means this Emacs instance was born to dump. */
bool will_dump_ : 1;
bool will_bootstrap_ : 1;
bool will_dump;
bool will_bootstrap;
#ifdef HAVE_PDUMPER
/* Set in an Emacs process that will likely dump with pdumper; all
Emacs processes may dump with pdumper, however. */
bool will_dump_with_pdumper_ : 1;
bool will_dump_with_pdumper;
/* Set in an Emacs process that has been restored from a portable
dump. */
bool dumped_with_pdumper_ : 1;
bool dumped_with_pdumper;
#endif
} gflags;
@ -645,7 +661,7 @@ INLINE bool
will_dump_p (void)
{
#if HAVE_PDUMPER
return gflags.will_dump_;
return gflags.will_dump;
#else
return false;
#endif
@ -655,7 +671,7 @@ INLINE bool
will_bootstrap_p (void)
{
#if HAVE_PDUMPER
return gflags.will_bootstrap_;
return gflags.will_bootstrap;
#else
return false;
#endif
@ -665,7 +681,7 @@ INLINE bool
will_dump_with_pdumper_p (void)
{
#if HAVE_PDUMPER
return gflags.will_dump_with_pdumper_;
return gflags.will_dump_with_pdumper;
#else
return false;
#endif
@ -675,7 +691,7 @@ INLINE bool
dumped_with_pdumper_p (void)
{
#if HAVE_PDUMPER
return gflags.dumped_with_pdumper_;
return gflags.dumped_with_pdumper;
#else
return false;
#endif