-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
libstd.dylib always depends on liballoc_jemalloc (and libpanic_unwind) #43637
Comments
Looking at all this feature flag stuff, I get more and more confused. For example, libstd does |
Cc @oli-obk |
I pushed some experiments with the feature flags to https://github.com/RalfJung/rust/tree/force_alloc_system (diff: rust-lang:eae446c...RalfJung:2b4b3f0). Note that I have no idea what I am doing here. But anyway, with that patch, xargo can actually successfully build libstd with the Xargo.toml given above. EDIT: However, cross-compilation still requires a C compiler due to compiler_builtins. :/ |
cc @aidanhs |
Another victim of the tantalising feature name of Setting the lib and exe default allocator crates in a target specification may have some relevance. #43524 (cc @vorner) is a recent issue talking about something similar. Failing that, there is a bug related to builds without jemalloc (fixed at some point by #43589), but that only affects stage0 builds. I've never used xargo, but a quick grep indicates that it implicitly does a stage0 compilation, so you could try applying that patch and see what happens. I'm not yet sure how the allocator crate specs and the patch above will interact, but I'm sure it will be exciting to find out. I have no idea about compiler builtins unfortunately. Possibly a question to ask on the xargo repo, as they might have more experience. |
I know. I read your other post about it. I just wanted to see whether we can build upon it. We'll retry without |
@oli-obk ah sorry, since jemalloc broke I've said this in a lot of places so I've forgotten who it's been said to. Apart from anything else though, it's actually a no-op right now because it was removed in the global allocator PR - my patch would make it actually do something again. |
I see. That may explain some things, but it does not explain where the magic dependencies come from -- compiling libstd literally has rustc look for liballoc_jemalloc and panic_unwind even though there is no "extern crate". However, why should libstd be forced to depend on jemalloc on stage1+? |
How is that determined? I started at the rustc calls that are actually run in the end, but they don't seem to specify a stage. Thinking about it, probably there are environment variables as well... makes me wonder how I could see what these look like. |
Related #37975 |
@eddyb helped with the magic dependencies, and it turns out the reason is that libstd is built as a dylib which requires it to get a panic and allocation library, which is how these additional dependencies appear. |
I tried to fix this by making building libstd as dylib optional (from what I understand, that shouldn't usually be needed for xargo use cases?), but I am not able to change the crate type depending on a feature. I can set the crate type inside lib.rs and then using
|
@RalfJung Ahh my bad, I guess you can't do it like this, because |
Sorry, my comment sounds way more authoritative than I actually felt. I was basing it on https://github.com/japaric/xargo/blob/b67abf8c1ad5e129618117715a10acf8aacadf6d/src/sysroot.rs#L298-L307 which appears to pick 0 by default, but a more careful examination doesn't show this being used anywhere. My mistake! |
The stage1 libstd.rlib and libstd.so are built by different compilers?!? Okay THAT is unexpected. But anyway the main reason libstd needs an allocator dependency is that it is a dylib, not just an rlib, and that's the source of my confusion. Ideally there would be a way to compile it as rlib-only. However, beyond that, it does seem reasonable to me to be able to configure which allocator and panic handler is used by the dylib. For the panic handler, that can already be controlled via Cargo.toml |
I don't think that's what @aidanhs is saying, I think you can |
I guess I misunderstood these two:
I thought rlibs included libstd.rlib. Seems it does not. |
@RalfJung |
Ah, these are xargo stages that have nothing to do with bootstrap stages. See https://github.com/japaric/xargo#multi-stage-builds for more information. |
If I understood things correctly, the problem here is the following:
Please correct me if this is wrong. Based on this, the ideal solution for me seems to be to provide some way for libstd.dylib to control its allocator independent of the target default, and without affecting the libstd.rlib. Is it possible to make the items of a crate different for the rlib and dylib version of the crate, respectively? If not, the problem outlined above would be a limitation affecting all crates that are both rlib and dylib. (I suppose that's a rare combination.) I don't expect this to be possible, but who knows. ;) |
This is a pretty old issue and fundamentally isn't really solvable in isolation, so I'm going to close this in favor of #36963 which we can probably do on the nearer horizon. |
I am trying to use xargo to build a libstd without jemalloc. (That should enable cross-compiling libstd without cross-compiling any C code.)
I have the following Xargo.toml:
Now
xargo build -v
shows:This shows that the correct feature flags are passed to rustc. However, for some reason, rustc behaves as if libstd contained
extern crate alloc_jemalloc
, which it does not. Is there magic going on here that adds alloc_jemalloc nevertheless? I did some grepping of the code but found nothing.(EDIT: There seems to be similar magic behavior for panic_unwind.)
If somehow it is not possible to get rid of this magic "link against liballoc_jemalloc", then (a)
libstd/Cargo.toml
should be changed to reflect this fact by always depending on liballoc_jemalloc, and (b) I hope there's a chance we can get a feature flag on liballoc_jemalloc itself to enable "dummy_jemalloc" mode (currently controlled by build.rs), and have libstd set that flag when force_alloc_system is set.The text was updated successfully, but these errors were encountered: