Skip to content

Commit 9284d4c

Browse files
committed
Add test for weak definitions
1 parent 222f5a0 commit 9284d4c

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//@ aux-build: weak_definition_a.rs
2+
3+
#![feature(linkage)]
4+
5+
use weak_definition_a as _;
6+
7+
// FIXME move this module to a separate crate once aux-build is allowed
8+
// This currently depends on the fact that miri skips the codegen check
9+
// that denies multiple symbols with the same name.
10+
mod first {
11+
#[no_mangle]
12+
#[linkage = "weak"]
13+
extern "C" fn foo() -> i32 {
14+
1
15+
}
16+
17+
#[no_mangle]
18+
#[linkage = "weak"]
19+
extern "C" fn bar() -> i32 {
20+
2
21+
}
22+
}
23+
24+
mod second {
25+
#[no_mangle]
26+
extern "C" fn bar() -> i32 {
27+
3
28+
}
29+
}
30+
31+
extern "C" {
32+
fn foo() -> i32;
33+
fn bar() -> i32;
34+
}
35+
36+
fn main() {
37+
unsafe {
38+
// If there is no non-weak definition, the weak definition will be used.
39+
assert_eq!(foo(), 1);
40+
// Non-weak definition takes presedence.
41+
assert_eq!(bar(), 3);
42+
}
43+
}

0 commit comments

Comments
 (0)