ld Assertion failed: (target->definition() != ld::Atom::definitionProxy) while building Haskell project

Hi,

What could be causing this on Monterey (M1 Max)? How to debug further? Reproduction steps filed in https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/301

0  0x104768224  __assert_rtn + 128
1  0x10476e4e8  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  0x1046b0b98  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  0x1046a3544  ld::tool::OutputFile::generateLinkEditInfo(ld::Internal&) + 1188
4  0x10469da90  ld::tool::OutputFile::write(ld::Internal&) + 140
5  0x10462b1d8  main + 584
A linker snapshot was created at:
	/tmp/libHSfuturice-integrations-0-inplace-ghc8.10.7.dylib-2022-00-08-222023.ld-snapshot
ld: Assertion failed: (target->definition() != ld::Atom::definitionProxy), function addChainedFixupLocation, file OutputFile.cpp, line 5903.
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
`clang' failed in phase `Linker'. (Exit code: 1)

Replies

You’ve clearly tripped an assertion within the linker. That is, by definition, a bug in the linker [1], and I’d appreciate you filing it as such. You’ll get more traction if you attach the build artefacts required to reproduce the problem (that is, all the .o files) because I don’t think our linker engineers have Haskell installed (-: Oh, and the assertion references a file, /tmp/libHSfuturice-integrations-0-inplace-ghc8.10.7.dylib-2022-00-08-222023.ld-snapshot, that’s likely to be helpful.

Please post your bug number, just for the record.

The backtrace you posted suggests that this is related to chained fixups, a new feature that’s on by default on modern systems. I know that you’re running the linker an Apple silicon, but are you also building for Apple silicon? Or are you building for Intel on Apple silicon?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Even if GHC is doing something wrong, the linker should print a nice diagnostic rather than crash.

Thanks! Filed feedback with the output and /tmp/...ld-snapshot contents. Bug number is 9839914.

Yes, building for Apple silicon on Apple silicon.

$ ghc --info
 ,("target platform string","aarch64-apple-darwin")
 ,("target os","OSDarwin")
 ,("target arch","ArchAArch64")
 ,("LLVM target","arm64-apple-darwin")
 ,("Build platform","aarch64-apple-darwin")
 ,("Host platform","aarch64-apple-darwin")
 ,("Target platform","aarch64-apple-darwin")

Bug number is FB9839914.

Thanks.

Yes, building for Apple silicon on Apple silicon.

OK.

Given that, I have one suggestion that might lead to a short-term workaround. If you set your deployment target to macOS 11 (currently I suspect it’s defaulting to macOS 12), does that help? You can do this using the -macos_version_min option, documented in the ld man page.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I tried -optl-mmacosx-version-min=11.0 and MACOSX_DEPLOYMENT_TARGET=11.0 which both resulted in many warnings like ld: warning: dylib (/opt/homebrew/lib/libpq.dylib) was built for newer macOS version (12.0) than being linked (11.0) followed by the same ld assertion failure.

Yeah, that’s a challenge. Homebrew builds from source and always sets the deployment target to the current system version, and the linker gets grumpy if you try to mix deployment targets (and rightly so!).

You could try building your dependencies on macOS 11, then copying them across to macOS 12, then re-running this test. Honestly though, I’m not sure it’s worth the effort going further down this path because…


I got some preliminary feedback on your bug report. Earlier I wrote:

Even if GHC is doing something wrong, the linker should print a nice diagnostic rather than crash.

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. You should get the details via official channels soon. If you don’t hear from our bugs folks by this time next week, drop me a line via email (my email address is in my signature; also, make sure to reference this thread ’cause I get way too much email :-).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"