Opened 3 years ago

Last modified 3 years ago

#64698 assigned enhancement

approach to fix Haskell (GHC) for PowerPC: some progress, ghc @7.6.3 builds for ppc but there is a bug to be fixed

Reported by: barracuda156 Owned by: essandess (Steve Smith)
Priority: Normal Milestone:
Component: ports Version: 2.7.1
Keywords: powerpc, leopard, snowleopard Cc:
Port: ghc, ghc-bootstrap

Description (last modified by barracuda156)

I want to bring GHC to PowerPC systems. So far I was able to bootstrap ghc 7.0.1 using ghc-bootstrap port file as a draft and substituting ppc distributive:

36-47% port -v installed ghc-bootstrap
The following ports are currently installed:
  ghc-bootstrap @7.0.1_0 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-02-19T12:58:35+0800'

Building ghc 7.8.x requires at least ghc 7.4.x, and Macports now uses ghc 7.6.2 as a bootstrap compiler. The latter is impossible for ppc as of now, unless we want to make our own distributive to that end. However it seems that ghc 7.6.x can be built with bootstrapped ghc 7.0.1 and Macports gcc. A first attempt fails on Stage 2 with haddock:

:info:build "rm" -f                              inplace/bin/haddock  
:info:build echo '#!/bin/sh'                             >> inplace/bin/haddock
:info:build echo 'executablename="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.6.3/inplace/lib/haddock"'            >> inplace/bin/haddock
:info:build echo 'datadir="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.6.3/inplace/lib"'       >> inplace/bin/haddock
:info:build echo 'bindir="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.6.3/inplace/bin"'        >> inplace/bin/haddock
:info:build echo 'topdir="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.6.3/inplace/lib"'     >> inplace/bin/haddock
:info:build echo 'pgmgcc="/opt/local/bin/gcc-mp-7"'            >> inplace/bin/haddock
:info:build cat utils/haddock/haddock.wrapper               >> inplace/bin/haddock
:info:build chmod +x                               inplace/bin/haddock
:info:build "inplace/bin/mkdirhier" libraries/ghc-prim/dist-install/doc/html/ghc-prim//.
:info:build "inplace/bin/mkdirhier" libraries/ghc-prim/dist-install/build/autogen/GHC//.
:info:build "inplace/bin/genprimopcode" --make-haskell-source < compiler/prelude/primops.txt > libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
:info:build "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.6.3/inplace/bin/haddock" --odir="libraries/ghc-prim/dist-install/doc/html/ghc-prim" --no-tmp-comp-dir --dump-interface=libraries/ghc-prim/dist-install/doc/html/ghc-prim/ghc-prim.haddock --html --hoogle --title="ghc-prim-0.3.0.0: GHC primitives" --prologue="libraries/ghc-prim/dist-install/haddock-prologue.txt"   --optghc=-H32m --optghc=-O --optghc=-package-name --optghc=ghc-prim-0.3.0.0 --optghc=-hide-all-packages --optghc=-i --optghc=-ilibraries/ghc-prim/. --optghc=-ilibraries/ghc-prim/dist-install/build --optghc=-ilibraries/ghc-prim/dist-install/build/autogen --optghc=-Ilibraries/ghc-prim/dist-install/build --optghc=-Ilibraries/ghc-prim/dist-install/build/autogen --optghc=-Ilibraries/ghc-prim/. --optghc=-optP-include --optghc=-optPlibraries/ghc-prim/dist-install/build/autogen/cabal_macros.h --optghc=-package --optghc=rts-1.0 --optghc=-split-objs --optghc=-package-name --optghc=ghc-prim --optghc=-XHaskell98 --optghc=-XCPP --optghc=-XMagicHash --optghc=-XForeignFunctionInterface --optghc=-XUnliftedFFITypes --optghc=-XUnboxedTuples --optghc=-XEmptyDataDecls --optghc=-XNoImplicitPrelude --optghc=-O2 --optghc=-no-user-package-db --optghc=-rtsopts --optghc=-odir --optghc=libraries/ghc-prim/dist-install/build --optghc=-hidir --optghc=libraries/ghc-prim/dist-install/build --optghc=-stubdir --optghc=libraries/ghc-prim/dist-install/build --optghc=-hisuf --optghc=hi --optghc=-osuf --optghc=o --optghc=-hcsuf --optghc=hc    libraries/ghc-prim/./GHC/Classes.hs  libraries/ghc-prim/./GHC/CString.hs  libraries/ghc-prim/./GHC/Debug.hs  libraries/ghc-prim/./GHC/Magic.hs  libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs  libraries/ghc-prim/./GHC/IntWord64.hs  libraries/ghc-prim/./GHC/Tuple.hs  libraries/ghc-prim/./GHC/Types.hs libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs +RTS -tlibraries/ghc-prim/dist-install/doc/html/ghc-prim/ghc-prim.haddock.t --machine-readable
:info:build haddock: internal error: evacuate(static): strange closure type 18699
:info:build     (GHC version 7.6.3 for powerpc_apple_darwin)
:info:build     Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
:info:build make[1]: *** [libraries/ghc-prim/dist-install/doc/html/ghc-prim/ghc-prim.haddock] Abort trap
:info:build make: *** [all] Error 2
:info:build make: Leaving directory `/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.6.3'
:info:build Command failed:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.6.3" && /usr/bin/make -j1 -w all 
:info:build Exit code: 2
:error:build Failed to build ghc: command execution failed
:debug:build Error code: CHILDSTATUS 91677 2
:debug:build Backtrace: command execution failed
:debug:build     while executing
:debug:build "system {*}$notty {*}$callback {*}$nice $fullcmdstring"
:debug:build     invoked from within
:debug:build "command_exec -callback portprogress::target_progress_callback build"
:debug:build     (procedure "portbuild::build_main" line 8)
:debug:build     invoked from within
:debug:build "$procedure $targetname"

I am trying to build it again with docs disabled now. Given how far it went it looks feasible. If it works eventually, we gonna have ghc 7.6.3 on PowerPC.

Technical question arises: how to arrange two-step bootstrap? That is, bootstrap 7.0.1, build 7.6.3 with it and use the latter to build something new. In other words, PowerPC needs a pre-bootstrap stage, assuming existing port ghc-bootstrap.

  1. S. If it works, I will test then on 10.5.8 and 10.4.11 both.

Attachments (5)

main.log (3.6 MB) - added by barracuda156 3 years ago.
7.8.4.config.log (223.6 KB) - added by barracuda156 3 years ago.
7.8.4.main.log.zip (503.0 KB) - added by barracuda156 3 years ago.
7.6.2_10.6.8_Rosetta_main.log (1.2 MB) - added by barracuda156 3 years ago.
On 10.6.8 Rosetta ghc seems totally broken. Even configure fails with numerous Unknown pseudo-op: errors.
PPC_patches_v1.zip (20.5 KB) - added by barracuda156 3 years ago.
If anyone wanna have a look:

Change History (40)

Changed 3 years ago by barracuda156

Attachment: main.log added

comment:1 Changed 3 years ago by barracuda156

Description: modified (diff)

comment:3 Changed 3 years ago by barracuda156

Well, ghc 7.6.3 built!

36-47% port -v installed ghc
The following ports are currently installed:
  ghc @7.6.3_4+gcc7 (active) requested_variants='+gcc7' platform='darwin 10' archs='ppc' date='2022-02-19T21:30:01+0800'

Moreover, it actually works:

36-47% ghc -o hello_haskell /Users/svacchanda/Dev/HelloWorld.hs 
[1 of 1] Compiling Main             ( /Users/svacchanda/Dev/HelloWorld.hs, /Users/svacchanda/Dev/HelloWorld.o )
Linking hello_haskell ...
36-47% /Users/svacchanda/Dev/hello_haskell 
Hello, World!
36-47% file /Users/svacchanda/Dev/hello_haskell 
/Users/svacchanda/Dev/hello_haskell: Mach-O executable ppc
36-47% /opt/local/bin/ghc-7.6.3 -v
Glasgow Haskell Compiler, Version 7.6.3, stage 2 booted by GHC version 7.0.1
Last edited 3 years ago by barracuda156 (previous) (diff)

comment:4 Changed 3 years ago by barracuda156

Summary: approach to fix Haskell (GHC) for PowerPC: some initial progressapproach to fix Haskell (GHC) for PowerPC: some progress, ghc @7.6.3 builds for ppc

comment:5 Changed 3 years ago by kencu (Ken)

I tried this a few years ago, when I brought ghc for 10.6.8 up to current.

https://github.com/kencu/ghc-for-older-darwin-systems

I could not get the i386 or PPC systems to upgrade then with reasonable efforts, but you might.

For x86_64, a few patches were needed and then step-by-step went through the versions up ro current.

You’ll learn a lot in the process!

Good luck!

comment:6 in reply to:  5 Changed 3 years ago by barracuda156

Replying to kencu:

I tried this a few years ago, when I brought ghc for 10.6.8 up to current.

https://github.com/kencu/ghc-for-older-darwin-systems

I could not get the i386 or PPC systems to upgrade then with reasonable efforts, but you might.

For x86_64, a few patches were needed and then step-by-step went through the versions up ro current.

You’ll learn a lot in the process!

Yes, I have seen your repo, of course. (Hoped to see some ppc versions there…)

How would you recommend to arrange a process in terms of ports?

It seems at the moment Macports uses ghc 7.6.2 as a bootstrap compiler for everything higher. We can’t do it for ppc, we need to use 7.0.1 or possibly 7.0.4 as a starting point. This part is technically as easy as changing version numbers and replacing checksums. It result ghc-bootstrap gets “occupied” by 7.0.1. Then I used it to build 7.6.3. Let’s assume it built correctly (if not, tweaking should be not too hard). So now I have ghc port “occupied” by 7.6.3, which should in fact be a bootstrap one (according to current Macports settings). Should we make a special ghc-bootstrap-ppc port to build 7.6.3 which then can be used hopefully normally in ghc-bootstrap port with added ppc arch? Or what’s a better way?

Good luck!

Version 0, edited 3 years ago by barracuda156 (next)

comment:7 Changed 3 years ago by kencu (Ken)

MacPorts is using ghc 9.something on all supported systems 10.7 and up

comment:8 in reply to:  7 Changed 3 years ago by barracuda156

Replying to kencu:

MacPorts is using ghc 9.something on all supported systems 10.7 and up

Yes, I was referring to ghc-bootstrap port only. It is still at 7.6.2 at the moment.

comment:9 Changed 3 years ago by kencu (Ken)

when I do this for 10.6.8, I don’t use MacPorts.

I tried doing what you are thinking of, and I think it worked for one upgrade, but then I got stuck.

It’s too hard…too many tweaks in the portfiles and portgroups to work around.

I have a folder for ghc on 10.6.8 stuff, and just build new versions in there.

if you look, Ben Ghamari, the big guru for ghc, has a script he uses to build all the releases.

I edited that script to get going.

Later on I’ll see if I can find that for you.

comment:10 in reply to:  9 Changed 3 years ago by barracuda156

Replying to kencu:

I have a folder for ghc on 10.6.8 stuff, and just build new versions in there.

if you look, Ben Ghamari, the big guru for ghc, has a script he uses to build all the releases.

I edited that script to get going.

Later on I’ll see if I can find that for you.

Thank you very much! Greatly appreciated.

comment:11 Changed 3 years ago by kencu (Ken)

I can’t spot the script, but here’s Ben’s github

https://github.com/bgamari

He seems a very nice, responsive fellow in their mailing lists, just likr Iain is for gcc.

Ask some nice questions about how to get PPC working, he might answer.

comment:12 Changed 3 years ago by kencu (Ken)

right off the top of my head, I’d probably today try cross-compiling a current ghc for PPC darwin from debian (where ghc works just great on PPC, btw)

comment:13 in reply to:  11 Changed 3 years ago by barracuda156

Replying to kencu:

I can’t spot the script, but here’s Ben’s github

https://github.com/bgamari

He seems a very nice, responsive fellow in their mailing lists, just likr Iain is for gcc.

Ask some nice questions about how to get PPC working, he might answer.

Awesome, thank you.

If no one objects, let’s keep this ticket open as a track record. I will update here once something gets improved. I wanna repeat the process on 10.5.8 too, so that it is reproducible for others.

comment:14 in reply to:  12 Changed 3 years ago by barracuda156

Replying to kencu:

right off the top of my head, I’d probably today try cross-compiling a current ghc for PPC darwin from debian (where ghc works just great on PPC, btw)

Wow. That’s promising. Maybe a bootstrap compiler can be made that way that can be used on PPC systems then.

comment:15 Changed 3 years ago by kencu (Ken)

I think so. If I recall how I got stuck on i386 and ppc, there were a few ghc compilers that did not properly support those targets in the late 7's or early 8's.

I think (not 100% certain) that those were fixed, at least i386, but then there was enough of a gap in compiler versions that I couldn't leap over it to the newer one, and fixing the broken ones was beyond my skills / patience of the time.

That is how I remember it going, from 2019, so take that with a grain of salt.

comment:16 Changed 3 years ago by barracuda156

Old info, but may happen to be useful: https://tim.dreamwidth.org/1715938.html Apparently stage 1 compiler is enough to build a bootstrap one.

comment:17 Changed 3 years ago by kencu (Ken)

here is how to use ghc to cross compile itself to another supported target.

https://gitlab.haskell.org/ghc/ghc/-/wikis/building/cross-compiling

I might first try using the x86_64 version to build the i386 version, as the simplest possible try that is most likely to work, and once you see how to do that, move on to the hard stuff.

Last edited 3 years ago by kencu (Ken) (previous) (diff)

comment:18 in reply to:  17 Changed 3 years ago by barracuda156

Replying to kencu:

here is how to use ghc to cross compile itself to another supported target.

https://gitlab.haskell.org/ghc/ghc/-/wikis/building/cross-compiling

I might first try using the x86_64 version to build the i386 version, as the simplest possible try that is most likely to work, and once you see how to do that, move on to the hard stuff.

Thank you!

At the moment I made a local ghc-ppc-bootstrap port, installed ghc 7.0.1 into it and started building ghc-bootstrap 7.6.2 with it. If that works (it should), then we can add ppc arch to ghc-bootstrap right-away, provided of course port file will include building procedure for PowerPC systems.

How about adding a new ghc-ppc-bootstrap port? I can test it on 10.5.8 and 10.4.11 prior to submitting a PR.

comment:19 Changed 3 years ago by barracuda156

Okay, on Tiger we got a problem. Apparently ghc 7.0.1 is built against system version of libiconv which does not exist in Tiger.

44-49:~ svacchanda$ sudo port -v install ghc-ppc-bootstrap
Password:
Portfile changed since last build; discarding previous state.
--->  Computing dependencies for ghc-ppc-bootstrap.
--->  Fetching distfiles for ghc-ppc-bootstrap
--->  Verifying checksums for ghc-ppc-bootstrap
--->  Checksumming ghc-7.0.1-powerpc-apple-darwin.tar.bz2
--->  Extracting ghc-ppc-bootstrap
--->  Extracting ghc-7.0.1-powerpc-apple-darwin.tar.bz2
Executing:  cd "/opt/local/var/macports/build/_opt_PPCTigerPorts_lang_ghc-ppc-bootstrap/ghc-ppc-bootstrap/work" && /usr/bin/bzip2 -dc '/opt/local/var/macports/distfiles/ghc-ppc-bootstrap/ghc-7.0.1-powerpc-apple-darwin.tar.bz2' | /usr/bin/gnutar --no-same-owner -xf - 
--->  Configuring ghc-ppc-bootstrap
Executing:  cd "/opt/local/var/macports/build/_opt_PPCTigerPorts_lang_ghc-ppc-bootstrap/ghc-ppc-bootstrap/work/ghc-7.0.1" && ./configure --prefix=/opt/local/share/ghc-ppc-bootstrap --with-macosx-deployment-target=10.4 --with-libiconv-prefix=/opt/local/lib 
checking for path to top of build tree... dyld: Library not loaded: /usr/lib/libiconv.2.dylib
  Referenced from: /opt/local/var/macports/build/_opt_PPCTigerPorts_lang_ghc-ppc-bootstrap/ghc-ppc-bootstrap/work/ghc-7.0.1/utils/ghc-pwd/ghc-pwd
  Reason: Incompatible library version: ghc-pwd requires version 7.0.0 or later, but libiconv.2.dylib provides version 5.0.0
configure: error: cannot determine current directory
Command failed:  cd "/opt/local/var/macports/build/_opt_PPCTigerPorts_lang_ghc-ppc-bootstrap/ghc-ppc-bootstrap/work/ghc-7.0.1" && ./configure --prefix=/opt/local/share/ghc-ppc-bootstrap --with-macosx-deployment-target=10.4 --with-libiconv-prefix=/opt/local/lib 
Exit code: 1
Error: Failed to configure ghc-ppc-bootstrap: consult /opt/local/var/macports/build/_opt_PPCTigerPorts_lang_ghc-ppc-bootstrap/ghc-ppc-bootstrap/work/ghc-7.0.1/config.log
Error: Failed to configure ghc-ppc-bootstrap: configure failure: command execution failed

Do I get it correctly that we are out of luck with 7.0.1 for Tiger, since it is pre-built and we cannot use Macports libiconv instead?

To be sure, I tried adding to port file this:

platform darwin 8 powerpc {
		depends_lib-append port:libiconv
		configure.cflags-append "-I${prefix}/include"
		configure.ldflags-append "-L/usr/lib"
		configure.env-append  DYLD_FALLBACK_LIBRARY_PATH=${prefix}/lib
		configure.args-append --with-macosx-deployment-target=10.4 \
							  --with-libiconv-prefix=${prefix}/lib
		configure.compiler-append apple-gcc-4.2
}

Configure failed identically.

Personally it is not a big deal, I just thought initially to solve the problem for all PPC systems. We may accept that it will be broken for Tiger, if no easy fix is there.

  1. S. I see people are having pains with libiconv and ghc:

https://trac.macports.org/ticket/57821 https://trac.macports.org/ticket/61222

comment:20 Changed 3 years ago by barracuda156

Replying to kencu:

when I do this for 10.6.8, I don’t use MacPorts. I tried doing what you are thinking of, and I think it worked for one upgrade, but then I got stuck.

So yes, I was able to build a ppc-version of ghc-bootstrap matching existing port:

36-47% port -v installed | grep ghc
  ghc @7.6.3_4+gcc7 (active) requested_variants='+gcc7' platform='darwin 10' archs='ppc' date='2022-02-19T21:30:01+0800'
  ghc-bootstrap @7.0.1_0 requested_variants='' platform='darwin 10' archs='ppc' date='2022-02-19T19:21:34+0800'
  ghc-bootstrap @7.6.2_3 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-02-21T06:12:08+0800'
  ghc-ppc-bootstrap @7.0.1_1+gcc42 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-02-21T00:16:34+0800'

ghc-ppc-bootstrap also installed with no issues on Leopard (as it should have):

36-47:~ svacchanda$ port -v installed ghc-ppc-bootstrap
The following ports are currently installed:
  ghc-ppc-bootstrap @7.0.1_1+gcc42 (active) requested_variants='' platform='darwin 9' archs='ppc' date='2022-02-21T09:39:40+0800'

So this should be reproducible.

Last edited 3 years ago by barracuda156 (previous) (diff)

comment:21 Changed 3 years ago by barracuda156

Building ghc 7.8.4 with 7.6.2 goes for some time but fails on this:

:info:build "/opt/local/share/ghc-bootstrap/bin/ghc" -o ghc/stage1/build/tmp/ghc-stage1 -hisuf hi -osuf  o -hcsuf hc -static  -H32m -O  -package-db libraries/bootstrapping.conf  -hide-all-packages -i -ighc/. -ighc/stage1/build -ighc/stage1/build/autogen -Ighc/stage1/build -Ighc/stage1/build/autogen     -optP-include -optPghc/stage1/build/autogen/cabal_macros.h -package array-0.4.0.1 -package base-4.6.0.1 -package bytestring-0.10.0.2 -package directory-1.2.0.1 -package filepath-1.3.0.1 -package ghc-7.8.4 -package process-1.1.0.2 -package unix-2.6.0.1 -Wall -XHaskell98 -XCPP -XPatternGuards -XNondecreasingIndentation   -no-user-package-db -rtsopts      -odir ghc/stage1/build -hidir ghc/stage1/build -stubdir ghc/stage1/build   -optl-m32 -optl-mmacosx-version-min=10.5 -optl-L'/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/compiler/stage1/build' -optl-L'/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/libraries/transformers/dist-boot/build' -optl-L'/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/libraries/hpc/dist-boot/build' -optl-L'/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/libraries/hoopl/dist-boot/build' -optl-L'/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/libraries/bin-package-db/dist-boot/build' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/binary-0.5.1.1' -optl-L'/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/libraries/Cabal/Cabal/dist-boot/build' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/process-1.1.0.2' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/pretty-1.1.1.0' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/directory-1.2.0.1' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/unix-2.6.0.1' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/time-1.4.0.1' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/old-locale-1.0.0.5' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/filepath-1.3.0.1' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/containers-0.5.0.0' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/bytestring-0.10.0.2' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/deepseq-1.3.0.1' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/array-0.4.0.1' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/base-4.6.0.1' -optl-L'/opt/local/lib' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/integer-gmp-0.5.0.0' -optl-L'/opt/local/lib' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/ghc-prim-0.3.0.0' -optl-L'/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2' -optl-ldl -optl-liconv -optl-lcharset -optl-lgmp -optl-lm -optl-ldl -static  -H32m -O  -package-db libraries/bootstrapping.conf  -hide-all-packages -i -ighc/. -ighc/stage1/build -ighc/stage1/build/autogen -Ighc/stage1/build -Ighc/stage1/build/autogen     -optP-include -optPghc/stage1/build/autogen/cabal_macros.h -package array-0.4.0.1 -package base-4.6.0.1 -package bytestring-0.10.0.2 -package directory-1.2.0.1 -package filepath-1.3.0.1 -package ghc-7.8.4 -package process-1.1.0.2 -package unix-2.6.0.1 -Wall -XHaskell98 -XCPP -XPatternGuards -XNondecreasingIndentation   -no-user-package-db -rtsopts      ghc/stage1/build/Main.o ghc/stage1/build/hschooks.o   
:info:build "cp" -p ghc/stage1/build/tmp/ghc-stage1 inplace/lib/bin/ghc-stage1
:info:build "rm" -f                                                     inplace/bin/ghc-stage1  
:info:build echo '#!/bin/sh'                                                   >> inplace/bin/ghc-stage1
:info:build echo 'executablename="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/inplace/lib/bin/ghc-stage1"'                                  >> inplace/bin/ghc-stage1
:info:build echo 'datadir="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/inplace/lib"'                             >> inplace/bin/ghc-stage1
:info:build echo 'bindir="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/inplace/bin"'                              >> inplace/bin/ghc-stage1
:info:build echo 'topdir="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/inplace/lib"'                           >> inplace/bin/ghc-stage1
:info:build echo 'pgmgcc="/opt/local/bin/gcc-mp-7"'                                  >> inplace/bin/ghc-stage1
:info:build echo 'export DYLD_LIBRARY_PATH="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/compiler/stage1/build:/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/libraries/transformers/dist-boot/build:/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/libraries/hpc/dist-boot/build:/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/libraries/hoopl/dist-boot/build:/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/libraries/bin-package-db/dist-boot/build:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/binary-0.5.1.1:/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/libraries/Cabal/Cabal/dist-boot/build:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/process-1.1.0.2:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/pretty-1.1.1.0:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/directory-1.2.0.1:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/unix-2.6.0.1:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/time-1.4.0.1:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/old-locale-1.0.0.5:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/filepath-1.3.0.1:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/containers-0.5.0.0:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/bytestring-0.10.0.2:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/deepseq-1.3.0.1:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/array-0.4.0.1:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/base-4.6.0.1:/opt/local/lib:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/integer-gmp-0.5.0.0:/opt/local/lib:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2/ghc-prim-0.3.0.0:/opt/local/share/ghc-bootstrap/lib/ghc-7.6.2:$DYLD_LIBRARY_PATH"' >> inplace/bin/ghc-stage1
:info:build cat ghc/ghc.wrapper                                     >> inplace/bin/ghc-stage1
:info:build chmod +x                                                     inplace/bin/ghc-stage1
:info:build "inplace/bin/ghc-cabal" check libraries/ghc-prim
:info:build "inplace/bin/ghc-cabal" configure libraries/ghc-prim dist-install "" --with-ghc="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/inplace/bin/ghc-stage1" --with-ghc-pkg="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/inplace/bin/ghc-pkg" --flag=include-ghc-prim --disable-library-for-ghci --enable-library-vanilla --enable-library-profiling --enable-shared --configure-option=CFLAGS=" -m32 -mmacosx-version-min=10.5 -fno-stack-protector   " --configure-option=LDFLAGS=" -m32 -mmacosx-version-min=10.5  " --configure-option=CPPFLAGS=" -m32  " --gcc-options=" -m32 -mmacosx-version-min=10.5 -fno-stack-protector     -m32 -mmacosx-version-min=10.5  " --configure-option=--with-iconv-includes="/opt/local/include" --configure-option=--with-iconv-libraries="/opt/local/lib" --configure-option=--with-gmp-includes="/opt/local/include" --configure-option=--with-gmp-libraries="/opt/local/lib" --with-gcc="/opt/local/bin/gcc-mp-7" --with-ld="/opt/local/bin/ld" --configure-option=--with-cc="/opt/local/bin/gcc-mp-7" --with-ar="/opt/local/bin/ar" --with-ranlib="/opt/local/bin/ranlib"  
:info:build Configuring ghc-prim-0.3.1.0...
:info:build ghc-cabal: The program ghc version >=6.4 is required but the version of
:info:build /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/inplace/bin/ghc-stage1
:info:build could not be determined.
:info:build make[1]: *** [libraries/ghc-prim/dist-install/package-data.mk] Error 1
:info:build make: *** [all] Error 2
:info:build make: Leaving directory `/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4'
:info:build Command failed:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4" && /usr/bin/make -j4 -w all VERBOSE=1 
:info:build Exit code: 2
:error:build Failed to build ghc: command execution failed
:debug:build Error code: CHILDSTATUS 3700 2
:debug:build Backtrace: command execution failed
:debug:build     while executing
:debug:build "system {*}$notty {*}$callback {*}$nice $fullcmdstring"
:debug:build     invoked from within
:debug:build "command_exec -callback portprogress::target_progress_callback build"
:debug:build     (procedure "portbuild::build_main" line 8)
:debug:build     invoked from within
:debug:build "$procedure $targetname"

Here is what I get with -v:

36-47% /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/inplace/bin/ghc-stage1 -v
ghc-stage1: internal error: evacuate(static): strange closure type 18673
    (GHC version 7.6.2 for powerpc_apple_darwin)
    Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
zsh: abort       -v

Last edited 3 years ago by barracuda156 (previous) (diff)

comment:22 Changed 3 years ago by barracuda156

Almost the same failure with 7.8.1:

>> inplace/bin/ghc-stage1
cat ghc/ghc.wrapper                                     >> inplace/bin/ghc-stage1
chmod +x                                                     inplace/bin/ghc-stage1
"inplace/bin/ghc-cabal" check libraries/ghc-prim
"inplace/bin/ghc-cabal" configure libraries/ghc-prim dist-install "" --with-ghc="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.1/inplace/bin/ghc-stage1" --with-ghc-pkg="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.1/inplace/bin/ghc-pkg" --flag=include-ghc-prim --disable-library-for-ghci --enable-library-vanilla --enable-library-profiling --enable-shared --configure-option=CFLAGS=" -m32 -mmacosx-version-min=10.5 -fno-stack-protector   " --configure-option=LDFLAGS=" -m32 -mmacosx-version-min=10.5  " --configure-option=CPPFLAGS=" -m32  " --configure-option=--with-iconv-includes="/opt/local/include" --configure-option=--with-iconv-libraries="/opt/local/lib" --configure-option=--with-gmp-includes="/opt/local/include" --configure-option=--with-gmp-libraries="/opt/local/lib" --with-gcc="/opt/local/bin/gcc-mp-7" --with-ld="/opt/local/bin/ld" --configure-option=--with-cc="/opt/local/bin/gcc-mp-7" --with-ar="/opt/local/bin/ar" --with-ranlib="/opt/local/bin/ranlib"  
Configuring ghc-prim-0.3.1.0...
ghc-cabal: ghc-stage1: internal error: evacuate(static): strange closure type
18672
(GHC version 7.6.2 for powerpc_apple_darwin)
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
make[1]: *** [libraries/ghc-prim/dist-install/package-data.mk] Error 1
make: *** [all] Error 2
make: Leaving directory `/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.1'
Command failed:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.1" && /usr/bin/make -j4 -w all VERBOSE=1 
Exit code: 2

Any idea why might this happen, "ghc-stage1: internal error: evacuate(static): strange closure type"?

comment:23 Changed 3 years ago by kencu (Ken)

I think that at that point, ghc started making bad bitrotted code on powerpc darwin, and then was ultimately dumped

https://gitlab.haskell.org/ghc/ghc/-/issues/2031

comment:24 in reply to:  23 Changed 3 years ago by barracuda156

Replying to kencu:

I think that at that point, ghc started making bad bitrotted code on powerpc darwin, and then was ultimately dumped

https://gitlab.haskell.org/ghc/ghc/-/issues/2031

Could be. I just tried to rebuild 7.6.3 with 7.6.2, and got the same error:

ghc-stage1: internal error: evacuate(static): strange closure type 24425
    (GHC version 7.6.2 for powerpc_apple_darwin)
    Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
  HC [stage 1] libraries/base/dist-install/build/Control/Monad.p_o
  HC [stage 1] libraries/base/dist-install/build/Text/ParserCombinators/ReadP.o
/bin/sh: line 1: 34056 Abort trap              "inplace/bin/ghc-stage1" -fPIC -dynamic -H32m -O -package-name base-4.6.0.1 -hide-all-packages -i -ilibraries/base/. -ilibraries/base/dist-install/build -ilibraries/base/dist-install/build/autogen -Ilibraries/base/dist-install/build -Ilibraries/base/dist-install/build/autogen -Ilibraries/base/include -I/opt/local/include -optP-DOPTIMISE_INTEGER_GCD_LCM -optP-include -optPlibraries/base/dist-install/build/autogen/cabal_macros.h -package ghc-prim-0.3.0.0 -package integer-gmp-0.5.0.0 -package rts-1.0 -package-name base -XHaskell98 -XCPP -O2 -no-user-package-db -rtsopts -odir libraries/base/dist-install/build -hidir libraries/base/dist-install/build -stubdir libraries/base/dist-install/build -hisuf dyn_hi -osuf dyn_o -hcsuf dyn_hc -c libraries/base/./GHC/Float.lhs -o libraries/base/dist-install/build/GHC/Float.dyn_o
make[1]: *** [libraries/base/dist-install/build/GHC/Float.dyn_o] Error 134
make[1]: *** Waiting for unfinished jobs....
make: *** [all] Error 2
make: Leaving directory `/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.6.3'
Command failed:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.6.3" && /usr/bin/make -j4 -w all 
Exit code: 2

