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
>> 
> 

  • GHC on OpenBSD/arm64? حبيب محمد الأمين محمد الهـاد
    • Re: GHC on OpenB... Lydia Sobot
      • Re: GHC on O... حبيب محمد الأمين محمد الهـاد
        • Re: GHC ... Lydia Sobot
          • Re: ... Greg Steuck
            • ... حبيب محمد الأمين محمد الهـاد
              • ... حبيب محمد الأمين محمد الهـاد
                • ... حبيب محمد الأمين محمد الهـاد
                • ... حبيب محمد الأمين محمد الهـاد
                • ... Greg Steuck
                • ... حبيب محمد الأمين محمد الهـاد
                • ... حبيب محمد الأمين محمد الهـاد
                • ... حبيب محمد الأمين محمد الهـاد
                • ... حبيب محمد الأمين محمد الهـاد
                • ... Greg Steuck
                • ... Greg Steuck
                • ... حبيب محمد الأمين محمد الهـاد

Reply via email to