-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
glibc: add NIX_LD_LIBRARY_PATH #31263
Conversation
I think this should target the |
@7c6f434c Yeah, it will result in a total rebuild of everything. This PR should have no conflicts with |
I have zero idea about how GitHub PR UI works this week, but in general it would be a good idea if this change was targeted towards `staging`.
I guess closing/re-opening is the simplest way (given there is no substantial discussion in this PR yet)
|
@yegortimoshenko Perhaps #29064 can be dealt in similar way? |
DL_SYSDEP_OSCHECK (_dl_fatal_printf); | ||
#endif | ||
|
||
+ char *nix_library_path = getenv ("NIX_LD_LIBRARY_PATH"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt that you can call getenv()
here without causing a security vulnerability in setuid programs but rather secure_getenv
or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dezgeg Fixed, see unsecvars.h
patch.
d4b552c
to
c269b3e
Compare
@gnidorah Yeah, we can definitely do the same thing with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, I thought of doing it in this way (concat strings) when I looked at this myself but decided that it would look too hacky. It seems not so when I look at it now ;)
+ strcpy (combined_library_path, library_path); | ||
+ | ||
+ if (strlen (library_path) > 0) | ||
+ strcat (combined_library_path, ":"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better to just set a character here to avoid O(n)? Save strlen(library_path)
and do combined_library_path[len] = ':'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combined_library_path
should end with NUL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course but you could do [len + 1] = '\0'
. My point is that we want to avoid as much overhead as possible because this code executes with /any/ new process in the entire OS. However I'm not adamant on those -- if others think it's negligible let's merge, I see no other problems with that.
+ if (strlen (library_path) > 0) | ||
+ strcat (combined_library_path, ":"); | ||
+ | ||
+ strcat (combined_library_path, nix_library_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strcpy(combined_library_path + len + (conditional) 1, nix_library_path)
would be more effective.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer this code to be as straightforward as possible :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
+ char *combined_library_path; | ||
+ | ||
+ if (nix_library_path) { | ||
+ combined_library_path = malloc (strlen (library_path) + strlen (nix_library_path) + 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compute library_path
length once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, good catch!
I expect tomorrow I'll be combining staging with glibc updates (fixing vulnerabilities). We might catch those together, if this PR seems OK-ish by the time I do it. |
c269b3e
to
c55304c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me. NIX_SSL_CERT_FILE
is the precedent of course. I wish we could have the proper return status, but I'll take your word that it would take a big ugly patch to do so.
If I understand glibc and the patch correctly, this applies for shared glibc but not for static one ( |
I don't really understand the motivation for this. If the problem is to allow some proprietary games to find libGL, then can't you do that by mounting /usr/lib/libGL.so in the mount namespace? Adding a lot of ad hoc |
Such additions are a bit risky. I personally currently can't see a better way around the use cases when you have a mix of binaries from nix and others (e.g. running on a non-nixos host). There it's common to have interferences due to one of those two groups wanting to override libs (like nixpkgs for opengl) and negatively affecting the others. Another thing is, that on 2.26 #28622 this gets us:
(not counting a trivial merge conflict in sysdeps/generic/unsecvars.h) I also tried to address some other nitpicks in https://github.com/vcunat/nixpkgs/commits/p/glibc-NIX_LD but not this linking error. Well, let me leave this open for now. |
@vcunat Do you plan to apply this patch to glibc 2.26? If so, I can rebase it on glibc 2.26 and resolve this. I also had patched @edolstra This is not only for games, or proprietary software; see #31136 (comment): avrdude is GPL'd. Quite a few games on Steam are open-source, too. This is essentially to make Nix composable with other package managers (PlatformIO, Steam): some of the software they distribute presumes that What is really ugly here is mutability of environment variables. If |
@yegortimoshenko: glibc-2.26 is in staging now. There are some security fixes in there, so I don't want to delay it. You can utilize my branch (it used merge instead of rebase). |
@yegortimoshenko: no, there's a much more complex situation. Maybe the libcapsule approach at the end, if combined with libglvnd and maybe some extra hacks. |
Yeah, we already do just that -- override
Yeah, that's definitely a case which we don't want to support.
Note: this is a non-existent case outside of FHS environments, otherwise agreed.
If by "environment" you mean installed stuff in Overall that's pretty much what I believed we are going to do. I have half-finished branch moving us to |
@oxij Please steal everything you want from |
@guibou Ok!
@abbradar I implemented it, it works :) See https://github.com/oxij/nixpkgs/commits/glibc/ld-fallback
I decided to name the variable `LD_FALLBACK_PATH` because it's a generic thing.
The only issue I currently see is that `ldd` doesn't recognize the effect of `LD_FALLBACK_PATH` and reports `libGL.so` missing in my tests (everything else works, however). But maybe this should be considered a feature and not a bug (because those libraries are missing in some sense). Not yet sure.
|
@oxij Cool! |
Are there any updates on this pull request, please? |
Is this still in progress? I'm seeing this error:
It's the same error mentioned here and here |
I'm going to take a stab at rebasing this patch against the latest glibc. |
My `glibc/ld-fallback` branch mentioned above works without any changes (just cherry-pick that commit, it still applies cleanly) and without the caveats of this implementation has, as discussed above, though.
So, if we are to merge something like this without upstreaming the patch, then I think my implementation should be chosen over this, if only for the fact that it is not Nix-specific and can, in principle, be upstreamed (given somebody puts a bunch of effort to make `ldd` respect `LD_FALLBACK` variable; which, btw, IIRC is also a caveat here).
|
@oxij can you create a PR? |
Just adding a note here that I'm fairly certain this would solve issues we're having with SteamVR+Proton: #71554 |
Why create an entirely new fallback mechanism if we can just use the one which is already built into ld-linux? I think this is what #59595 tries to do. |
@DavHau I guess for every upstream mechanism there is some package making assumptions about it in a way that is inconvenient for Nixpkgs… |
I marked this as stale due to inactivity. → More info |
Fun fact in https://github.com/Mic92/nix-ld I also introduced NIX_LD_LIBRARY_PATH. |
I marked this as stale due to inactivity. → More info |
I PRed my glibc patch at #248547. |
Motivation for this change
Will eventually lead to fix of #21109. Related: #31182 (comment).
To test this, replace
glibc
with path to glibc built with this patch and paste this into terminal (provided that you havenix-shell
andpatchelf
on path):If you see a progress bar, then it works. It should also correctly handle case where some libraries are on
LD_LIBRARY_PATH
and others are onNIX_LD_LIBRARY_PATH
, and case whenLD_LIBRARY_PATH
is empty butNIX_LD_LIBRARY_PATH
is not./cc @abbradar
Things done
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)