So it is not necessarily some problem with 7.8.x code but rather my initially built 7.6.2 is faulty. (Or otherwise you are right and it is just broken like clang.)

I will try getting some advice from early developers of ghc for ppc, if I can find there contacts. Tried Christian.Maeder@… but e-mail is dead. He was supporting PowerPC darwin back then. UPD. I just now was able to see the Gitlab link, since TenFourFox could not load it, and you refer to Maeder’s ticket. Yeah, looks like very few people were working on this even back then.

Last edited 3 years ago by barracuda156 (previous) (diff)

comment:25 in reply to:  23 Changed 3 years ago by barracuda156

Replying to kencu:

I think that at that point, ghc started making bad bitrotted code on powerpc darwin, and then was ultimately dumped

A quick question: can we use a pkg somehow to install within Macports ecosystem? There is ghc 7.0.4 in pkg version on Haskell website but no tar source. Expanding payload gives GHC.framework. Inside framework there is usr folder which contains, apparently, what we would have seen in destroot.

I am not sure how to produce an installable source archive from this. Or try to "cheat macports" and jump to destroot stage by modifying .macports.ghc.state file?

UPD. Well, I did exactly that, jumping to destroot stage by copying relevant folders from expanded payload. I only had to manually delete dylibs prior to that, since port file could not handle it. 7.0.4 installed and I am rebuilding 7.6.2 with it now. So far it seems working.

