ctor/lib.rs
1#![recursion_limit = "256"]
2#![no_std]
3#![doc = include_str!("../docs/BUILD.md")]
4//! # ctor
5#![doc = include_str!("../docs/PREAMBLE.md")]
6#![doc = include_str!("../docs/REEXPORT.md")]
7#![doc = include_str!("../docs/GENERATED.md")]
8// Used as part of ctor collection for Apple/UEFI.
9#![cfg_attr(
10 all(any(target_vendor = "apple", target_os = "uefi"), linktime_used_linker),
11 feature(used_with_arg)
12)]
13#![cfg_attr(
14 all(any(target_vendor = "apple", target_os = "uefi"), linktime_asan),
15 feature(sanitize)
16)]
17
18#[cfg(feature = "std")]
19extern crate std;
20
21mod macros;
22mod parse;
23mod priority;
24#[cfg(target_os = "aix")]
25mod priority_aix;
26
27pub mod statics;
28
29#[doc = include_str!("../docs/LIFE_BEFORE_MAIN.md")]
30pub mod life_before_main {}
31
32#[doc(hidden)]
33#[allow(unused)]
34pub mod __support {
35 // Required for proc_macro.
36 pub use crate::__ctor_parse as ctor_parse;
37
38 // Re-export link_section::TypedSection and declarative::{section, in_section}
39 #[cfg(any(all(feature = "priority", target_vendor = "apple"), target_os = "uefi"))]
40 pub use link_section::declarative::in_section;
41}
42
43#[cfg(all(feature = "priority", target_vendor = "apple"))]
44crate::__ctor_parse_internal!(
45 __ctor_features,
46 /// Define a link section when using the priority parameter on Apple
47 /// targets. This is awkwardly placed in the root module because it needs to
48 /// use a generated macro and we cannot use an absolute path to it. (see
49 /// <https://github.com/rust-lang/rust/issues/52234>)
50 #[ctor(unsafe, naked)]
51 #[allow(unsafe_code)]
52 #[doc(hidden)]
53 fn priority_ctor() {
54 unsafe {
55 crate::collect::run_constructors();
56 }
57 }
58);
59
60/// Runs every registered constructor once, in ascending priority order.
61///
62/// UEFI never runs `.init_array`, so a UEFI binary must call this at startup. A
63/// repeat call is a no-op. A concurrent or re-entrant call panics.
64///
65/// # Safety
66///
67/// Runs arbitrary user code with the usual life-before-main caveats.
68#[cfg(target_os = "uefi")]
69#[allow(unsafe_code)]
70pub unsafe fn run_constructors() {
71 use core::sync::atomic::{AtomicU8, Ordering};
72 // 0 = not started, 1 = running, 2 = finished.
73 static STATE: AtomicU8 = AtomicU8::new(0);
74 match STATE.compare_exchange(0, 1, Ordering::AcqRel, Ordering::Acquire) {
75 Ok(_) => {
76 unsafe { crate::collect::run_constructors() };
77 STATE.store(2, Ordering::Release);
78 }
79 Err(2) => {}
80 Err(_) => panic!("run_constructors called while already running"),
81 }
82}
83
84/// Collected constructors for platforms requiring manual invocation.
85#[cfg(any(all(feature = "priority", target_vendor = "apple"), target_os = "uefi"))]
86#[doc(hidden)]
87pub mod collect {
88 use core::sync::atomic::{AtomicU8, Ordering};
89
90 #[doc(hidden)]
91 pub const PROCESSED: isize = isize::MIN;
92 #[doc(hidden)]
93 pub const LATE: isize = isize::MAX;
94
95 const GUARD_NOT_RUN: u8 = 0;
96 const GUARD_RUNNING: u8 = 1;
97 const GUARD_FINISHED: u8 = 2;
98
99 /// A constructor record.
100 #[derive(Copy, Clone)]
101 #[repr(C)]
102 pub struct Constructor {
103 pub priority: isize,
104 pub ctor: unsafe extern "C" fn(),
105 }
106
107 /// Run all constructors in the CTOR section. It is assumed that there is
108 /// only ever one of these calls active at any time, regardless of how many
109 /// versions of the ctor crate are in use.
110 ///
111 /// # Safety
112 ///
113 /// We use a guard section to ensure that only one version of the ctor crate
114 /// is running constructors at any time.
115 ///
116 /// If another copy of this function is running, we will return early, but
117 /// the constructors will not have been guaranteed to have run.
118 #[allow(unsafe_code)]
119 pub(crate) unsafe fn run_constructors() {
120 // Multiple ctor crates may contribute multiple guards, but there will
121 // only ever be one "first" guard.
122 let Some(guard) = _CTR0GR_ISIZE_FN.first() else {
123 return;
124 };
125
126 // In the unlikely case we are racing multiple threads, one will win.
127 loop {
128 match guard.compare_exchange_weak(
129 GUARD_NOT_RUN,
130 GUARD_RUNNING,
131 Ordering::AcqRel,
132 Ordering::Acquire,
133 ) {
134 Ok(_) => break,
135 Err(GUARD_NOT_RUN) => {
136 // Spurious failure, try again
137 continue;
138 }
139 Err(_) => return,
140 }
141 }
142
143 // SAFETY: Limit the scope of the mutable slice. This slice is only ever
144 // accessed under the guard.
145 unsafe {
146 let slice = _CTOR0_ISIZE_FN.as_mut_slice();
147 slice.sort_unstable_by_key(|constructor| constructor.priority);
148 }
149
150 unsafe {
151 let start = _CTOR0_ISIZE_FN.start_ptr_mut();
152 let end = _CTOR0_ISIZE_FN.end_ptr_mut();
153 let mut ptr = start;
154 while ptr < end {
155 let mut constructor = ptr.read();
156 if constructor.priority != crate::collect::PROCESSED {
157 constructor.priority = crate::collect::PROCESSED;
158 ptr.write(constructor);
159 (constructor.ctor)();
160 }
161 ptr = ptr.add(1);
162 }
163 }
164
165 guard.store(GUARD_FINISHED, Ordering::Release);
166 }
167
168 // Note: The section names must be <= 16 characters long to fit in the mach-o limits.
169 // These sections are shared between multiple versions of the ctor crate.
170
171 link_section::declarative::section!(
172 #[section(unsafe, type = mutable, name = _CTOR0_ISIZE_FN)]
173 static _CTOR0_ISIZE_FN: link_section::TypedMutableSection<Constructor>;
174 );
175
176 link_section::declarative::section!(
177 #[section(unsafe, type = typed, name = _CTR0GR_ISIZE_FN)]
178 static _CTR0GR_ISIZE_FN: link_section::TypedSection<AtomicU8>;
179 );
180
181 link_section::declarative::in_section!(
182 #[in_section(unsafe, type = typed, name = _CTR0GR_ISIZE_FN)]
183 pub static GUARD_ATOMIC: AtomicU8 = AtomicU8::new(GUARD_NOT_RUN);
184 );
185
186 // TODO: We should allow explicit export_name on the ctor itself.
187 #[cfg(all(feature = "priority", target_vendor = "apple"))]
188 #[used]
189 #[doc(hidden)]
190 #[allow(unsafe_code)]
191 #[cfg_attr(clippy, allow(unknown_lints, unsafe_attr_outside_unsafe))]
192 #[export_name = concat!(
193 "ctor_ap_",
194 env!("CARGO_PKG_VERSION_MAJOR"),
195 "_",
196 env!("CARGO_PKG_VERSION_MINOR"),
197 "_",
198 env!("CARGO_PKG_VERSION_PATCH")
199 )]
200 pub static APPLE_PRIORITY_ANCHOR: fn() = crate::priority_ctor;
201
202 #[macro_export]
203 #[doc(hidden)]
204 macro_rules! __keep_alive {
205 () => {
206 // UEFI runs constructors explicitly and has no anchor to keep alive.
207 /// Force `ld64` to pull the archive member owning `APPLE_PRIORITY_ANCHOR`
208 /// (see https://github.com/mmastrac/linktime/issues/496).
209 #[cfg(target_vendor = "apple")]
210 const _: () = {
211 mod __ctor_force {
212 ::core::arch::global_asm!(
213 ".pushsection __DATA,__ctor_force,regular,no_dead_strip\n",
214 // Pointer-align a `.quad` with the anchor
215 ".p2align 3\n",
216 ".quad {0}\n",
217 ".popsection\n",
218 sym $crate::collect::APPLE_PRIORITY_ANCHOR,
219 );
220 }
221 };
222 };
223 }
224
225 #[macro_export]
226 #[doc(hidden)]
227 macro_rules! __register_ctor {
228 (priority = (), fn = $fn:ident) => {
229 $crate::__register_ctor!(priority = ($crate::collect::EARLY), fn = $fn);
230 };
231 (priority = early, fn = $fn:ident) => {
232 $crate::__register_ctor!(priority = ($crate::collect::EARLY), fn = $fn);
233 };
234 (priority = late, fn = $fn:ident) => {
235 $crate::__register_ctor!(priority = ($crate::collect::LATE), fn = $fn);
236 };
237 (priority = $priority:tt, fn = $fn:ident) => {
238 $crate::__keep_alive!();
239 $crate::__support::in_section!(
240 #[in_section(unsafe, type = mutable, name = _CTOR0_ISIZE_FN)]
241 const _: $crate::collect::Constructor = $crate::collect::Constructor {
242 priority: $priority,
243 ctor: $fn,
244 };
245 );
246 };
247 (priority = $priority:tt, fn = (array $array:ident)) => {
248 $crate::__keep_alive!();
249 $crate::__support::in_section!(
250 #[in_section(unsafe, type = mutable, name = _CTOR0_ISIZE_FN)]
251 const _: [$crate::collect::Constructor; if $array.len() == 0 { 1 } else { $array.len() }] = {
252 use core::mem::MaybeUninit;
253
254 // If length zero, register a stub that doesn't get executed
255 if $array.len() == 0 {
256 unsafe extern "C" fn empty_ctor() {}
257 [$crate::collect::Constructor {
258 priority: $crate::collect::PROCESSED,
259 ctor: empty_ctor,
260 }; if $array.len() == 0 { 1 } else { $array.len() }]
261 } else {
262 let mut array: MaybeUninit<[$crate::collect::Constructor; if $array.len() == 0 { 1 } else { $array.len() }]> = MaybeUninit::uninit();
263 let mut array_ptr: *mut $crate::collect::Constructor = array.as_mut_ptr() as _;
264 const fn ctor_fn(i: usize) -> $crate::collect::Constructor {
265 $crate::collect::Constructor {
266 priority: $priority,
267 ctor: $array[i],
268 }
269 }
270
271 let mut i = 0;
272 while i < $array.len() {
273 unsafe { array_ptr.add(i).write(ctor_fn(i)) };
274 i += 1;
275 }
276
277 unsafe { array.assume_init() }
278 }
279 };
280 );
281 };
282 }
283}
284
285/// Declarative form of the `#[ctor]` macro.
286pub mod declarative {
287 /// Declarative form of the [`#[ctor]`](crate::ctor) macro.
288 ///
289 /// The declarative forms wrap and parse a proc_macro-like syntax like so, and
290 /// are identical in expansion to the undecorated procedural macros. The
291 /// declarative forms support the same attribute parameters as the procedural
292 /// macros.
293 ///
294 /// ```rust
295 /// # #[cfg(not(miri))] mod test { use ctor::*; use libc_print::*;
296 /// ctor::declarative::ctor! {
297 /// #[ctor(unsafe)]
298 /// fn foo() {
299 /// libc_println!("Hello, world!");
300 /// }
301 /// }
302 /// # }
303 ///
304 /// // ... the above is identical to:
305 ///
306 /// # #[cfg(not(miri))] mod test_2 { use ctor::*; use libc_print::*;
307 /// #[ctor(unsafe)]
308 /// fn foo() {
309 /// libc_println!("Hello, world!");
310 /// }
311 /// # }
312 /// ```
313 #[doc(inline)]
314 pub use crate::__support::ctor_parse as ctor;
315}
316
317/// Marks a function or static variable as a library/executable constructor.
318/// This uses OS-specific linker sections to call a specific function at load
319/// time.
320///
321/// # Important notes
322///
323/// Rust does not make any guarantees about stdlib support for life-before or
324/// life-after main. This means that the `ctor` crate may not work as expected
325/// in some cases, such as when used in an `async` runtime or making use of
326/// stdlib services.
327///
328/// Multiple startup functions/statics are supported, but the invocation order
329/// is not guaranteed.
330///
331/// The `ctor` crate assumes it is available as a direct dependency, If you
332/// re-export `ctor` items as part of your crate, you can use the `crate_path`
333/// parameter to redirect the macro's output to the correct crate, or use the
334/// [`declarative::ctor`] form.
335///
336/// # Examples
337///
338/// Print a startup message (using `libc_print` for safety):
339///
340/// ```rust
341/// # #[cfg(not(miri))] mod test {
342/// # use ctor::ctor;
343/// use libc_print::std_name::println;
344///
345/// #[ctor(unsafe)]
346/// fn foo() {
347/// // Using libc_print which is safe in `#[ctor]`
348/// println!("Hello, world!");
349/// }
350///
351/// # fn main() {
352/// println!("main()");
353/// # }}
354/// ```
355///
356/// Make changes to `static` variables:
357///
358/// ```rust
359/// # mod test {
360/// use ctor::*;
361/// use std::sync::atomic::{AtomicBool, Ordering};
362/// static INITED: AtomicBool = AtomicBool::new(false);
363///
364/// #[ctor(unsafe)]
365/// fn set_inited() {
366/// INITED.store(true, Ordering::SeqCst);
367/// }
368/// # }
369/// ```
370///
371/// Initialize a `HashMap` at startup time:
372///
373/// ```rust
374/// # mod test {
375/// # use std::collections::HashMap;
376/// # use ctor::*;
377/// #[ctor(unsafe)]
378/// pub static STATIC_CTOR: HashMap<u32, String> = {
379/// let mut m = HashMap::new();
380/// for i in 0..100 {
381/// m.insert(i, format!("x*100={}", i*100));
382/// }
383/// m
384/// };
385/// # }
386/// # pub fn main() {
387/// # assert_eq!(test::STATIC_CTOR.len(), 100);
388/// # assert_eq!(test::STATIC_CTOR[&20], "x*100=2000");
389/// # }
390/// ```
391///
392/// # Details
393///
394/// The `#[ctor]` macro makes use of linker sections to ensure that a function
395/// is run at startup time.
396///
397/// ```rust
398/// # mod test {
399/// # use ctor::*;
400/// #[ctor(unsafe)]
401/// fn my_init_fn() {
402/// /* ... */
403/// }
404/// # }
405/// ```
406///
407/// The above example translates into the following Rust code (approximately):
408///
409/// ```rust
410/// # fn my_init_fn() {}
411/// #[used]
412/// #[cfg_attr(target_os = "linux", link_section = ".init_array")]
413/// #[cfg_attr(target_vendor = "apple", link_section = "__DATA,__mod_init_func,mod_init_funcs")]
414/// #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
415/// /* ... other platforms elided ... */
416/// static INIT_FN: extern fn() = {
417/// extern fn init_fn() { my_init_fn(); };
418/// init_fn
419/// };
420/// ```
421///
422/// For `static` items, the macro generates a `std::sync::OnceLock` that is
423/// initialized at startup time. `#[ctor]` on `static` items requires the
424/// default `std` feature.
425///
426/// ```rust
427/// # mod test {
428/// # use ctor::*;
429/// # use std::collections::HashMap;
430/// #[ctor]
431/// static FOO: HashMap<u32, String> = unsafe {
432/// let mut m = HashMap::new();
433/// for i in 0..100 {
434/// m.insert(i, format!("x*100={}", i*100));
435/// }
436/// m
437/// };
438/// # }
439/// ```
440///
441/// The above example translates into the following Rust code (approximately),
442/// which eagerly initializes the `HashMap` inside a `OnceLock` at startup time:
443///
444/// ```rust
445/// # mod test {
446/// # use ctor::ctor;
447/// # use std::collections::HashMap;
448/// static FOO: FooStatic = FooStatic { value: ::std::sync::OnceLock::new() };
449/// struct FooStatic {
450/// value: ::std::sync::OnceLock<HashMap<u32, String>>,
451/// }
452///
453/// impl ::core::ops::Deref for FooStatic {
454/// type Target = HashMap<u32, String>;
455/// fn deref(&self) -> &Self::Target {
456/// self.value.get_or_init(|| unsafe {
457/// let mut m = HashMap::new();
458/// for i in 0..100 {
459/// m.insert(i, format!("x*100={}", i*100));
460/// }
461/// m
462/// })
463/// }
464/// }
465///
466/// #[ctor]
467/// unsafe fn init_foo_ctor() {
468/// _ = &*FOO;
469/// }
470/// # }
471/// ```
472#[doc(inline)]
473#[cfg(feature = "proc_macro")]
474pub use ::linktime_proc_macro::ctor;
475
476__declare_features!(
477 ctor: __ctor_features;
478
479 /// Do not give the constructor a name in the generated code (allows for
480 /// multiple constructors with the same name). Equivalent to wrapping the
481 /// constructor in an anonymous const (i.e.: `const _ = { ... };`).
482 anonymous {
483 attr: [(anonymous) => (anonymous)];
484 };
485 /// Place the constructor body in a custom link section. By default, this
486 /// uses the appropriate platform-specific link section.
487 ///
488 /// Co-locating startup functions may improve performance by allowing the binary
489 /// to page them in and out of memory together.
490 body_link_section {
491 attr: [(body(link_section = $body_section:literal)) => ($body_section)];
492 example: "body(link_section = \".text.startup\")";
493 default {
494 (target_os = "linux") => ".text.startup",
495 (target_os = "android") => ".text.startup",
496 (target_os = "freebsd") => ".text.startup",
497 // Windows MSVC: sort startup functions near the start of the binary
498 (all(target_os = "windows", any(target_env = "gnu", target_env = "msvc"))) => ".text$A",
499 // Windows non-MSVC: .text.startup
500 (all(target_os = "windows", not(any(target_env = "gnu", target_env = "msvc")))) => ".text.startup",
501 (target_vendor = "apple") => "__TEXT,__text_startup,regular,pure_instructions",
502 _ => ()
503 }
504 };
505 /// The path to the `ctor` crate containing the support macros. If you
506 /// re-export `ctor` items as part of your crate, you can use this to
507 /// redirect the macro’s output to the correct crate.
508 ///
509 /// Using the declarative [`ctor!`][c] form is
510 /// preferred over this parameter.
511 ///
512 /// [c]: crate::declarative::ctor!
513 crate_path {
514 attr: [(crate_path = $path:pat) => (($path))];
515 example: "crate_path = ::path::to::ctor::crate";
516 };
517 /// Specify a custom export name prefix for the constructor function.
518 ///
519 /// If specified, an export with the given prefix will be generated in the form:
520 ///
521 /// `<prefix><priority>_<unique_id>`
522 export_name_prefix {
523 attr: [(export_name_prefix = $export_name_prefix_str:literal) => ($export_name_prefix_str)];
524 example: "export_name_prefix = \"ctor_\"";
525 default {
526 (target_os = "aix") => "__sinit",
527 _ => (),
528 }
529 };
530 /// Place the constructor function pointer in a custom link section. By
531 /// default, this uses the appropriate platform-specific link section.
532 // NOTE: Keep in sync w/dtor::ctor_link_section!
533 link_section {
534 attr: [(link_section = $section:literal) => ($section)];
535 example: "link_section = \".ctors\"";
536 // Historical note: GCC 4.7 stopped providing .ctors/.dtors compatible
537 // crt files. Modern compilers, with the exception of Apple, MSVC, and
538 // AIX, will use `.init_array`.
539 default {
540 (target_vendor = "apple") => "__DATA,__mod_init_func,mod_init_funcs",
541 // Most LLVM/GCC targets can use .init_array
542 (any(
543 target_os = "linux",
544 target_os = "android",
545 target_os = "freebsd",
546 target_os = "netbsd",
547 target_os = "openbsd",
548 target_os = "dragonfly",
549 target_os = "illumos",
550 target_os = "haiku",
551 target_os = "vxworks",
552 target_os = "nto",
553 target_family = "wasm"
554 )) => ".init_array",
555 // No OS
556 (target_os = "none") => ".init_array",
557 // xtensa targets: .ctors
558 (target_arch = "xtensa") => ".ctors",
559 // Windows targets: .CRT$XCU
560 (all(target_os = "windows", any(target_env = "gnu", target_env = "msvc"))) => ".CRT$XCU",
561 // ... except mingw32 (https://llvm.googlesource.com/clang/+/1a209b667f83588866326a0384fa943ea2287b6c)
562 (all(target_os = "windows", not(any(target_env = "gnu", target_env = "msvc")))) => ".ctors",
563 // Research suggests that MSVC will use .CRT$XCU for UEFI targets, but won't actually
564 // run them. The gnu-efi project _does_ at least document .init_array support:
565 // https://github.com/vathpela/gnu-efi/blob/master/gnuefi/elf_x86_64_efi.lds
566 (target_os = "uefi") => ".init_array",
567 (target_os = "aix") => (), // AIX uses export_name_prefix
568 // Fall back to .init_array which is effectively the gold standard
569 // for LLVM/GCC targets moving forward
570 #[warn("Falling back to .init_array for unsupported target. If this \
571 works for you, please file an issue to add support for your target \
572 at https://github.com/mmastrac/linktime/issues")]
573 _ => ".init_array",
574 }
575 };
576 /// Use the least-possibly mangled version of the linker invocation for this
577 /// constructor. This is not recommended for general use as it may prevent
578 /// authors of binary crates from having low-level control over the order of
579 /// initialization.
580 ///
581 /// There are no guarantees about the order of execution of constructors
582 /// with this attribute, just that it will be called at some point before
583 /// `main`.
584 ///
585 /// `naked` constructors are always executed directly by the underlying C
586 /// library and/or dynamic loader.
587 ///
588 /// `naked` cannot be used with the `priority` attribute.
589 naked {
590 attr: [(naked) => (naked)];
591 };
592 /// The priority of the constructor. Higher-`N`-priority constructors are
593 /// run last. `N` must be between 0 and 999 inclusive for ordering
594 /// guarantees (`N` >= 1000 ordering is platform-defined).
595 ///
596 /// Priority is specified as numeric value, string literal, or the
597 /// identifiers `early`, `default`, or `late`. The integer value will be
598 /// clamped to a platform-defined range (typically 0-65535), while string
599 /// priorities are passed through unprocessed.
600 ///
601 /// Most platforms reserve the numeric values range of 0..100 for their own
602 /// internal use and it may not be safe to access platform services (`libc`
603 /// or other) in constructors with those priorities.
604 ///
605 /// Priority is applied as follows:
606 ///
607 /// - `N` is run in increasing order, from `0 <= N <= 999`.
608 /// - `early` is run at a priority level where it is safe to access the C
609 /// runtime. This is equivalent to a priority of 101 on most platforms.
610 /// - `default` is the default, and is run after `early`. This is
611 /// equivalent to a priority of 500.
612 /// - `late` is run last, and will be positioned to run after most
613 /// constructors, even outside the range `0 <= N <= 999`. The equivalent
614 /// priority is platform-defined.
615 /// - `main` is run, for binary targets.
616 ///
617 /// Ordering with explicit priority values outside of `0 <= N <= 999` is
618 /// platform-defined with respect to the list above, however platforms will
619 /// order constructors within a given priority range in ascending order
620 /// (i.e.: 10000 will run before 20000).
621 priority {
622 attr: [(priority = $priority_value:tt) => ($priority_value)];
623 example: "priority = N | early | late";
624 validate: [($priority:literal), (early), (late), (default)];
625 default {
626 (feature = "priority") => default,
627 _ => ()
628 }
629 };
630 /// Enable support for the priority parameter.
631 priority_enabled {
632 feature: "priority";
633 };
634 /// Enable support for the proc-macro `#[ctor]` attribute. The declarative
635 /// form (`ctor!(...)`) is always available. It is recommended that crates
636 /// re-exporting the `ctor` macro disable this feature and only use the
637 /// declarative form.
638 proc_macro {
639 feature: "proc_macro";
640 };
641 /// Enable support for the standard library.
642 std {
643 feature: "std";
644 };
645 r#unsafe {
646 /// attr
647 ///
648 /// Marks a ctor as unsafe. Required.
649 ///
650 /// The `ctor` crate rejects `#[ctor]` without marking the item unsafe;
651 /// that error can be suppressed by passing
652 /// `RUSTFLAGS="--cfg linktime_no_fail_on_missing_unsafe"` to Cargo.
653 attr: [(unsafe) => (no_fail_on_missing_unsafe)];
654 default {
655 (linktime_no_fail_on_missing_unsafe) => (no_fail_on_missing_unsafe),
656 _ => (),
657 }
658 };
659 used_linker {
660 /// attr
661 ///
662 /// Mark generated function pointers `used(linker)`. Requires nightly
663 /// for the nightly-only feature `feature(used_with_arg)` (see
664 /// <https://github.com/rust-lang/rust/issues/93798>).
665 ///
666 /// This can be made the default by using the `cfg` flag
667 /// `linktime_used_linker` (`RUSTFLAGS="--cfg linktime_used_linker"`).
668 ///
669 /// For a crate using this macro to function correctly with and without
670 /// this flag, it is recommended to add the following line to the top of
671 /// lib.rs in the crate root:
672 ///
673 /// `#![cfg_attr(linktime_used_linker, feature(used_with_arg))]`
674 attr: [(used(linker)) => (used_linker)];
675 default {
676 (linktime_used_linker) => used_linker,
677 _ => (),
678 }
679 };
680);
681
682#[cfg(doc)]
683__generate_docs!(__ctor_features);