Skip to content

Commit 9d6ea5f

Browse files
authored
Unrolled build for rust-lang#137926
Rollup merge of rust-lang#137926 - Kobzol:lld-no-start-stop-test, r=lqd Add a test for `-znostart-stop-gc` usage with LLD This test replicates the behavior of https://github.com/dtolnay/linkme, to test that it still works even with LLD. Without `-znostart-stop-gc` the test fails. r? ``@lqd`` try-job: x86_64-gnu try-job: x86_64-msvc-1
2 parents 9fb94b3 + 7bf4e99 commit 9d6ea5f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This test checks that encapsulation symbols are not garbage collected by the linker.
2+
// LLD will remove them by default, so this test checks that we pass `-znostart-stop-gc` to LLD
3+
// to avoid that behavior. Without that flag, the test should fail.
4+
// This test is inspired by the behavior of the linkme crate.
5+
//
6+
//@ build-pass
7+
//@ only-x86_64-unknown-linux-gnu
8+
9+
unsafe extern "Rust" {
10+
// The __start_ section name is magical for the linker,
11+
// It will put link sections named EXTERNFNS after it.
12+
#[link_name = "__start_EXTERNFNS"]
13+
static SECTION_START: fn();
14+
}
15+
16+
#[used]
17+
#[unsafe(link_section = "EXTERNFNS")]
18+
static EXTERN_FN_LOCAL: fn() = extern_fn;
19+
20+
fn extern_fn() {}
21+
22+
fn main() {
23+
// We need to reference the SECTION_START symbol to avoid it being garbage collected
24+
let slice = unsafe { SECTION_START };
25+
}

0 commit comments

Comments
 (0)