Built a bootkit for NetBSD/aarch64

Also the package is now more explicit about LLVM. It used to invoke whatever llc(1) and opt(1) found in the $PATH when -fllvm is passed to the compiler, though it's not the default backend. Now LLVM is an explicit, optional dependency on platforms where NCG backend is available, and a mandatory dependency on others.

Note that the LLVM backend tends to produce faster code but it runs significantly slower than NCG. AArch64 support of NCG is being worked on, but it hasn't been merged to the 9.0 branch yet (or even the master branch).
This commit is contained in:
pho 2021-05-21 01:45:00 +00:00
parent 346af0ccce
commit c2eee27828
6 changed files with 108 additions and 12 deletions

View file

@ -1,9 +1,9 @@
# $NetBSD: Makefile,v 1.12 2021/05/01 09:04:57 pho Exp $
# $NetBSD: Makefile,v 1.13 2021/05/21 01:45:00 pho Exp $
# -----------------------------------------------------------------------------
# Package metadata
#
DISTNAME= ghc-9.0.1-src
PKGREVISION= 4
PKGREVISION= 5
PKGNAME= ${DISTNAME:S/-src$//}
CATEGORIES= lang
MASTER_SITES= https://downloads.haskell.org/~ghc/${PKGVERSION_NOREV}/
@ -26,9 +26,12 @@ CONFLICTS+= ghc-[0-9]*
BROKEN_EXCEPT_ON_PLATFORM+= Darwin-*-x86_64
BROKEN_EXCEPT_ON_PLATFORM+= FreeBSD-*-i386
BROKEN_EXCEPT_ON_PLATFORM+= FreeBSD-*-x86_64
BROKEN_EXCEPT_ON_PLATFORM+= NetBSD-*-aarch64
BROKEN_EXCEPT_ON_PLATFORM+= NetBSD-*-x86_64
BROKEN_EXCEPT_ON_PLATFORM+= SunOS-*-x86_64
.include "options.mk"
# -----------------------------------------------------------------------------
# Distfiles
@ -205,7 +208,7 @@ BUILD_DEPENDS+= ${PYPKGPREFIX}-sphinx-[0-9]*:../../textproc/py-sphinx
# NetBSD 9.x have libcurses with a newer major version than the
# bootstrap kit is linked against. For now, work around this with
# compat80.
.if ${OPSYS} == "NetBSD" && empty(OS_VERSION:M[0-8].*)
.if !empty(MACHINE_PLATFORM:MNetBSD-*-x86_64) && empty(OS_VERSION:M[0-8].*)
BUILD_DEPENDS+= compat80-[0-9]*:../../emulators/compat80
# In a sandboxed build environment, we have to reach over to the
# installed libraries themselves, since the symlinks compat80 adds

View file

@ -1,4 +1,4 @@
# $NetBSD: bootstrap.mk,v 1.9 2021/04/30 03:05:30 pho Exp $
# $NetBSD: bootstrap.mk,v 1.10 2021/05/21 01:45:00 pho Exp $
# -----------------------------------------------------------------------------
# Select a bindist of bootstrapping compiler on a per-platform basis.
#
@ -37,7 +37,14 @@ BOOT_ARCHIVE:= ghc-${BOOT_VERSION}-boot-x86_64-unknown-freebsd.tar.xz
DISTFILES:= ${DISTFILES} ${BOOT_ARCHIVE} # Available in LOCAL_PORTS
.endif
.if !empty(MACHINE_PLATFORM:MNetBSD-*-x86_64) || make(distinfo) || make (makesum) || make(mdi)
.if !empty(MACHINE_PLATFORM:MNetBSD-*-aarch64) || make(distinfo) || make(makesum) || make(mdi)
# Cross-compiled from x86_64 on a QEMU guest. It took days to compile...
BOOT_VERSION:= 9.0.1
BOOT_ARCHIVE:= ghc-${BOOT_VERSION}-boot-aarch64-unknown-netbsd.tar.xz
DISTFILES:= ${DISTFILES} ${BOOT_ARCHIVE} # Available in LOCAL_PORTS
.endif
.if !empty(MACHINE_PLATFORM:MNetBSD-*-x86_64) || make(distinfo) || make(makesum) || make(mdi)
BOOT_VERSION:= 8.10.4
BOOT_ARCHIVE:= ghc-${BOOT_VERSION}-boot-x86_64-unknown-netbsd.tar.xz
DISTFILES:= ${DISTFILES} ${BOOT_ARCHIVE} # Available in LOCAL_PORTS

View file

@ -1,9 +1,13 @@
$NetBSD: distinfo,v 1.13 2021/05/05 09:18:52 pho Exp $
$NetBSD: distinfo,v 1.14 2021/05/21 01:45:00 pho Exp $
SHA1 (ghc-8.10.4-boot-x86_64-unknown-netbsd.tar.xz) = 3ff01d768393b3866e7a7543f9f55646aaffce7a
RMD160 (ghc-8.10.4-boot-x86_64-unknown-netbsd.tar.xz) = 39bf10b13054a6316c8477609fb98abe4277fa6c
SHA512 (ghc-8.10.4-boot-x86_64-unknown-netbsd.tar.xz) = 730347bb5eaac4efac8ec487fafd2da6fe2932db45f59e324c83698eb0b0e8a6a4b4fd513de17fb9c152ccee328660cfe1638cad631ce5e35b2dbfddda0d8850
Size (ghc-8.10.4-boot-x86_64-unknown-netbsd.tar.xz) = 49500236 bytes
SHA1 (ghc-9.0.1-boot-aarch64-unknown-netbsd.tar.xz) = db416c1e32a0b65e964aa80db3ecd4492a9e62d0
RMD160 (ghc-9.0.1-boot-aarch64-unknown-netbsd.tar.xz) = 29250c03e4d29a04f2904508cd0d87d47a0e4340
SHA512 (ghc-9.0.1-boot-aarch64-unknown-netbsd.tar.xz) = 6ae93b63ecaacc9740f88b0c78095ea660cdf3d7d30bf02b66da3d1a31ceaaf3fd33053b7863ced70ef8b4b844257e6bd856d44648e21876f802e395d265c4d6
Size (ghc-9.0.1-boot-aarch64-unknown-netbsd.tar.xz) = 83725368 bytes
SHA1 (ghc-9.0.1-boot-i386-unknown-freebsd.tar.xz) = 7b33f71d9ec9951934137703eef61c106f261808
RMD160 (ghc-9.0.1-boot-i386-unknown-freebsd.tar.xz) = 98ba27e49e84738a9db92daf669ca7839dd5c0d9
SHA512 (ghc-9.0.1-boot-i386-unknown-freebsd.tar.xz) = 4fcf2eaa25b33ca77ad4ce465258ca6f9487995219d69416933a84b3d70b7908a09004f3279b4368f81ebb4fdd14465859147ebe683ac7f538307ce5dd74241d
@ -28,7 +32,7 @@ SHA1 (netbsd-9.0-amd64-libterminfo.tar.gz) = db6b385b8676efc135c08b06e3dd6fd11b9
RMD160 (netbsd-9.0-amd64-libterminfo.tar.gz) = 5a246633c90ee85f71efcc02d8280bd0c50ab5a7
SHA512 (netbsd-9.0-amd64-libterminfo.tar.gz) = 79288d44b84df8848afc2cdfee628cc4fd1ec0334159403ef8ba994d617bc56a7114af3031198afb5f3b8f45c0463a848099431e32bc6725042908576b6f95b8
Size (netbsd-9.0-amd64-libterminfo.tar.gz) = 27744 bytes
SHA1 (patch-aclocal.m4) = 5de0a62459cddff19973b27e1f2a7dfac7a51dab
SHA1 (patch-aclocal.m4) = 65f53d7ae4d2124d7191cd0e184b415749a488fb
SHA1 (patch-compiler_GHC_Driver_Pipeline.hs) = cc2c53f14420b8b75bd70b73e2c95bb52a10cd0c
SHA1 (patch-compiler_GHC_SysTools_Process.hs) = 36d7171e571d56c4e6ae1ed99d2851c0b0dac084
SHA1 (patch-configure.ac) = a67c57f39c152a9fc8af830045cf001e957590e2
@ -45,6 +49,7 @@ SHA1 (patch-libraries_unix_System_Posix_Env_ByteString.hsc) = 3f675fc5d6bf5cc59a
SHA1 (patch-libraries_unix_System_Posix_Files_Common.hsc) = 6efef280832d376915a8987e4e8aac283408f607
SHA1 (patch-libraries_unix_System_Posix_Signals.hsc) = 49215dce493a6bbc440f91a3959e592f86fc779b
SHA1 (patch-libraries_unix_include_execvpe.h) = 560c6e9b644687fad62e380f73f08359c48639a2
SHA1 (patch-llvm-targets) = ff9311421ce0e4c6f666d4f753c8f3b4b7ca1058
SHA1 (patch-rts_ProfHeap.c) = bc1492578eac7b194caaf1221586cd6c13aa9583
SHA1 (patch-rts_ghc.mk) = 6e3daf71fb7e656131aa2aeeb0346c651520216a
SHA1 (patch-rts_posix_GetTime.c) = 036e09510c893ab8677a2b4add0193e7f811bb82

48
lang/ghc90/options.mk Normal file
View file

@ -0,0 +1,48 @@
# $NetBSD: options.mk,v 1.1 2021/05/21 01:45:00 pho Exp $
PKG_OPTIONS_VAR= PKG_OPTIONS.ghc
# GHC has a native implementation of codegen for some platforms. On
# those platforms LLVM is optional. It's a requirement anywhere else.
# See compiler/GHC/Driver/Backend.hs
GHC_NCG_SUPPORTED= i386 x86_64 powerpc powerpc64 sparc
.if !empty(GHC_NCG_SUPPORTED:M${MACHINE_ARCH})
PKG_SUPPORTED_OPTIONS+= llvm
PKG_SUGGESTED_OPTIONS+= llvm
GHC_LLVM_REQUIRED= no
.else
GHC_LLVM_REQUIRED= yes
.endif
.if !empty(PKG_SUPPORTED_OPTIONS)
. include "../../mk/bsd.options.mk"
.endif
.if !empty(PKG_OPTIONS:Mllvm) || ${GHC_LLVM_REQUIRED} == "yes"
. include "../../lang/llvm/buildlink3.mk"
. include "../../lang/llvm/version.mk"
CONFIGURE_ENV+= LLC=${PREFIX:Q}/bin/llc
CONFIGURE_ENV+= OPT=${PREFIX:Q}/bin/opt
# Maybe GHC doesn't like this but it's the only option available to us.
SUBST_CLASSES+= llvm
SUBST_STAGE.llvm= post-extract
SUBST_MESSAGE.llvm= Accept whichever version of LLVM installed via pkgsrc
SUBST_FILES.llvm= configure.ac
SUBST_SED.llvm= -e 's/LlvmVersion=[0-9]*/LlvmVersion=${LLVM_VERSION:C/^([0-9]*)\..*/\1/}/'
# Clang is also required on Darwin.
# See compiler/GHC/SysTools/Tasks.hs (runClang).
. if ${OPSYS} == "Darwin"
. include "../../lang/clang/buildlink3.mk"
CONFIGURE_ENV+= CLANG=${PREFIX:Q}/bin/clang
. else
CONFIGURE_ENV+= CLANG=${FALSE}
. endif
.else
CONFIGURE_ENV+= LLC=${FALSE:Q}
CONFIGURE_ENV+= OPT=${FALSE:Q}
CONFIGURE_ENV+= CLANG=${FALSE:Q}
.endif

View file

@ -1,10 +1,15 @@
$NetBSD: patch-aclocal.m4,v 1.3 2021/05/05 09:18:52 pho Exp $
$NetBSD: patch-aclocal.m4,v 1.4 2021/05/21 01:45:00 pho Exp $
Remove _AC_PROG_CC_C99 macro that is removed in autoconf-2.71 to fix
build failure.
Hunk #0:
Remove _AC_PROG_CC_C99 macro that is removed in autoconf-2.71 to fix
build failure.
Already fixed in the upstream:
https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4987
Already fixed in the upstream:
https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4987
Hunk #1:
Mark the stack as non-executable on NetBSD/aarch64.
TODO: Send this to the upstream.
--- aclocal.m4.orig 2021-01-26 14:49:54.000000000 +0000
+++ aclocal.m4
@ -26,3 +31,14 @@ https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4987
dnl restore saved state
FP_COPY_SHELLVAR([fp_save_CC],[CC])
FP_COPY_SHELLVAR([fp_save_CFLAGS],[CFLAGS])
@@ -759,6 +748,10 @@ AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
$3="$$3 -Wl,-z,noexecstack"
$4="$$4 -z noexecstack"
;;
+ aarch64*netbsd*)
+ $3="$$3 -Wl,-z,noexecstack"
+ $4="$$4 -z noexecstack"
+ ;;
powerpc-ibm-aix*)
# We need `-D_THREAD_SAFE` to unlock the thread-local `errno`.

View file

@ -0,0 +1,17 @@
$NetBSD: patch-llvm-targets,v 1.1 2021/05/21 01:45:00 pho Exp $
Define the LLVM target for NetBSD/aarch64. This file is generated with
utils/llvm-targets/gen-data-layout.sh
TODO: Send this to the upstream.
--- llvm-targets.orig 2020-12-21 18:11:39.000000000 +0000
+++ llvm-targets
@@ -48,6 +48,7 @@
,("amd64-portbld-freebsd", ("e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", "x86-64", ""))
,("x86_64-unknown-freebsd", ("e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", "x86-64", ""))
,("aarch64-unknown-freebsd", ("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", "generic", "+neon"))
+,("aarch64-unknown-netbsd", ("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", "generic", "+neon"))
,("armv6-unknown-freebsd-gnueabihf", ("e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64", "arm1176jzf-s", "+strict-align"))
,("armv7-unknown-freebsd-gnueabihf", ("e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64", "generic", "+strict-align"))
,("arm-unknown-nto-qnx-eabi", ("e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64", "arm7tdmi", "+strict-align"))