Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GHC unusable on darwin when linking against -libc++ #149937

Open
jkachmar opened this issue Dec 9, 2021 · 9 comments
Open

GHC unusable on darwin when linking against -libc++ #149937

jkachmar opened this issue Dec 9, 2021 · 9 comments
Labels
0.kind: bug 6.topic: darwin Running or building packages on Darwin 6.topic: haskell

Comments

@jkachmar
Copy link
Contributor

jkachmar commented Dec 9, 2021

Describe the bug

When a Haskell program that links against -libc++ is compiled using LLVM & GHC from nixpkgs on macOS (darwin), compilation fails with the following error:

ghc: loadArchive: Neither an archive, nor a fat archive: `/nix/store/?-clang-wrapper-5.0.2/bin/clang++'

<no location info>: error:
    loadArchive "/nix/store/?-clang-wrapper-5.0.2/bin/clang++": failed

This occurs on x86_64-darwin as well as aarch64-darwin.

I have verified that it can be alleviated by applying this patch, recompiling GHC, and attempting to rebuild a project that failed previously.

Steps To Reproduce

Steps to reproduce the behavior on a macOS system:

  1. Clone graphql-engine
  2. Insert the shell.nix included below into the repository root directory
  3. Enter the nix-shell
  4. Run cp cabal.project.dev-sh.local cabal.project.local
  5. If you are using an aarch64-darwin system
    a. Update the cabal.project.freeze index-state to hackage.haskell.org 2021-12-09T17:38:20Z
  6. Run cabal update && cabal build graphql-engine
shell.nix
{ pkgs ? import <nixpkgs> { }
, unstable ? import <unstable> { }
}:

let
  inherit (pkgs.lib.strings) makeLibraryPath;

  haskellDeps = (with pkgs; [
    haskell.compiler.ghc8107
    cabal-install
  ]);

  # `freetds` needs to be given a `unixODBC` package explicitly when
  # `odbcSupport` is enabled.
  freetdsWithODBC = pkgs.freetds.override {
    odbcSupport = true;
    inherit (pkgs) unixODBC;
  };

  dynamicLibraries = with pkgs; [
    libkrb5
    ncurses
    openssl
    pcre
    zlib

    # Postgres, ODBC, MSSQL, & MySQL deps.
    freetdsWithODBC
    libmysqlclient
    postgresql
    unixODBC
  ];

in
pkgs.mkShell {
  buildInputs =
    haskellDeps
    ++ dynamicLibraries;

  DYLD_FALLBACK_LIBRARY_PATH = makeLibraryPath dynamicLibraries;
}

Expected behavior

The project should compile successfully, as it does when the patch linked above is applied.

To verify: replace haskell.compiler.ghc8107 with the following snippet in the shell.nix file provided above and rebuild the nix-shell environment.

    (haskell.compiler.ghc8107.overrideAttrs (oldAttrs: {
      patches = (oldAttrs.patches or [ ]) ++ [
        (pkgs.fetchpatch {
          url = "https://raw.githubusercontent.com/input-output-hk/haskell.nix/613ec38dbd62ab7929178c9c7ffff71df9bb86be/overlays/patches/ghc/ghc-macOS-loadArchive-fix.patch";
          name = "ghc-macos-loadArchive-fix.patch";
          sha256 = "0IUpuzjZb1G+gP3q6RnwQbW4mFzc/OZ/7QqZy+57kx0=";
        })
      ];
    }))

NOTE Doing this will rebuild GHC from source, which is a very time consuming operation!

Notify maintainers

@cdepillabout @expipiplus1 @maralorn @sternenseemann

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[jkachmar@manhattan-transfer:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"aarch64-darwin"`
 - host os: `Darwin 21.1.0, macOS 12.0.1`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.4`
 - channels(jkachmar): `"nixpkgs-21.11pre334206.ff17a0fffea"`
 - channels(root): `"nixpkgs-21.11pre334206.ff17a0fffea"`
 - nixpkgs: `/nix/store/i00nm8lvxx4kybwym08ydkxpqf3irgwl-source`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
@veprbl veprbl added 6.topic: darwin Running or building packages on Darwin 6.topic: haskell labels Dec 10, 2021
@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 12, 2022
@jkachmar
Copy link
Contributor Author

jkachmar commented Dec 2, 2022

this issue is not stale.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 2, 2022
@jkachmar
Copy link
Contributor Author

jkachmar commented Dec 2, 2022

for future reference, there is a GHC thread associated with this issue: https://gitlab.haskell.org/ghc/ghc/-/issues/16590

@sternenseemann
Copy link
Member

@jkachmar Do you want to bump the thread on the GHC side maybe? Seems like the issue may have slipped through the cracks as the milestone remains 8.8.2…

@ahihi
Copy link

ahihi commented Apr 23, 2023

another haskell package broken by this is tidal.

i am using haskell.packages.ghc94.ghcWithPackages (p: [p.tidal]), would anyone happen to know how to apply the patch in this case? (if it still works against GHC 9.4.4)

@sternenseemann
Copy link
Member

sternenseemann commented Aug 10, 2023

This now affects inline-c-cpp 0.5.0.1 which started using system-cxx-std-lib on darwin with GHC >= 9.4 which is a bit worrying:

Building library for inline-c-cpp-0.5.0.1..
[1 of 4] Compiling Language.C.Inline.Cpp ( src/Language/C/Inline/Cpp.hs, dist/build/Language/C/Inline/Cpp.o, dist/build/Language/C/Inline/Cpp.dyn_o )

src/Language/C/Inline/Cpp.hs:16:1: warning: [-Wunused-imports]
    The import of ‘Data.Monoid’ is redundant
      except perhaps to import instances from ‘Data.Monoid’
    To import instances alone, use: import Data.Monoid()
   |
16 | import           Data.Monoid ((<>), mempty)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2 of 4] Compiling Language.C.Inline.Cpp.Exception ( src/Language/C/Inline/Cpp/Exception.hs, dist/build/Language/C/Inline/Cpp/Exception.o, dist/build/Language/C/Inline/Cpp/Exception.dyn_o )
ghc: loadArchive: Neither an archive, nor a fat archive: `/nix/store/7dkbcs6vgwbkb6rafh03j9j0bn8qpki0-clang-wrapper-11.1.0/bin/clang++'

