Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified)) by mollari.NetBSD.org (Postfix) with ESMTPS id D3A391A9239 for ; Thu, 17 Feb 2022 07:16:12 +0000 (UTC) Received: by mail.netbsd.org (Postfix, from userid 605) id 8ED1A84E65; Thu, 17 Feb 2022 07:16:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.netbsd.org (Postfix) with ESMTP id CA2B084E19 for ; Thu, 17 Feb 2022 07:16:11 +0000 (UTC) X-Virus-Scanned: amavisd-new at netbsd.org Received: from mail.netbsd.org ([127.0.0.1]) by localhost (mail.netbsd.org [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id t-n3S-seJ6Lw for ; Thu, 17 Feb 2022 07:16:11 +0000 (UTC) Received: from cvs.NetBSD.org (ivanova.NetBSD.org [IPv6:2001:470:a085:999:28c:faff:fe03:5984]) by mail.netbsd.org (Postfix) with ESMTP id E820584CD9 for ; Thu, 17 Feb 2022 07:16:10 +0000 (UTC) Received: by cvs.NetBSD.org (Postfix, from userid 500) id E15B4FB24; Thu, 17 Feb 2022 07:16:10 +0000 (UTC) Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_164508217064230" MIME-Version: 1.0 Date: Thu, 17 Feb 2022 07:16:10 +0000 From: "Masatake Daimon" Subject: CVS commit: pkgsrc/lang/ghc92 To: pkgsrc-changes@NetBSD.org Reply-To: pho@netbsd.org X-Mailer: log_accum Message-Id: <20220217071610.E15B4FB24@cvs.NetBSD.org> Sender: pkgsrc-changes-owner@NetBSD.org List-Id: Precedence: bulk List-Unsubscribe: This is a multi-part message in MIME format. --_----------=_164508217064230 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Module Name: pkgsrc Committed By: pho Date: Thu Feb 17 07:16:10 UTC 2022 Modified Files: pkgsrc/lang/ghc92: Makefile distinfo Added Files: pkgsrc/lang/ghc92/patches: patch-rts_Linker.c Log Message: lang/ghc92: Work around an issue where GHCi sometimes crashes on NetBSD To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 pkgsrc/lang/ghc92/Makefile \ pkgsrc/lang/ghc92/distinfo cvs rdiff -u -r0 -r1.1 pkgsrc/lang/ghc92/patches/patch-rts_Linker.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. --_----------=_164508217064230 Content-Disposition: inline Content-Length: 5246 Content-Transfer-Encoding: binary Content-Type: text/x-diff; charset=us-ascii Modified files: Index: pkgsrc/lang/ghc92/Makefile diff -u pkgsrc/lang/ghc92/Makefile:1.2 pkgsrc/lang/ghc92/Makefile:1.3 --- pkgsrc/lang/ghc92/Makefile:1.2 Thu Feb 10 12:21:11 2022 +++ pkgsrc/lang/ghc92/Makefile Thu Feb 17 07:16:10 2022 @@ -1,10 +1,10 @@ -# $NetBSD: Makefile,v 1.2 2022/02/10 12:21:11 pho Exp $ +# $NetBSD: Makefile,v 1.3 2022/02/17 07:16:10 pho Exp $ # ----------------------------------------------------------------------------- # Package metadata # DISTNAME= ghc-9.2.1-src PKGNAME= ${DISTNAME:S/-src$//} -PKGREVISION= 1 +PKGREVISION= 2 CATEGORIES= lang MASTER_SITES= https://downloads.haskell.org/~ghc/${PKGVERSION_NOREV}/ EXTRACT_SUFX= .tar.xz @@ -66,16 +66,6 @@ CONFIGURE_ARGS.common+= \ --with-ffi-libraries=${BUILDLINK_PREFIX.libffi}/${BUILDLINK_LIBDIRS.libffi:Q} .include "../../mk/bsd.prefs.mk" -.if ${OPSYS} == "NetBSD" -# The GHC rts, by default, creates executable objects on the heap by first -# mmap(2)'ing an anonymous memory with PROT_READ|PROT_WRITE and then calling -# mprotect(2) with PROT_READ|PROT_EXEC after filling its content. However, -# NetBSD PaX mprotect doesn't allow this practice. That is, turning pages that -# have been initially mapped as non-executable into something executable is a -# no-no. We must therefore take a different path although it might be a bit slower. -CONFIGURE_ARGS.common+= --enable-libffi-adjustors -# See rts/adjustor/NativeAmd64.c and rts/adjustor/LibffiAdjustor.c -.endif # We must pass non-wrapper tools to ./configure because they will be # embedded in the compiler (actually ${WRKSRC}/settings). Index: pkgsrc/lang/ghc92/distinfo diff -u pkgsrc/lang/ghc92/distinfo:1.2 pkgsrc/lang/ghc92/distinfo:1.3 --- pkgsrc/lang/ghc92/distinfo:1.2 Tue Feb 8 07:45:02 2022 +++ pkgsrc/lang/ghc92/distinfo Thu Feb 17 07:16:10 2022 @@ -1,4 +1,4 @@ -$NetBSD: distinfo,v 1.2 2022/02/08 07:45:02 pho Exp $ +$NetBSD: distinfo,v 1.3 2022/02/17 07:16:10 pho Exp $ BLAKE2s (ghc-8.10.4-boot-x86_64-unknown-netbsd.tar.xz) = 03efbb455a52d0dbc246b1c8b30f82121f5354a1ca0eb1b08b6225b90286a18f SHA512 (ghc-8.10.4-boot-x86_64-unknown-netbsd.tar.xz) = 730347bb5eaac4efac8ec487fafd2da6fe2932db45f59e324c83698eb0b0e8a6a4b4fd513de17fb9c152ccee328660cfe1638cad631ce5e35b2dbfddda0d8850 @@ -46,6 +46,7 @@ SHA1 (patch-llvm-targets) = cba672c60c9c SHA1 (patch-m4_find__llvm__prog.m4) = cc56b21739aff5faec378a1c47f514613c18db9e SHA1 (patch-m4_fptools__set__c__ld__flags.m4) = 2d37b779d662e66521d2b5fda994174c9dfcbc29 SHA1 (patch-mk_config.mk.in) = ae2134a50e571090d504549b2b3fed8bb953fceb +SHA1 (patch-rts_Linker.c) = aa04adb7d3275f4cf4e6b516a489beaed8642f21 SHA1 (patch-rts_ProfHeap.c) = fafbb740ee87949da12749834478769548322993 SHA1 (patch-rts_ghc.mk) = 6e3daf71fb7e656131aa2aeeb0346c651520216a SHA1 (patch-rts_posix_GetTime.c) = 036e09510c893ab8677a2b4add0193e7f811bb82 Added files: Index: pkgsrc/lang/ghc92/patches/patch-rts_Linker.c diff -u /dev/null pkgsrc/lang/ghc92/patches/patch-rts_Linker.c:1.1 --- /dev/null Thu Feb 17 07:16:10 2022 +++ pkgsrc/lang/ghc92/patches/patch-rts_Linker.c Thu Feb 17 07:16:10 2022 @@ -0,0 +1,58 @@ +$NetBSD: patch-rts_Linker.c,v 1.1 2022/02/17 07:16:10 pho Exp $ + +NetBSD-specific way of switching pages from rw- to r-x. Should not be +upstreamed until we figure out why the hunk #0 is necessary. + +Even when the RTS linker is not used, libraries/ghci/GHCi/InfoTable.hsc +(fillExecBuffer) calls rts/ExecPage.c (allocateExecPage) to store some +executable code, which in turn calls mmapForLinker() and fails. + +Minimal test case: +https://gist.github.com/depressed-pho/a629247b48b3e6178e35a14c62e9d44f + +This was previously not an issue, until +https://gitlab.haskell.org/ghc/ghc/-/issues/20051 happened and lead to +https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6155 + +--- rts/Linker.c.orig 2021-10-28 20:41:34.000000000 +0000 ++++ rts/Linker.c +@@ -1115,9 +1115,17 @@ mmapForLinker (size_t bytes, uint32_t pr + mmap_again: + #endif + ++#if defined(DYNAMIC) && defined(netbsd_HOST_OS) ++ /* Dynamic RTS only uses this function for allocating some anonymous pages ++ * for code generated on-the-fly, which doesn't need to be in a certain ++ * range. On NetBSD, when ASLR is enabled, specifying an address hint ++ * sometimes fail with ENOMEM even when MAP_FIXED is not used. ++ */ ++#else + if (mmap_32bit_base != 0) { + map_addr = mmap_32bit_base; + } ++#endif + + IF_DEBUG(linker, + debugBelch("mmapForLinker: \tprotection %#0x\n", prot)); +@@ -1218,7 +1226,20 @@ mmap_again: + void * + mmapAnonForLinker (size_t bytes) + { +- return mmapForLinker (bytes, PROT_READ|PROT_WRITE, MAP_ANONYMOUS, -1, 0); ++ int prot; ++ ++#if defined(netbsd_HOST_OS) ++ /* PROT_MPROTECT(PROT_EXEC) means that the pages are going to be marked as ++ * executable in the future. On NetBSD requesting additional permissions with ++ * mprotect(2) only succeeds when permissions were initially requested in this ++ * manner. ++ */ ++ prot = PROT_READ|PROT_WRITE|PROT_MPROTECT(PROT_EXEC); ++#else ++ prot = PROT_READ|PROT_WRITE; ++#endif ++ ++ return mmapForLinker (bytes, prot, MAP_ANONYMOUS, -1, 0); + } + + void munmapForLinker (void *addr, size_t bytes, const char *caller) --_----------=_164508217064230--