Skip to content

Commit 2d53d94

Browse files
authored
Rollup merge of rust-lang#45650 - michaelwoerister:per-crate-type-symbol-threshold, r=alexcrichton
Take crate-type into account when generating symbol export lists (linker version scripts) r? @alexcrichton cc rust-lang#45613
2 parents 57b4658 + d3951ff commit 2d53d94

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/librustc_trans/back/linker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ impl<'a> Linker for EmLinker<'a> {
747747
fn exported_symbols(tcx: TyCtxt, crate_type: CrateType) -> Vec<String> {
748748
let mut symbols = Vec::new();
749749

750-
let export_threshold = symbol_export::threshold(tcx);
750+
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
751751
for &(ref name, _, level) in tcx.exported_symbols(LOCAL_CRATE).iter() {
752752
if level.is_below_threshold(export_threshold) {
753753
symbols.push(name.clone());

src/test/run-make/symbol-visibility/Makefile

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,25 @@ all:
99
else
1010

1111
NM=nm -D
12-
DYLIB_EXT=so
1312
CDYLIB_NAME=liba_cdylib.so
1413
RDYLIB_NAME=liba_rust_dylib.so
1514
EXE_NAME=an_executable
15+
COMBINED_CDYLIB_NAME=libcombined_rlib_dylib.so
1616

1717
ifeq ($(UNAME),Darwin)
1818
NM=nm -gU
19-
DYLIB_EXT=dylib
2019
CDYLIB_NAME=liba_cdylib.dylib
2120
RDYLIB_NAME=liba_rust_dylib.dylib
2221
EXE_NAME=an_executable
22+
COMBINED_CDYLIB_NAME=libcombined_rlib_dylib.dylib
2323
endif
2424

2525
all:
2626
$(RUSTC) an_rlib.rs
2727
$(RUSTC) a_cdylib.rs
2828
$(RUSTC) a_rust_dylib.rs
2929
$(RUSTC) an_executable.rs
30+
$(RUSTC) a_cdylib.rs --crate-name combined_rlib_dylib --crate-type=rlib,cdylib
3031

3132
# Check that a cdylib exports its public #[no_mangle] functions
3233
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c public_c_function_from_cdylib)" -eq "1" ]
@@ -47,4 +48,13 @@ all:
4748
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -c public_c_function_from_rlib)" -eq "0" ]
4849
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -c public_rust_function_from_exe)" -eq "0" ]
4950

51+
52+
# Check the combined case, where we generate a cdylib and an rlib in the same
53+
# compilation session:
54+
# Check that a cdylib exports its public #[no_mangle] functions
55+
[ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -c public_c_function_from_cdylib)" -eq "1" ]
56+
# Check that a cdylib exports the public #[no_mangle] functions of dependencies
57+
[ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
58+
# Check that a cdylib DOES NOT export any public Rust functions
59+
[ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -c _ZN.*h.*E)" -eq "0" ]
5060
endif

0 commit comments

Comments
 (0)