-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Move computation of allocator shim contents to cg_ssa #147526
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
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred in tests/ui/sanitizer cc @rcvalle Some changes occurred in compiler/rustc_codegen_ssa |
rustbot has assigned @petrochenkov. Use |
cc @anforowicz if this gets merged, https://source.chromium.org/chromium/chromium/src/+/main:build/rust/allocator/lib.rs;l=99-107 would need to be removed to avoid a symbol conflict as the definition gets moved from the allocator shim to libstd. cc @jdonszelmann as I believe this will help a bit with externally implementable items. |
This comment has been minimized.
This comment has been minimized.
Currently it is possible to avoid linking the allocator shim when __rust_no_alloc_shim_is_unstable_v2 is defined when linking rlibs directly as some build systems need. However this requires liballoc to be compiled with --cfg no_global_oom_handling, which places huge restrictions on what functions you can call and makes it impossible to use libstd. Or alternatively you have to define __rust_alloc_error_handler and (when using libstd) __rust_alloc_error_handler_should_panic using #[rustc_std_internal_symbol]. With this commit you can either use libstd and define __rust_alloc_error_handler_should_panic or not use libstd and use #[alloc_error_handler] instead. Both options are still unstable though. Eventually the alloc_error_handler may either be removed entirely (though the PR for that has been stale for years now) or we may start using weak symbols for it instead. For the latter case this commit is a prerequisite anyway.
In the future this should make it easier to use weak symbols for the allocator shim on platforms that properly support weak symbols. And it would allow reusing the allocator shim code for handling default implementations of the upcoming externally implementable items feature on platforms that don't properly support weak symbols.
I pushed a fix for the miri failures, but it only shows up at https://github.com/bjorn3/rust/tree/alloc_shim_weak_shape, not on this PR. |
98c96d6
to
614496e
Compare
The Miri subtree was changed cc @rust-lang/miri |
2684fab
to
98c96d6
Compare
In the future this should make it easier to use weak symbols for the allocator shim on platforms that properly support weak symbols. And it would allow reusing the allocator shim code for handling default implementations of the upcoming externally implementable items feature on platforms that don't properly support weak symbols.
In addition to make this possible, the alloc error handler is now handled in a way such that it is possible to avoid using the allocator shim when liballoc is compiled without
no_global_oom_handling
if you use#[alloc_error_handler]
. Previously this was only possible if you avoided liballoc entirely or compiled it withno_global_oom_handling
. You still need to avoid libstd and to define the symbol that indicates that avoiding the allocator shim is unstable.