This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
op.h: Add additional padding to struct opslab to ensure proper alignment
authorJohn Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Fri, 19 Jun 2020 14:40:38 +0000 (16:40 +0200)
committerSawyer X <xsawyerx@cpan.org>
Sat, 20 Jun 2020 13:35:47 +0000 (16:35 +0300)
On m68k, the natural alignment is 16 bits which causes the opslab_opslot
member of struct opslab to be aligned at a 16-bit offset. Other 32-bit
and 64-bit architectures have a natural alignment of at least 32 bits, so
the offset is always guaranteed to be at least 32-bit-aligned.

Fix this by adding additional padding bytes before the opslab_opslot
member, both for cases when PERL_DEBUG_READONLY_OPS defined and not
defined to ensure the offset of oplab_slots is always 32-bit-aligned.
On architectures which have a natural alignment of at least 32 bits,
the padding does not affect the alignment, offsets or struct size.

AUTHORS
op.h

diff --git a/AUTHORS b/AUTHORS
index 1a46800..e4ea405 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -651,6 +651,7 @@ John Macdonald                 <jmm@revenge.elegant.com>
 John Malmberg                  <wb8tyw@gmail.com>
 John Nolan                     <jpnolan@Op.Net>
 John P. Linderman              <jpl.jpl@gmail.com>
+John Paul Adrian Glaubitz      <glaubitz@physik.fu-berlin.de>
 John Peacock                   <jpeacock@messagesystems.com>
 John Pfuntner                  <pfuntner@vnet.ibm.com>
 John Poltorak                  <jp@eyup.org>
diff --git a/op.h b/op.h
index fc21f03..b9f6da8 100644 (file)
--- a/op.h
+++ b/op.h
@@ -713,6 +713,9 @@ struct opslab {
                                            units) */
 # ifdef PERL_DEBUG_READONLY_OPS
     bool       opslab_readonly;
+    U8          opslab_padding;         /* padding to ensure that opslab_slots is always */
+# else
+    U16         opslab_padding;         /* located at an offset with 32-bit alignment */
 # endif
     OPSLOT     opslab_slots;           /* slots begin here */
 };