Skip to content

Commit bd84a48

Browse files
committed
Use rustc_std_internal_symbol instead of linkage = "weak"
1 parent 4d4fd99 commit bd84a48

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

compiler/rustc_symbol_mangling/src/v0.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,16 @@ pub(super) fn mangle<'tcx>(
8282
}
8383

8484
pub fn mangle_internal_symbol<'tcx>(tcx: TyCtxt<'tcx>, item_name: &str) -> String {
85-
if item_name == "rust_eh_personality" {
85+
match item_name {
8686
// rust_eh_personality must not be renamed as LLVM hard-codes the name
87-
return "rust_eh_personality".to_owned();
88-
} else if item_name == "__rust_no_alloc_shim_is_unstable" {
87+
"rust_eh_personality" => return item_name.to_owned(),
8988
// Temporary back compat hack to give people the chance to migrate to
9089
// include #[rustc_std_internal_symbol].
91-
return "__rust_no_alloc_shim_is_unstable".to_owned();
90+
"__rust_no_alloc_shim_is_unstable" => return item_name.to_owned(),
91+
// Apple availability symbols need to not be mangled to be usable by
92+
// C/Objective-C code.
93+
"__isPlatformVersionAtLeast" | "__isOSVersionAtLeast" => return item_name.to_owned(),
94+
_ => {}
9295
}
9396

9497
let prefix = "_R";

library/std/src/sys/platform_version/darwin/public_extern.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ use super::{current_version, pack_u32_os_version};
7171
// SAFETY: The signature is the same as what Clang expects, and we export weakly to allow linking
7272
// both this and `libclang_rt.*.a`, similar to how `compiler-builtins` does it:
7373
// https://github.com/rust-lang/compiler-builtins/blob/0.1.113/src/macros.rs#L494
74-
#[cfg_attr(not(feature = "compiler-builtins-mangled-names"), unsafe(no_mangle), linkage = "weak")]
74+
//
75+
// NOTE: This symbol has a workaround in the compiler's symbol mangling to avoid mangling it, while
76+
// still not exposing it from non-cdylib (like `#[no_mangle]` would).
77+
#[rustc_std_internal_symbol]
7578
// extern "C" is correct, Clang assumes the function cannot unwind:
7679
// https://github.com/llvm/llvm-project/blob/llvmorg-20.1.0/clang/lib/CodeGen/CGObjC.cpp#L3980
7780
//
@@ -139,7 +142,7 @@ pub(super) extern "C" fn __isPlatformVersionAtLeast(
139142

140143
/// Old entry point for availability. Used when compiling with older Clang versions.
141144
// SAFETY: Same as for `__isPlatformVersionAtLeast`.
142-
#[cfg_attr(not(feature = "compiler-builtins-mangled-names"), unsafe(no_mangle), linkage = "weak")]
145+
#[rustc_std_internal_symbol]
143146
pub(super) extern "C" fn __isOSVersionAtLeast(major: u32, minor: u32, subminor: u32) -> i32 {
144147
let version = pack_u32_os_version(major, minor, subminor);
145148
(version <= current_version()) as i32

0 commit comments

Comments
 (0)