Skip to content

macOS Sierra and Haskell "malformed mach-o: load commands size" #22810

@Dridus

Description

@Dridus

Issue description

The (at this point infamous) load commands size problem still occurs on nixpkgs even after the GHC 8.0.2 / LTS 8.0 update.

I'll try to summarize the underlying issue, but please be aware I'm not an expert and am just stitching together things from other issues. Please correct me if the details are wrong.

This issue is due to a change in macOS's linker in Sierra which limits the mach-O linker load commands to 32768 bytes. Those load commands are dominated by RPATH entries and nix exacerbates the issue greatly by having a ton of long named directories, around one per dependency.

In GHC (https://ghc.haskell.org/trac/ghc/ticket/12479), Stack (commercialhaskell/stack#2577), and Cabal (haskell/cabal#3955, haskell/cabal#3982, et al) it looks like it was resolved by carefully managing the location of dylibs to all be located in the same place so that only one RPATH needed emitting (https://ghc.haskell.org/trac/ghc/ticket/12479#comment:42, probably others).

I could imagine a similar solution could be cooked up by generic-builder and with-package-wrapper to create a lib directory for each haskell derivation to build that has symlinks for each transient dependency, but I'm really quite new to all this so I haven't attempted it yet.

Steps to reproduce

nix-build stack-a5b8d468.nix with stack-a5b8d468.nix:

let
  bootstrap = import <nixpkgs> {};
  pkgsSrc = bootstrap.fetchFromGitHub {
    owner = "NixOS";
    repo = "nixpkgs";
    rev = "a5b8d468a504e0eedcda71de1694201806fb921d";
    sha256 = "0alh9v12nyxsdlssg72k892zdzzc15wr8fqy8qpq9rc282bpx7xm";
  };
  pkgs = import pkgsSrc {};
in
  pkgs.stack

On my system yields:

…
[ 10 of 121] Compiling System.Process.Read ( src/System/Process/Read.hs, dist/build/System/Process/Read.o )

<no location info>: error:
    ghc: panic! (the 'impossible' happened)
  (GHC version 8.0.2 for x86_64-apple-darwin):
	Loading temp shared object failed: dlopen(/private/var/folders/4b/7smbp2kj7m770r24jxxfwr700000gn/T/nix-build-stack-1.3.2.drv-0/ghc46406_0/libghc_135.dylib, 5): no suitable image found.  Did find:
	/private/var/folders/4b/7smbp2kj7m770r24jxxfwr700000gn/T/nix-build-stack-1.3.2.drv-0/ghc46406_0/libghc_135.dylib: malformed mach-o: load commands size (41792) > 32768

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
…

stack-a5b8d468.txt

Technical details

  • System: macOS Sierra 10.12.3
  • Nix version: nix-env (Nix) 1.11.4
  • Nixpkgs version: a5b8d46

Metadata

Metadata

Assignees

Labels

0.kind: bugSomething is broken6.topic: darwinRunning or building packages on Darwin6.topic: haskellGeneral-purpose, statically typed, purely functional programming language

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions