Skip to content

Linker errors with >=ghc-9.2

I am unable to link Haskell programs with GHC >= 9.2. This might be due to a misconfiguration error, but I've previously attempted multiple things without success.

When building a hello world program:

main = putStrLn "Hello world"

It goes:

(troubleshooting-linker-ghc) (๑˃ᴗ˂)ﻭ ghc Main.hs
[1 of 1] Compiling Main             ( Main.hs, Main.o )
Linking Main ...
ld64.lld: error: unknown argument '--gc-sections'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)

I'm currently troubleshooting this with @bgamari

Additional info:

$ ld64.lld --version
Homebrew LLD 14.0.6
$ which ld64.lld
/usr/local/opt/llvm/bin/ld64.lld

If I remove the LLVM linker from my path, I get instead

[1 of 1] Compiling Main             ( Main.hs, Main.o )
Linking Main ...
clang: error: invalid linker name in argument '-fuse-ld=lld'
`gcc' failed in phase `Linker'. (Exit code: 1)

Additional info:

$ which gcc
/usr/bin/gcc
$ 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.3)
Target: x86_64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

GHC Info

 [("Project name","The Glorious Glasgow Haskell Compilation System")
 ,("GCC extra via C opts","")
 ,("C compiler command","gcc")
 ,("C compiler flags","--target=x86_64-apple-darwin ")
 ,("C++ compiler flags","--target=x86_64-apple-darwin ")
 ,("C compiler link flags","--target=x86_64-apple-darwin  -fuse-ld=lld")
 ,("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.lld")
 ,("ld flags","")
 ,("ld supports compact unwind","NO")
 ,("ld supports build-id","NO")
 ,("ld supports filelist","NO")
 ,("ld is GNU ld","YES")
 ,("Merge objects command","ld.lld")
 ,("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/romes/.ghcup/ghc/9.2.2/lib/ghc-9.2.2/lib/bin/unlit")
 ,("cross compiling","NO")
 ,("target platform string","x86_64-apple-darwin")
 ,("target os","OSDarwin")
 ,("target arch","ArchX86_64")
 ,("target word size","8")
 ,("target word big endian","NO")
 ,("target has GNU nonexec stack","NO")
 ,("target has .ident directive","YES")
 ,("target has subsections via symbols","YES")
 ,("target has RTS linker","YES")
 ,("Unregisterised","NO")
 ,("LLVM target","x86_64-apple-darwin")
 ,("LLVM llc command","llc")
 ,("LLVM opt command","opt")
 ,("LLVM clang command","clang")
 ,("Use interpreter","YES")
 ,("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","NO")
 ,("RTS expects libdw","NO")
 ,("Project version","9.2.2")
 ,("Project Git commit id","fbaee70d380973f71fa6e9e15be746532e5a4fc5")
 ,("Booter version","8.10.7")
 ,("Stage","2")
 ,("Build platform","x86_64-apple-darwin")
 ,("Host platform","x86_64-apple-darwin")
 ,("Target platform","x86_64-apple-darwin")
 ,("Have interpreter","YES")
 ,("Object splitting supported","NO")
 ,("Have native code generator","YES")
 ,("Target default backend","NCG")
 ,("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")
 ,("GHC Dynamic","YES")
 ,("GHC Profiled","NO")
 ,("Debug on","NO")
 ,("LibDir","/Users/romes/.ghcup/ghc/9.2.2/lib/ghc-9.2.2/lib")
 ,("Global Package DB","/Users/romes/.ghcup/ghc/9.2.2/lib/ghc-9.2.2/lib/package.conf.d")
 ]
Edited by Rodrigo Mesquita
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information