Skip to content

Commit 5a433c4

Browse files
committed
Add test for weak definitions
1 parent 222f5a0 commit 5a433c4

File tree

1 file changed

+41
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)