diff options
| author | Sam James <sam@gentoo.org> | 2024-12-07 02:56:24 +0000 |
|---|---|---|
| committer | Sam James <sam@gentoo.org> | 2024-12-07 02:56:24 +0000 |
| commit | c5519b9fe9925b4900f182d6b60ffba86ef5aede (patch) | |
| tree | 01a9c829d0a0b4de7bbd037fc5c2831be81958db /dev-lang/perl/files/perl-5.40.0-alignment.patch | |
| parent | 6b0798dda77b78e89aa6270f54bc04f4749107e5 (diff) | |
| download | gentoo-c5519b9fe9925b4900f182d6b60ffba86ef5aede.tar.gz gentoo-c5519b9fe9925b4900f182d6b60ffba86ef5aede.tar.bz2 gentoo-c5519b9fe9925b4900f182d6b60ffba86ef5aede.zip | |
dev-lang/perl: fix alignment issues on x32 and with some SSE configurations
Closes: https://bugs.gentoo.org/936468
Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'dev-lang/perl/files/perl-5.40.0-alignment.patch')
| -rw-r--r-- | dev-lang/perl/files/perl-5.40.0-alignment.patch | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/dev-lang/perl/files/perl-5.40.0-alignment.patch b/dev-lang/perl/files/perl-5.40.0-alignment.patch new file mode 100644 index 000000000000..661ed59f2a51 --- /dev/null +++ b/dev-lang/perl/files/perl-5.40.0-alignment.patch @@ -0,0 +1,70 @@ +https://bugs.gentoo.org/936468 +https://github.com/Perl/perl5/issues/22577 +https://github.com/Perl/perl5/pull/22609 + +From ffbda81ab95a3db3eff972ad22b633c60365bb8e Mon Sep 17 00:00:00 2001 +From: Tony Cook <tony@develop-help.com> +Date: Wed, 18 Sep 2024 16:32:34 +1000 +Subject: [PATCH] bodies_by_type[SVt_PVNV]: handle __float128 NV alignment on + 32-bit + +Perl SV body structures include xmg_stash and xmg_u fields at the +front, which are only valid for type SVt_PVMG and higher. + +This allows those fields to be at a constant offset from the start +of the body. + +To save memory perl generally allocates the bodies where +type < SVt_PVMG without the space needed for these two fields, +offsetting the body pointer back by the size of the two fields. At +least for the first body in an arena this is technically +undefined behaviour, but we've done it forever. + +With -msse __float128 requires 16 byte alignment, but for XPVNV +bodies the hack used here means that the base of the XPVNV +body ends up mis-aligned on 32-bit systems. + +On 64-bit systems the combined size of those fields is 16-bytes so +the modified pointer is still properly aligned. + +To fix this allocate the full XPVNV structure when 16 byte alignment +is required for NV, NV is more than 8 bytes and pointers are small +enough that the NV would have been mis-aligned. + +Fixes #22577 +--- + sv_inline.h | 15 ++++++++++++++- + 1 file changed, 14 insertions(+), 1 deletion(-) + +diff --git a/sv_inline.h b/sv_inline.h +index a0fe8ec870c2..7cbca95feef7 100644 +--- a/sv_inline.h ++++ b/sv_inline.h +@@ -218,12 +218,25 @@ static const struct body_details bodies_by_type[] = { + SVt_PVIV, FALSE, NONV, HASARENA, + FIT_ARENA(0, sizeof(XPVIV) - STRUCT_OFFSET(XPV, xpv_cur)) }, + ++#if NVSIZE > 8 && PTRSIZE < 8 && MEM_ALIGNBYTES > 8 ++ /* NV may need strict 16 byte alignment. ++ ++ On 64-bit systems the NV ends up aligned despite the hack ++ avoiding allocation of xmg_stash and xmg_u, so only do this ++ for 32-bit systems. ++ */ ++ { sizeof(XPVNV), ++ sizeof(XPVNV), ++ 0, ++ SVt_PVNV, FALSE, HADNV, HASARENA, ++ FIT_ARENA(0, sizeof(XPVNV)) }, ++#else + { sizeof(XPVNV) - STRUCT_OFFSET(XPV, xpv_cur), + copy_length(XPVNV, xnv_u) - STRUCT_OFFSET(XPV, xpv_cur), + + STRUCT_OFFSET(XPV, xpv_cur), + SVt_PVNV, FALSE, HADNV, HASARENA, + FIT_ARENA(0, sizeof(XPVNV) - STRUCT_OFFSET(XPV, xpv_cur)) }, +- ++#endif + { sizeof(XPVMG), copy_length(XPVMG, xnv_u), 0, SVt_PVMG, FALSE, HADNV, + HASARENA, FIT_ARENA(0, sizeof(XPVMG)) }, + + |
