Skip to content

global_allocator does not work with -C prefer-dynamic #100781

@nicbn

Description

@nicbn

Could not find anything related to this online. Using RUSTFLAGS="-C prefer-dynamic" cargo run on this does not panic.

use std::alloc::{GlobalAlloc, Layout}; #[global_allocator] static ALLOC: Alloc = Alloc; pub struct Alloc; unsafe impl GlobalAlloc for Alloc { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { panic!() } unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { panic!() } unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { panic!() } unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { panic!() } } fn main() { let _ = Box::new(1); }

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (29e4a9ee0 2022-08-10) binary: rustc commit-hash: 29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6 commit-date: 2022-08-10 host: x86_64-unknown-linux-gnu release: 1.65.0-nightly LLVM version: 14.0.6 

Metadata

Metadata

Assignees

No one assigned

    Labels

    -Cprefer-dynamicCodegen option: Prefer dynamic linking to static linking.A-allocatorsArea: Custom and system allocatorsA-diagnosticsArea: Messages for errors, warnings, and lintsA-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions