From 02b7edbcbb1739eea0f584e0464361c77b3400f6 Mon Sep 17 00:00:00 2001 From: maya Date: Tue, 6 Aug 2019 08:50:28 +0000 Subject: libusb1: patch some undefined behaviour, disable strict aliasing, change -O2 to -O1 when building with clang. This isn't in a separate hacks.mk file because I think that hides the problem too much, it's an issue with the code in the package, not with the compiler's choices. Fixes functionality when built with clang. From Shingo Nishioka in PR pkg/54441. --- devel/libusb1/Makefile | 10 +++++++++- devel/libusb1/distinfo | 3 ++- devel/libusb1/patches/patch-ub | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 devel/libusb1/patches/patch-ub (limited to 'devel') diff --git a/devel/libusb1/Makefile b/devel/libusb1/Makefile index 8adf3fa0586..738b52005b9 100644 --- a/devel/libusb1/Makefile +++ b/devel/libusb1/Makefile @@ -1,7 +1,8 @@ -# $NetBSD: Makefile,v 1.18 2019/06/22 11:30:11 nia Exp $ +# $NetBSD: Makefile,v 1.19 2019/08/06 08:50:28 maya Exp $ DISTNAME= libusb-1.0.22 PKGNAME= ${DISTNAME:S/libusb/libusb1/} +PKGREVISION= 1 CATEGORIES= devel MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=libusb/} EXTRACT_SUFX= .tar.bz2 @@ -20,6 +21,13 @@ USE_LIBTOOL= yes USE_TOOLS+= pkg-config MAKE_JOBS_SAFE= no +.include "../../mk/compiler.mk" +.if !empty(PKGSRC_COMPILER:Mclang) +# Uses undefined behaviour +BUILDLINK_TRANSFORM+= opt:-O2:-O1 +CFLAGS+= -fno-strict-aliasing +.endif + PKGCONFIG_OVERRIDE+= libusb-1.0.pc.in # systemd dependency diff --git a/devel/libusb1/distinfo b/devel/libusb1/distinfo index f81998e2343..6abcac0a0b8 100644 --- a/devel/libusb1/distinfo +++ b/devel/libusb1/distinfo @@ -1,4 +1,4 @@ -$NetBSD: distinfo,v 1.10 2019/06/21 16:58:23 sjmulder Exp $ +$NetBSD: distinfo,v 1.11 2019/08/06 08:50:28 maya Exp $ SHA1 (libusb-1.0.22.tar.bz2) = 10116aa265aac4273a0c894faa089370262ec0dc RMD160 (libusb-1.0.22.tar.bz2) = 59b800abb0b4c088dbee950fa67bb31240b8a134 @@ -7,3 +7,4 @@ Size (libusb-1.0.22.tar.bz2) = 598833 bytes SHA1 (patch-configure) = 2776ff354ea8f17663a9a5330f6fe990af27d8fe SHA1 (patch-configure.ac) = 9344b3d6439348164410d1b2071cf14c3f388354 SHA1 (patch-libusb_os_sunos__usb.c) = 4896e497d451487a09b3be9ad74f72595a441086 +SHA1 (patch-ub) = 14bffca93ec8445cbfccb613dfda92f652b0ceb0 diff --git a/devel/libusb1/patches/patch-ub b/devel/libusb1/patches/patch-ub new file mode 100644 index 00000000000..135d1a30c94 --- /dev/null +++ b/devel/libusb1/patches/patch-ub @@ -0,0 +1,36 @@ +$NetBSD: patch-ub,v 1.1 2019/08/06 08:50:28 maya Exp $ + +Avoid undefined behaviour that breaks clang + +--- libusb/descriptor.c.orig 2019-08-02 09:59:25.784968424 +0900 ++++ libusb/descriptor.c 2019-08-02 09:59:44.009134412 +0900 +@@ -54,7 +54,9 @@ + for (cp = descriptor; *cp; cp++) { + switch (*cp) { + case 'b': /* 8-bit byte */ +- *dp++ = *sp++; ++ memcpy(dp, sp, 1); ++ dp += 1; ++ sp += 1; + break; + case 'w': /* 16-bit word, convert from little endian to CPU */ + dp += ((uintptr_t)dp & 1); /* Align to word boundary */ +@@ -63,7 +65,7 @@ + memcpy(dp, sp, 2); + } else { + w = (sp[1] << 8) | sp[0]; +- *((uint16_t *)dp) = w; ++ memcpy(dp, &w, 4); + } + sp += 2; + dp += 2; +@@ -76,7 +78,7 @@ + } else { + d = (sp[3] << 24) | (sp[2] << 16) | + (sp[1] << 8) | sp[0]; +- *((uint32_t *)dp) = d; ++ memcpy(dp, &d, 4); + } + sp += 4; + dp += 4; + -- cgit v1.2.3