Skip to content

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Oct 9, 2025

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 with no_global_oom_handling. You still need to avoid libstd and to define the symbol that indicates that avoiding the allocator shim is unstable.

@rustbot
Copy link
Collaborator

rustbot commented Oct 9, 2025

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred in tests/ui/sanitizer

cc @rcvalle

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 9, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 9, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@bjorn3
Copy link
Member Author

bjorn3 commented Oct 9, 2025

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.

@rust-log-analyzer

This comment has been minimized.

bjorn3 added 3 commits October 9, 2025 14:53
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.
@bjorn3
Copy link
Member Author

bjorn3 commented Oct 9, 2025

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.

@bjorn3 bjorn3 force-pushed the alloc_shim_weak_shape branch from 98c96d6 to 614496e Compare October 9, 2025 15:29
@rustbot
Copy link
Collaborator

rustbot commented Oct 9, 2025

The Miri subtree was changed

cc @rust-lang/miri

@bjorn3 bjorn3 force-pushed the alloc_shim_weak_shape branch from 2684fab to 98c96d6 Compare October 9, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants