pcre2: add patch fixing a build issue on m68k
PATCH 1/1 pcre2: add patch fixing a build issue on m68k
A pretty nasty difference in alignment rules between most architectures and m68k lead pcre2 to fail building its 16-bit and 32-bit variants on m68k. This commit adds a patch that fixes that.
Fixes:
http://autobuild.buildroot.net/results/f6a45df5cb80e3fd94d57163bd28a0014a02bf4/
--- package/pcre2/0001-fix-heapframe-alignment.patch | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 package/pcre2/0001-fix-heapframe-alignment.patch
package/pcre2/0001-fix-heapframe-alignment.patch new file +47 -0
@@ -0,0 +1,47 @@ +src/pcre2_intmodedep.h: fix alignment of fields in struct heapframe + +pcre2_intmodedep.h has a check to verify that the size of the struct +heapframe is a multiple of 4 bytes. On most architectures this works +fine, but not on m68k. Indeed, when building the 16-bit variant of +pcre2, the heapframe structure contains: + + PCRE2_UCHAR occu[2]; + PCRE2_SPTR eptr; + +Where PCRE2_UCHAR is a 16-bit data type, and PCRE2_SPTR is a +pointer. The occu[] array starts at byte 0x32, so not aligned on a +32-bit boundary. With 2 x 16-bit, the occur[] array ends at byte 0x36. + +Now, on most architectures, the alignment required for a pointer will +make the eptr field start at 0x38 (on 32 bit architectures). However, +on m68k, it is fine to have a pointer aligned only on a 16-bit +boundary, and the eptr pointer will be at offset 0x36. + +This doesn't cause a problem per-se, but breaks the check that +heapframe should be a multiple of 4 bytes. + +To fix this, we make sure eptr is aligned by introducing an unused +field of 16 bits before the occu[] array + +Fixes the following build failure on m68k: + +src/pcre2_intmodedep.h:818:14: error: size of array 'check_heapframe_size' is negative + typedef char check_heapframe_size[ + ^~~~~~~~~~~~~~~~~~~~ + +Signed-off-by: Thomas Petazzoni <[email protected]> +Upstream: https://bugs.exim.org/show_bug.cgi?id=2247 + +Index: src/pcre2_intmodedep.h +=================================================================== +--- a/src/pcre2_intmodedep.h (revision 923) ++++ b/src/pcre2_intmodedep.h (working copy) +@@ -797,8 +797,10 @@ + PCRE2_UCHAR occu[6]; /* Used for other case code units */ + #elif PCRE2_CODE_UNIT_WIDTH == 16 + PCRE2_UCHAR occu[2]; /* Used for other case code units */ ++ uint8_t unused[2]; /* Ensure 32 bit alignment */ + #else + PCRE2_UCHAR occu[1]; /* Used for other case code units */ ++ uint8_t unused[2]; /* Ensure 32 bit alignment */ + #endif
Signature · 1 line
2.14.3
PATCH 1/1 pcre2: add patch fixing a build issue on m68k
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas Petazzoni <[email protected]> writes:
Hi,
Quoted 6 lines
A pretty nasty difference in alignment rules between most architectures and m68k lead pcre2 to fail building its 16-bit and 32-bit variants on m68k. This commit adds a patch that fixes that.
package/pcre2/0001-fix-heapframe-alignment.patch new file +2
-0+Index: src/pcre2_intmodedep.h +===================================================================
package/pcre2/0001-fix-heapframe-alignment.patch line 46
Quoted 10 lines
package/pcre2/0001-fix-heapframe-alignment.patch new file +10
-0+--- a/src/pcre2_intmodedep.h (revision 923) ++++ b/src/pcre2_intmodedep.h (working copy) +@@ -797,8 +797,10 @@ + PCRE2_UCHAR occu[6]; /* Used for other case code units */ + #elif PCRE2_CODE_UNIT_WIDTH == 16 + PCRE2_UCHAR occu[2]; /* Used for other case code units */ ++ uint8_t unused[2]; /* Ensure 32 bit alignment */ + #else + PCRE2_UCHAR occu[1]; /* Used for other case code units */ ++ uint8_t unused[2]; /* Ensure 32 bit alignment */
I haven't looked at the code, but doesn't this #else refer to the 32bit variant, which may require 4 byte alignment depending on architecture, so the 2 bytes padding you are adding would cause eptr to move to offset 0x3c instead of 0x38?
That in itself may not be an issue, but it is a change of behaviour.
Signature · 1 line
Bye, Peter Korsgaard
PATCH 1/1 pcre2: add patch fixing a build issue on m68k
Hello,
Quoted 17 lines · Peter Korsgaard
Quoted 6 lines
A pretty nasty difference in alignment rules between most architectures and m68k lead pcre2 to fail building its 16-bit and 32-bit variants on m68k. This commit adds a patch that fixes that.
package/pcre2/0001-fix-heapframe-alignment.patch new file +2
-0+Index: src/pcre2_intmodedep.h +===================================================================package/pcre2/0001-fix-heapframe-alignment.patch line 46
Quoted 10 lines
package/pcre2/0001-fix-heapframe-alignment.patch new file +10
-0+--- a/src/pcre2_intmodedep.h (revision 923) ++++ b/src/pcre2_intmodedep.h (working copy) +@@ -797,8 +797,10 @@ + PCRE2_UCHAR occu[6]; /* Used for other case code units */ + #elif PCRE2_CODE_UNIT_WIDTH == 16 + PCRE2_UCHAR occu[2]; /* Used for other case code units */ ++ uint8_t unused[2]; /* Ensure 32 bit alignment */ + #else + PCRE2_UCHAR occu[1]; /* Used for other case code units */ ++ uint8_t unused[2]; /* Ensure 32 bit alignment */
Quoted 4 lines
I haven't looked at the code, but doesn't this #else refer to the 32bit variant, which may require 4 byte alignment depending on architecture, so the 2 bytes padding you are adding would cause eptr to move to offset
0x3cinstead of0x38?
Without this additional unused[2] for the 32-bit variant, pcre2 32-bit variant would not build on m68k.
Indeed, the occu[] array starts at offset 0x32, which is a multiple of 2, but not a multiple of 4. Then you add a single PCRE2_UCHAR, which in the 32-bit variant is 32-bit long, you end up with the eptr pointer at offset 0x32 + 4, which is 0x36, which again is a multiple of 2, but not a multiple of 4.
By adding these additional two bytes, I make sure that the eptr field is at offset 0x38. This is why the unused[2] in the #else case is needed for the m68k to build.
However, it is true that on non-m68k platform, the single PCRE2_UCHAR occu[1] will probably be aligned on a 32-bit boundary, which indeed would shift the rest of the structure.
So perhaps I should instead do something like this:
uint8_t return_id;
uint8_t op;
#if PCRE2_CODE_UNIT_WIDTH == 8
PCRE2_UCHAR occu[6]; /* Used for other case code units */
#elif PCRE2_CODE_UNIT_WIDTH == 16
PCRE2_UCHAR occu[2]; /* Used for other case code units */
uint8_t unused[2]; /* Ensure 32 bit alignment */
#else
uint8_t unused[2]; /* Ensure 32 bit alignment */
PCRE2_UCHAR occu[1]; /* Used for other case code units */
#endif
PCRE2_SPTR eptr;
This should give the same offset for the different fields, regardless of the architecture, correct ?
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering http://bootlin.com
PATCH 1/1 pcre2: add patch fixing a build issue on m68k
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas Petazzoni <[email protected]> writes:
Hi,
Quoted 19 lines
However, it is true that on non-m68k platform, the single
PCRE2_UCHARoccu[1] will probably be aligned on a 32-bit boundary, which indeed would shift the rest of the structure.So perhaps I should instead do something like this:
uint8_treturn_id;
uint8_top;#if
PCRE2_CODE_UNIT_WIDTH== 8
PCRE2_UCHARoccu[6]; /* Used for other case code units */
#elifPCRE2_CODE_UNIT_WIDTH== 16
PCRE2_UCHARoccu[2]; /* Used for other case code units */
uint8_tunused[2]; /* Ensure 32 bit alignment */
#else
uint8_tunused[2]; /* Ensure 32 bit alignment */
PCRE2_UCHARoccu[1]; /* Used for other case code units */
#endif
Quoted 4 lines
PCRE2_SPTReptr;This should give the same offset for the different fields, regardless of the architecture, correct ?
Yes, indeed!
Signature · 1 line
Bye, Peter Korsgaard