Bug 261798 - lang/ghc: Fails to compile due to base/ports LLVM triple target names: error: Warning: Couldn't figure out LLVM version!
Summary: lang/ghc: Fails to compile due to base/ports LLVM triple target names: error:...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Many People
Assignee: freebsd-haskell (Nobody)
URL:
Keywords: needs-qa, regression
Depends on:
Blocks:
 
Reported: 2022-02-08 19:21 UTC by Filipe da Silva Santos
Modified: 2022-02-13 18:25 UTC (History)
4 users (show)

See Also:
bugzilla: maintainer-feedback? (haskell)
koobs: maintainer-feedback? (brooks)
koobs: maintainer-feedback? (dim)
koobs: merge-quarterly?


Attachments
patch (1.80 KB, patch)
2022-02-08 19:21 UTC, Filipe da Silva Santos
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Filipe da Silva Santos 2022-02-08 19:21:07 UTC
Created attachment 231654 [details]
patch

Salve, salve!

GHC searches for a `amd64-portbld-freebsd` version of LLVM, which does not match either base or ports version identifiers.

If we try to compile a simple hello world:

```
$ ghc -fllvm main.hs -o main.o
[1 of 1] Compiling Main             ( main.hs, main.o )

<no location info>: error:
    Warning: Couldn't figure out LLVM version!
             Make sure you have installed LLVM between [9 and 13)
ghc: panic! (the 'impossible' happened)
  (GHC version 8.10.7:
        Failed to lookup LLVM data layout
  Target: x86_64-portbld-freebsd
  Available targets:
      i386-unknown-windows
      i686-unknown-windows
      x86_64-unknown-windows
      arm-unknown-linux-gnueabihf
      arm-unknown-linux-musleabihf
      armv6-unknown-linux-gnueabihf
      armv6-unknown-linux-musleabihf
      armv6l-unknown-linux-gnueabihf
      armv6l-unknown-linux-musleabihf
      armv7-unknown-linux-gnueabihf
      armv7-unknown-linux-musleabihf
      armv7a-unknown-linux-gnueabi
      armv7a-unknown-linux-musleabi
      armv7a-unknown-linux-gnueabihf
      armv7a-unknown-linux-musleabihf
      armv7l-unknown-linux-gnueabi
      armv7l-unknown-linux-musleabi
      armv7l-unknown-linux-gnueabihf
      armv7l-unknown-linux-musleabihf
      aarch64-unknown-linux-gnu
      aarch64-unknown-linux-musl
      aarch64-unknown-linux
      i386-unknown-linux-gnu
      i386-unknown-linux-musl
      i386-unknown-linux
      x86_64-unknown-linux-gnu
      x86_64-unknown-linux-musl
      x86_64-unknown-linux
      x86_64-unknown-linux-android
      armv7-unknown-linux-androideabi
      aarch64-unknown-linux-android
      armv7a-unknown-linux-androideabi
      powerpc64le-unknown-linux-gnu
      powerpc64le-unknown-linux-musl
      powerpc64le-unknown-linux
      s390x-ibm-linux
      i386-apple-darwin
      x86_64-apple-darwin
      arm64-apple-darwin
      aarch64-apple-darwin
      armv7-apple-ios
      aarch64-apple-ios
      i386-apple-ios
      x86_64-apple-ios
      amd64-portbld-freebsd
      x86_64-unknown-freebsd
      aarch64-unknown-freebsd
      armv6-unknown-freebsd-gnueabihf
      armv7-unknown-freebsd-gnueabihf
      arm-unknown-nto-qnx-eabi
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1179:37 in ghc:Outputable
        pprPanic, called at compiler/llvmGen/LlvmCodeGen.hs:113:20 in ghc:LlvmCodeGen

Please report this as a GHC bug:  https://www.haskell.org/ghc/reportabug
```

It seems `amd64-portbld-freebsd` was in fact de identifier used on ports LLVM (please see https://gitlab.haskell.org/ghc/ghc/-/issues/15718), but that is not the case anymore. Now all versions (tested 90 (default), 10 (default on PowerPC) and 13) use `x86_64-portbld-freebsd`, causing GHC to fail.

Although `x86_64-unknown-freebsd` (base LLVM) is correct, the way GHC searches for LLVM is neither clear nor documented, and it does not seem to use base LLVM at all.

This patch addresses the problem renaming the identifier to the correct one. Poudriere testport does not complain. Built on both 13.0-RELEASE and 14.0-CURRENT.

Cheers!
Comment 1 Kubilay Kocak freebsd_committer freebsd_triage 2022-02-08 21:53:34 UTC
From ghc patch:

  +-    "amd64-portbld-freebsd"
  ++    "x86_64-portbld-freebsd"

Is/was the triple name for base/ports LLVM's intended and expected and is this issue just that GHC hadn't yet followed, or is this something that's better addressed in those ports at a toolchain/arch level with respect to how LLVM is built and presents itself?

^Triage: Loop in ports llvm (brooks) and base toolchain (dim)
Comment 2 Brooks Davis freebsd_committer freebsd_triage 2022-02-09 00:32:44 UTC
I dug back to llvm60 (the version in the ghc issue) and don't see an obvious path for amd64-portbld-freebsd to end up on the target list. The relevant cmake flags are:

-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-portbld-freebsd13.0 -DLLVM_HOST_TRIPLE=x86_64-portbld-freebsd13.0

If we once patched the port to use that triple it's been a long time (though maybe it was a change in cmake infrastructure?).  Presumably ghc should be patched to look for x86_64. Looking at the patch, I might leave the amd64 lines alone and simply add the new one.


On the LLVM port side, there's an argument there's an argument for dropping `portbld` from LLVM_DEFAULT_TARGET_TRIPLE since it's non-standard, but I don't think that's especially related to this PR.
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-02-13 18:25:21 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=c7644898c7e173dd486e0a23b07c487d2460dee9

commit c7644898c7e173dd486e0a23b07c487d2460dee9
Author:     Filipe da Silva Santos <contact@shiori.com.br>
AuthorDate: 2022-02-13 18:19:38 +0000
Commit:     Gleb Popov <arrowd@FreeBSD.org>
CommitDate: 2022-02-13 18:23:45 +0000

    lang/ghc: Add a patch for correctly selecting a LLVM backend.

    PR:             261798
    MFH:            2022Q1

 lang/ghc/Makefile                                             |  1 +
 lang/ghc/files/patch-llvm-targets (new)                       | 11 +++++++++++
 .../files/patch-utils_llvm-targets_gen-data-layout.sh (new)   | 11 +++++++++++
 3 files changed, 23 insertions(+)
Comment 4 commit-hook freebsd_committer freebsd_triage 2022-02-13 18:25:23 UTC
A commit in branch 2022Q1 references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=ace7cc4996e7fd6728f5a421e16ded21c498e30e

commit ace7cc4996e7fd6728f5a421e16ded21c498e30e
Author:     Filipe da Silva Santos <contact@shiori.com.br>
AuthorDate: 2022-02-13 18:19:38 +0000
Commit:     Gleb Popov <arrowd@FreeBSD.org>
CommitDate: 2022-02-13 18:24:45 +0000

    lang/ghc: Add a patch for correctly selecting a LLVM backend.

    PR:             261798
    MFH:            2022Q1
    (cherry picked from commit c7644898c7e173dd486e0a23b07c487d2460dee9)

 lang/ghc/Makefile                                             |  1 +
 lang/ghc/files/patch-llvm-targets (new)                       | 11 +++++++++++
 .../files/patch-utils_llvm-targets_gen-data-layout.sh (new)   | 11 +++++++++++
 3 files changed, 23 insertions(+)
Comment 5 Gleb Popov freebsd_committer freebsd_triage 2022-02-13 18:25:46 UTC
Thanks for the patch!