<no location info>: error:
    loadArchive "/nix/store/7dkbcs6vgwbkb6rafh03j9j0bn8qpki0-clang-wrapper-11.1.0/bin/clang++": failed
entire log
setupCompilerEnvironmentPhase
Build with /nix/store/kwl5616ryrwxr41l7719c76qdn3xbzmz-ghc-9.4.6.
unpacking sources
unpacking source archive /nix/store/14pkp20vacz5vqxxxj83vkqxl12pp6db-inline-c-cpp-0.5.0.1.tar.gz
source root is inline-c-cpp-0.5.0.1
setting SOURCE_DATE_EPOCH to timestamp 1689439242 of file inline-c-cpp-0.5.0.1/inline-c-cpp.cabal
patching sources
compileBuildDriverPhase
setupCompileFlags: -package-db=/private/tmp/nix-build-inline-c-cpp-0.5.0.1.drv-0/tmp.ar9LV8Uym2/setup-package.conf.d -j2 -threaded -rtsopts
[1 of 2] Compiling Main             ( Setup.hs, /private/tmp/nix-build-inline-c-cpp-0.5.0.1.drv-0/tmp.ar9LV8Uym2/Main.o )
[2 of 2] Linking Setup
updateAutotoolsGnuConfigScriptsPhase
configuring
configureFlags: --verbose --prefix=/nix/store/zqmnyib4p1as9pijmd0yi94dzxni4hwh-inline-c-cpp-0.5.0.1 --libdir=$prefix/lib/$compiler --libsubdir=$abi/$libname --docdir=/nix/store/zmhw7wdwbcc469kdwhvs3l8qyz6pk2vi-inline-c-cpp-0.5.0.1-doc/share/doc/inline-c-cpp-0.5.0.1 --with-gcc=clang --package-db=/private/tmp/nix-build-inline-c-cpp-0.5.0.1.drv-0/tmp.ar9LV8Uym2/package.conf.d --ghc-options=-j2 --disable-split-objs --enable-library-profiling --profiling-detail=exported-functions --disable-profiling --enable-shared --disable-coverage --enable-static --disable-executable-dynamic --enable-tests --disable-benchmarks --enable-library-vanilla --disable-library-for-ghci --ghc-options=-haddock --extra-lib-dirs=/nix/store/615kyc08c08q09q0rkj1axz747fqhx0p-ncurses-6.4/lib --extra-lib-dirs=/nix/store/l0k5zjbwy26chrgjpkjbgsnk7cgv72m1-libffi-3.4.4/lib --extra-lib-dirs=/nix/store/4grhdymvkqzzqhp1jqgmwvlzj59k9cxw-gmp-with-cxx-6.2.1/lib --extra-include-dirs=/nix/store/sp25w6mky64jq7klf45rgnfbm1vgj8yv-libiconv-50/include --extra-lib-dirs=/nix/store/sp25w6mky64jq7klf45rgnfbm1vgj8yv-libiconv-50/lib --extra-include-dirs=/nix/store/iz441b6aw6kh5q0pybfxgx2qwdzq5zm1-libcxx-11.1.0-dev/include --extra-lib-dirs=/nix/store/i3ni49qiynsjnkwpmrwf71i5zzq850bb-libcxx-11.1.0/lib --extra-include-dirs=/nix/store/x8c3sx9v4gpwcbqrb0p10fzp6vz2ix65-libcxxabi-11.1.0-dev/include --extra-lib-dirs=/nix/store/njjd128h1bgxyx4fvkb2vx3ql2jqqhs6-libcxxabi-11.1.0/lib --extra-include-dirs=/nix/store/h9v8rcj9d89r50cypvdhqg00r4dgayd7-compiler-rt-libc-11.1.0-dev/include --extra-lib-dirs=/nix/store/myy52viyispq1zhrmivk2b4c0h9qvsmb-compiler-rt-libc-11.1.0/lib --extra-lib-dirs=/nix/store/q2d0ya7rc5kmwbwvsqc2djvv88izn1q6-apple-framework-CoreFoundation-11.0.0/lib --extra-framework-dirs=/nix/store/q2d0ya7rc5kmwbwvsqc2djvv88izn1q6-apple-framework-CoreFoundation-11.0.0/Library/Frameworks --extra-include-dirs=/nix/store/6gqnpkyz9zcf9hc24b8qlxp746xvfhcf-libobjc-11.0.0/include --extra-lib-dirs=/nix/store/6gqnpkyz9zcf9hc24b8qlxp746xvfhcf-libobjc-11.0.0/lib
Using Parsec parser
Configuring inline-c-cpp-0.5.0.1...
Flags chosen: std-vector-example=False
Dependency base >=4.7 && <5: using base-4.17.2.0
Dependency bytestring: using bytestring-0.11.5.1
Dependency containers: using containers-0.6.7
Dependency inline-c >=0.9.0.0: using inline-c-0.9.1.8
Dependency safe-exceptions: using safe-exceptions-0.1.7.4
Dependency system-cxx-std-lib ==1.0: using system-cxx-std-lib-1.0
Dependency template-haskell: using template-haskell-2.19.0.0
Dependency text: using text-2.0.2
Dependency base >=4 && <5: using base-4.17.2.0
Dependency bytestring: using bytestring-0.11.5.1
Dependency containers: using containers-0.6.7
Dependency hspec: using hspec-2.10.10
Dependency inline-c: using inline-c-0.9.1.8
Dependency inline-c-cpp: using inline-c-cpp-0.5.0.1
Dependency safe-exceptions: using safe-exceptions-0.1.7.4
Dependency system-cxx-std-lib ==1.0: using system-cxx-std-lib-1.0
Dependency template-haskell: using template-haskell-2.19.0.0
Dependency vector: using vector-0.13.0.0
Source component graph:
    component lib
    component test:tests dependency lib
