Skip to content

functions marked with #[no_mangle] cannot be GC-ed on MacOS #139744

Closed
@usamoi

Description

@usamoi

Code

I tried this code:

// src/main.rs

unsafe extern "C" {
    unsafe static UNDEFINED: usize;
}

#[unsafe(no_mangle)]
pub fn used() {
    println!("UNDEFINED = {}", unsafe { UNDEFINED });
}

pub fn marker() -> usize {
    0
}

fn main() {
    assert_eq!(marker(), 0_usize);
}
cargo build --target aarch64-apple-darwin

I expected to see this happen: it builds

Instead, this happened: it emits linker errors

Version it worked on

1.86.0

Version with regression

nightly-2025-02-26; bisects to #133832

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.I-prioritizeIssue: Indicates that prioritization has been requested for this issue.O-appleOperating system: Apple (macOS, iOS, tvOS, visionOS, watchOS)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions