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

Add '--allowed-rpath-prefixes' option to '--shrink-rpath' … #98

Merged
merged 2 commits into from
Sep 1, 2016

Conversation

dezgeg
Copy link
Contributor

@dezgeg dezgeg commented Jun 3, 2016

Fixes #97. In essence, the problem is that some packages in Nixpkgs have
RPATHs pointing to both $NIX_BUILD_TOP and $out, e.g.:

/tmp/nix-build-openldap-2.4.44.drv-0/openldap-2.4.44/libraries/libldap_r/.libs
/tmp/nix-build-openldap-2.4.44.drv-0/openldap-2.4.44/libraries/liblber/.libs
/nix/store/bfkmdxmv3a3f0g3d2q8jkdz2wam93c5z-openldap-2.4.44/lib
/nix/store/bfkmdxmv3a3f0g3d2q8jkdz2wam93c5z-openldap-2.4.44/lib64

Currently, running patchelf --shrink-rpath does the wrong thing by
keeping the /tmp/ paths and deleting the /nix/store ones. Now we can fix
the problem by using

patchelf --shrink-rpath --allowed-rpath-prefixes $NIX_STORE_DIR

in the Nixpkgs fixupPhase instead.


I haven't yet tested the Nixpkgs part and whether this really fixes it, but hopefully will soon.

We're going to need this logic in another place, so make a function of
this.
Fixes NixOS#97. In essence, the problem is that some packages in Nixpkgs have
RPATHs pointing to both $NIX_BUILD_TOP and $out, e.g.:

/tmp/nix-build-openldap-2.4.44.drv-0/openldap-2.4.44/libraries/libldap_r/.libs
/tmp/nix-build-openldap-2.4.44.drv-0/openldap-2.4.44/libraries/liblber/.libs
/nix/store/bfkmdxmv3a3f0g3d2q8jkdz2wam93c5z-openldap-2.4.44/lib
/nix/store/bfkmdxmv3a3f0g3d2q8jkdz2wam93c5z-openldap-2.4.44/lib64

Currently, running `patchelf --shrink-rpath` does the wrong thing by
keeping the /tmp/ paths and deleting the /nix/store ones. Now we can fix
the problem by using

patchelf --shrink-rpath --allowed-rpath-prefixes $NIX_STORE_DIR

in the Nixpkgs fixupPhase instead.
@domenkozar
Copy link
Member

Nice, this looks like it could prevent some of the issues we had in the past. cc @edolstra

}

static bool hasAllowedPrefix(const string & s, const vector<string> & allowedPrefixes){
for (vector<string>::const_iterator it = allowedPrefixes.begin(); it != allowedPrefixes.end(); ++it) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> for (auto & it : allowedPrefixes).

@edolstra edolstra merged commit 9d2f4a1 into NixOS:master Sep 1, 2016
dezgeg added a commit to NixOS/nixpkgs that referenced this pull request Sep 14, 2017
dezgeg added a commit to NixOS/nixpkgs that referenced this pull request Sep 14, 2017
@timokau
Copy link
Member

timokau commented Mar 29, 2018

Is there any reason this was never used in the patchelf shell-hook? It sounds like it was implemented for that purpose.

Edit: When I tried to use it (patchelf --shrink-rpath --allowed-rpath-prefixes /nix/store binary) I got stat: No such file or directory.

@dtzWill
Copy link
Member

dtzWill commented Mar 30, 2018

Is there any reason this was never used in the patchelf shell-hook? It sounds like it was implemented for that purpose.

Not sure. I know we do scan the output for references to the build path, but that's not quite the same.

Edit: When I tried to use it (patchelf --shrink-rpath --allowed-rpath-prefixes /nix/store binary) I got stat: No such file or directory.

Try using patchelf built from this repo or patchelfUnstable from Nixpkgs-- the normal patchelf is version 0.9 (from Feb 26, 2016-- before this PR was merged).

So maybe it was never used because no new release of patchelf was made?

@timokau
Copy link
Member

timokau commented Mar 30, 2018

Not sure. I know we do scan the output for references to the build path, but that's not quite the same.

Yeah I think this PR was intended to fix those issues detected by the scanning (or at least some of them).

Try using patchelf built from this repo or patchelfUnstable from Nixpkgs-- the normal patchelf is version 0.9 (from Feb 26, 2016-- before this PR was merged).

Oh that makes sense, I just kinda assumed it was already in the release because the PR is so long ago. I guess patchelf is "feature complete" enough not to warrant regular releases.
I've worked around it for now by deleting the /build libraries, but it'd be nicer to have an automated, generalized fix for this of course.

Maybe cutting a new patchelf release would be a good idea?

So maybe it was never used because no new release of patchelf was made?

Makes sense.

@vcunat
Copy link
Member

vcunat commented Aug 6, 2023

So perhaps we can apply this in nixpkgs after all those years?
NixOS/nixpkgs#247478

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