pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/lang/perl5 perl5: backport upstream commits to remove ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/c9a8394b0b64
branches:  trunk
changeset: 402511:c9a8394b0b64
user:      maya <maya%pkgsrc.org@localhost>
date:      Thu Oct 10 17:59:57 2019 +0000

description:
perl5: backport upstream commits to remove a codepath that assumes
unaligned accesses are OK.
Remove relevant hacks.mk entry to disable optimizations.

PR pkg/53568

diffstat:

 lang/perl5/Makefile                  |    4 +-
 lang/perl5/distinfo                  |    4 +-
 lang/perl5/hacks.mk                  |   12 +-
 lang/perl5/patches/patch-alignment_1 |  273 +++++++++++++++++++++++++++++++++++
 lang/perl5/patches/patch-alignment_2 |  187 +++++++++++++++++++++++
 5 files changed, 467 insertions(+), 13 deletions(-)

diffs (truncated from 527 to 300 lines):

diff -r 8aeb16106f3c -r c9a8394b0b64 lang/perl5/Makefile
--- a/lang/perl5/Makefile       Thu Oct 10 15:43:44 2019 +0000
+++ b/lang/perl5/Makefile       Thu Oct 10 17:59:57 2019 +0000
@@ -1,8 +1,10 @@
-# $NetBSD: Makefile,v 1.255 2019/08/11 10:14:17 adam Exp $
+# $NetBSD: Makefile,v 1.256 2019/10/10 17:59:57 maya Exp $
 
 .include "license.mk"
 .include "Makefile.common"
 
+PKGREVISION=   1
+
 COMMENT=       Practical Extraction and Report Language
 
 CONFLICTS+=    perl-base-[0-9]* perl-thread-[0-9]*
diff -r 8aeb16106f3c -r c9a8394b0b64 lang/perl5/distinfo
--- a/lang/perl5/distinfo       Thu Oct 10 15:43:44 2019 +0000
+++ b/lang/perl5/distinfo       Thu Oct 10 17:59:57 2019 +0000
@@ -1,4 +1,4 @@
-$NetBSD: distinfo,v 1.158 2019/08/11 10:14:17 adam Exp $
+$NetBSD: distinfo,v 1.159 2019/10/10 17:59:57 maya Exp $
 
 SHA1 (perl-5.30.0.tar.xz) = cc8d1e08ffe4624c197a44d02855632725d39f8e
 RMD160 (perl-5.30.0.tar.xz) = 64ff4c65823122c337e18278585d71def1de9c5d
@@ -6,6 +6,8 @@
 Size (perl-5.30.0.tar.xz) = 12419868 bytes
 SHA1 (patch-Configure) = 6000aafeb993fd096c9b1327302b510aa0d386bb
 SHA1 (patch-Makefile.SH) = 93cae9736ef94cdd9e5748f7e0a0183332c2f3b3
+SHA1 (patch-alignment_1) = b68c0916b271523922caa7f89edb165284e7b5f4
+SHA1 (patch-alignment_2) = cae8495c4a092e31da422bf5684481091ee2adf3
 SHA1 (patch-caretx.c) = b76b4175a58123fa4dfd2adf36b2207dcb6cf65a
 SHA1 (patch-cflags.SH) = 7ad64e5a17b876bff4bbe238abc4a57354acf4fe
 SHA1 (patch-cpan_ExtUtils-MakeMaker_lib_ExtUtils_MM__Unix.pm) = 3a2b39c9eb903e68ef7d03ae448c51c147c19aa1
diff -r 8aeb16106f3c -r c9a8394b0b64 lang/perl5/hacks.mk
--- a/lang/perl5/hacks.mk       Thu Oct 10 15:43:44 2019 +0000
+++ b/lang/perl5/hacks.mk       Thu Oct 10 17:59:57 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: hacks.mk,v 1.23 2019/04/23 09:27:46 adam Exp $
+# $NetBSD: hacks.mk,v 1.24 2019/10/10 17:59:57 maya Exp $
 
 .if !defined(PERL5_HACKS_MK)
 PERL5_HACKS_MK=        defined