Last edited 3 years ago by barracuda156 (previous) (diff)

comment:26 Changed 3 years ago by barracuda156

Summary: approach to fix Haskell (GHC) for PowerPC: some progress, ghc @7.6.3 builds for ppcapproach to fix Haskell (GHC) for PowerPC: some progress, ghc @7.6.3 builds for ppc but there is a bug to be fixed

comment:27 in reply to:  23 Changed 3 years ago by barracuda156

Replying to kencu:

I think that at that point, ghc started making bad bitrotted code on powerpc darwin, and then was ultimately dumped https://gitlab.haskell.org/ghc/ghc/-/issues/2031

The link is very helpful. Interestingly, support for PowerPC has been removed just three years ago: https://gitlab.haskell.org/ghc/ghc/-/commit/374e44704b64afafc1179127e6c9c5bf1715ef39

So even if it might be unfeasible to bring it back into the newest versions of ghc, this timeline should imply that late 8.x.x were still supporting PPC, at least in principle.

I have reviewed the code, and while it is not from 7.6.2 version, nevertheless files that match retain PPC-relevant code which were later removed. It was not immediately obvious to which branch that commit was referring, but I think 8.x.x. In any case, it should be possible to build 7.6.x, 7.8.x and probably through early 8.x.x branches for PPC. (Another question is how functional they gonna be. Like with clang, it could be the case that even they build, they gonna remain broken.)

