Bug 196899 - [arm] lang/ghc porting project, marked as i386/amd64 only
Summary: [arm] lang/ghc porting project, marked as i386/amd64 only
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: arm Any
: --- Affects Some People
Assignee: freebsd-haskell mailing list
URL: https://www.haskell.org/haskellwiki/ARM
Depends on: 228706
  Show dependency treegraph
Reported: 2015-01-19 16:54 UTC by Sean Bruno
Modified: 2018-08-31 09:04 UTC (History)
6 users (show)

See Also:
pgj: maintainer-feedback+

armv6 fix (2.49 KB, patch)
2015-08-02 08:46 UTC, mikael.urankar
no flags Details | Diff
patch (107.85 KB, patch)
2018-04-08 18:34 UTC, mikael.urankar
no flags Details | Diff
patch (104.68 KB, patch)
2018-04-08 18:41 UTC, mikael.urankar
no flags Details | Diff
patch (13.26 KB, patch)
2018-06-02 18:23 UTC, mikael.urankar
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sean Bruno freebsd_committer 2015-01-19 16:54:32 UTC
The Glasgow Haskell Compiler port is marked as i386/amd64 only even though it appears that upstream support multiple architectures.  

A small porting project is probably required to scope out what needs to be modified in the port to support ARMv6.  When adding ARMv6 to the list of supported architectures, the build bails:

===>   Returning to build of ghc-7.8.3_1
====>> Recording filesystem state for prebuild... done
=======================<phase: configure      >============================
===>   ghc-7.8.3_1 depends on file: /usr/local/share/xsl/docbook/html - found
===>   ghc-7.8.3_1 depends on file: /usr/local/bin/xsltproc - found
===>   ghc-7.8.3_1 depends on executable: gmake - found
===>   ghc-7.8.3_1 depends on executable: gcc48 - found
===>   ghc-7.8.3_1 depends on file: /usr/local/bin/as - found
===>   ghc-7.8.3_1 depends on file: /usr/local/bin/autoconf-2.69 - found
===>   ghc-7.8.3_1 depends on file: /usr/local/bin/perl5.18.4 - found
===>   ghc-7.8.3_1 depends on shared library: libgmp.so - found (/usr/local/lib/libgmp.so.10.1.3)
===>   ghc-7.8.3_1 depends on shared library: libffi.so.6 - found (/usr/local/lib/libffi.so.6.0.4)
===>   ghc-7.8.3_1 depends on shared library: libiconv.so.3 - found (/usr/local/lib/libiconv.so.2.5.1)
===>  Configuring for ghc-7.8.3_1
cd: /wrkdirs/usr/ports/lang/ghc/work/ghc-7.6.3-boot: No such file or directory
*** Error code 2

make: stopped in /usr/ports/lang/ghc
Comment 1 Bugzilla Automation freebsd_committer 2015-01-19 16:54:32 UTC
Auto-assigned to maintainer haskell@FreeBSD.org
Comment 2 Gabor Pali freebsd_committer 2015-01-19 19:07:29 UTC
That is because in order to build GHC you will need a GHC.  Currently, we only have bootstrap compilers prepared for i386 and amd64, that is why they are mentioned as the only supported architectures.  Officially there is no FreeBSD/arm support for GHC at upstream, but I admit that recently Linux and iOS have gained some of it [1,2].

Building a bootstrap compiler requires some handcrafted magic, explained at the GHC developer's wiki [3,4] -- I cannot tell how much additional effort would be required for this.  Personally, I have not got to investigate this, but as far as I know, Olivier Houchard (cognet@) has some preliminary porting experiences with GHC.

Please note that I have been running buildbots for the i386 and amd64 platforms for GHC-head [5], so if you manage to get something up and running on armv6, I could add a buildbot for that as well, so we could monitor its health.  If you join #haskell-FreeBSD @ Freenode then I am happy to answer any further related questions.

[1] https://ghc.haskell.org/trac/ghc/wiki/Platforms
[2] https://ghcarm.wordpress.com/
[3] https://ghc.haskell.org/trac/ghc/wiki/Building
[4] https://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompiling
[5] http://haskell.inf.elte.hu/builders/
Comment 3 mikael.urankar 2015-08-02 08:46:19 UTC
Created attachment 159455 [details]
armv6 fix

I've successfully compiled an "unregisterised" version of ghc for armv6 (thanks Gábor for your help)

Some issues I encounter:

I'm hitting this problem at runtime:
I've tried to use ld.gold but the issue is still there (I may have missed something)
Compiling with -O0 just works (cf SRC_HC_OPTS, GhcStage*HcOpts in the patch) 

ghc-stage1 has a .text segment larger than the default maximum set by the kernel.
Section Headers:
[Nr] Name  Type     Addr     Off    Size    ES Flg Lk Inf Al
[13] .text PROGBITS 00014168 004168 474c7fc 00 AX  0  0   8

error message:
Text segment size exceeds system limit

This issue is solved with: sysctl kern.maxtsiz=80000000

The DYNAMIC option is mandatory on armv6:
ghc.mk:159: *** dyn is not in $(GhcLibWays), but $(DYNAMIC_GHC_PROGRAMS) is YES.  Stop.

I can't find a way to make it mandatory for armv6 using the 'options' framework (or any other means)

I've attached a patch for review. I've heard that you'll update ghc to a newer version,
let me know if you want me to generate a patch against your development repository.

The boostrap binaries can be found here:

build log with BOOT option on:

build log with BOOT option off:
Comment 4 Gabor Pali freebsd_committer 2015-08-10 16:59:08 UTC
Unfortunately, I do not have an armv6 development environment around to experiment with.  (Although, perhaps I may be able to get something up and working through the QEMU support in poudriére).

Regarding the bootstrap compiler, I have the following comments to consider before moving on:

- As far as I am aware, FreeBSD 10.x officially comes with armv6 support, so probably there should be a separate version created for 10.  Of course, for a time being this is not a serious issue, but it is also something to be worth keeping in mind.

- According to the GHC porting guide, building the "unregisterised" version of the compiler is only the first step in making GHC work on a new platform.  Its performance is quite suboptimal (due to the missing support for native code generation) and it may also explain the problems that you are also experiencing.  For example, it cannot do object splitting that could be a reason for running of the memory during linking.

- It might be better to experiment with a more recent version of the compiler, 7.10.2 has just been released -- that could be a better bootstrapping option to choose in the long run.  It probably has a better support for ARM too.  I am also recommending this because I have been indeed working on a major update that brings GHC 7.10 to the ports tree.  It is mostly done and can be found in the development repository [1].

Regarding forcing the DYNAMIC option to be on for armv6 (although I am a bit doubtful if this is really the case), you could just change the respective conditionals in bsd.cabal.mk to add the necessary configuration flags unconditionally when building for ARM.

[1] https://github.com/freebsd-haskell/ports
Comment 5 mikael.urankar 2018-04-08 18:34:59 UTC
Created attachment 192347 [details]


I've managed to build the "registerised" version of ghc-8.4.1 for armv6, armv7
and aarch64 with the attached patch and the following bootstrap compilers:

They're based on 12-CURRENT (I don't have time or resources to do the same work

Building ghc under emulation (with qemu-user-static) doesn't work.

There is an issue with CABAL_ARCH, it's always set to x86_64 even for arm* arch
and I don't know how to fix it:
root@12armv7: uname -p
root@12armv7: make -C textproc/hs-case-insensitive -V CABAL_ARCH

Templates/config.sub and Templates/config.guess should be in a separate bug report, I'll do that later.

My patch wasn't tested at all on amd64.
Comment 6 mikael.urankar 2018-04-08 18:41:31 UTC
Created attachment 192349 [details]
Comment 7 Gleb Popov freebsd_committer 2018-05-04 10:36:48 UTC
I'll take a look at that after https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=227968 lands. It would also be helpful, if you rebase your current work on top of my patch from PR 227968.
Comment 8 mikael.urankar 2018-06-02 18:23:46 UTC
Created attachment 193949 [details]

regen after ports r470870

bootstrap available here:
Comment 10 Sean Bruno freebsd_committer 2018-06-02 19:13:53 UTC
(In reply to mikael.urankar from comment #8)
Do you think we should host the bootstrap bits in the distcache somewhere?
Comment 11 Gleb Popov freebsd_committer 2018-06-02 21:03:59 UTC
(In reply to mikael.urankar from comment #8)
What is the reason to use gold and llvm50?
Comment 12 mikael.urankar 2018-06-03 12:52:12 UTC
(In reply to Sean Bruno from comment #10)
I overlooked this part, it would be nice if the bootstrap are hosted somewhere on freebsd.org (what is distcache?)
Comment 13 mikael.urankar 2018-06-03 12:56:03 UTC
(In reply to Gleb Popov from comment #11)
llvm is mandatory on arm* to build the registerised version [1]
ld.gold is the only linker that produces working binaries (all other linker I tried makes ghc-stage2 crash)
clang also produces bad binaries (with ld.gold as a linker)

To recap, the only working toolchain combination is: gcc + ld.gold.

[1] https://ghc.haskell.org/trac/ghc/wiki/Building/ARMLinuxGnuEABI
Comment 14 Gleb Popov freebsd_committer 2018-06-03 16:20:19 UTC
(In reply to mikael.urankar)
> I overlooked this part, it would be nice if the bootstrap are hosted somewhere on freebsd.org (what is distcache?)

I host my bootstraps on people.freebsd.org. I can also host yours when we get this committed.

> llvm is mandatory on arm* to build the registerised version [1]
ld.gold is the only linker that produces working binaries (all other linker I tried makes ghc-stage2 crash)

Ok, but why LLVM 5.0? Doesn't 6.0 work?

> clang also produces bad binaries (with ld.gold as a linker)

Have you tried lld?
Comment 15 mikael.urankar 2018-06-03 18:30:59 UTC
(In reply to Gleb Popov from comment #14)
I have to use gcc for arm* and gcc doesn't recognize lld as a linker:
gcc6: error: unrecognized command line option '-fuse-ld=lld'; did you mean '-fuse-ld=bfd'?
I can try with lld if bug #227302 lands.

llvm60 is not a 'suppported' version for ghc-8.4.2, I'll let you read [1] for details.

[1] https://ghc.haskell.org/trac/ghc/wiki/ImprovedLLVMBackend
Comment 16 Gleb Popov freebsd_committer 2018-06-05 16:04:43 UTC
It is hard to comment on the patch, would you mind creating a diff on Phabricator? http://reviews.freebsd.org/
Comment 17 mikael.urankar 2018-06-06 10:25:46 UTC
(In reply to Gleb Popov from comment #16)
done, it's the first time I use phab, I hope it's ok:
Comment 18 commit-hook freebsd_committer 2018-08-31 08:52:22 UTC
A commit references this bug:

Author: arrowd
Date: Fri Aug 31 08:51:35 UTC 2018
New revision: 478531
URL: https://svnweb.freebsd.org/changeset/ports/478531

  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

Comment 19 Gleb Popov freebsd_committer 2018-08-31 09:04:31 UTC
Thanks for you contribution, Mikael, and everyone involved.