@@ -22,16 +22,6 @@
 BUILDLINK_TRANSFORM+=  opt:-O[0-9]*:-Os
 .endif
 
-### [ Wed Nov 21 11:35:48 IST 2018 : maya ]
-### Alignment fault on perl 5.28.0
-### Might be specific to GCC 4.9
-### https://rt.perl.org/Public/Bug/Display.html?id=133495
-### See PR pkg/53568
-.if ${OPSYS} == "SunOS" && !empty(MACHINE_ARCH:Msparc*)
-PKG_HACKS+=            sun-sparc-alignment-fault
-BUILDLINK_TRANSFORM+=  opt:-O3:-O2
-.endif
-
 ### [Fri Jan 31 11:09:04 CST 2014 : schnoebe]
 ### [Fri Oct 28 11:53:57 EDT 2016 : dholland - extended to gcc5]
 ### gcc-[45].*.* in NetBSD/alpha causes unaligned access exception in perl.
diff -r 8aeb16106f3c -r c9a8394b0b64 lang/perl5/patches/patch-alignment_1
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lang/perl5/patches/patch-alignment_1      Thu Oct 10 17:59:57 2019 +0000
@@ -0,0 +1,273 @@
+$NetBSD: patch-alignment_1,v 1.1 2019/10/10 17:59:57 maya Exp $
+
+Apply upstream commit (not needed in perl >= 5.32.x)
+
+From ee9ac1cd8eb988fea70841eae211b11355711416 Mon Sep 17 00:00:00 2001
+From: Matt Turner <mattst88%gmail.com@localhost>
+Date: Wed, 4 Sep 2019 21:04:47 -0700
+Subject: [PATCH] Digest-MD5: Consolidate byte-swapping paths
+
+The code guarded by #ifndef U32_ALIGNMENT_REQUIRED attempts to optimize
+byte-swapping by doing unaligned loads, but accessing data through
+unaligned pointers is undefined behavior in C. Moreover, compilers are
+more than capable of recognizing these open-coded byte-swap patterns and
+emitting a bswap instruction, or an unaligned load instruction, or a
+combined load, etc. There's no need for multiple paths to attain the
+desired result.
+
+See https://rt.perl.org/Ticket/Display.html?id=133495
+---
+ cpan/Digest-MD5/MD5.xs      |  44 +----------------
+ cpan/Digest-MD5/Makefile.PL | 114 --------------------------------------------
+ cpan/Digest-MD5/t/files.t   |   2 +-
+ 3 files changed, 3 insertions(+), 157 deletions(-)
+
+diff --git a/cpan/Digest-MD5/MD5.xs b/cpan/Digest-MD5/MD5.xs
+index a48d951056..964d37fb0e 100644
+--- cpan/Digest-MD5/MD5.xs.orig
++++ cpan/Digest-MD5/MD5.xs
+@@ -106,20 +106,6 @@ static MAGIC *THX_sv_magicext(pTHX_ SV *sv, SV *obj, int type,
+  * values.  The following macros (and functions) allow us to convert
+  * between native integers and such values.
+  */
+-#undef BYTESWAP
+-#ifndef U32_ALIGNMENT_REQUIRED
+- #if BYTEORDER == 0x1234      /* 32-bit little endian */
+-  #define BYTESWAP(x) (x)     /* no-op */
+-
+- #elif BYTEORDER == 0x4321    /* 32-bit big endian */
+-  #define BYTESWAP(x)         ((((x)&0xFF)<<24)       \
+-                      |(((x)>>24)&0xFF)       \
+-                      |(((x)&0x0000FF00)<<8)  \
+-                      |(((x)&0x00FF0000)>>8)  )
+- #endif
+-#endif
+-
+-#ifndef BYTESWAP
+ static void u2s(U32 u, U8* s)
+ {
+     *s++ = (U8)(u         & 0xFF);
+@@ -132,7 +118,6 @@ static void u2s(U32 u, U8* s)
+                         ((U32)(*(s+1)) << 8)  |  \
+                         ((U32)(*(s+2)) << 16) |  \
+                         ((U32)(*(s+3)) << 24))
+-#endif
+ 
+ /* This structure keeps the current state of algorithm.
+  */
+@@ -279,29 +264,16 @@ MD5Transform(MD5_CTX* ctx, const U8* buf, STRLEN blocks)
+     U32 C = ctx->C;
+     U32 D = ctx->D;
+ 
+-#ifndef U32_ALIGNMENT_REQUIRED
+-    const U32 *x = (U32*)buf;  /* really just type casting */
+-#endif
+-
+     do {
+       U32 a = A;
+       U32 b = B;
+       U32 c = C;
+       U32 d = D;
+ 
+-#if BYTEORDER == 0x1234 && !defined(U32_ALIGNMENT_REQUIRED)
+-      const U32 *X = x;
+-        #define NEXTx  (*x++)
+-#else
+-      U32 X[16];      /* converted values, used in round 2-4 */
++      U32 X[16];      /* little-endian values, used in round 2-4 */
+       U32 *uptr = X;
+       U32 tmp;
+- #ifdef BYTESWAP
+-        #define NEXTx  (tmp=*x++, *uptr++ = BYTESWAP(tmp))
+- #else
+         #define NEXTx  (s2u(buf,tmp), buf += 4, *uptr++ = tmp)
+- #endif
+-#endif
+ 
+ #ifdef MD5_DEBUG
+       if (buf == ctx->buffer)
+@@ -313,7 +285,7 @@ MD5Transform(MD5_CTX* ctx, const U8* buf, STRLEN blocks)
+           int i;
+           fprintf(stderr,"[");
+           for (i = 0; i < 16; i++) {
+-              fprintf(stderr,"%x,", x[i]);
++              fprintf(stderr,"%x,", x[i]); /* FIXME */
+           }
+           fprintf(stderr,"]\n");
+       }
+@@ -468,30 +440,18 @@ MD5Final(U8* digest, MD5_CTX *ctx)
+ 
+     bits_low = ctx->bytes_low << 3;
+     bits_high = (ctx->bytes_high << 3) | (ctx->bytes_low  >> 29);
+-#ifdef BYTESWAP
+-    *(U32*)(ctx->buffer + fill) = BYTESWAP(bits_low);    fill += 4;
+-    *(U32*)(ctx->buffer + fill) = BYTESWAP(bits_high);   fill += 4;
+-#else
+     u2s(bits_low,  ctx->buffer + fill);   fill += 4;
+     u2s(bits_high, ctx->buffer + fill);   fill += 4;
+-#endif
+ 
+     MD5Transform(ctx, ctx->buffer, fill >> 6);
+ #ifdef MD5_DEBUG
+     fprintf(stderr,"       Result: %s\n", ctx_dump(ctx));
+ #endif
+ 
+-#ifdef BYTESWAP
+-    *(U32*)digest = BYTESWAP(ctx->A);  digest += 4;
+-    *(U32*)digest = BYTESWAP(ctx->B);  digest += 4;
+-    *(U32*)digest = BYTESWAP(ctx->C);  digest += 4;
+-    *(U32*)digest = BYTESWAP(ctx->D);
+-#else
+     u2s(ctx->A, digest);
+     u2s(ctx->B, digest+4);
+     u2s(ctx->C, digest+8);
+     u2s(ctx->D, digest+12);
+-#endif
+ }
+ 
+ #ifndef INT2PTR
+diff --git a/cpan/Digest-MD5/Makefile.PL b/cpan/Digest-MD5/Makefile.PL
+index 1015058bac..76906d1046 100644
+--- cpan/Digest-MD5/Makefile.PL.orig
++++ cpan/Digest-MD5/Makefile.PL
+@@ -5,7 +5,6 @@ use Config qw(%Config);
+ use ExtUtils::MakeMaker;
+ 
+ my @extra;
+-push(@extra, DEFINE => "-DU32_ALIGNMENT_REQUIRED") unless free_u32_alignment();
+ push(@extra, INSTALLDIRS => 'perl') if $] >= 5.008 && $] < 5.012;
+ 
+ if ($^O eq 'VMS') {
+@@ -39,119 +38,6 @@ WriteMakefile(
+ 
+ 
+ 
+-sub free_u32_alignment
+-{
+-    $|=1;
+-    if (exists $Config{d_u32align}) {
+-       print "Perl's config says that U32 access must ";
+-       print "not " unless $Config{d_u32align};
+-       print "be aligned.\n";
+-       return !$Config{d_u32align};
+-    }
+-    
+-    if ($^O eq 'VMS' || $^O eq 'MSWin32') {
+-       print "Assumes that $^O implies free alignment for U32 access.\n";
+-       return 1;
+-    }
+-    
+-    if ($^O eq 'hpux' && $Config{osvers} < 11.0) {
+-       print "Will not test for free alignment on older HP-UX.\n";
+-       return 0;
+-    }
+-    
+-    print "Testing alignment requirements for U32... ";
+-    open(ALIGN_TEST, ">u32align.c") or die "$!";
+-    print ALIGN_TEST <<'EOT'; close(ALIGN_TEST);
+-/*--------------------------------------------------------------*/
+-/*  This program allocates a buffer of U8 (char) and then tries */
+-/*  to access it through a U32 pointer at every offset.  The    */
+-/*  program  is expected to die with a bus error/seg fault for  */
+-/*  machines that do not support unaligned integer read/write   */
+-/*--------------------------------------------------------------*/
+-
+-#include <stdio.h>
+-#include "EXTERN.h"
+-#include "perl.h"
+-
+-#ifdef printf
+- #undef printf
+-#endif
+-
+-int main(int argc, char** argv, char** env)
+-{
+-#if BYTEORDER == 0x1234 || BYTEORDER == 0x4321
+-    volatile U8 buf[] = "\0\0\0\1\0\0\0\0";
+-    volatile U32 *up;
+-    int i;
+-
+-    if (sizeof(U32) != 4) {
+-      printf("sizeof(U32) is not 4, but %d\n", sizeof(U32));
+-      exit(1);
+-    }
+-
+-    fflush(stdout);
+-
+-    for (i = 0; i < 4; i++) {
+-      up = (U32*)(buf + i);
+-      if (! ((*up == 1 << (8*i)) ||   /* big-endian */
+-             (*up == 1 << (8*(3-i)))  /* little-endian */
+-            )
+-         )
+-      {
+-          printf("read failed (%x)\n", *up);
+-          exit(2);
+-      }
+-    }
+-
+-    /* write test */
+-    for (i = 0; i < 4; i++) {
+-      up = (U32*)(buf + i);
+-      *up = 0xBeef;
+-      if (*up != 0xBeef) {
+-          printf("write failed (%x)\n", *up);
+-          exit(3);
+-      }
+-    }
+-
+-    printf("no restrictions\n");
+-    exit(0);
+-#else
+-    printf("unusual byteorder, playing safe\n");
+-    exit(1);
+-#endif
+-    return 0;
+-}
+-/*--------------------------------------------------------------*/
+-EOT
+-
+-    my $cc_cmd = "$Config{cc} $Config{ccflags} -I$Config{archlibexp}/CORE";
+-    my $exe = "u32align$Config{exe_ext}";
+-    $cc_cmd .= " -o $exe";
+-    my $rc;
+-    $rc = system("$cc_cmd $Config{ldflags} u32align.c $Config{libs}");
+-    if ($rc) {
+-      print "Can't compile test program.  Will ensure alignment to play safe.\n\n";
+-      unlink("u32align.c", $exe, "u32align$Config{obj_ext}");



Home | Main Index | Thread Index | Old Index