Habib, I just wanted to tell you that I am following your progress, just don't have time yet to reproduce nor much insight to share. Thank you for digging into this, I know it's a hard slog.
One thing that occurred to me some time ago was to try comparing the runs upstream does in their working cross-environment to what we attempt. Their setup is heavily factored, so we can't easily extract the relevant command lines. Looking at their logs might be illuminating, also running the same environment under linux might help. None of it is easy or fun. On Sat, Oct 26, 2024 at 10:52 PM حبيب محمد الأمين محمد الهـاد < ha.ala...@gmail.com> wrote: > Progress report: > > - I managed to build the C parts of rts through Hadrian. It proved > impossible to pass multiple options via LDFLAGS, as Hadrian doesn't > allow spaces in arguments passed to tools. I fixed this with a > bin/clang-with-sysroot-env shim. > - There are some (C) libraries built without a Cabal file, like > libffi, and there seems to be no way to pass arguments through > Hadrian to control these builds. > - Using $CONF_GCC_LINKER_OPTS_STAGE{0,1,2} seems to work and passes > through arguments with spaces to both rts and libffi; I had tried > $CONF_LD_LINKER_OPTS_STAGE{0,1,2} before, but the compiler binary > is called as a linker, so only the former arguments to configure > work to control flags to the linker (even for Clang). Anyway, > I still seem to require the shim, despite it seeming to pass > arguments to rts, but whatever, it gets me past the libffi build. > - To get any further than that, to compile libffi, I had to edit the > Hadrian code directly (it's part of the GHC source tree). > > I'm now working on getting the Haskell parts of rts to compile > without “invalid instruction mnemonic” errors; so far, > with some more arguments via Hadrian to GHC of the form > -optl--host=aarch64-unknown-openbsd (and similar), I can get it to > compile a little bit instead of blowing up with the errors straight > away, but it does eventually spit out the same errors, just further > along in the build. > > Cheers, > Habib > > On 25 Oct 2024, at 15:48, حبيب محمد الأمين محمد الهـاد < > ha.ala...@gmail.com> wrote: > > For some reason, pretty much all the options aren't getting passed > through to cabal configure. These are the log messages for what > arguments get passed to cabal configure and ultimately to configure (rts > is the part of the build that fails with the missing libpthread and libm > I mentioned in my previous message): > > # | Package 'rts' configuration flags: configure --distdir > /home/habib/ghc-9.10.1/_build/stage1/rts --disable-executable-stripping > --disable-library-stripping --disable-executable-stripping > --disable-library-stripping --cabal-file rts/rts.cabal --ipid rts-1.0.2 > --prefix ${pkgroot}/.. --htmldir > ${pkgroot}/../../doc/html/libraries/rts-1.0.2 > --with-ghc=/home/habib/ghc-9.10.1/_build/stage0/bin/aarch64-unknown-openbsd-ghc > --with-ghc-pkg=/home/habib/ghc-9.10.1/_build/stage0/bin/aarch64-unknown-openbsd-ghc-pkg > --with-gcc=clang --with-ar=/usr/local/bin/llvm-ar-13 > --ghc-option=-no-global-package-db > --ghc-option=-package-db=/home/habib/ghc-9.10.1/_build/stage1/inplace/package.conf.d > --ghc-pkg-option=--global-package-db=/home/habib/ghc-9.10.1/_build/stage1/inplace/package.conf.d > --enable-library-vanilla --disable-library-profiling > --disable-library-for-ghci --disable-shared --with-ld=clang > --with-alex=/usr/local/bin/alex --with-happy=/usr/local/bin/happy > --configure-option=CFLAGS=-Qunused-arguments -iquote > /home/habib/ghc-9.10.1/rts -Qunused-arguments > --configure-option=LDFLAGS=--target=aarch64-unknown-openbsd > --configure-option=--host=aarch64-unknown-openbsd > --configure-option=--with-cc=clang > --ghc-option=-ghcversion-file=rts/include/ghcversion.h > --ghc-option=-ghcversion-file=rts/include/ghcversion.h > --configure-option=LDFLAGS= --configure-option=CPPFLAGS= > --extra-lib-dirs=/home/habib/ghc-9.10.1/aarch64-sysroot/usr/lib > --extra-lib-dirs=/usr/lib > --extra-include-dirs=/home/habib/ghc-9.10.1/aarch64-sysroot/usr/include > --extra-include-dirs=/usr/include --ghc-option= --ghc-option= --ghc-option= > --ghc-option= --ghc-option= -v3 --flags=-profiling -debug -dynamic threaded > libm -librt -libdl -use-system-libffi libffi-adjustors need-pthread -libbfd > -need-atomic -libdw -libnuma -libzstd -static-libzstd -leading-underscore > -unregisterised tables-next-to-code -find-ptr -v2 > […] > Running: /bin/sh //home/habib/ghc-9.10.1/rts/configure > '--with-compiler=ghc' '--prefix=${pkgroot}/..' 'CFLAGS=-Qunused-arguments > -iquote /home/habib/ghc-9.10.1/rts -Qunused-arguments' > 'LDFLAGS=--target=aarch64-unknown-openbsd' '--host=aarch64-unknown-openbsd' > '--with-cc=clang' 'LDFLAGS=' 'CPPFLAGS=' 'CC=/usr/local/llvm13/bin/clang' > '--host=aarch64-openbsd' > > This is from running (on one line): > > hadrian/build \ > --docs=none \ > --flavour=quickest \ > "stage0.*.cabal.configure.opts += --configure-option=LDFLAGS= > --configure-option=--target=aarch64-unknown-openbsd" \ > "stage1.*.cabal.configure.opts += > --configure-option=LDFLAGS=\"-syslibroot=$SYSROOT -L/usr/lib > -L$SYSROOT/usr/lib\"" \ > "stage1.*.cabal.configure.opts += > --configure-option=CPPFLAGS=\"-isysroot=$SYSROOT -I/usr/include > -I$SYSROOT/usr/include\"" \ > "stage1.*.cabal.configure.opts += --extra-lib-dirs=$SYSROOT/usr/lib" \ > "stage1.*.cabal.configure.opts += --extra-lib-dirs=/usr/lib" \ > "stage1.*.cabal.configure.opts += > --extra-include-dirs=$SYSROOT/usr/include" \ > "stage1.*.cabal.configure.opts += --extra-include-dirs=/usr/include" \ > "stage1.*.cabal.configure.opts += --ghc-option=\"-optl > -L$SYSROOT/usr/lib\"" \ > "stage1.*.cabal.configure.opts += --ghc-option=\"-optl -L/usr/lib\"" \ > "stage1.*.cabal.configure.opts += --ghc-option=\"-optl -lpthread -lm\"" \ > "stage1.*.cabal.configure.opts += --ghc-option=\"-optc > -I$SYSROOT/usr/include\"" \ > "stage1.*.cabal.configure.opts += --ghc-option=\"-optc -I/usr/include\"" > \ > "stage1.*.cabal.configure.opts += -v3" \ > "stage1.*.ghc.hs.opts += \"-optl -L$SYSROOT/usr/lib\"" \ > "stage1.*.ghc.hs.opts += \"-optl -L/usr/lib\"" \ > "stage1.*.ghc.hs.opts += \"-optl -lpthread -lm\"" \ > "stage1.*.ghc.hs.opts += \"-optc -I$SYSROOT/usr/include\"" \ > "stage1.*.ghc.hs.opts += \"-optc -I/usr/include\"" \ > "stage1.*.ghc.c.opts += -I$SYSROOT/usr/include -I/usr/include" \ > "stage1.*.ghc.link.opts += -L$SYSROOT/usr/lib -L/usr/lib -lpthread -lm" \ > "stage1.*.cc.c.opts += -L$SYSROOT/usr/lib -L/usr/lib -lpthread -lm" \ > -VVVVVVVVVV --freeze1 \ > stage2:exe:ghc-bin > > It seems like pretty much none of the arguments are getting passed > through (unlike with the stage0 compilation, where I verified that the > flags I was giving to Hadrian were getting passed through). > > I'm gonna create a ticket on GHC's Gitlab. > > Cheers, > Habib > > On 25 Oct 2024, at 13:20, حبيب محمد الأمين محمد الهـاد < > ha.ala...@gmail.com> wrote: > > What follows are my notes on where I'm at so far, how I got here, what > my next steps are, and some rambling and infodump that may be useful. > > I managed to build the stage 1 compiler Wednesday. It seems to run as > expected, though I can't test actual compilation and whether it can > successfully output AArch64 binaries, as it (correctly) gives an error > about the lack of Prelude. > > I spent yesterday trying to build the stage 2 compiler using the stage > 1 compiler. By default, the configure tests fail at C compiler cannot > create executables, and the logs show this: > > configure:2773: /usr/local/llvm13/bin/clang -Qunused-arguments -iquote > /home/habib/ghc-9.10.1/rts -Qunused-arguments > --target=aarch64-unknown-openbsd conftest.c >&5 > ld: error: /tmp/conftest-0430b9.o is incompatible with /usr/lib/crt0.o > libraries: m, pthread”. > > However, by setting `-syslibroot` and `-isysroot` (indirectly and with > difficulty via Hadrian) to a folder containing the `/usr/lib` and > `/usr/include` directories from an OpenBSD/arm64 installation, as well > as including the , I managed to fix that error (so I know it's having an > effect), but then I get an error like this: > > Error: hadrian: Missing dependencies on foreign libraries: > * Missing (or bad) C libraries: m, pthread > […] > If the libraries are already installed but in a non-standard > location then you can use the flags --extra-include-dirs= > and --extra-lib-dirs= to specify where they are. > > (I then added those flags as well, but no dice.) > > Well, the sysroot definitely contains a `libpthread.so.27.1` (and a > libm.so.*); does it need to be symlinked without the version as well? > Perhaps my tar of it from an OpenBSD/arm64 installation didn't properly > capture the symlinks on the original installation? > > Anyway, I won't be able to work on this much today, but I'm gonna try > increasing the verbosity of configure as the error message above (I've > elided this part) suggests, though I've already increased Hadrian's > verbosity as far as I can, not sure if it forwards that to the tools it > runs. I'm also gonna try and check that I shouldn't have a libpthread.so > symlink without the version suffix, and try and pass in the sysroot > and/or include and lib directories through GHC's -optl and -optc flags. > > I searched for a while yesterday if there were any known issues with > building GHC on OpenBSD failing due to pthreads, but nothing fruitful. > > Sorry I couldn't trim this message further, I'm in a bit of a rush. I > just wanted to leave this here with some notes in case one of you knows > something about building GHC on OpenBSD w/ pthreads, or in general the > interaction between GHC, OpenBSD, and pthreads. Or to hopefully stop you > wasting your time if you're still stuck on the stage 1 compiler (sorry, > I meant to send the initial version of this message on Wednesday, but > some things prevented me). > > BTW, before I forget, steps to get a seemingly-working stage 1 compiler > (it seems to run fine, but I can't test compilation as it fails to > find the Prelude module; AFAICT, there's a complicated interplay here > between the libraries/package dbs for each stage of the compiler, and > the compilers themselves, but suffice to say that I'm gonna take the > building of the stage 2 compiler as the confirmation that stage 1 can > successfully compile AArch64 binaries): > > export PATH="/usr/local/llvm13/bin:$PATH" > # I don't recall why this is needed, but I'm fairly sure it is > export LD_LIBRARY_PATH=/usr/local/llvm13/lib > export SYSROOT="$PWD/aarch64-sysroot" # populate this yourself > > cabal update > > # This isn't necessary for stage 1 to build, but I have a hunch it was > # holding me back from building stage 2 (which I still haven't). The > # configure script picks up clang-13 and all that, but not these tools, > # and I rebuilt on a freshly extracted source tree with these exports, > # and it still worked to build stage 1 (though it crapped out halfway > # through; I don't recall the error message, but I remember thinking it > # seemed transient, so I just restarted it and it seemed to resume from > # the same file, and I got a running stage 1 build that still fails to > # find Prelude) > export \ > AR=/usr/local/bin/llvm-ar-13 \ > RANLIB=/usr/local/bin/llvm-ranlib-13 \ > LD=/usr/local/bin/ld.lld-13 \ > OBJDUMP=/usr/local/bin/llvm-objdump-13 \ > NM=/usr/local/bin/llvm-nm-13 > > ./configure --target=aarch64-unknown-openbsd > > # I wipe out the LDFLAGS because it erroneously had a flag > # `--host=aarch64-unknown-openbsd`, which it gets from the target; > # there's some discussion in Greg's link about how that's wrong, and > # questioning why it does that, so I just wiped that flag; it added > # `--target` as well, but that gets added through other means, too, and > # I even add it myself as you can see, though not sure how needed it is. > hadrian/build \ > --docs=none \ > --flavour=quickest \ > "stage0.*.cabal.configure.opts += \ > --configure-option=LDFLAGS= \ > --configure-option=--target=aarch64-unknown-openbsd" \ > stage1:exe:ghc-bin > > # I'm trying this monster command now to build stage 2, I've tried > # most of the different flags in there with different variations, but > # not all together, and some I haven't. breaking it up into lines and > # paragraphs, but I paste all of these commands on one line. I've frozen > # the stage 1 compiler just in case something I do rebuilds it (it takes > # 4 hours on my 4 core, 8gb amd64 QEMU machine being emulated on an M1 > # Pro). > hadrian/build \ > --docs=none \ > --flavour=quickest \ > > "stage0.*.cabal.configure.opts += \ > --configure-option=LDFLAGS= \ > --configure-option=--target=aarch64-unknown-openbsd" \ > > "stage1.*.cabal.configure.opts += \ > --configure-option=LDFLAGS=\"-syslibroot=$SYSROOT -L/usr/lib > -L$SYSROOT/usr/lib\" \ > --configure-option=CPPFLAGS=\"-isysroot=$SYSROOT -I/usr/include > -I$SYSROOT/usr/include\" \ > > --configure-option=--extra-lib-dirs=$SYSROOT/usr/lib\" \ > --configure-option=--extra-lib-dirs=/usr/lib\" \ > --configure-option=--extra-include-dirs=$SYSROOT/usr/include\" \ > --configure-option=--extra-include-dirs=/usr/include\" \ > > --configure-option=--ghc-option=\"-optl -L$SYSROOT/usr/lib\" > --configure-option=--ghc-option=\"-optl -L/usr/lib\" > --configure-option=--ghc-option=\"-optl -lpthread\" > --configure-option=--ghc-option=\"-optc -I$SYSROOT/usr/include\" \ > --configure-option=--ghc-option=\"-optc -I/usr/include\" \ > > --configure-option=-v3" \ > > "stage1.*.ghc.c.opts += -I$SYSROOT/usr/include -I/usr/include" \ > "stage1.*.ghc.link.opts += -L$SYSROOT/usr/lib -L/usr/lib -lpthread" \ > "stage1.*.cc.c.opts += -L$SYSROOT/usr/lib -L/usr/lib -lpthread" \ > -VVVVVVVVVV --freeze1 \ > stage2:exe:ghc-bin > > I only put them all together like that so you can see the different > contortions I'm testing out to get options passed to the compiler > and linker. sysroot should mean that -I/usr/lib should be treated as > $SYSROOT/usr/lib, but I'm not sure if it is or not, all I had to go > on were configure logs, no compiler logs (hopefully -v3 should change > that). I'm dumping all this on you guys in a disorganised fashion > because I can't work on this much today, so I hope my messy notes and > rambling will be useful. > > (One last note I forgot to add; testing this with GHC 9.8.3 may prove > easier to test whether the stage 1 compiler can successfully output > binary files, as the Cabal version from ports would be compatible with > it, and so one can more easily populate the package db to get Prelude?) > > Cheers, > Habib > > On 21 Oct 2024, at 04:01, حبيب محمد الأمين محمد الهـاد < > ha.ala...@gmail.com> wrote: > > I just finished a PR to get GHCup to build and run on OpenBSD (though > not necessarily support it w/ working build manifests and bindists yet), > so it'll be great to see GHC in ports on OpenBSD/arm64. > > I'll hopefully start working on it this week. Lydia, feel free to share > any notes w/ myself and Greg if you make any progress or are banging > your head against a specific error. > > Cheers, > Habib > > On 19 Oct 2024, at 06:54, Greg Steuck <gne...@openbsd.org> wrote: > > Lydia Sobot <chilledfr...@disroot.org> writes: > > Perfect. How far in are you? > > Not very, still figuring out how exactly the pieces fit in together > > > FWIW, I made some effort in this area and it didn't go particularly > smoothly. Some info in https://gitlab.haskell.org/ghc/ghc/-/issues/24431 > > > > > > -- nest.cx is Gmail hosted, use PGP: https://pgp.key-server.io/0x0B1542BD8DF5A1B0 Fingerprint: 5E2B 2D0E 1E03 2046 BEC3 4D50 0B15 42BD 8DF5 A1B0