Configured component graph:
    component inline-c-cpp-0.5.0.1-6C1fxl1owFc3VsqLIRQQRO
        include base-4.17.2.0
        include bytestring-0.11.5.1
        include containers-0.6.7
        include inline-c-0.9.1.8-7cc9PpNNNL69CckDq67EYe
        include safe-exceptions-0.1.7.4-SuhjkWOeDpIDfz6Z2L5V3
        include system-cxx-std-lib-1.0
        include template-haskell-2.19.0.0
        include text-2.0.2
    component inline-c-cpp-0.5.0.1-4qmVoSMtH1K3yH8202PYLR-tests
        include base-4.17.2.0
        include bytestring-0.11.5.1
        include containers-0.6.7
        include hspec-2.10.10-7XNnWy1DmEW26mZxaACYDV
        include inline-c-0.9.1.8-7cc9PpNNNL69CckDq67EYe
        include inline-c-cpp-0.5.0.1-6C1fxl1owFc3VsqLIRQQRO
        include safe-exceptions-0.1.7.4-SuhjkWOeDpIDfz6Z2L5V3
        include system-cxx-std-lib-1.0
        include template-haskell-2.19.0.0
        include vector-0.13.0.0-3W9cV5Nx58ZJW9PdUODEAh
Linked component graph:
    unit inline-c-cpp-0.5.0.1-6C1fxl1owFc3VsqLIRQQRO
        include base-4.17.2.0
        include bytestring-0.11.5.1
        include containers-0.6.7
        include inline-c-0.9.1.8-7cc9PpNNNL69CckDq67EYe
        include safe-exceptions-0.1.7.4-SuhjkWOeDpIDfz6Z2L5V3
        include system-cxx-std-lib-1.0
        include template-haskell-2.19.0.0
        include text-2.0.2
        Language.C.Inline.Cpp=inline-c-cpp-0.5.0.1-6C1fxl1owFc3VsqLIRQQRO:Language.C.Inline.Cpp,Language.C.Inline.Cpp.Exception=inline-c-cpp-0.5.0.1-6C1fxl1owFc3VsqLIRQQRO:Language.C.Inline.Cpp.Exception,Language.C.Inline.Cpp.Exceptions=inline-c-cpp-0.5.0.1-6C1fxl1owFc3VsqLIRQQRO:Language.C.Inline.Cpp.Exceptions,Language.C.Inline.Cpp.Unsafe=inline-c-cpp-0.5.0.1-6C1fxl1owFc3VsqLIRQQRO:Language.C.Inline.Cpp.Unsafe
    unit inline-c-cpp-0.5.0.1-4qmVoSMtH1K3yH8202PYLR-tests
        include base-4.17.2.0
        include bytestring-0.11.5.1
        include containers-0.6.7
        include hspec-2.10.10-7XNnWy1DmEW26mZxaACYDV
        include inline-c-0.9.1.8-7cc9PpNNNL69CckDq67EYe
        include inline-c-cpp-0.5.0.1-6C1fxl1owFc3VsqLIRQQRO
        include safe-exceptions-0.1.7.4-SuhjkWOeDpIDfz6Z2L5V3
        include system-cxx-std-lib-1.0
        include template-haskell-2.19.0.0
        include vector-0.13.0.0-3W9cV5Nx58ZJW9PdUODEAh
Ready component graph:
    definite inline-c-cpp-0.5.0.1-6C1fxl1owFc3VsqLIRQQRO
        depends base-4.17.2.0
        depends bytestring-0.11.5.1
        depends containers-0.6.7
        depends inline-c-0.9.1.8-7cc9PpNNNL69CckDq67EYe
        depends safe-exceptions-0.1.7.4-SuhjkWOeDpIDfz6Z2L5V3
        depends system-cxx-std-lib-1.0
        depends template-haskell-2.19.0.0
        depends text-2.0.2
    definite inline-c-cpp-0.5.0.1-4qmVoSMtH1K3yH8202PYLR-tests
        depends base-4.17.2.0
        depends bytestring-0.11.5.1
        depends containers-0.6.7
        depends hspec-2.10.10-7XNnWy1DmEW26mZxaACYDV
        depends inline-c-0.9.1.8-7cc9PpNNNL69CckDq67EYe
        depends inline-c-cpp-0.5.0.1-6C1fxl1owFc3VsqLIRQQRO
        depends safe-exceptions-0.1.7.4-SuhjkWOeDpIDfz6Z2L5V3
        depends system-cxx-std-lib-1.0
        depends template-haskell-2.19.0.0
        depends vector-0.13.0.0-3W9cV5Nx58ZJW9PdUODEAh
Using Cabal-3.8.1.0 compiled by ghc-9.4
Using compiler: ghc-9.4.6
Using install prefix:
/nix/store/zqmnyib4p1as9pijmd0yi94dzxni4hwh-inline-c-cpp-0.5.0.1
Executables installed in:
/nix/store/zqmnyib4p1as9pijmd0yi94dzxni4hwh-inline-c-cpp-0.5.0.1/bin
Libraries installed in:
/nix/store/zqmnyib4p1as9pijmd0yi94dzxni4hwh-inline-c-cpp-0.5.0.1/lib/ghc-9.4.6/aarch64-osx-ghc-9.4.6/inline-c-cpp-0.5.0.1-6C1fxl1owFc3VsqLIRQQRO
Dynamic Libraries installed in:
/nix/store/zqmnyib4p1as9pijmd0yi94dzxni4hwh-inline-c-cpp-0.5.0.1/lib/ghc-9.4.6/aarch64-osx-ghc-9.4.6
Private executables installed in:
/nix/store/zqmnyib4p1as9pijmd0yi94dzxni4hwh-inline-c-cpp-0.5.0.1/libexec/aarch64-osx-ghc-9.4.6/inline-c-cpp-0.5.0.1
Data files installed in:
/nix/store/zqmnyib4p1as9pijmd0yi94dzxni4hwh-inline-c-cpp-0.5.0.1/share/aarch64-osx-ghc-9.4.6/inline-c-cpp-0.5.0.1
Documentation installed in:
/nix/store/zmhw7wdwbcc469kdwhvs3l8qyz6pk2vi-inline-c-cpp-0.5.0.1-doc/share/doc/inline-c-cpp-0.5.0.1
Configuration files installed in:
/nix/store/zqmnyib4p1as9pijmd0yi94dzxni4hwh-inline-c-cpp-0.5.0.1/etc
No alex found
Using ar found on system at:
/nix/store/6j9rsw4086h5g8db7anxy6bbrsv4zqz7-cctools-binutils-darwin-11.1.0-973.0.1/bin/ar
No c2hs found
No cpphs found
No doctest found
Using gcc version 11.1.0 given by user at:
/nix/store/7dkbcs6vgwbkb6rafh03j9j0bn8qpki0-clang-wrapper-11.1.0/bin/clang
Using ghc version 9.4.6 found on system at:
/nix/store/kwl5616ryrwxr41l7719c76qdn3xbzmz-ghc-9.4.6/bin/ghc
Using ghc-pkg version 9.4.6 found on system at:
/nix/store/kwl5616ryrwxr41l7719c76qdn3xbzmz-ghc-9.4.6/bin/ghc-pkg-9.4.6
No ghcjs found
No ghcjs-pkg found
No greencard found
Using haddock version 2.27.0 found on system at:
/nix/store/kwl5616ryrwxr41l7719c76qdn3xbzmz-ghc-9.4.6/bin/haddock-ghc-9.4.6
No happy found
Using haskell-suite found on system at: haskell-suite-dummy-location
Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location
No hmake found
Using hpc version 0.68 found on system at:
/nix/store/kwl5616ryrwxr41l7719c76qdn3xbzmz-ghc-9.4.6/bin/hpc
Using hsc2hs version 0.68.8 found on system at:
/nix/store/kwl5616ryrwxr41l7719c76qdn3xbzmz-ghc-9.4.6/bin/hsc2hs
Using hscolour version 1.24 found on system at:
/nix/store/q0rhsn2fw84zz6vqhlyw4rqxc1c32c68-hscolour-1.24.4/bin/HsColour
No jhc found
Using ld found on system at:
/nix/store/dnvdnqc5cdx499j2y0pyqlsdvd868y08-cctools-binutils-darwin-wrapper-11.1.0-973.0.1/bin/ld
No pkg-config found
Using runghc version 9.4.6 found on system at:
/nix/store/kwl5616ryrwxr41l7719c76qdn3xbzmz-ghc-9.4.6/bin/runghc-9.4.6
Using strip found on system at:
/nix/store/7dkbcs6vgwbkb6rafh03j9j0bn8qpki0-clang-wrapper-11.1.0/bin/strip
Using tar found on system at:
/nix/store/1vgr8znsf6dksxcy35m0i4zqc170ymnr-gnutar-1.35/bin/tar
No uhc found
building
Preprocessing library for inline-c-cpp-0.5.0.1..
Building library for inline-c-cpp-0.5.0.1..
[1 of 4] Compiling Language.C.Inline.Cpp ( src/Language/C/Inline/Cpp.hs, dist/build/Language/C/Inline/Cpp.o, dist/build/Language/C/Inline/Cpp.dyn_o )

