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:
parent
12e6b53744
commit
fbf9869702
7 changed files with 74 additions and 11 deletions
17
src/test/run-make/cdylib-fewer-symbols/Makefile
Normal file
17
src/test/run-make/cdylib-fewer-symbols/Makefile
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Test that allocator-related symbols don't show up as exported from a cdylib as
|
||||
# they're internal to Rust and not part of the public ABI.
|
||||
|
||||
-include ../tools.mk
|
||||
|
||||
ifdef IS_MSVC
|
||||
all:
|
||||
true
|
||||
else
|
||||
all:
|
||||
$(RUSTC) foo.rs
|
||||
nm -g "$(call DYLIB,foo)"
|
||||
nm -g "$(call DYLIB,foo)" | grep -vq __rdl_
|
||||
nm -g "$(call DYLIB,foo)" | grep -vq __rde_
|
||||
nm -g "$(call DYLIB,foo)" | grep -vq __rg_
|
||||
nm -g "$(call DYLIB,foo)" | grep -vq __rust_
|
||||
endif
|
||||
16
src/test/run-make/cdylib-fewer-symbols/foo.rs
Normal file
16
src/test/run-make/cdylib-fewer-symbols/foo.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![crate_type = "cdylib"]
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn foo() -> u32 {
|
||||
3
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue