emacs-31 407de5142c2: Port pdumper to m68k

Paul Eggert <[email protected]> Wed, 15 Jul 2026 13:02:12 -0400 (EDT)
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: emacs-31
commit 407de5142c2631d42d53c8da470188f61e46ab22
Author: Paul Eggert <[email protected]>
Commit: Paul Eggert <[email protected]>

    Port pdumper to m68k
    
    Problem reported by John Paul Adrian Glaubitz (bug#44531).
    * src/pdumper.c (DUMP_RELOCATION_ALIGNMENT_BITS): Remove.  It’s
    not needed for optimization, as today’s compilers deduce that
    multiplying and dividing by the alignment can be done with shifts.
    All uses changed to use DUMP_RELOCATION_ALIGNMENT.
    (DUMP_RELOCATION_ALIGNMENT) [__mc68000__]:
    Now min (4, alignof (Lisp_Object)), not 4.
    (dump_reloc_set_offset): Change eassert to eassume to help
    the compiler.
---
 etc/NEWS      |  3 +++
 src/pdumper.c | 22 ++++++++++++++++------
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 155af8f5d93..27512710eb1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -29,6 +29,9 @@ applies, and please also update docstrings as needed.
 The traditional unexec dumper, deprecated since Emacs 27, has been
 removed.
 
++++
+*** The portable dumper now works on m68k a.out targets.
+
 ---
 ** Emacs's old 'ctags' program is no longer built or installed.
 You are encouraged to use Universal Ctags <https://ctags.io/> instead.
diff --git a/src/pdumper.c b/src/pdumper.c
index b0f40c6e3ce..f20d42a07f9 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -268,10 +268,20 @@ struct dump_table_locator
 enum
   {
    DUMP_RELOC_TYPE_BITS = 5,
-   DUMP_RELOC_ALIGNMENT_BITS = 2,
 
-   /* Minimum alignment required by dump file format.  */
-   DUMP_RELOCATION_ALIGNMENT = 1 << DUMP_RELOC_ALIGNMENT_BITS,
+   /* Minimum alignment required by dump file format.  Although this can
+      be any integer power of 2 up to alignof (Lisp_Alignment),
+      larger values help dump_reloc_set_offset support larger offsets.
+      The fix for bug#44531 was discovered late during Emacs 31 development,
+      so on Emacs 31 the value is 4 except on hosts where 4 is known to fail.
+      The only known failure is m68k a.out, so work around the problem
+      only if __mc68000__ is defined and the Lisp_Object alignment is 2,
+      which is a known property of the m68k a.out format.  */
+#ifdef __mc68000__
+   DUMP_RELOCATION_ALIGNMENT = min (4, alignof (Lisp_Object)),
+#else
+   DUMP_RELOCATION_ALIGNMENT = 4,
+#endif
 
    /* The alignment granularity (in bytes) for objects we store in the
       dump.  Always suitable for heap objects; may be more aligned.  */
@@ -303,14 +313,14 @@ dump_reloc_set_type (struct dump_reloc *reloc, enum dump_reloc_type type)
 static dump_off
 dump_reloc_get_offset (struct dump_reloc reloc)
 {
-  return reloc.raw_offset << DUMP_RELOC_ALIGNMENT_BITS;
+  return reloc.raw_offset * DUMP_RELOCATION_ALIGNMENT;
 }
 
 static void
 dump_reloc_set_offset (struct dump_reloc *reloc, dump_off offset)
 {
-  eassert (offset >= 0);
-  reloc->raw_offset = offset >> DUMP_RELOC_ALIGNMENT_BITS;
+  eassume (offset >= 0);
+  reloc->raw_offset = offset / DUMP_RELOCATION_ALIGNMENT;
   if (dump_reloc_get_offset (*reloc) != offset)
     error ("dump relocation out of range");
 }