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

Unable to build with ghc-9.2.3 on macOS #348

Closed
alt-romes opened this issue Jul 10, 2022 · 9 comments
Closed

Unable to build with ghc-9.2.3 on macOS #348

alt-romes opened this issue Jul 10, 2022 · 9 comments

Comments

@alt-romes
Copy link

alt-romes commented Jul 10, 2022

Hey, I think I haven't been able to build any package that depends on primitive because of a linker error.

I've just tried to do a build from scratch of primitive using ghc-9.2.3, macOS 12.4 Intel, with the result below
Unfortunately I don't know how to troubleshoot linker errors here, but I'd be happy to help try to fix this if you have some pointers.

Build profile: -w ghc-9.2.3 -O1
In order, the following will be built (use -v for more details):
 - primitive-0.7.4.0 (lib) (first run)
Configuring library for primitive-0.7.4.0..
Preprocessing library for primitive-0.7.4.0..
Building library for primitive-0.7.4.0..
[ 1 of 13] Compiling Control.Monad.Primitive ( Control/Monad/Primitive.hs, .../primitive/dist-newstyle/build/x86_64-osx/ghc-9.2.3/primitive-0.7.4.0/build/Control/Monad/Primitive.o, .../primitive/dist-newstyle/build/x86_64-osx/ghc-9.2.3/primitive-0.7.4.0/build/Control/Monad/Primitive.dyn_o )
[ 2 of 13] Compiling Data.Primitive.Array ( Data/Primitive/Array.hs, .../primitive/dist-newstyle/build/x86_64-osx/ghc-9.2.3/primitive-0.7.4.0/build/Data/Primitive/Array.o, .../primitive/dist-newstyle/build/x86_64-osx/ghc-9.2.3/primitive-0.7.4.0/build/Data/Primitive/Array.dyn_o )
[ 3 of 13] Compiling Data.Primitive.MVar ( Data/Primitive/MVar.hs, .../primitive/dist-newstyle/build/x86_64-osx/ghc-9.2.3/primitive-0.7.4.0/build/Data/Primitive/MVar.o, .../primitive/dist-newstyle/build/x86_64-osx/ghc-9.2.3/primitive-0.7.4.0/build/Data/Primitive/MVar.dyn_o )
[ 4 of 13] Compiling Data.Primitive.MachDeps ( Data/Primitive/MachDeps.hs, .../primitive/dist-newstyle/build/x86_64-osx/ghc-9.2.3/primitive-0.7.4.0/build/Data/Primitive/MachDeps.o, .../primitive/dist-newstyle/build/x86_64-osx/ghc-9.2.3/primitive-0.7.4.0/build/Data/Primitive/MachDeps.dyn_o )
[ 5 of 13] Compiling Data.Primitive.Internal.Operations ( Data/Primitive/Internal/Operations.hs, .../primitive/dist-newstyle/build/x86_64-osx/ghc-9.2.3/primitive-0.7.4.0/build/Data/Primitive/Internal/Operations.o, .../primitive/dist-newstyle/build/x86_64-osx/ghc-9.2.3/primitive-0.7.4.0/build/Data/Primitive/Internal/Operations.dyn_o )
ld.lld: error: /var/folders/8m/hh324vyn7svdt_7lpmlfghg40000gn/T/ghc14729_0/ghc_51.o: unknown file type
`ld.lld' failed in phase `Merge objects'. (Exit code: 1)
@chessai
Copy link
Member

chessai commented Jul 10, 2022

Are you able to share a link to the codebase you're trying to build? Are you building with cabal, nix, or stack? What operating system are you using?

cc @bgamari in case this is a bug

@alt-romes
Copy link
Author

alt-romes commented Jul 10, 2022

I did it as straightforward as I could before reporting it (see below).
I have, however, come across it multiple times when compiling other packages too.
The codebase I'm building is primitive itself :-)

On macOS 12.4 Intel:

git clone https://github.com/haskell/primitive && cd primitive
cabal build

and then got that output

I'm pretty sure I've previously attempted deleting all cabal/store/ghc-version to try and fix it when building other things, with no effect; though I can try once again if you really think it might make a difference in finding the issue.

I guess I should also cabal build with debug flags: which ones?

EDIT: I might add, I am also unable to compile with ghc-9.2.2, though ghc-9.0.2 works.

Thanks :)

@chessai
Copy link
Member

chessai commented Jul 10, 2022

cabal clean
cabal build -v3

Maybe this could glean a bit more information

@alt-romes
Copy link
Author

alt-romes commented Jul 10, 2022

Maybe this could glean a bit more information

Unfortunately doesn't seem to buy us much

[ 5 of 13] Compiling Data.Primitive.Internal.Operations ( Data/Primitive/Internal/Operations.hs, /Users/romes/projects/primitive/dist-newstyle/build/x86_64-osx/ghc-9.2.3/primitive-0.7.4.0/build/Data/Primitive/Internal/Operations.o, /Users/romes/projects/primitive/dist-newstyle/build/x86_64-osx/ghc-9.2.3/primitive-0.7.4.0/build/Data/Primitive/Internal/Operations.dyn_o )
ld.lld: error: /var/folders/8m/hh324vyn7svdt_7lpmlfghg40000gn/T/ghc21323_0/ghc_51.o: unknown file type
`ld.lld' failed in phase `Merge objects'. (Exit code: 1)

and there's this warning before which I don't think should be too relevant

Searching for strip in path.
Found strip at /usr/bin/strip
/usr/bin/strip --version
/usr/bin/strip returned ExitFailure 1 with error message:
error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip:
unrecognized option: --version
Usage:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip
[-AnuSXx] [-] [-d filename] [-s filename] [-R filename] [-o output] file [...]
Warning: cannot determine version of /usr/bin/strip :
""

