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

haskell.compiler.*: don't declare stage0 ghc as dep to stdenv #343988

Merged

Conversation

sternenseemann
Copy link
Member

Some GHC bindists have a normal $out/lib directory which contains symlinks to all core libs. Because it is a normal lib directory, the bintools setup hook will pick up on it and cause ld to pass the appropriate -L and -rpath flags. We do not want this to happen, especially in the case of the stage2 compiler. Not only will the final ghc have an unnecessary reference (and thus increased closure size) to the binary ghc, but the extra libraries in the rpath mess with the rts and cause e.g. segfaults in GHCi.

Unfortunately, there is no way to prevent this. It is a fundamental flaw in the cc and bintools wrappers that they do not actually distinguish between the roles of dependencies (build, host, target). Instead the mangleVar* function will translate the dependencies split up by roles into platforms. This means that the wrappers can't distinguish between depsBuildBuild and depsHostTarget (== buildInputs) when natively compiling. As long as we are natively compiling the wrappers will put the stage0 ghc (be it in depsBuildBuild, nativeBuildInputs etc.) into the linker flags of the final ghc.

The solution is to sidestep the issue. We just had ghc in depsBuildBuild to have it added to PATH. GHC itself will pass the appropriate linker flags if necessary. To avoid the setup hooks picking up on the GHC libraries we just don't put it into depsBuildBuild or any other dependency list. Since the GHC build system accepts the GHC binary via an absolute path, we don't even need to add the stage0 GHC to PATH.

Description of changes

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

Some GHC bindists have a normal `$out/lib` directory which contains
symlinks to all core libs. Because it is a normal lib directory, the
bintools setup hook will pick up on it and cause ld to pass the
appropriate -L and -rpath flags. We do not want this to happen,
especially in the case of the stage2 compiler. Not only will the final
ghc have an unnecessary reference (and thus increased closure size) to
the binary ghc, but the extra libraries in the rpath mess with the rts
and cause e.g. segfaults in GHCi.

Unfortunately, there is no way to prevent this. It is a fundamental flaw
in the cc and bintools wrappers that they do not actually distinguish
between the roles of dependencies (build, host, target). Instead
the mangleVar* function will translate the dependencies split up by
roles into platforms. This means that the wrappers can't distinguish
between depsBuildBuild and depsHostTarget (== buildInputs) when natively
compiling. As long as we are natively compiling the wrappers will put
the stage0 ghc (be it in depsBuildBuild, nativeBuildInputs etc.) into
the linker flags of the final ghc.

The solution is to sidestep the issue. We just had ghc in depsBuildBuild
to have it added to PATH. GHC itself will pass the appropriate linker
flags if necessary. To avoid the setup hooks picking up on the GHC
libraries we just don't put it into depsBuildBuild or any other
dependency list. Since the GHC build system accepts the GHC binary via
an absolute path, we don't even need to add the stage0 GHC to PATH.
This seems to be a build time only dependency as there is no
corresponding settings entry.
Ideally we don't want to use bintools.bintools and also not really
encode knowledge of what is wrapped and what not in our GHC derivation.
Unfortunately, not all tools are part of the wrapper derivation as well.
This should be gradually improved (e.g. in the case of the darwin tools
and strip).
@sternenseemann sternenseemann merged commit 5b15a1f into NixOS:haskell-updates Sep 23, 2024
8 of 9 checks passed
@sternenseemann sternenseemann deleted the ghc-no-ghc-lib-link branch September 23, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant