Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
usamoi opened this issue Apr 13, 2025 · 1 comment · May be fixed by #139752
Open

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

usamoi opened this issue Apr 13, 2025 · 1 comment · May be fixed by #139752
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) regression-untriaged Untriaged performance or correctness regression.

Comments

@usamoi
Copy link
Contributor

usamoi commented Apr 13, 2025

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

@usamoi usamoi added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Apr 13, 2025
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 13, 2025
@jieyouxu jieyouxu added the A-linkage Area: linking into static, shared libraries and binaries label Apr 13, 2025
@madsmtm
Copy link
Contributor

madsmtm commented Apr 13, 2025

For completeness, the error looks like:

error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "/var/folders/0j/tk3sfgz540712zgqd1hrry0m0000gn/T/rustc7pYeFN/symbols.o" "<2 object files omitted>" "<sysroot>/lib/rustlib/aarch64-apple-darwin/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "-lSystem" "-lc" "-lm" "-arch" "arm64" "-mmacosx-version-min=11.0.0" "-o" "foo" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: Undefined symbols for architecture arm64:
            "_UNDEFINED", referenced from:
                foo::used::h39a7b37900f3aa5a in foo.foo.d6039e2b53427ca7-cgu.0.rcgu.o
                foo::used::h39a7b37900f3aa5a in foo.foo.d6039e2b53427ca7-cgu.0.rcgu.o
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

@rustbot label O-apple

@rustbot rustbot added the O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) label Apr 13, 2025
Zalathar added a commit to Zalathar/rust that referenced this issue Apr 24, 2025
set subsections_via_symbols for ld64 helper sections

closes rust-lang#139744
cc `@madsmtm`
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 24, 2025
set subsections_via_symbols for ld64 helper sections

closes rust-lang#139744
cc `@madsmtm`

---
try-job: x86_64-msvc-1
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 24, 2025
set subsections_via_symbols for ld64 helper sections

closes rust-lang#139744
cc `@madsmtm`

---
try-job: x86_64-msvc-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) regression-untriaged Untriaged performance or correctness regression.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants