Skip to content

Commit 7b9e1a9

Browse files
committed
test/codegen: test inter-crate linkage with static relocation
Add a codegen-test that verifies inter-crate linkage with the static relocation model. We expect all symbols that are part of a rust compilation to end up in the same DSO, thus we expect `dso_local` annotations.
1 parent a0771bd commit 7b9e1a9

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Auxiliary crate that exports a function and static. Both always
2+
// evaluate to `71`. We force mutability on the static to prevent
3+
// it from being inlined as constant.
4+
5+
#![crate_type = "lib"]
6+
7+
#[no_mangle]
8+
pub fn extern_fn() -> u8 { unsafe { extern_static } }
9+
10+
#[no_mangle]
11+
pub static mut extern_static: u8 = 71;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Verify linkage of external symbols in the static relocation model on MSVC.
2+
//
3+
// compile-flags: -O -C relocation-model=static
4+
// aux-build: extern_decl.rs
5+
// only-x86_64-pc-windows-msvc
6+
7+
#![crate_type = "rlib"]
8+
9+
extern crate extern_decl;
10+
11+
// The `extern_decl` definitions are imported from a statically linked rust
12+
// crate, thus they are expected to be marked `dso_local` without `dllimport`.
13+
//
14+
// The `access_extern()` symbol is from this compilation unit, thus we expect
15+
// it to be marked `dso_local` as well, given the static relocation model.
16+
//
17+
// CHECK: @extern_static = external dso_local local_unnamed_addr global i8
18+
// CHECK: define dso_local i8 @access_extern() {{.*}}
19+
// CHECK: declare dso_local i8 @extern_fn() {{.*}}
20+
21+
#[no_mangle]
22+
pub fn access_extern() -> u8 {
23+
unsafe {
24+
extern_decl::extern_fn() + extern_decl::extern_static
25+
}
26+
}

0 commit comments

Comments
 (0)