diff options
| author | bors <bors@rust-lang.org> | 2023-05-25 16:59:57 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-05-25 16:59:57 +0000 | 
| commit | a2b1646c597329d0a25efa3889b66650f65de1de (patch) | |
| tree | f09c5d967f915501387578d1d89574c68343eeb8 /compiler/rustc_builtin_macros | |
| parent | cade26637fe1c23965ce644299ed5200db7c92dd (diff) | |
| parent | 33d9b5880885862fdf4ec5bf70f45bf0e503a7fc (diff) | |
| download | rust-a2b1646c597329d0a25efa3889b66650f65de1de.tar.gz rust-a2b1646c597329d0a25efa3889b66650f65de1de.zip  | |
Auto merge of #86844 - bjorn3:global_alloc_improvements, r=pnkfelix
Support #[global_allocator] without the allocator shim This makes it possible to use liballoc/libstd in combination with `--emit obj` if you use `#[global_allocator]`. This is what rust-for-linux uses right now and systemd may use in the future. Currently they have to depend on the exact implementation of the allocator shim to create one themself as `--emit obj` doesn't create an allocator shim. Note that currently the allocator shim also defines the oom error handler, which is normally required too. Once `#![feature(default_alloc_error_handler)]` becomes the only option, this can be avoided. In addition when using only fallible allocator methods and either `--cfg no_global_oom_handling` for liballoc (like rust-for-linux) or `--gc-sections` no references to the oom error handler will exist. To avoid this feature being insta-stable, you will have to define `__rust_no_alloc_shim_is_unstable` to avoid linker errors. (Labeling this with both T-compiler and T-lang as it originally involved both an implementation detail and had an insta-stable user facing change. As noted above, the `__rust_no_alloc_shim_is_unstable` symbol requirement should prevent unintended dependence on this unstable feature.)
Diffstat (limited to 'compiler/rustc_builtin_macros')
| -rw-r--r-- | compiler/rustc_builtin_macros/src/global_allocator.rs | 8 | 
1 files changed, 3 insertions, 5 deletions
diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index 866cc5adbf3..f0d378d12f7 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -1,7 +1,7 @@ use crate::util::check_builtin_macro_attribute; use rustc_ast::expand::allocator::{ - AllocatorKind, AllocatorMethod, AllocatorTy, ALLOCATOR_METHODS, + global_fn_name, AllocatorMethod, AllocatorTy, ALLOCATOR_METHODS, }; use rustc_ast::ptr::P; use rustc_ast::{self as ast, AttrVec, Expr, FnHeader, FnSig, Generics, Param, StmtKind}; @@ -40,8 +40,7 @@ pub fn expand( // Generate a bunch of new items using the AllocFnFactory let span = ecx.with_def_site_ctxt(item.span); - let f = - AllocFnFactory { span, ty_span, kind: AllocatorKind::Global, global: item.ident, cx: ecx }; + let f = AllocFnFactory { span, ty_span, global: item.ident, cx: ecx }; // Generate item statements for the allocator methods. let stmts = ALLOCATOR_METHODS.iter().map(|method| f.allocator_fn(method)).collect(); @@ -63,7 +62,6 @@ pub fn expand( struct AllocFnFactory<'a, 'b> { span: Span, ty_span: Span, - kind: AllocatorKind, global: Ident, cx: &'b ExtCtxt<'a>, } @@ -92,7 +90,7 @@ impl AllocFnFactory<'_, '_> { })); let item = self.cx.item( self.span, - Ident::from_str_and_span(&self.kind.fn_name(method.name), self.span), + Ident::from_str_and_span(&global_fn_name(method.name), self.span), self.attrs(), kind, );  | 
