-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make #[used] work when linking with ld64
- Loading branch information
Showing
7 changed files
with
202 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tests/ui/attributes/auxiliary/used_pre_main_constructor.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//! Add a constructor that runs pre-main, similar to what the `ctor` crate does. | ||
//! | ||
//! #[ctor] | ||
//! fn constructor() { | ||
//! println!("constructor"); | ||
//! } | ||
//@ no-prefer-dynamic explicitly test with crates that are built as an archive | ||
#![crate_type = "rlib"] | ||
|
||
#[cfg_attr( | ||
any( | ||
target_os = "linux", | ||
target_os = "android", | ||
target_os = "freebsd", | ||
target_os = "netbsd", | ||
target_os = "openbsd", | ||
target_os = "dragonfly", | ||
target_os = "illumos", | ||
target_os = "haiku" | ||
), | ||
link_section = ".init_array" | ||
)] | ||
#[cfg_attr(target_vendor = "apple", link_section = "__DATA,__mod_init_func,mod_init_funcs")] | ||
#[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] | ||
#[used] | ||
static CONSTRUCTOR: extern "C" fn() = constructor; | ||
|
||
#[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".text.startup")] | ||
extern "C" fn constructor() { | ||
println!("constructor"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//! Ensure that `#[used]` in archives are correctly registered. | ||
//! | ||
//! Regression test for https://github.com/rust-lang/rust/issues/133491. | ||
//@ run-pass | ||
//@ check-run-results | ||
//@ aux-build: used_pre_main_constructor.rs | ||
|
||
//@ ignore-wasm ctor doesn't work on WASM | ||
|
||
// Make sure `rustc` links the archive, but intentionally do not import/use any items. | ||
extern crate used_pre_main_constructor as _; | ||
|
||
fn main() { | ||
println!("main"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
constructor | ||
main |