@@ -381,6 +381,7 @@ pub fn rust_oom(layout: Layout) -> ! {
381
381
#[ doc( hidden) ]
382
382
#[ allow( unused_attributes) ]
383
383
#[ unstable( feature = "alloc_internals" , issue = "none" ) ]
384
+ #[ cfg( not( bootstrap) ) ]
384
385
pub mod __default_lib_allocator {
385
386
use super :: { GlobalAlloc , Layout , System } ;
386
387
// These are used as a fallback for implementing the `__rust_alloc`, etc symbols
@@ -437,3 +438,54 @@ pub mod __default_lib_allocator {
437
438
}
438
439
}
439
440
}
441
+
442
+ #[ cfg( not( test) ) ]
443
+ #[ doc( hidden) ]
444
+ #[ allow( unused_attributes) ]
445
+ #[ unstable( feature = "alloc_internals" , issue = "none" ) ]
446
+ #[ cfg( bootstrap) ]
447
+ pub mod __default_lib_allocator {
448
+ use super :: { GlobalAlloc , Layout , System } ;
449
+
450
+ #[ rustc_std_internal_symbol]
451
+ pub unsafe extern "C" fn __rdl_alloc ( size : usize , align : usize ) -> * mut u8 {
452
+ // SAFETY: see the guarantees expected by `Layout::from_size_align` and
453
+ // `GlobalAlloc::alloc`.
454
+ unsafe {
455
+ let layout = Layout :: from_size_align_unchecked ( size, align) ;
456
+ System . alloc ( layout)
457
+ }
458
+ }
459
+
460
+ #[ rustc_std_internal_symbol]
461
+ pub unsafe extern "C" fn __rdl_dealloc ( ptr : * mut u8 , size : usize , align : usize ) {
462
+ // SAFETY: see the guarantees expected by `Layout::from_size_align` and
463
+ // `GlobalAlloc::dealloc`.
464
+ unsafe { System . dealloc ( ptr, Layout :: from_size_align_unchecked ( size, align) ) }
465
+ }
466
+
467
+ #[ rustc_std_internal_symbol]
468
+ pub unsafe extern "C" fn __rdl_realloc (
469
+ ptr : * mut u8 ,
470
+ old_size : usize ,
471
+ align : usize ,
472
+ new_size : usize ,
473
+ ) -> * mut u8 {
474
+ // SAFETY: see the guarantees expected by `Layout::from_size_align` and
475
+ // `GlobalAlloc::realloc`.
476
+ unsafe {
477
+ let old_layout = Layout :: from_size_align_unchecked ( old_size, align) ;
478
+ System . realloc ( ptr, old_layout, new_size)
479
+ }
480
+ }
481
+
482
+ #[ rustc_std_internal_symbol]
483
+ pub unsafe extern "C" fn __rdl_alloc_zeroed ( size : usize , align : usize ) -> * mut u8 {
484
+ // SAFETY: see the guarantees expected by `Layout::from_size_align` and
485
+ // `GlobalAlloc::alloc_zeroed`.
486
+ unsafe {
487
+ let layout = Layout :: from_size_align_unchecked ( size, align) ;
488
+ System . alloc_zeroed ( layout)
489
+ }
490
+ }
491
+ }
0 commit comments