Last edited 3 years ago by barracuda156 (previous) (diff)

comment:28 Changed 3 years ago by barracuda156

Rebuilding 7.8.2 with 7.0.4 worked, however building 7.8.4 failed, again on the same spot with the same error.

I attach logs if anyone interested.

36-47% /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc/ghc/work/ghc-7.8.4/inplace/bin/ghc-stage1 --version
The Glorious Glasgow Haskell Compilation System, version 7.8.4
ghc-stage1: internal error: evacuate(static): strange closure type 24576
    (GHC version 7.6.2 for powerpc_apple_darwin)
    Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
zsh: abort       --version

At the same time this does not happen with the 7.6.2 installed:

36-47% /opt/local/share/ghc-bootstrap/bin/ghc-7.6.2 --version
The Glorious Glasgow Haskell Compilation System, version 7.6.2
Last edited 3 years ago by barracuda156 (previous) (diff)

Changed 3 years ago by barracuda156

Attachment: 7.8.4.config.log added

Changed 3 years ago by barracuda156

Attachment: 7.8.4.main.log.zip added

comment:29 Changed 3 years ago by kencu (Ken)

BTW, if you have an hour and want to see this working on PPC to wet your whistle, this is on a G4 iMac:

$ uname -a
Linux debianimacppc32 5.15.0-2-powerpc #1 Debian 5.15.5-2 (2021-12-18) ppc GNU/Linux

