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

ghc_wrapper is killed on MacOS arm64 running tests under rules_haskell_tests #2101

Open
cgrindel opened this issue Jan 4, 2024 · 6 comments

Comments

@cgrindel
Copy link
Contributor

cgrindel commented Jan 4, 2024

Describe the bug

The ghc_wrapper is killed when executing bazel test //... in rules_haskell_tests on MacBook Pro (M2 Pro).

ERROR: /Users/chuckgrindel/code/tweag/rules_haskell/cg/macos_arm64/rules_haskell_tests/tests/haddock/BUILD.bazel:18:16: HaskellBuildLibrary @//tests/haddock:haddock-lib-a failed: (Killed): ghc_wrapper failed: error executing command (from target //tests/haddock:haddock-lib-a) bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/rules_haskell/haskell/ghc_wrapper bazel-out/darwin_arm64-fastbuild/bin/tests/haddock/compile_flags_haddock-lib-a__HaskellBuildLibrary ... (remaining 1 argument skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
ld: warning: -single_module is obsolete
/var/folders/5q/_th2byd13h11mxtnvm5ck9_40000gq/T/ghc90734_0/libghc_7.dylib.resign: replacing existing signature
/Applications/Xcode-15.1.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /var/folders/5q/_th2byd13h11mxtnvm5ck9_40000gq/T/ghc90734_0/libghc_7.dylib
bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/rules_haskell/haskell/ghc_wrapper: line 80: 90734 Killed: 9               "${compile_flags[@]}" "${extra_args[@]}" 2>&1
     90736 Done                    | drop_loaded_and_warning 1>&2

To Reproduce

Change into rules_haskell_tests.

cd rules_haskell_tests

Create .bazelrc.local file.

build --config=macos-bindist

Build and test.

 BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 bazel test //...

Expected behavior

Success.

Environment

  • OS name + version: MacOS 14.2.1 (23C71)
  • Bazel version: 6.4.0
  • Version of the rules: 0.18

Additional context

Messages found in MacOS Console

CODE SIGNING: cs_invalid_page(0x100318000): p=90734[ghc-9.2.8] final status 0x23020200, denying page sending SIGKILL

CODE SIGNING: process 90734[ghc-9.2.8]: rejecting invalid page at address 0x100318000 from offset 0x0 in file "/private/var/folders/5q/_th2byd13h11mxtnvm5ck9_40000gq/T/ghc90734_0/libghc_7.dylib" (cs_mtime:1704409989.686403126 == mtime:1704409989.686403126) (signed:1 validated:1 tainted:1 nx:0 wpmapped:0 dirty:0 depth:0)

ghc-9.2.8[90734] Corpse allowed 1 of 5

Possible related to input-output-hk/haskell.nix#2018.

@aherrmann
Copy link
Member

Looking at the error message, the relevant code is probably here:

# Resign the binary after patching it.
# This is necessary on MacOS Monterey on M1.
# The moving back and forth is necessary because the OS caches the signature.
# See this note from nixpkgs for reference:
# https://github.com/NixOS/nixpkgs/blob/5855ff74f511423e3e2646248598b3ffff229223/pkgs/os-specific/darwin/signing-utils/utils.sh#L1-L6
os.rename(output, f"{output}.resign")
subprocess.check_call([CODESIGN] + ["-f", "-s", "-"] + [f"{output}.resign"])
os.rename(f"{output}.resign", output)

@avdv
Copy link
Member

avdv commented Feb 2, 2024

I tracked this down to how the darwinCC in rules_nixpkgs_cc is constructed: tools from different toolchains are mixed (stdenv.cc and darwin.cctools based on llvm) and this seems to cause trouble.

See tweag/rules_nixpkgs#479

avdv added a commit to tweag/rules_nixpkgs that referenced this issue Feb 2, 2024
…nking

On aarch64 Darwin, when using a nixpkgs provided cc toolchain, we have [seen][1]
the linking step to fail as the process got killed:

```
bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/rules_haskell/haskell/ghc_wrapper: line 80: 90734 Killed: 9
               "${compile_flags[@]}" "${extra_args[@]}" 2>&1
     90736 Done                    | drop_loaded_and_warning 1>&2
```

More specifically this happened when trying to add an rpath to a dylib calling the `install_name_tool`, but
running the same command manually succeeded.

This seems to be caused by mixing different tools from stdenv.cc and darwin.cctools, especially the fact that
the tools from the latter overwrote tools from the former.

Only add missing tools not provided by the current cc toolchain from the darwin.cctools package instead.

[1]: tweag/rules_haskell#2101
@cgrindel
Copy link
Contributor Author

cgrindel commented Feb 2, 2024

@avdv Good find. Can we close this issue or do you think that there is more work to do here?

@avdv
Copy link
Member

avdv commented Feb 5, 2024

Can we close this issue or do you think that there is more work to do here?

@cgrindel Maybe we should upgrade rules_nixpkgs to a revision that has this fix? WDYT?

@cgrindel
Copy link
Contributor Author

cgrindel commented Feb 5, 2024

That is a good idea. Should we create a separate issue to track?

@avdv
Copy link
Member

avdv commented Feb 8, 2024

That is a good idea. Should we create a separate issue to track?

👍 done: #2119

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

No branches or pull requests

3 participants