src/Language/C/Inline/Cpp.hs:16:1: warning: [-Wunused-imports]
    The import of ‘Data.Monoid’ is redundant
      except perhaps to import instances from ‘Data.Monoid’
    To import instances alone, use: import Data.Monoid()
   |
16 | import           Data.Monoid ((<>), mempty)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2 of 4] Compiling Language.C.Inline.Cpp.Exception ( src/Language/C/Inline/Cpp/Exception.hs, dist/build/Language/C/Inline/Cpp/Exception.o, dist/build/Language/C/Inline/Cpp/Exception.dyn_o )
ghc: loadArchive: Neither an archive, nor a fat archive: `/nix/store/7dkbcs6vgwbkb6rafh03j9j0bn8qpki0-clang-wrapper-11.1.0/bin/clang++'

<no location info>: error:
    loadArchive "/nix/store/7dkbcs6vgwbkb6rafh03j9j0bn8qpki0-clang-wrapper-11.1.0/bin/clang++": failed

@yihuang
Copy link
Contributor

yihuang commented May 13, 2024

another haskell package broken by this is tidal.

i am using haskell.packages.ghc94.ghcWithPackages (p: [p.tidal]), would anyone happen to know how to apply the patch in this case? (if it still works against GHC 9.4.4)

I find that I just need to pin to older nixpkgs to make tidal work:

$ nix-shell -p "ghc.withPackages (a: [a.tidal])" \
    -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/release-23.05.tar.gz \
    --run "ghci -ghci-script ~/.local/share/nvim/plugged/vim-tidal/Tidal.ghci"

@sternenseemann
Copy link
Member

sternenseemann commented Jun 15, 2024

Seems like we can do one of four things:

@siraben
Copy link
Member

siraben commented Jun 15, 2024

How is this related to the koka update?

@sternenseemann
Copy link
Member

How is this related to the koka update?

I wish it was! Just a mistake when copy-pasting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug 6.topic: darwin Running or building packages on Darwin 6.topic: haskell
Development

Successfully merging a pull request may close this issue.

6 participants