Edit: full output @ https://pastebin.mozilla.org/THLoQxJx/slim

@chessai
Copy link
Member

chessai commented Jul 10, 2022

Instead of interpreting and splitting up the output into chunks, it's always preferable to paste the full, uninterrupted output

@andrewthad
Copy link
Collaborator

From the error logs:

Searching for strip in path.
Found strip at /usr/bin/strip
/usr/bin/strip --version
/usr/bin/strip returned ExitFailure 1 with error message:
error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip:
unrecognized option: --version
Usage:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip
[-AnuSXx] [-] [-d filename] [-s filename] [-R filename] [-o output] file [...]
Warning: cannot determine version of /usr/bin/strip :

I've not sure if this is a problem with OSX or a problem with @alt-romes's specific set up. On Ubuntu, I can run:

cabal unpack primitive-0.7.4.0
cd primitive-0.7.4.0
cabal build

And it works fine. I'd like to know if another OSX user is able to reproduce this issue.

@alt-romes alt-romes changed the title Unable to build with ghc-9.2.3 Unable to build with ghc-9.2.3 on macOS Jul 11, 2022
@qua3k
Copy link

qua3k commented Jul 16, 2022

Hi, I just ran into this today. I reproduced with both LLVM@14 and LLVM@12 from Homebrew. This is also on M1 ARM.

user@MacBook ~ % cabal install vector       
Resolving dependencies...
Build profile: -w ghc-9.2.2 -O1
In order, the following will be built (use -v for more details):
 - primitive-0.7.4.0 (lib) (requires build)
 - vector-0.13.0.0 (lib) (requires build)
Starting     primitive-0.7.4.0 (lib)
Building     primitive-0.7.4.0 (lib)

Failed to build primitive-0.7.4.0.
Build log ( /Users/user/.cabal/logs/ghc-9.2.2/prmtv-0.7.4.0-4f8a5dbe.log ):
Configuring library for primitive-0.7.4.0..
Preprocessing library for primitive-0.7.4.0..
Building library for primitive-0.7.4.0..
[ 1 of 12] Compiling Control.Monad.Primitive ( Control/Monad/Primitive.hs, dist/build/Control/Monad/Primitive.o, dist/build/Control/Monad/Primitive.dyn_o )
[ 2 of 12] Compiling Data.Primitive.Array ( Data/Primitive/Array.hs, dist/build/Data/Primitive/Array.o, dist/build/Data/Primitive/Array.dyn_o )
[ 3 of 12] Compiling Data.Primitive.MVar ( Data/Primitive/MVar.hs, dist/build/Data/Primitive/MVar.o, dist/build/Data/Primitive/MVar.dyn_o )
[ 4 of 12] Compiling Data.Primitive.MachDeps ( Data/Primitive/MachDeps.hs, dist/build/Data/Primitive/MachDeps.o, dist/build/Data/Primitive/MachDeps.dyn_o )
[ 5 of 12] Compiling Data.Primitive.Internal.Operations ( Data/Primitive/Internal/Operations.hs, dist/build/Data/Primitive/Internal/Operations.o, dist/build/Data/Primitive/Internal/Operations.dyn_o )
ld.lld: error: /var/folders/0c/smkz_9457_71qqm2bvrm1vgw0000gn/T/ghc6699_0/ghc_49.o: unknown file type
`ld.lld' failed in phase `Merge objects'. (Exit code: 1)
cabal: Failed to build primitive-0.7.4.0 (which is required by
vector-0.13.0.0). See the build log above for details.

Some more logs

user@MacBook Internal % ghc Operations.hs ../MachDeps.hs -optlm --verbose       
[2 of 2] Compiling Data.Primitive.Internal.Operations ( Operations.hs, Operations.o )
ld.lld: /var/folders/0c/smkz_9457_71qqm2bvrm1vgw0000gn/T/ghc29570_0/ghc_12.ldscript
ld.lld: /var/folders/0c/smkz_9457_71qqm2bvrm1vgw0000gn/T/ghc29570_0/ghc_11.o
ld.lld: error: /var/folders/0c/smkz_9457_71qqm2bvrm1vgw0000gn/T/ghc29570_0/ghc_11.o: unknown file type
`ld.lld' failed in phase `Merge objects'. (Exit code: 1)

Attempting to use GNU ld yields

[2 of 2] Compiling Data.Primitive.Internal.Operations ( Operations.hs, Operations.o )
ld: warning: platform not specified
ld: warning: -arch not specified
ld: warning: No platform min-version specified on command line
ld: warning: ignoring file /var/folders/0c/smkz_9457_71qqm2bvrm1vgw0000gn/T/ghc30007_0/ghc_12.ldscript, building for -unknown but attempting to link with file built for unknown-unsupported file format ( 0x49 0x4E 0x50 0x55 0x54 0x28 0x22 0x2F 0x76 0x61 0x72 0x2F 0x66 0x6F 0x6C 0x64 )
Undefined symbols for architecture unknown:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture unknown
`ld' failed in phase `Merge objects'. (Exit code: 1)

@qua3k
Copy link

qua3k commented Jul 16, 2022

I've managed to successfully build with ghc versions <9.2, so there may have been problems porting, although this seems like a compiler bug...

@alt-romes
Copy link
Author

alt-romes commented Jul 18, 2022

I've opened an issue in GHC for this. It's already tracked and the problem is described here https://gitlab.haskell.org/ghc/ghc/-/issues/21570#note_436198

As a temporary workaround, one might uninstall GHC with ghcup, making sure LLVM isn't in $PATH, and then re-installing GHC with ghcup.

Afterwards LLVM can be put back into $PATH if desired

Further discussion on the GHC issue tracker.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants