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

Before testing if libraries link, do a vanilla run to check if the compiler is misconfigured #4395

Open
ezyang opened this Issue Mar 14, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@ezyang
Copy link
Contributor

ezyang commented Mar 14, 2017

@angerman was reporting on IRC that Cabal couldn't find iconv, but everything seemed like it was in order. When he posted -v3 logs, the true error came to light:

/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/14587779232007237709.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/8235644401115438165 '-D__GLASGOW_HASKELL__=803' '-Ddarwin_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' -Idist-install/build/autogen -I/Users/angerman/tmp/libiconv-1.15/include -Iinclude -I. -I/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -I/Users/angerman/Projects/Haskell/obsidian/ghc/includes -I/Users/angerman/Projects/Haskell/obsidian/ghc/includes/dist-derivedconstants/header -liconv -L/Users/angerman/tmp/libiconv-1.15/lib/.libs -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/integer-simple/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/ghc-prim/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -Wall -fno-stack-protector -Wno-unknown-pragmas
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang
returned ExitFailure 1 with error message:
clang: error: invalid linker name in argument '-fuse-ld=gold'
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/178448449274243042.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/1148079871137522503 -liconv -L/Users/angerman/tmp/libiconv-1.15/lib/.libs -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/integer-simple/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/ghc-prim/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -Wall -fno-stack-protector -Wno-unknown-pragmas
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang
returned ExitFailure 1 with error message:
clang: error: invalid linker name in argument '-fuse-ld=gold'
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/144128232716531729.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/823378840143542612 -liconv -L/Users/angerman/tmp/libiconv-1.15/lib/.libs -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/integer-simple/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/ghc-prim/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -Wall -fno-stack-protector -Wno-unknown-pragmas
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang
returned ExitFailure 1 with error message:
clang: error: invalid linker name in argument '-fuse-ld=gold'
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/8965443031474833169.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/12648177091998097157 -c '-D__GLASGOW_HASKELL__=803' '-Ddarwin_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' -Idist-install/build/autogen -I/Users/angerman/tmp/libiconv-1.15/include -Iinclude -I. -I/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -I/Users/angerman/Projects/Haskell/obsidian/ghc/includes -I/Users/angerman/Projects/Haskell/obsidian/ghc/includes/dist-derivedconstants/header -Wall -fno-stack-protector -Wno-unknown-pragmas
ghc-cabal: Missing dependency on a foreign library:
* Missing C library: iconv
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
make[1]: *** [libraries/base/dist-install/package-data.mk] Error 1
make: *** [all] Error 2

The failure of clang had nothing to do with linking iconv: rather, it was failing because of clang: error: invalid linker name in argument '-fuse-ld=gold'.

The way to solve this problem is, before we test if any of the libraries fail the linker, FIRST check if we can build a vanilla C file at all. If we can't, that means that there's something wrong with the options: output the error message verbatim.

There's a few other lessons too:

  1. Even after the failure, Cabal goes off and tries to compile the headers. This caused me to take more time to diagnose the problem, because the true "failure" was further up the scrollback. We should error more quickly.

  2. The error message should suggest running at higher verbosity to see the error message the compiler output, or just unconditionally report the actual error that caused the problem. None of this cloak and dagger "I ran something but I'm not going to tell you what I did, neener-neener."

Also, can we finally get keep-tmp-files for Cabal? This thing where the temporary files disappear before I can look at them is really annoying.

@23Skidoo

This comment has been minimized.

Copy link
Member

23Skidoo commented Mar 14, 2017

@ezyang

This comment has been minimized.

Copy link
Contributor Author

ezyang commented Mar 14, 2017

Doesn't do you much good if you don't plumb it where necessary ;)

withTempFile :: FilePath    -- ^ Temp dir to create the file in
                -> String   -- ^ File name template. See 'openTempFile'.
                -> (FilePath -> Handle -> IO a) -> IO a
withTempFile tmpDir template action =
  withTempFileEx defaultTempFileOptions tmpDir template action
@23Skidoo

This comment has been minimized.

Copy link
Member

23Skidoo commented Mar 14, 2017

That's a backwards compat shim for Custom setups. I suppose we could deprecate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment