-
Notifications
You must be signed in to change notification settings - Fork 689
Add #[inline] to memfd_create to delay codegen and prevent undefined symbols in dylibs #2049
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
Conversation
Are there plans to merge this MR? I've also hit this issue and would appreciate this change being merged. |
No, because I still think it's the wrong solution. As described in the issue, I think it's a linker problem, and we need somebody to explore the linker more. |
I agree with you, when |
Wait, rustc itself is consuming Nix? That's surprising. It seems like a dependency loop situation. I thought that rustc had very few external dependencies. |
I am trying to add this crate to the compiler's list of third-party dependencies. This crate is a dependency of I don't think it's quite accurate to say that the compiler has very few external dependencies. It certainly does not have a lot and dependencies are added rather carefully, but everyone who works on the compiler and the core tooling have done a lot of work to enable people to build a robust package ecosystem, so it doesn't really make sense to deprive ourselves of the fruits of our labor. There's no dependency loop, for the same reason that we can write the Rust compiler in Rust. The new compiler will depend on |
My use case is similar to the one mentioned in the ticket. I'm building a static library in Rust that exposes C bindings for downstream C/C++ libraries to use. The consumers of my library build on CentOS7 with glibc 2.17, which causes a linking failure when using my library due to the missing I would say this is more of a portability issue than a linker issue. Using the |
This bug makes a little more sense if it only affects cdylib projects.
Do you mean glibc 2.27? |
I still don't like hacking Nix to workaround a glibc bug. But looking closer, I realize that |
This is not a glibc bug. We are both targeting CentOS 7, which predates |
I agree that (but if you're willing to do a little compatability break to fix a mistake, don't let me of all people discourage you) |
Yeah, but new syscalls get added all the time. Why is this the only one that causes linker failures? |
Unfortunately moving I can get around this issue in other ways, so if this MR doesn't get merged it's not a huge deal for me. |
The Rust standard library handles use of new system calls by using a combination of weak linkage and |
I mean that new syscalls get added to Nix all the time. For example, I can build a cdylib that uses Nix with the "fs" feature, which enables the |
You must pass the linker flag |
How do you pass that linker flag? For me, the following program builds fine as a cdylib on both FreeBSD and Linux. Can you cause it to fail with that flag? mod ffi {
extern "C" {
pub fn does_not_exist() -> libc::c_int;
}
}
pub extern "C" fn foo() -> i32 {
unsafe { ffi::does_not_exist() }
} |
This does not appear to be true when actually linking the final binary using that shared library with missing symbols (on both my nixos and the debian So "undefined symbol in shared library" is an error by default with no linker configs involved. Here's a repro: rust-lang/rust#111769 (comment) |
Oooh, it's "dylib" crates that you're worried about. I thought it was "cdylib". Now that I try using a dylib I can reproduce the problem. But I like the |
…d --no-allow-shlib-undefined
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.
LGTM, assuming CI passes.
I think this is related to #1972
I want this because I'm trying to use
ctrlc
in the compiler (rust-lang/rust#111769), which uses this crate, and the feature set thatctrlc
uses pulls in this function.The compiler is primarily built as a shared object, and it is linked against an old version of glibc (2.17) so there is no
memfd_create
symbol available when it is built. Adding#[inline]
causes this function to be codegenned differently; it is kept as MIR then since it is in fact dead, we never actually codegen it. Without#[inline]
this function is eagerly codegenned then since dylibs have poor/no dead code elimination, we end up with an undefined symbol.