Skip to content

Commit 61991a5

Browse files
Update run-make/symbol-visibility to also cover shared-generics
1 parent 07704a4 commit 61991a5

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

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

+37-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ COMBINED_CDYLIB_NAME=libcombined_rlib_dylib.dylib
2323
endif
2424

2525
all:
26-
$(RUSTC) an_rlib.rs
27-
$(RUSTC) a_cdylib.rs
28-
$(RUSTC) a_rust_dylib.rs
29-
$(RUSTC) an_executable.rs
30-
$(RUSTC) a_cdylib.rs --crate-name combined_rlib_dylib --crate-type=rlib,cdylib
26+
$(RUSTC) -Zshare-generics=no an_rlib.rs
27+
$(RUSTC) -Zshare-generics=no a_cdylib.rs
28+
$(RUSTC) -Zshare-generics=no a_rust_dylib.rs
29+
$(RUSTC) -Zshare-generics=no an_executable.rs
30+
$(RUSTC) -Zshare-generics=no a_cdylib.rs --crate-name combined_rlib_dylib --crate-type=rlib,cdylib
3131

3232
# Check that a cdylib exports its public #[no_mangle] functions
3333
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c public_c_function_from_cdylib)" -eq "1" ]
@@ -39,10 +39,15 @@ all:
3939
# Check that a Rust dylib exports its monomorphic functions
4040
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rust_dylib)" -eq "1" ]
4141
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c _ZN.*public_rust_function_from_rust_dylib.*E)" -eq "1" ]
42+
# Check that a Rust dylib does not export generics if -Zshare-generics=no
43+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c _ZN.*public_generic_function_from_rust_dylib.*E)" -eq "0" ]
44+
4245

4346
# Check that a Rust dylib exports the monomorphic functions from its dependencies
4447
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
4548
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_rust_function_from_rlib)" -eq "1" ]
49+
# Check that a Rust dylib does not export generics if -Zshare-generics=no
50+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c _ZN.*public_generic_function_from_rlib.*E)" -eq "0" ]
4651

4752
# Check that an executable does not export any dynamic symbols
4853
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -c public_c_function_from_rlib)" -eq "0" ]
@@ -57,4 +62,31 @@ all:
5762
[ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
5863
# Check that a cdylib DOES NOT export any public Rust functions
5964
[ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -c _ZN.*h.*E)" -eq "0" ]
65+
66+
67+
$(RUSTC) -Zshare-generics=yes an_rlib.rs
68+
$(RUSTC) -Zshare-generics=yes a_cdylib.rs
69+
$(RUSTC) -Zshare-generics=yes a_rust_dylib.rs
70+
$(RUSTC) -Zshare-generics=yes an_executable.rs
71+
72+
# Check that a cdylib exports its public #[no_mangle] functions
73+
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c public_c_function_from_cdylib)" -eq "1" ]
74+
# Check that a cdylib exports the public #[no_mangle] functions of dependencies
75+
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
76+
# Check that a cdylib DOES NOT export any public Rust functions
77+
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c _ZN.*h.*E)" -eq "0" ]
78+
79+
# Check that a Rust dylib exports its monomorphic functions, including generics this time
80+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rust_dylib)" -eq "1" ]
81+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c _ZN.*public_rust_function_from_rust_dylib.*E)" -eq "1" ]
82+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c _ZN.*public_generic_function_from_rust_dylib.*E)" -eq "1" ]
83+
84+
# Check that a Rust dylib exports the monomorphic functions from its dependencies
85+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
86+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_rust_function_from_rlib)" -eq "1" ]
87+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c _ZN.*public_generic_function_from_rlib.*E)" -eq "1" ]
88+
89+
# Check that an executable does not export any dynamic symbols
90+
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -c public_c_function_from_rlib)" -eq "0" ]
91+
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -c public_rust_function_from_exe)" -eq "0" ]
6092
endif

src/test/run-make-fulldeps/symbol-visibility/a_rust_dylib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ pub fn public_rust_function_from_rust_dylib() {}
1717

1818
// This should be exported
1919
#[no_mangle]
20-
pub extern "C" fn public_c_function_from_rust_dylib() {}
20+
pub extern "C" fn public_c_function_from_rust_dylib() {
21+
let _ = public_generic_function_from_rust_dylib(1u16);
22+
}
23+
24+
// This should be exported if -Zshare-generics=yes
25+
pub fn public_generic_function_from_rust_dylib<T>(x: T) -> T { x }

src/test/run-make-fulldeps/symbol-visibility/an_rlib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@
1313
pub fn public_rust_function_from_rlib() {}
1414

1515
#[no_mangle]
16-
pub extern "C" fn public_c_function_from_rlib() {}
16+
pub extern "C" fn public_c_function_from_rlib() {
17+
let _ = public_generic_function_from_rlib(0u64);
18+
}
19+
20+
pub fn public_generic_function_from_rlib<T>(x: T) -> T {
21+
x
22+
}

0 commit comments

Comments
 (0)