rustc: Handle some libstd symbole exports better
Right now symbol exports, particularly in a cdylib, are handled by assuming that `pub extern` combined with `#[no_mangle]` means "export this". This isn't actually what we want for some symbols that the standard library uses to implement itself, for example symbols related to allocation. Additionally other special symbols like `rust_eh_personallity` have no need to be exported from cdylib crate types (only needed in dylib crate types). This commit updates how rustc handles these special symbols by adding to the hardcoded logic of symbols like `rust_eh_personallity` but also adding a new attribute, `#[rustc_std_internal_symbol]`, which forces the export level to be considered the same as all other Rust functions instead of looking like a C function. The eventual goal here is to prevent functions like `__rdl_alloc` from showing up as part of a Rust cdylib as it's just an internal implementation detail. This then further allows such symbols to get gc'd by the linker when creating a cdylib.
This commit is contained in:
@@ -107,7 +107,7 @@ mod contents {
|
||||
// ABI
|
||||
|
||||
#[no_mangle]
|
||||
#[linkage = "external"]
|
||||
#[rustc_std_internal_symbol]
|
||||
pub unsafe extern fn __rde_alloc(size: usize,
|
||||
align: usize,
|
||||
err: *mut u8) -> *mut u8 {
|
||||
@@ -122,13 +122,13 @@ mod contents {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[linkage = "external"]
|
||||
#[rustc_std_internal_symbol]
|
||||
pub unsafe extern fn __rde_oom(err: *const u8) -> ! {
|
||||
System.oom((*(err as *const AllocErr)).clone())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[linkage = "external"]
|
||||
#[rustc_std_internal_symbol]
|
||||
pub unsafe extern fn __rde_dealloc(ptr: *mut u8,
|
||||
size: usize,
|
||||
align: usize) {
|
||||
@@ -137,7 +137,7 @@ mod contents {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[linkage = "external"]
|
||||
#[rustc_std_internal_symbol]
|
||||
pub unsafe extern fn __rde_usable_size(layout: *const u8,
|
||||
min: *mut usize,
|
||||
max: *mut usize) {
|
||||
@@ -153,7 +153,7 @@ mod contents {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[linkage = "external"]
|
||||
#[rustc_std_internal_symbol]
|
||||
pub unsafe extern fn __rde_realloc(ptr: *mut u8,
|
||||
_old_size: usize,
|
||||
old_align: usize,
|
||||
@@ -177,7 +177,7 @@ mod contents {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[linkage = "external"]
|
||||
#[rustc_std_internal_symbol]
|
||||
pub unsafe extern fn __rde_alloc_zeroed(size: usize,
|
||||
align: usize,
|
||||
err: *mut u8) -> *mut u8 {
|
||||
@@ -196,7 +196,7 @@ mod contents {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[linkage = "external"]
|
||||
#[rustc_std_internal_symbol]
|
||||
pub unsafe extern fn __rde_alloc_excess(size: usize,
|
||||
align: usize,
|
||||
excess: *mut usize,
|
||||
@@ -210,7 +210,7 @@ mod contents {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[linkage = "external"]
|
||||
#[rustc_std_internal_symbol]
|
||||
pub unsafe extern fn __rde_realloc_excess(ptr: *mut u8,
|
||||
old_size: usize,
|
||||
old_align: usize,
|
||||
@@ -227,7 +227,7 @@ mod contents {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[linkage = "external"]
|
||||
#[rustc_std_internal_symbol]
|
||||
pub unsafe extern fn __rde_grow_in_place(ptr: *mut u8,
|
||||
old_size: usize,
|
||||
old_align: usize,
|
||||
@@ -237,7 +237,7 @@ mod contents {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[linkage = "external"]
|
||||
#[rustc_std_internal_symbol]
|
||||
pub unsafe extern fn __rde_shrink_in_place(ptr: *mut u8,
|
||||
_old_size: usize,
|
||||
old_align: usize,
|
||||
|
||||
Reference in New Issue
Block a user