commercialhaskell / stack

The Haskell Tool Stack

Home Page:http://haskellstack.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GHC 8.4.3 on macos will generate linker error

WenjunHuang opened this issue · comments

When I use "stack ghc something.hs" on macos,ghc will generate the following linker error:
ld64.lld: warning: ignoring unknown argument: --gc-sections
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -search_paths_first
ld64.lld: warning: -sdk_version is required when emitting min version load command. Setting sdk version to match provided min version
Cannot open text.o: bad relocation (Invalid pointer diff) in section __TEXT/__text (r1_address=160, r1_type=5, r1_extern=1, r1_length=3, r1_pcrel=0, r1_symbolnum=19), (r2_address=160, r2_type=0, r2_extern=1, r2_length=3, r2_pcrel=0, r2_symbolnum=13)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gcc' failed in phase Linker'. (Exit code: 1)

I found that the problem may be caused by the settings.After copy the settings from homebrew ghc installations,the problem disappear.
[("GCC extra via C opts", " -fwrapv -fno-builtin"),
("C compiler command", "clang"),
("C compiler flags", " -fno-stack-protector"),
("C compiler link flags", " "),
("C compiler supports -no-pie", "YES"),
("Haskell CPP command","clang"),
("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"),
("ar command", "ar"),
("ar flags", "qcls"),
("ar supports at file", "NO"),
("ranlib command", "ranlib"),
("touch command", "touch"),
("dllwrap command", "/bin/false"),
("windres command", "/bin/false"),
("libtool command", "libtool"),
("perl command", "/usr/local/bin/perl"),
("cross compiling", "NO"),
("target os", "OSDarwin"),
("target arch", "ArchX86_64"),
("target word size", "8"),
("target has GNU nonexec stack", "False"),
("target has .ident directive", "True"),
("target has subsections via symbols", "True"),
("target has RTS linker", "YES"),
("Unregisterised", "NO"),
("LLVM llc command", "llc"),
("LLVM opt command", "opt"),
("LLVM clang command", "clang")
]

I have encountered the same problem. Plus, with resolver: nightly-2018-10-24, stack produces the same error with GHC 8.6.1.

And yes, the error disappeared after I copied settings file from homebrew-installed one.
The diff was like this:

 [("GCC extra via C opts", " -fwrapv -fno-builtin"),
- ("C compiler command", "gcc"),
+ ("C compiler command", "clang"),
  ("C compiler flags", " -fno-stack-protector"),
- ("C compiler link flags", " -fuse-ld=lld"),
- ("C compiler supports -no-pie", "NO"),
- ("Haskell CPP command","gcc"),
+ ("C compiler link flags", " "),
+ ("C compiler supports -no-pie", "YES"),
+ ("Haskell CPP command","clang"),
  ("Haskell CPP flags","-E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs"),
- ("ld command", "ld.lld"),
+ ("ld command", "ld"),
  ("ld flags", ""),
- ("ld supports compact unwind", "NO"),
+ ("ld supports compact unwind", "YES"),
  ("ld supports build-id", "NO"),
- ("ld supports filelist", "NO"),
- ("ld is GNU ld", "YES"),
+ ("ld supports filelist", "YES"),
+ ("ld is GNU ld", "NO"),
  ("ar command", "ar"),
  ("ar flags", "qcls"),
  ("ar supports at file", "NO"),
- ("ranlib command", ""),
+ ("ranlib command", "ranlib"),
  ("touch command", "touch"),
  ("dllwrap command", "/bin/false"),
  ("windres command", "/bin/false"),

I believe #4366 addresses this. Would you try the workaround there?

facing the same issue, uninstalling llvm (and excluding it's binaries from the PATH) doesn't help:

Linking /Users/vyorkin/.stack/setup-exe-cache/x86_64-osx/tmp-Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.2 ...
clang: error: invalid linker name in argument '-fuse-ld=lld'
`gcc' failed in phase `Linker'. (Exit code: 1)

(macOS)

looks like it needs a different gcc version (not clang?)
idk where to start looking
if I remove -fuse-ld=lld in settings

(~/.stack/programs/x86_64-osx/ghc-*/lib/ghc-*/settings),

it complains about ld: unknown option: --gc-sections

UPD: resolved by removing ~/.stack and reinstalling stack

Closing as it seems original issue was addressed with FAQ entry

I am encountering same issue on macOS 10.14.1 . I did already remove ~/.stack and retried. Same error. For the referenced "workaround" it is unclear why that has not been incorporated into the codebase. I am completely new to haskell and my intro has been hours of dealing with scary linker issues - and reinstalling stack every which way in the book.

What is actually meant by the settings? There are multiple files and I'm not sure which one to update .

OK for other haskell newbies: the "settings" referred to from #4373 (comment) above is here:
~/.stack/programs/x86_64-osx/ghc-8.8.3/lib/ghc-8.8.3/settings

For convenience here is the entire updated settings file with the diff applied

[("GCC extra via C opts", " -fwrapv -fno-builtin"),
 ("C compiler command", "clang"),
 ("C compiler flags", ""),
 ("C compiler link flags", " "),
 ("C compiler supports -no-pie", "YES"),
 ("Haskell CPP command","clang"),
 ("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"),
 ("ar command", "ar"),
 ("ar flags", "qcls"),
 ("ar supports at file", "NO"),
 ("ranlib command", "ranlib"),
 ("touch command", "touch"),
 ("dllwrap command", "/bin/false"),
 ("windres command", "/bin/false"),
 ("libtool command", "libtool"),
 ("perl command", "/usr/bin/perl"),
 ("cross compiling", "NO"),
 ("target os", "OSDarwin"),
 ("target arch", "ArchX86_64"),
 ("target word size", "8"),
 ("target has GNU nonexec stack", "False"),
 ("target has .ident directive", "True"),
 ("target has subsections via symbols", "True"),
 ("target has RTS linker", "YES"),
 ("Unregisterised", "NO"),
 ("LLVM llc command", "llc"),
 ("LLVM opt command", "opt"),
 ("LLVM clang command", "clang")
 ]

There is one followup: given my co-worker on macOS did not encounter this issue - then are there specific gcc configuration options that are known to allow that linker to work? I had installed it this way:

  brew install gcc --enable-cxx --enable-fortran --use-llvm

Thanks @javadba! I'm also a newbie (albeit months later than you!) and your comments helped me!

And thanks @bonotake for that diff!

And yes, the error disappeared after I copied settings file from homebrew-installed one. The diff was like this:

 [("GCC extra via C opts", " -fwrapv -fno-builtin"),
- ("C compiler command", "gcc"),
+ ("C compiler command", "clang"),
  ("C compiler flags", " -fno-stack-protector"),
- ("C compiler link flags", " -fuse-ld=lld"),
- ("C compiler supports -no-pie", "NO"),
- ("Haskell CPP command","gcc"),
+ ("C compiler link flags", " "),
+ ("C compiler supports -no-pie", "YES"),
+ ("Haskell CPP command","clang"),
  ("Haskell CPP flags","-E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs"),
- ("ld command", "ld.lld"),
+ ("ld command", "ld"),
  ("ld flags", ""),
- ("ld supports compact unwind", "NO"),
+ ("ld supports compact unwind", "YES"),
  ("ld supports build-id", "NO"),
- ("ld supports filelist", "NO"),
- ("ld is GNU ld", "YES"),
+ ("ld supports filelist", "YES"),
+ ("ld is GNU ld", "NO"),
  ("ar command", "ar"),
  ("ar flags", "qcls"),
  ("ar supports at file", "NO"),
- ("ranlib command", ""),
+ ("ranlib command", "ranlib"),
  ("touch command", "touch"),
  ("dllwrap command", "/bin/false"),
  ("windres command", "/bin/false"),

where is this file?

~/
❯ which stack
/usr/local/bin/stack

~/
❯

@geofflangenderfer , based on #4373 (comment), the 'settings' being discussed are part of GHC (not Stack, as such) in its subdirectory /lib/ghc-x.y.z/settings (where x.y.z is the GHC version). The Stack-supplied versions of GHC are in Stack's 'programs' directory (eg at stack path --programs).