$ which ghc
/usr/bin/ghc

$ ghc -v
Glasgow Haskell Compiler, Version 8.8.4, stage 2 booted by GHC version 8.8.4
Using binary package database: /usr/lib/ghc/package.conf.d/package.cache
package flags []
loading package database /usr/lib/ghc/package.conf.d
wired-in package ghc-prim mapped to ghc-prim-0.5.3
wired-in package integer-wired-in mapped to integer-gmp-1.0.2.0
wired-in package base mapped to base-4.13.0.0
wired-in package rts mapped to rts
wired-in package template-haskell mapped to template-haskell-2.15.0.0
wired-in package ghc mapped to ghc-8.8.4
*** Deleting temp files:
Deleting: 
*** Deleting temp dirs:
Deleting: 
ghc: no input files
Usage: For basic information, try the `--help' option.

comment:30 in reply to:  29 Changed 3 years ago by barracuda156

Replying to kencu:

BTW, if you have an hour and want to see this working on PPC to wet your whistle, this is on a G4 iMac:

$ uname -a
Linux debianimacppc32 5.15.0-2-powerpc #1 Debian 5.15.5-2 (2021-12-18) ppc GNU/Linux

$ which ghc
/usr/bin/ghc

$ ghc -v
Glasgow Haskell Compiler, Version 8.8.4, stage 2 booted by GHC version 8.8.4
Using binary package database: /usr/lib/ghc/package.conf.d/package.cache
package flags []
loading package database /usr/lib/ghc/package.conf.d
wired-in package ghc-prim mapped to ghc-prim-0.5.3
wired-in package integer-wired-in mapped to integer-gmp-1.0.2.0
wired-in package base mapped to base-4.13.0.0
wired-in package rts mapped to rts
wired-in package template-haskell mapped to template-haskell-2.15.0.0
wired-in package ghc mapped to ghc-8.8.4
*** Deleting temp files:
Deleting: 
*** Deleting temp dirs:
Deleting: 
ghc: no input files
Usage: For basic information, try the `--help' option.

