-
Notifications
You must be signed in to change notification settings - Fork 667
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 a feature + cfg attribute to exclude GNU extension functions #1116
Comments
What C library are you using? musl? newlib? something else? The correct solution would be to guard such functions with a |
Thanks a bunch for the quick response! Oh, that's interesting... I just read up about target_env, that sounds like the right solution, and I believe should be sufficient for my needs. Let me know if this fix is something this will be addressed by you/one of the other nix devs, or something I should be contributing a patch for. I am following up about the exact libc we use (I'm not overly familiar with that part of our build system and so am waiting to hear back from others about this. I will post here as soon as I find out) |
Please submit a PR. Nix thrives on the contributions of our users. |
Ah, so apparently we do use glibc, its just that we don't allow binaries that make calls to GNU_SOURCE functions... This actually means, that the target_env solution may not be enough to exclude the GNU specific functions. While it would be ideal to add Question - Would you be willing to accept a PR if I add both |
… GNU function wrappers are included more selectively
…y include GNU function wrappers
I still don't understand exactly what your problem is. If the C library is missing a function that Nix wraps, that shouldn't be a problem. It happens all the time, in fact, because libc and Nix define functions newly added on recent OS versions, but still compile and test on older versions. I just checked, and it wasn't a problem to add a bogus |
Ah, so sorry for the confusion... I think I finally got to the bottom of this. I believe you are completely right... I just did the same test of a bogus extern C and wrapping it. This results in a few undefined symbols in the resulting binary. While this is not an error by itself, we have additional build checks in our project that mark any missing symbols as an error causing build breaks on our side... So definitely my bad with the earlier description... I think the amended description looks something like this - We are linking against a version of glibc without the GNU extension functions. Thus the presence of calls to Please let me know if this makes sense... With regards to use of nix in our codebase, I think this sort of leaves us in the same place as before... I'm wondering if it would be reasonable to accept a feature flag to exclude such gnu source functions? This would allow us to use upstream nix as is, instead of a having to maintain a fork with this one extra patch. |
No, we wouldn't accept such a patch. When using Rust with FFI, missing symbols are the norm. You need to fix your build infrastructure. |
Alright, thanks for the info. |
Hi, I'd like to ask that this bug be reopened, possibly with the title modified.
The issue runs thusly: the Firefox build infrastructure builds against an older version of glibc to ensure the broadest possible compatibility for official Firefox releases ( Just because the You might say that |
But as I explained earlier, I can add complete bogus |
Possibly compiling with
They are not defined in the libc we are linking against, as I explained earlier. |
Sorry; there are two different things named "libc". I meant they would still be defined in rust-lang/libc, which you must link against too. |
So a missing extern C function doesn't cause issues with respect to missing symbols... But the nix wrapper that calls such a function does result in missing symbols in the binary... Hence rust/libc is not an issue here |
It's possible that we don't have a new enough version of |
@froydnj libc never makes syscalls directly; it always calls the system's C library (except when the symbol in question is a macro, in which case rust-lang/libc must reimplement it). And you most certainly have a sufficiently recent version of libc, because Nix would pull it in. I understand your problem, but your proposed solution is far too narrow. C libraries add new symbols all the time. Even POSIX adds new functions, and glibc doesn't adopt them all at once. If Nix were to adopt your feature flag, it would probably only work for a narrow range of glibc versions. If Nix were a C library, it would solve this problem with something like autoconf and a bunch of |
I agree that the proposed solution in the patches upthread is far too narrow. A more widely applicable solution would be for
Our position is that we'd like our software to run on the widest range of machines as is feasible. We'd prefer to be told about problems with that goal at build time rather than after our users download the software.
To what end? |
Are you talking about ELF symbol versioning, or something that glibc does with the preprocessor? I didn't think that glibc made use of ELF symbol versioning.
To see if anybody else has run into the same problem. Nix is far from the only crate that calls native C functions, and you may not be the only person concerned with missing symbols. |
I am talking about ELF symbol versioning. glibc is the motivating example for porting over SunOS/Solaris's symbol versioning feature, cf https://www.akkadia.org/drepper/symbol-versioning. |
I didn't think that glibc used it. FreeBSD does, and that causes other problems with rust-lang/libc. Do you have an idea for how libc (or other FFI projects) could use ELF symbol versioning more intelligently? |
I didn't realize that it was already a problem for
and then annotating each symbol that needs it with the appropriate feature check ("glibc_2_22", etc.). That's a lot of clutter, though. |
No, that's not ELF symbol versioning. ELF symbol versioning is how a library can contain multiple versions of the same symbol. For example, |
glibc uses exactly the same mechanism as FreeBSD, as the paper above suggests. You have, for
And glibc also has multiple versions of the same symbol, using
As for supporting multiple versions of the same symbol, I'm not sure what a good solution looks like. I can see a crate with features for each of |
I don't think there's any reason for a Rust crate to export multiple versions of the same symbol, unless it's a crate that's normally built as a shared library. The problem is that a Rust crate may need to link to a C crate that does export multiple versions, and right now there's no way to select which one to use except "always use the oldest supported symbol version". Here's a longer discussion. |
Hi,
I was wondering if it would be possible to add a feature flag and the appropriate cfg calls to separate POSIX functions from the GNU specific extensions (usable when _GNU_SOURCE is defined).
My use case is as follows. I am using some packages (lucet) that have a dependency on the nix packages. While I'm using these packages in a Linux system, we are linking against libraries without the GNU extension functions... Thus the presence of calls to
process_vm_writev
,process_vm_readv
andsetns
is causing problems. Additionally, it seems that the nix wrappers for these functions cannot be eliminated by dead code removal, and so persist in the final library, resulting in missing symbol errors.Currently, it seems that these functions are protected only with
#[cfg(any(target_os = "linux"))]
. Thus the easiest workaround that comes to mind is to pretend that target_os is not linux, but this feels hacky at best... I was wondering if it would be possible to add a new feature flag which we can set at compile time, that would exclude these GNU specific functions...(also, I apologize if I got some details wrong... I'm still quite new to rust :) )
Please let me know... If required, I am also happy to contribute a patch for the same...
The text was updated successfully, but these errors were encountered: