Skip to content

Commit 46e0b02

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 a2da749 commit 46e0b02

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-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,25 @@
1+
// Verify linkage of external symbols in the static relocation model.
2+
//
3+
// compile-flags: -O -C relocation-model=static
4+
// aux-build: extern_decl.rs
5+
6+
#![crate_type = "rlib"]
7+
8+
extern crate extern_decl;
9+
10+
// The `extern_decl` definitions are imported from a statically linked rust
11+
// crate, thus they are expected to be marked `dso_local` without `dllimport`.
12+
//
13+
// The `access_extern()` symbol is from this compilation unit, thus we expect
14+
// it to be marked `dso_local` as well, given the static relocation model.
15+
//
16+
// CHECK: @extern_static = external dso_local local_unnamed_addr global i8
17+
// CHECK: define dso_local i8 @access_extern() {{.*}}
18+
// CHECK: declare dso_local i8 @extern_fn() {{.*}}
19+
20+
#[no_mangle]
21+
pub fn access_extern() -> u8 {
22+
unsafe {
23+
extern_decl::extern_fn() + extern_decl::extern_static
24+
}
25+
}

0 commit comments

Comments
 (0)