Awesome! If you get a chance, could you try building for powerpc-apple-darwin target on Debian PPC?

8.8.4 won’t work unless patched, but 8.6.5 has powerpc-apple-darwin code still.

For example, in ghc-8.6.5/compiler/codeGen/CodeGen/Platform.hs:

import qualified CodeGen.Platform.ARM        as ARM
import qualified CodeGen.Platform.ARM64      as ARM64
import qualified CodeGen.Platform.PPC        as PPC
import qualified CodeGen.Platform.PPC_Darwin as PPC_Darwin
import qualified CodeGen.Platform.SPARC      as SPARC
import qualified CodeGen.Platform.X86        as X86
import qualified CodeGen.Platform.X86_64     as X86_64
import qualified CodeGen.Platform.NoRegs     as NoRegs

Changed 3 years ago by barracuda156

On 10.6.8 Rosetta ghc seems totally broken. Even configure fails with numerous Unknown pseudo-op: errors.

comment:31 Changed 3 years ago by barracuda156

This might be the cause of the problem with above builds. Another example, failure of 7.4.2:

Configuring ghc-prim-0.2.0.0...
ghc-cabal: ghc-stage1: internal error: evacuate(static): strange closure type 24576
(GHC version 7.0.1 for powerpc_apple_darwin)
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
make[1]: *** [libraries/ghc-prim/dist-install/package-data.mk] Error 1
make: *** [all] Error 2
make: Leaving directory `/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc-bootstrap/ghc-bootstrap/work/ghc-7.4.2'
Command failed:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc-bootstrap/ghc-bootstrap/work/ghc-7.4.2" && /usr/bin/make -j4 -w all 
Exit code: 2
Error: Failed to build ghc-bootstrap: command execution failed
Error: See /opt/local/var/macports/logs/_opt_PPCSnowLeopardPorts_lang_ghc-bootstrap/ghc-bootstrap/main.log for details.
Error: Follow https://guide.macports.org/#project.tickets if you believe there is a bug.

Now compare output of -v and --version:

36-160% /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc-bootstrap/ghc-bootstrap/work/ghc-7.4.2/inplace/bin/ghc-stage1 --version
The Glorious Glasgow Haskell Compilation System, version 7.4.2
36-160% /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_ghc-bootstrap/ghc-bootstrap/work/ghc-7.4.2/inplace/bin/ghc-stage1 -v
ghc-stage1: internal error: evacuate(static): strange closure type 24576
    (GHC version 7.0.1 for powerpc_apple_darwin)
    Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
zsh: abort       -v

It seems that if --version is passed instead of -v, error may not occur.

comment:32 in reply to:  17 Changed 3 years ago by barracuda156

Replying to kencu:

I have noticed that configure apparently misdiagnoses float order:

checking whether byte ordering is bigendian... yes
checking whether float word order is big endian... no

Both must be big endian on PPC, aren't they?

comment:33 Changed 3 years ago by barracuda156

UPD: Spend hours trying to build ghc 7.7 with variety of settings, and could not get past building Float in final stage. It always ends with internal error: evacuate(static): strange closure type.

Judging from some seemingly related tickets, this is a bug in compiler itself, so may not be fixable: https://gitlab.haskell.org/ghc/ghc/-/issues/9268 https://git-annex.branchable.com/bugs/internal_error__58___evacuate__58___strange_closure_type/

I will skip 7.7–7.8 and try building 7.10, where the bug might have been fixed (of course, ppc case is unknown).

comment:34 Changed 3 years ago by barracuda156

I was advised to skip older versions and rather work on the recent: https://gitlab.haskell.org/ghc/ghc/-/issues/16106

Cross-compiling is yet to be done, in the meanwhile I kinda brought back PPC support into ghc 9.2.2 source code. There is at least one patch that has to be rewritten though to match new syntax: https://gitlab.haskell.org/ghc/ghc/-/issues/21371

Will keep updating here.

Changed 3 years ago by barracuda156

Attachment: PPC_patches_v1.zip added

If anyone wanna have a look:

comment:35 Changed 3 years ago by barracuda156

Keywords: snowleopard added
Owner: set to essandess
Status: newassigned
Note: See TracTickets for help on using tickets.