Skip to content

Commit 2402b40

Browse files
committed
Add test for weak definitions
1 parent 222f5a0 commit 2402b40

File tree

1 file changed

+39
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)