Skip to content

Commit ea9f613

Browse files
Add test case for symbol visibility in dylibs.
1 parent bfd4910 commit ea9f613

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
include ../tools.mk
2+
3+
all:
4+
$(RUSTC) an_rlib.rs
5+
$(RUSTC) a_cdylib.rs
6+
$(RUSTC) a_rust_dylib.rs
7+
$(RUSTC) an_executable.rs
8+
9+
# Check that a cdylib exports its public #[no_mangle] functions
10+
[ "$$(nm -D $(TMPDIR)/liba_cdylib.so | grep -c public_c_function_from_cdylib)" -eq "1" ]
11+
# Check that a cdylib exports the public #[no_mangle] functions of dependencies
12+
[ "$$(nm -D $(TMPDIR)/liba_cdylib.so | grep -c public_c_function_from_rlib)" -eq "1" ]
13+
# Check that a cdylib DOES NOT export any public Rust functions
14+
[ "$$(nm -D $(TMPDIR)/liba_cdylib.so | grep -c _ZN.*h.*E)" -eq "0" ]
15+
16+
# Check that a Rust dylib exports its monomorphic functions
17+
[ "$$(nm -D $(TMPDIR)/liba_rust_dylib.so | grep -c public_c_function_from_rust_dylib)" -eq "1" ]
18+
[ "$$(nm -D $(TMPDIR)/liba_rust_dylib.so | grep -c _ZN.*public_rust_function_from_rust_dylib.*E)" -eq "1" ]
19+
20+
# Check that a Rust dylib exports the monomorphic functions from its dependencies
21+
[ "$$(nm -D $(TMPDIR)/liba_rust_dylib.so | grep -c public_c_function_from_rlib)" -eq "1" ]
22+
[ "$$(nm -D $(TMPDIR)/liba_rust_dylib.so | grep -c public_rust_function_from_rlib)" -eq "1" ]
23+
24+
# Check that an executable does not export any dynamic symbols
25+
[ "$$(nm -D $(TMPDIR)/an_executable | grep -c public_c_function_from_rlib)" -eq "0" ]
26+
[ "$$(nm -D $(TMPDIR)/an_executable | grep -c public_rust_function_from_exe)" -eq "0" ]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type="cdylib"]
12+
13+
extern crate an_rlib;
14+
15+
// This should not be exported
16+
pub fn public_rust_function_from_cdylib() {}
17+
18+
// This should be exported
19+
#[no_mangle]
20+
pub extern "C" fn public_c_function_from_cdylib() {
21+
an_rlib::public_c_function_from_rlib();
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type="dylib"]
12+
13+
extern crate an_rlib;
14+
15+
// This should be exported
16+
pub fn public_rust_function_from_rust_dylib() {}
17+
18+
// This should be exported
19+
#[no_mangle]
20+
pub extern "C" fn public_c_function_from_rust_dylib() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type="bin"]
12+
13+
extern crate an_rlib;
14+
15+
pub fn public_rust_function_from_exe() {}
16+
17+
fn main() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type="rlib"]
12+
13+
pub fn public_rust_function_from_rlib() {}
14+
15+
#[no_mangle]
16+
pub extern "C" fn public_c_function_from_rlib() {}

0 commit comments

Comments
 (0)