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

auto-patchelf: doesn't use existing RPATHs from executables #392940

Open
3 tasks done
corngood opened this issue Mar 25, 2025 · 2 comments
Open
3 tasks done

auto-patchelf: doesn't use existing RPATHs from executables #392940

corngood opened this issue Mar 25, 2025 · 2 comments
Labels
0.kind: bug Something is broken

Comments

@corngood
Copy link
Contributor

Nixpkgs version

  • Unstable (25.05)

Describe the bug

According to auto-patchelf --help:

  --ignore-existing     Do not add the existing rpaths of the patched files to the list of directories to search for
                        dependencies.

This option was added in 62b6336 (Cc: @Pandapip1)

This implies that the existing RPATHs of patched files will be searched for dependencies. However, populate_cache limits itself to *.so*, so the RPATH of executables without an extension always ignored.

Steps to reproduce

$ nix build --impure --expr 'with import ./. {}; stdenvNoCC.mkDerivation { name = "test"; nativeBuildInputs = [ autoPatchelfHook ]; unpackPhase = ":"; installPhase = "install -Dm 755 ${perl}/bin/perl $out/bin/perl"; }'
error: builder for '/nix/store/qrvzl3fv0i2saaivfkyppjx93hya4jsc-test.drv' failed with exit code 1;
       last 25 log lines:
       >           PosixPath('/nix/store/h9lc1dpi14z7is86ffhl3ld569138595-audit-tmpdir.sh/lib'),
       >           PosixPath('/nix/store/m54bmrhj6fqz8nds5zcj97w9s9bckc9v-compress-man-pages.sh/lib'),
       >           PosixPath('/nix/store/wgrbkkaldkrlrni33ccvm3b6vbxzb656-make-symlinks-relative.sh/lib'),
       >           PosixPath('/nix/store/5yzw0vhkyszf2d179m0qfkgxmp5wjjx4-move-docs.sh/lib'),
       >           PosixPath('/nix/store/fyaryjvghbkpfnsyw97hb3lyb37s1pd6-move-lib64.sh/lib'),
       >           PosixPath('/nix/store/kd4xwxjpjxi71jkm6ka0np72if9rm3y0-move-sbin.sh/lib'),
       >           PosixPath('/nix/store/pag6l61paj1dc9sv15l7bm5c17xn5kyk-move-systemd-user-units.sh/lib'),
       >           PosixPath('/nix/store/cmzya9irvxzlkh7lfy6i82gbp0saxqj3-multiple-outputs.sh/lib'),
       >           PosixPath('/nix/store/hxv896faph0rqxjq2ycxpcrbnngc95sz-patch-shebangs.sh/lib'),
       >           PosixPath('/nix/store/cickvswrvann041nqxb0rxilc46svw1n-prune-libtool-files.sh/lib'),
       >           PosixPath('/nix/store/xyff06pkhki3qy1ls77w10s0v79c9il0-reproducible-builds.sh/lib'),
       >           PosixPath('/nix/store/z7k98578dfzi6l3hsvbivzm7hfqlk0zc-set-source-date-epoch-to-latest.sh/lib'),
       >           PosixPath('/nix/store/pilsssjjdxvdphlg2h19p0bfx5q0jzkn-strip.sh/lib')],
       >  'paths': [PosixPath('/nix/store/fb94vsj0lyk5xqd5wb7450m32j047ia4-test')],
       >  'recursive': True,
       >  'runtime_dependencies': []}
       > setting interpreter of /nix/store/fb94vsj0lyk5xqd5wb7450m32j047ia4-test/bin/perl
       > searching for dependencies of /nix/store/fb94vsj0lyk5xqd5wb7450m32j047ia4-test/bin/perl
       >     libperl.so -> not found!
       >     libcrypt.so.2 -> not found!
       > auto-patchelf: 2 dependencies could not be satisfied
       > error: auto-patchelf could not satisfy dependency libperl.so wanted by /nix/store/fb94vsj0lyk5xqd5wb7450m32j047ia4-test/bin/perl
       > error: auto-patchelf could not satisfy dependency libcrypt.so.2 wanted by /nix/store/fb94vsj0lyk5xqd5wb7450m32j047ia4-test/bin/perl
       > auto-patchelf failed to find all the required dependencies.
       > Add the missing dependencies to --libs or use `--ignore-missing="foo.so.1 bar.so etc.so"`.
       For full logs, run 'nix log /nix/store/qrvzl3fv0i2saaivfkyppjx93hya4jsc-test.drv'.

Expected behaviour

auto-patchelf should leave an executable unchanged if it's RPATH satisfies all dependencies.

Screenshots

No response

Relevant log output

Additional context

No response

System metadata

  • system: "x86_64-linux"
  • host os: Linux 6.14.0-rc7, NixOS, 25.05 (Warbler), 25.05.20250319.a84ebe2
  • multi-user?: no
  • sandbox: yes
  • version: nix-env (Nix) 2.24.12
  • channels(root): ""
  • nixpkgs: not found

Notify maintainers


Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a 👍 reaction to issues you find important.

@corngood corngood added the 0.kind: bug Something is broken label Mar 25, 2025
@corngood
Copy link
Contributor Author

Note that changing the file extension in the test script causes it to work:

$ nix build --impure --expr 'with import ./. {}; stdenvNoCC.mkDerivation { name = "test"; nativeBuildInputs = [ autoPatchelfHook ]; unpackPhase = ":"; installPhase = "install -Dm 755 ${perl}/bin/perl $out/bin/perl.so"; }'

@corngood
Copy link
Contributor Author

Changing the glob in populate_cache to * does fix the problem, but I'm not sure if that's the right approach.

populate_cache currently does two things:

  • add all .so files being patched to the cache (so they are preferred)
    # Add all shared objects of the current output path to the cache,
    # before lib_dirs, so that they are chosen first in find_dependency.
  • recursively add all .so files in all rpaths to the cache

I'm not sure the latter is a good idea. Should we perhaps limit existing RPATHs to have an effect only on the ELF containing them?

populate_cache is also used on the lib dirs, where it probably does make sense to limit it to .so files, and to recurse (though maybe it should be optional?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

No branches or pull requests

1 participant