File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 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
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+ }
You can’t perform that action at this time.
0 commit comments