Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 Aug 2018 08:51:33 +0000 (UTC)
From:      Gleb Popov <arrowd@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r478531 - in head/lang/ghc: . files
Message-ID:  <201808310851.w7V8pXxG053285@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: arrowd
Date: Fri Aug 31 08:51:33 2018
New Revision: 478531
URL: https://svnweb.freebsd.org/changeset/ports/478531

Log:
  lang/ghc: Add support for ARM arches: aarch64, armv6, armv7.
  
  PR:		196899
  Submitted by:	Mikael Urankar <mikael.urankar@gmail.com>
  Reviewed by:	arrowd, mat, tcberner
  Approved by:	tcberner (mentor)
  Differential Revision:	https://reviews.freebsd.org/D15674

Added:
  head/lang/ghc/files/extra-patch-aclocal.m4   (contents, props changed)
  head/lang/ghc/files/patch-configure   (contents, props changed)
  head/lang/ghc/files/patch-llvm-targets   (contents, props changed)
Modified:
  head/lang/ghc/Makefile
  head/lang/ghc/bsd.cabal.mk
  head/lang/ghc/distinfo
  head/lang/ghc/files/patch-configure.ac

Modified: head/lang/ghc/Makefile
==============================================================================
--- head/lang/ghc/Makefile	Fri Aug 31 08:46:10 2018	(r478530)
+++ head/lang/ghc/Makefile	Fri Aug 31 08:51:33 2018	(r478531)
@@ -15,7 +15,7 @@ COMMENT=	Compiler for the functional language Haskell
 LICENSE=	BSD3CLAUSE
 LICENSE_FILE=	${WRKSRC}/LICENSE
 
-ONLY_FOR_ARCHS=	i386 amd64
+ONLY_FOR_ARCHS=	aarch64 amd64 armv6 armv7 i386
 
 GHC_VERSION=		8.4.3
 HSCOLOUR_VERSION=	1.24.4
@@ -56,6 +56,10 @@ OPTIONS_DEFINE=		DYNAMIC PROFILE DOCS
 OPTIONS_SUB=		yes
 
 OPTIONS_DEFAULT=	PROFILE DYNAMIC
+# ghci segfaults on arm when dynamic linking is used
+OPTIONS_EXCLUDE_armv6=	DYNAMIC
+OPTIONS_EXCLUDE_armv7=	DYNAMIC
+OPTIONS_EXCLUDE_aarch64=	DYNAMIC
 
 BOOT_DESC=		Use installed GHC for bootstrapping
 BOOTH_DESC=		Use installed HsColour for bootstrapping
@@ -93,6 +97,26 @@ BOOT_GHC_VERSION=	8.4.2
 DISTFILES+=		ghc-${BOOT_GHC_VERSION}-boot-${ARCH}-freebsd${EXTRACT_SUFX}:boot
 .endif # MBOOT
 
+.if ${ARCH} == aarch64 || ${ARCH} == armv6 || ${ARCH} == armv7
+# CONFIGURE_TARGET must to be the same as the llvm triple
+CONFIGURE_TARGET=	${ARCH}-unknown-freebsd${"${ARCH:Maarch64}" != "":?:-gnueabihf}
+EXTRA_PATCHES+=		${PATCHDIR}/extra-patch-aclocal.m4
+BUILD_DEPENDS+=		ld.gold:devel/binutils \
+			llc50:devel/llvm50
+RUN_DEPENDS+=		ld.gold:devel/binutils \
+			llc50:devel/llvm50
+USE_GCC=		yes
+CONFIGURE_ENV+=		OPT=opt50 LLC=llc50
+
+.  if ${OSVERSION} < 1200064
+IGNORE=	lang/ghc on ARM requires at least __FreeBSD_version 1200064
+.  endif
+
+.  ifdef QEMU_EMULATING
+IGNORE=	qemu-user-static isn't able to build lang/ghc, but it builds fine on a real hardware
+.  endif
+.endif
+
 # Turn off for a while, see PR 228727
 CONFIGURE_ARGS+=	--enable-dtrace=0
 .if ${OSVERSION} < 1200000
@@ -159,7 +183,9 @@ CONFIGURE_ENV+=	PATH=${SLAVES_PREFIX}/bin:${PATH}
 .endif # MDOCS
 
 post-extract:
-.if empty(PORT_OPTIONS:MBOOT) && ${OPSYS} == FreeBSD && ${OSVERSION} >= 1200031
+# don't use the "wrap" trick on arches that use post-ino64 bootstrap binaries (arm*)
+.if empty(PORT_OPTIONS:MBOOT) && ${OPSYS} == FreeBSD && ${OSVERSION} >= 1200031 && \
+    ${ARCH} != aarch64 && ${ARCH} != armv6 && ${ARCH} != armv7
 	@${REINPLACE_CMD} -e 's|@SettingsCCompilerLinkFlags@|& -Wl,--wrap=readdir_r,--wrap=stat,--wrap=lstat,--wrap=fstat,--wrap=mknod|' ${BOOT_DIR}/settings.in
 .endif
 
@@ -192,6 +218,12 @@ post-patch:
 		s|%%AR%%|${AR}|; \
 		s|%%LD%%|${LD}|' \
 		${WRKSRC}/libraries/Cabal/Cabal/Distribution/Simple/Program/Builtin.hs
+# we must use binutils:ld on arm
+.if ${ARCH} == aarch64 || ${ARCH} == armv6 || ${ARCH} == armv7
+	@${REINPLACE_CMD} -e 's|LD_NO_GOLD=ld|LD_NO_GOLD=${LOCALBASE}/bin/ld|' \
+		${WRKSRC}/aclocal.m4
+.endif
+
 .if empty(PORT_OPTIONS:MBOOT)
 	@${REINPLACE_CMD} -e '/^mandir/d' ${BOOT_DIR}/mk/build.mk
 	@${REINPLACE_CMD} -e '/^infodir/d' ${BOOT_DIR}/mk/build.mk
@@ -205,7 +237,8 @@ pre-configure: apply-slist
 
 	@${MKDIR} ${TMPDIR}
 .if empty(PORT_OPTIONS:MBOOT) && ${OPSYS} == FreeBSD && \
-    ${OSVERSION} >= 1200031
+    ${OSVERSION} >= 1200031 && \
+    ${ARCH} != aarch64 && ${ARCH} != armv6 && ${ARCH} != armv7
 	${CC} ${CFLAGS} -c -o ${BOOT_DIR}/wrap.o ${PATCHDIR}/wrap.c
 	for x in ${BOOT_DIR}/rts/dist/build/libCffi*.a; do \
 	    ${AR} q $$x ${BOOT_DIR}/wrap.o; ${RANLIB} $$x; \

Modified: head/lang/ghc/bsd.cabal.mk
==============================================================================
--- head/lang/ghc/bsd.cabal.mk	Fri Aug 31 08:46:10 2018	(r478530)
+++ head/lang/ghc/bsd.cabal.mk	Fri Aug 31 08:51:33 2018	(r478531)
@@ -54,10 +54,7 @@ GHC_LIB_DOCSDIR_REL=	share/doc/ghc-${GHC_VERSION}/html
 
 CABAL_LIBDIR=		${PREFIX}/lib/cabal/ghc-${GHC_VERSION}
 CABAL_LIBSUBDIR=	${PACKAGE}
-CABAL_ARCH=		x86_64
-.if ("${ARCH}" == "i386")
-CABAL_ARCH=		i386
-.endif
+CABAL_ARCH=		${ARCH:S/amd64/x86_64/:C/armv.*/arm/}
 CABAL_ARCHSUBDIR=	${CABAL_ARCH}-freebsd-ghc-${GHC_VERSION}
 CABAL_LIBDIR_REL=	${CABAL_LIBDIR:S,^${PREFIX}/,,}
 

