NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.79k stars 13.9k forks source link

bap: Error loading z3ml on darwin #272953

Open gmacon opened 10 months ago

gmacon commented 10 months ago

Describe the bug

The bap tool is failing to load libz3.dylib because it doesn't exist.

Steps To Reproduce

Steps to reproduce the behavior:

On a darwin machine:

nix build github:NixOS/nixpkgs/ec750fd01963ab6b20ee1f0cb488754e8036d89d#ocamlPackages.bap
./result/bin/bap .
echo $?

(That's the commit of nixpkgs that's pinned in my project's flake.lock, but git says there were no changes to the bap derivation between that commit and master.)

Expected behavior

bap prints nothing and exits successfully

Screenshots

Here's what happens for me:

$ nix build github:NixOS/nixpkgs/ec750fd01963ab6b20ee1f0cb488754e8036d89d#ocamlPackages.bap
$ ./result/bin/bap .
Failed to load plugin "primus-symbolic-executor": Failed to load z3ml: error loading shared library: Dynlink.Error (Dynlink.Cannot_open_dll "Failure(\"dlopen(/var/folders/m9/hhy3f7td5y7_0try7slr3czr001dz5/T/z3ml953701.cmxs, 0x000A): Library not loaded: '/nix/store/h2p3jkzblpb2sqdxgd11yww7dldgb243-z3-4.8.17-ocaml/lib/ocaml/4.14.1/site-lib/stublibs/libz3.dylib'\\n  Referenced from: '/private/var/folders/m9/hhy3f7td5y7_0try7slr3czr001dz5/T/z3ml953701.cmxs'\\n  Reason: tried: '/nix/store/h2p3jkzblpb2sqdxgd11yww7dldgb243-z3-4.8.17-ocaml/lib/ocaml/4.14.1/site-lib/stublibs/libz3.dylib' (no such file), '/usr/local/lib/libz3.dylib' (no such file), '/usr/lib/libz3.dylib' (no such file)\")")
Failed to load 1 plugins, details follow:
The plugin `/nix/store/l6sjrwiqkx6sjw23hjz6dpa6kx1j8in6-ocaml4.14.1-bap-2.5.0/lib/bap/primus_symbolic_executor.plugin' has failed with the following error:
Failed to load z3ml: error loading shared library: Dynlink.Error (Dynlink.Cannot_open_dll "Failure(\"dlopen(/var/folders/m9/hhy3f7td5y7_0try7slr3czr001dz5/T/z3ml953701.cmxs, 0x000A): Library not loaded: '/nix/store/h2p3jkzblpb2sqdxgd11yww7dldgb243-z3-4.8.17-ocaml/lib/ocaml/4.14.1/site-lib/stublibs/libz3.dylib'\\n  Referenced from: '/private/var/folders/m9/hhy3f7td5y7_0try7slr3czr001dz5/T/z3ml953701.cmxs'\\n  Reason: tried: '/nix/store/h2p3jkzblpb2sqdxgd11yww7dldgb243-z3-4.8.17-ocaml/lib/ocaml/4.14.1/site-lib/stublibs/libz3.dylib' (no such file), '/usr/local/lib/libz3.dylib' (no such file), '/usr/lib/libz3.dylib' (no such file)\")")

$ echo $?
1

Additional context

$ ls -l /nix/store/h2p3jkzblpb2sqdxgd11yww7dldgb243-z3-4.8.17-ocaml/lib/ocaml/4.14.1/site-lib/stublibs
.r-xr-xr-x 426k root 31 Dec  1969 dllz3ml.so
.r--r--r--    3 root 31 Dec  1969 dllz3ml.so.owner

I think the presence of the .so file there is suspicious.

I tried overriding the derivation to add the fixDarwinDylibNames hook, but that didn't fix the problem.

I also mentioned this problem on Matrix but didn't get any responses there.

Notify maintainers

@maurer

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-darwin"`
 - host os: `Darwin 21.6.0, macOS 10.16`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.18.1`
 - channels(gmacon3): `"nixpkgs-22.11-darwin"`
 - channels(root): `"nixpkgs-23.05-darwin"`
 - nixpkgs: `/Users/gmacon3/.nix-defexpr/channels/nixpkgs`

Add a :+1: reaction to issues you find important.

gmacon commented 9 months ago

I thought I would try my hand at bisecting this today, but I was unable to find a good commit. This suggests either

  1. this has never worked on darwin, or
  2. something about how macOS works has changed, causing the breakage.