haskell / ghcup-hs

https://www.haskell.org/ghcup/
GNU Lesser General Public License v3.0
281 stars 86 forks source link

M1 clang/llvm issue #311

Open hasufell opened 2 years ago

hasufell commented 2 years ago

In GitLab by @mixman on Jan 8, 2022, 19:23

Hi! Any pointers on getting GHCUp installed GHC/Cabal with LLVM working on an M1 laptop?

I'm failing to build this project on aarch64-osx with ghcup+llvm. However, -O0 builds fine as does Rosetta's x86_64-osx.

Prerequisitives:

1) Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2) GHCUp

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | \
    BOOTSTRAP_HASKELL_NONINTERACTIVE=1 \
    BOOTSTRAP_HASKELL_GHC_VERSION=8.10.7 \
    BOOTSTRAP_HASKELL_CABAL_VERSION=3.6.2.0 \
    sh

Steps to reproduce:

git clone --recursive https://github.com/futurice/haskell-mega-repo.git
brew install fftw pkg-config python3 xz postgresql
cabal new-update
cp -r data.sample data
cabal new-build avatar-app

WITHOUT llvm:

<no location info>: error:
    Warning: Couldn't figure out LLVM version!
             Make sure you have installed LLVM between [9 and 13)

WITH llvm:

0  0x100a5c224  __assert_rtn + 128
1  0x100a624e8  ld::tool::OutputFile::addDyldInfo(ld::Internal&, ld::Internal::FinalSection*, ld::Atom const*, ld::Fixup*, ld::Fixup*, ld::Fixup*, ld::Atom const*, ld::Atom const*, unsigned long long, unsigned long long) (.cold.1) + 0
2  0x1009a4b98  ld::tool::OutputFile::addDyldInfo(ld::Internal&, ld::Internal::FinalSection*, ld::Atom const*, ld::Fixup*, ld::Fixup*, ld::Fixup*, ld::Atom const*, ld::Atom const*, unsigned long long, unsigned long long) + 0
3  0x100997544  ld::tool::OutputFile::generateLinkEditInfo(ld::Internal&) + 1188
4  0x100991a90  ld::tool::OutputFile::write(ld::Internal&) + 140
5  0x10091f1d8  main + 584
A linker snapshot was created at:
    /tmp/libHSfuturice-integrations-0-inplace-ghc8.10.7.dylib-2022-00-08-123320.ld-snapshot
ld: Assertion failed: (target->definition() != ld::Atom::definitionProxy), function addChainedFixupLocation, file OutputFile.cpp, line 5903.
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)
cabal: Failed to build futurice-integrations-0 (which is required by
exe:avatar-server from avatar-app-0).

Runtime information

$ uname -a

Darwin jussi-max.local 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T6000 arm64

$ clang --version

Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

$ gcc --version

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

$ cabal --version

cabal-install version 3.6.2.0
compiled using version 3.6.2.0 of the Cabal library

$ ghc --info

ghc --info
 [("Project name","The Glorious Glasgow Haskell Compilation System")
 ,("GCC extra via C opts","")
 ,("C compiler command","gcc")
 ,("C compiler flags","")
 ,("C++ compiler flags","")
 ,("C compiler link flags","")
 ,("C compiler supports -no-pie","NO")
 ,("Haskell CPP command","gcc")
 ,("Haskell CPP flags","-E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs")
 ,("ld command","ld")
 ,("ld flags","")
 ,("ld supports compact unwind","YES")
 ,("ld supports build-id","NO")
 ,("ld supports filelist","YES")
 ,("ld is GNU ld","NO")
 ,("Merge objects command","ld")
 ,("Merge objects flags","-r")
 ,("ar command","ar")
 ,("ar flags","qcls")
 ,("ar supports at file","NO")
 ,("ranlib command","ranlib")
 ,("otool command","otool")
 ,("install_name_tool command","install_name_tool")
 ,("touch command","touch")
 ,("dllwrap command","/bin/false")
 ,("windres command","/bin/false")
 ,("libtool command","libtool")
 ,("unlit command","/Users/jussi.vaihia@futurice.com/.ghcup/ghc/8.10.7/lib/ghc-8.10.7/bin/unlit")
 ,("cross compiling","NO")
 ,("target platform string","aarch64-apple-darwin")
 ,("target os","OSDarwin")
 ,("target arch","ArchAArch64")
 ,("target word size","8")
 ,("target has GNU nonexec stack","NO")
 ,("target has .ident directive","YES")
 ,("target has subsections via symbols","NO")
 ,("target has RTS linker","YES")
 ,("Unregisterised","NO")
 ,("LLVM target","arm64-apple-darwin")
 ,("LLVM llc command","/opt/homebrew/opt/llvm@11/bin/llc")
 ,("LLVM opt command","/opt/homebrew/opt/llvm@11/bin/opt")
 ,("LLVM clang command","clang")
 ,("integer library","integer-gmp")
 ,("Use interpreter","YES")
 ,("Use native code generator","NO")
 ,("Support SMP","YES")
 ,("RTS ways","l debug thr thr_debug thr_l thr_p dyn debug_dyn thr_dyn thr_debug_dyn l_dyn thr_l_dyn thr_debug_p debug_p")
 ,("Tables next to code","YES")
 ,("Leading underscore","YES")
 ,("Use LibFFI","YES")
 ,("Use Threads","YES")
 ,("Use Debugging","NO")
 ,("RTS expects libdw","NO")
 ,("Project version","8.10.7")
 ,("Project Git commit id","1f02b7430b2fbab403d7ffdde9cfd006e884678e")
 ,("Booter version","8.10.3")
 ,("Stage","2")
 ,("Build platform","aarch64-apple-darwin")
 ,("Host platform","aarch64-apple-darwin")
 ,("Target platform","aarch64-apple-darwin")
 ,("Have interpreter","YES")
 ,("Object splitting supported","NO")
 ,("Have native code generator","NO")
 ,("Support dynamic-too","YES")
 ,("Support parallel --make","YES")
 ,("Support reexported-modules","YES")
 ,("Support thinning and renaming package flags","YES")
 ,("Support Backpack","YES")
 ,("Requires unified installed package IDs","YES")
 ,("Uses package keys","YES")
 ,("Uses unit IDs","YES")
 ,("Dynamic by default","NO")
 ,("GHC Dynamic","YES")
 ,("GHC Profiled","NO")
 ,("Debug on","NO")
 ,("LibDir","/Users/jussi.vaihia@futurice.com/.ghcup/ghc/8.10.7/lib/ghc-8.10.7")
 ,("Global Package DB","/Users/jussi.vaihia@futurice.com/.ghcup/ghc/8.10.7/lib/ghc-8.10.7/package.conf.d")
 ]

I'm stumped. Tips?

hasufell commented 2 years ago

In GitLab by @maerwald on Jan 8, 2022, 22:07

Looks like either a project or ghc issue to me.

@angerman @bgamari

hasufell commented 2 years ago

In GitLab by @angerman on Jan 8, 2022, 22:23

Try llvm 12. But I think I’ve seen that big once before, a long time ago though.

hasufell commented 2 years ago

In GitLab by @mixman on Jan 10, 2022, 21:49

I received a reply on https://developer.apple.com/forums/thread/698203 that this is indeed a linker bug related to chained fixups format introduced in macOS 12.

All programs and dylibs built with a deployment target of macOS 12 or iOS 15 or later now use the chained fixups format. This uses different load commands and LINKEDIT data, and won’t run or load on older OS versions. (49851380)

hasufell commented 2 years ago

In GitLab by @angerman on Jan 10, 2022, 22:03

@bgamari what did we bump macOS min version to?

hasufell commented 2 years ago

In GitLab by @mixman on Jan 11, 2022, 04:39

For the most part builds work fine on macOS 12. The individual apps within this very same project build fine. Bringing it all together hits this linker failure. There are some C libraries in use like lzma (with known issues https://github.com/haskell-hvr/lzma/issues/21). Bug report filed with Apple (9839914) to get more eyes on the issue.

hasufell commented 2 years ago

In GitLab by @bgamari on Jan 11, 2022, 05:03

The minimum deployment target is now 10.10.

hasufell commented 2 years ago

In GitLab by @stuartkurtz on Jan 18, 2022, 05:41

GHC 9.2.1 works, 9.0.x, 8.10.x do not. Perhaps the GHC team already has this one figured out.

hasufell commented 2 years ago

In GitLab by @angerman on Jan 18, 2022, 06:19

9.2 doesn’t use llvm and comes with a native code generator for AArch64.

hasufell commented 2 years ago

In GitLab by @maerwald on Jan 19, 2022, 19:49

from that thread:

It seems that GHC is doing something wrong and our resolution for this bug will be to convert that assert into a proper error message.

hasufell commented 2 years ago

In GitLab by @maerwald on Jan 19, 2022, 19:51

Does this mean we should rebuild the 8.10.7 and 9.0.2 bindists with a different deployment target?