Modified: head/lang/ghc/distinfo
==============================================================================
--- head/lang/ghc/distinfo	Fri Aug 31 08:46:10 2018	(r478530)
+++ head/lang/ghc/distinfo	Fri Aug 31 08:51:33 2018	(r478531)
@@ -7,3 +7,9 @@ SHA256 (ghc-8.4.2-boot-i386-freebsd.tar.xz) = 67323073
 SIZE (ghc-8.4.2-boot-i386-freebsd.tar.xz) = 69976728
 SHA256 (hscolour-1.24.4.tar.gz) = 243332b082294117f37b2c2c68079fa61af68b36223b3fc07594f245e0e5321d
 SIZE (hscolour-1.24.4.tar.gz) = 28729
+SHA256 (ghc-8.4.2-boot-aarch64-freebsd.tar.xz) = 18412f10bb172dbaff7f31505845fbd43fdde14046463fdacc42e26683be311d
+SIZE (ghc-8.4.2-boot-aarch64-freebsd.tar.xz) = 100240140
+SHA256 (ghc-8.4.2-boot-armv6-freebsd.tar.xz) = 61d3a4486dbb904b05a735e98f23a49c2b464d6b19212dd655ff578f36d02f0d
+SIZE (ghc-8.4.2-boot-armv6-freebsd.tar.xz) = 107368936
+SHA256 (ghc-8.4.2-boot-armv7-freebsd.tar.xz) = eedb9416870bfe82315155751871e31e815b718b381ccf4f7e45a99a6ad7c94d
+SIZE (ghc-8.4.2-boot-armv7-freebsd.tar.xz) = 110153548

Added: head/lang/ghc/files/extra-patch-aclocal.m4
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lang/ghc/files/extra-patch-aclocal.m4	Fri Aug 31 08:51:33 2018	(r478531)
@@ -0,0 +1,54 @@
+--- aclocal.m4.orig	2018-03-25 21:22:32 UTC
++++ aclocal.m4
+@@ -648,6 +648,14 @@ AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
+         $3="$$3 -D_HPUX_SOURCE"
+         $5="$$5 -D_HPUX_SOURCE"
+         ;;
++    arm*freebsd*)
++        # On arm/freebsd, tell gcc to generate Arm
++        # instructions (ie not Thumb) and to link using the gold linker.
++        # Forcing LD to be ld.gold is done in FIND_LD m4 macro.
++        $2="$$2 -marm"
++        $3="$$3 -Wl,-z,noexecstack"
++        $4="$$4 -z noexecstack"
++        ;;
+     arm*linux*)
+         # On arm/linux and arm/android, tell gcc to generate Arm
+         # instructions (ie not Thumb).
+@@ -656,6 +664,11 @@ AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
+         $4="$$4 -z noexecstack"
+         ;;
+ 
++    aarch64*freebsd*)
++        $3="$$3 -Wl,-z,noexecstack"
++        $4="$$4 -z noexecstack"
++        ;;
++
+     aarch64*linux*)
+         $3="$$3 -Wl,-z,noexecstack"
+         $4="$$4 -z noexecstack"
+@@ -1917,6 +1930,10 @@ case "$1" in
+ # converts the canonicalized target into someting llvm can understand
+ AC_DEFUN([GHC_LLVM_TARGET], [
+   case "$2-$3" in
++    *-freebsd*-gnueabihf)
++      llvm_target_vendor="unknown"
++      llvm_target_os="freebsd-gnueabihf"
++      ;;
+     hardfloat-*eabi)
+       llvm_target_vendor="unknown"
+       llvm_target_os="$3""hf"
+@@ -2361,13 +2378,6 @@ AC_DEFUN([FIND_LD],[
+       [enable_ld_override=yes])
+ 
+     find_ld() {
+-        # Make sure the user didn't specify LD manually.
+-        if test "z$LD" != "z"; then
+-            AC_CHECK_TARGET_TOOL([LD], [ld])
+-            LD_NO_GOLD=$LD
+-            return
+-        fi
+-
+         # Manually iterate over possible names since we want to ensure that, e.g.,
+         # if ld.lld is installed but gcc doesn't support -fuse-ld=lld, that we
+         # then still try ld.gold and -fuse-ld=gold.

Added: head/lang/ghc/files/patch-configure
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lang/ghc/files/patch-configure	Fri Aug 31 08:51:33 2018	(r478531)
@@ -0,0 +1,22 @@
+--- configure.orig	2018-03-06 20:04:54 UTC
++++ configure
+@@ -9108,6 +9108,19 @@ $as_echo_n "checking Setting up CFLAGS, LDFLAGS, IGNOR
+         IGNORE_LINKER_LD_FLAGS="$IGNORE_LINKER_LD_FLAGS -z noexecstack"
+         ;;
+ 
++    arm*freebsd*)
++        # On arm/freebsd, tell gcc to generate Arm
++        # instructions (ie not Thumb).
++        CFLAGS="$CFLAGS -marm"
++        LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"
++        IGNORE_LINKER_LD_FLAGS="$IGNORE_LINKER_LD_FLAGS -z noexecstack"
++        ;;
++
++    aarch64*freebsd*)
++        LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"
++        IGNORE_LINKER_LD_FLAGS="$IGNORE_LINKER_LD_FLAGS -z noexecstack"
++        ;;
++
+     powerpc-ibm-aix*)
+         # We need `-D_THREAD_SAFE` to unlock the thread-local `errno`.
+         CFLAGS="$CFLAGS -D_THREAD_SAFE"

Modified: head/lang/ghc/files/patch-configure.ac
==============================================================================
--- head/lang/ghc/files/patch-configure.ac	Fri Aug 31 08:46:10 2018	(r478530)
+++ head/lang/ghc/files/patch-configure.ac	Fri Aug 31 08:51:33 2018	(r478531)
@@ -1,11 +1,11 @@
---- configure.ac.orig	2018-03-06 16:48:53 UTC
+--- configure.ac.orig	2018-04-17 19:30:22 UTC
 +++ configure.ac
 @@ -447,6 +447,9 @@ XCODE_VERSION()
  dnl ** Building a cross compiler?
  dnl --------------------------------------------------------------
  CrossCompiling=NO
 +
-+build=`echo $build | sed -e 's/amd64-/x86_64-/g; s/-freebsd.*$/-freebsd/g'`
++build=`echo $build | sed -e 's/amd64-/x86_64-/g; s/armv[[67]]-/arm-/g; s/-freebsd.*$/-freebsd/g'`
 +
  # If 'host' and 'target' differ, then this means we are building a cross-compiler.
  if test "$TargetPlatform" != "$HostPlatform" ; then

Added: head/lang/ghc/files/patch-llvm-targets
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lang/ghc/files/patch-llvm-targets	Fri Aug 31 08:51:33 2018	(r478531)
@@ -0,0 +1,10 @@
+--- llvm-targets.orig	2018-03-17 14:04:41 UTC
++++ llvm-targets
+@@ -20,4 +20,7 @@
+ ,("aarch64-apple-ios", ("e-m:o-i64:64-i128:128-n32:64-S128", "generic", "+neon"))
+ ,("i386-apple-ios", ("e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128", "yonah", ""))
+ ,("x86_64-apple-ios", ("e-m:o-i64:64-f80:128-n8:16:32:64-S128", "core2", ""))
++,("armv6-unknown-freebsd-gnueabihf", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "arm1176jzf-s", "+strict-align"))
++,("armv7-unknown-freebsd-gnueabihf", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "generic", "+strict-align"))
++,("aarch64-unknown-freebsd", ("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", "generic", "+neon"))
+ ]



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808310851.w7V8pXxG053285>