summaryrefslogtreecommitdiffstats
path: root/vendor/ctor
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
commita4b7ed7a42c716ab9f05e351f003d589124fd55d (patch)
treeb620cd3f223850b28716e474e80c58059dca5dd4 /vendor/ctor
parentAdding upstream version 1.67.1+dfsg1. (diff)
downloadrustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz
rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ctor')
-rw-r--r--vendor/ctor/.cargo-checksum.json2
-rw-r--r--vendor/ctor/Cargo.lock32
-rw-r--r--vendor/ctor/Cargo.toml20
-rw-r--r--vendor/ctor/README.md110
-rw-r--r--vendor/ctor/src/lib.rs122
5 files changed, 201 insertions, 85 deletions
diff --git a/vendor/ctor/.cargo-checksum.json b/vendor/ctor/.cargo-checksum.json
index 205fc57ef..881ab9a4e 100644
--- a/vendor/ctor/.cargo-checksum.json
+++ b/vendor/ctor/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.lock":"9794ac45e01be41a56e8d5e906980ebac9c1eb61cb6241fd0c505ee1de584f49","Cargo.toml":"f828f4e4be32e17c2e6227cc3a62b829731b1dcb18b88a8e4c535cf2c39059b4","LICENSE-APACHE":"a8ad31b1c3f40dca5a84119351b8fa8ddc868edd77fad8a8ebf6d8f2d16fa4ae","LICENSE-MIT":"bccaa8b6c09f94e81f06696e179dbe058464bbdfbc823b6d49cada1d71e84ac3","src/example.rs":"3a78174dc8e3b16a2ff3c0f2c9dce638bdcbec13526f1199e4c6d104bb54f9df","src/lib.rs":"51ea0531b0b3abba1438dcf9d76e99e2a4ca2a36a03ff0fcb6afc31a6d4c7e01"},"package":"f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c"} \ No newline at end of file
+{"files":{"Cargo.lock":"c94961376ad5bf496fa72918db433cca408c6087e519ea7d6880c7f27e6fb1bd","Cargo.toml":"98cdf96be2836f575910a1321d904fe7f2a343073b7cdb16a2ccebd8ec391a72","LICENSE-APACHE":"a8ad31b1c3f40dca5a84119351b8fa8ddc868edd77fad8a8ebf6d8f2d16fa4ae","LICENSE-MIT":"bccaa8b6c09f94e81f06696e179dbe058464bbdfbc823b6d49cada1d71e84ac3","README.md":"bd98f68b043b52d3b3302d084ed8e080bb88cc53ebe9c1ba01ddedc63975e586","src/example.rs":"3a78174dc8e3b16a2ff3c0f2c9dce638bdcbec13526f1199e4c6d104bb54f9df","src/lib.rs":"aed5f84c38445a4c702cf90a82b4ee682c5a815d5539161c89e98646668a74a6"},"package":"6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096"} \ No newline at end of file
diff --git a/vendor/ctor/Cargo.lock b/vendor/ctor/Cargo.lock
index 790e889ff..728691879 100644
--- a/vendor/ctor/Cargo.lock
+++ b/vendor/ctor/Cargo.lock
@@ -4,7 +4,7 @@ version = 3
[[package]]
name = "ctor"
-version = "0.1.22"
+version = "0.1.26"
dependencies = [
"libc-print",
"quote",
@@ -13,50 +13,50 @@ dependencies = [
[[package]]
name = "libc"
-version = "0.2.120"
+version = "0.2.135"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ad5c14e80759d0939d013e6ca49930e59fc53dd8e5009132f76240c179380c09"
+checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c"
[[package]]
name = "libc-print"
-version = "0.1.18"
+version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "57ccf937aa7e09a1741635a6b33b9dcde399c1f332f76eb7ae69426005d0bf6b"
+checksum = "a574491aebd99996f31b32469bbd3b50e580c35f6305663d68f6d6b28eaced09"
dependencies = [
"libc",
]
[[package]]
name = "proc-macro2"
-version = "1.0.36"
+version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
+checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
dependencies = [
- "unicode-xid",
+ "unicode-ident",
]
[[package]]
name = "quote"
-version = "1.0.16"
+version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b4af2ec4714533fcdf07e886f17025ace8b997b9ce51204ee69b6da831c3da57"
+checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
dependencies = [
"proc-macro2",
]
[[package]]
name = "syn"
-version = "1.0.89"
+version = "1.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ea297be220d52398dcc07ce15a209fce436d361735ac1db700cab3b6cdfb9f54"
+checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1"
dependencies = [
"proc-macro2",
"quote",
- "unicode-xid",
+ "unicode-ident",
]
[[package]]
-name = "unicode-xid"
-version = "0.2.2"
+name = "unicode-ident"
+version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
+checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
diff --git a/vendor/ctor/Cargo.toml b/vendor/ctor/Cargo.toml
index efcd2cffe..8f7cd4b96 100644
--- a/vendor/ctor/Cargo.toml
+++ b/vendor/ctor/Cargo.toml
@@ -12,10 +12,10 @@
[package]
edition = "2018"
name = "ctor"
-version = "0.1.22"
+version = "0.1.26"
authors = ["Matt Mastracci <matthew@mastracci.com>"]
description = "__attribute__((constructor)) for Rust"
-readme = "../README.md"
+readme = "README.md"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/mmastrac/rust-ctor"
@@ -26,15 +26,23 @@ proc-macro = true
[[example]]
name = "example"
path = "src/example.rs"
+
[dependencies.quote]
-version = "1.0.9"
+version = "1.0.20"
[dependencies.syn]
-version = "1.0.73"
-features = ["full", "parsing", "printing", "proc-macro"]
+version = "1.0.98"
+features = [
+ "full",
+ "parsing",
+ "printing",
+ "proc-macro",
+]
default-features = false
+
[dev-dependencies.libc-print]
-version = "0.1.15"
+version = "0.1.20"
+
[badges.travis-ci]
branch = "master"
repository = "mmastrac/rust-ctor"
diff --git a/vendor/ctor/README.md b/vendor/ctor/README.md
new file mode 100644
index 000000000..faa1b2b63
--- /dev/null
+++ b/vendor/ctor/README.md
@@ -0,0 +1,110 @@
+# rust-ctor
+
+[![Build Status](https://api.travis-ci.com/mmastrac/rust-ctor.svg?branch=master)](https://travis-ci.com/mmastrac/rust-ctor)
+[![docs.rs](https://docs.rs/ctor/badge.svg)](https://docs.rs/ctor)
+[![crates.io](https://img.shields.io/crates/v/ctor.svg)](https://crates.io/crates/ctor)
+
+Module initialization/teardown functions for Rust (like `__attribute__((constructor))` in C/C++) for Linux, OSX, FreeBSD, NetBSD, Illumos, OpenBSD, DragonFlyBSD, Android, iOS, and Windows.
+
+This library currently requires **Rust > 1.31.0** at a minimum for the
+procedural macro support.
+
+Idea inspired by [this code](https://github.com/neon-bindings/neon/blob/2277e943a619579c144c1da543874f4a7ec39879/src/lib.rs#L42) in the Neon project.
+
+## Support
+
+This library works and [is regularly tested](https://travis-ci.org/mmastrac/rust-ctor)
+on Linux, OSX and Windows, with both `+crt-static` and `-crt-static`. Other platforms are supported
+but not tested as part of the automatic builds. This library will also work as expected in both
+`bin` and `cdylib` outputs, ie: the `ctor` and `dtor` will run at executable or library
+startup/shutdown respectively.
+
+## Warnings
+
+Rust's philosophy is that nothing happens before or after main and
+this library explicitly subverts that. The code that runs in the `ctor`
+and `dtor` functions should be careful to limit itself to `libc`
+functions and code that does not rely on Rust's stdlib services.
+
+For example, using stdout in a `dtor` function is a guaranteed panic. Consider
+using the [`libc-print` crate](https://crates.io/crates/libc-print) for output
+to stderr/stdout during `#[ctor]` and `#[dtor]` methods. Other issues
+may involve signal processing or panic handling in that early code.
+
+In most cases, `sys_common::at_exit` is a better choice than `#[dtor]`. Caveat emptor!
+
+On some platforms, unloading of shared libraries may not actually
+happen until process exit, even if explicitly unloaded. The rules for
+this are arcane and difficult to understand. For example, thread-local
+storage on OSX will affect this (see [this comment](https://github.com/rust-lang/rust/issues/28794#issuecomment-368693049)).
+
+## Examples
+
+Marks the function `foo` as a module constructor, called when a static
+library is loaded or an executable is started:
+
+```rust
+ static INITED: AtomicBool = AtomicBool::new(false);
+
+ #[ctor]
+ fn foo() {
+ INITED.store(true, Ordering::SeqCst);
+ }
+```
+
+Creates a `HashMap` populated with strings when a static
+library is loaded or an executable is started (new in `0.1.7`):
+
+```rust
+ #[ctor]
+ /// This is an immutable static, evaluated at init time
+ static STATIC_CTOR: HashMap<u32, &'static str> = {
+ let mut m = HashMap::new();
+ m.insert(0, "foo");
+ m.insert(1, "bar");
+ m.insert(2, "baz");
+ m
+ };
+```
+
+Print a message at shutdown time. Note that Rust may have shut down
+some stdlib services at this time.
+
+```rust
+ #[dtor]
+ unsafe fn shutdown() {
+ // Using println or eprintln here will panic as Rust has shut down
+ libc::printf("Shutting down!\n\0".as_ptr() as *const i8);
+ }
+```
+
+## Under the Hood
+
+The `#[ctor]` macro makes use of linker sections to ensure that a
+function is run at startup time.
+
+The above example translates into the following Rust code (approximately):
+
+```rust
+ #[used]
+ #[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".init_array")]
+ #[cfg_attr(target_os = "freebsd", link_section = ".init_array")]
+ #[cfg_attr(target_os = "netbsd", link_section = ".init_array")]
+ #[cfg_attr(target_os = "openbsd", link_section = ".init_array")]
+ #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
+ #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
+ static FOO: extern fn() = {
+ #[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".text.startup")]
+ extern fn foo() { /* ... */ };
+ foo
+ };
+```
+
+The `#[dtor]` macro effectively creates a constructor that calls `libc::atexit` with the provided function, ie roughly equivalent to:
+
+```rust
+ #[ctor]
+ fn dtor_atexit() {
+ libc::atexit(dtor);
+ }
+```
diff --git a/vendor/ctor/src/lib.rs b/vendor/ctor/src/lib.rs
index 1f36d752a..ea9563780 100644
--- a/vendor/ctor/src/lib.rs
+++ b/vendor/ctor/src/lib.rs
@@ -6,9 +6,9 @@
//! `__attribute__((constructor))` in C/C++) for Linux, OSX, and Windows via
//! the `#[ctor]` and `#[dtor]` macros.
//!
-//! This library works and has been tested for Linux, OSX and Windows. This
-//! library will also work as expected in both `bin` and `cdylib` outputs,
-//! ie: the `ctor` and `dtor` will run at executable or library
+//! This library works and is regularly tested on Linux, OSX and Windows, with both `+crt-static` and `-crt-static`.
+//! Other platforms are supported but not tested as part of the automatic builds. This library will also work as expected in both
+//! `bin` and `cdylib` outputs, ie: the `ctor` and `dtor` will run at executable or library
//! startup/shutdown respectively.
//!
//! This library currently requires Rust > `1.31.0` at a minimum for the
@@ -22,12 +22,36 @@
// https://github.com/Alexpux/mingw-w64/blob/d0d7f784833bbb0b2d279310ddc6afb52fe47a46/mingw-w64-crt/crt/crtdll.c
+// In addition, OSX has removed support for section-based shutdown hooks after
+// warning about it for a number of years:
+
+// https://reviews.llvm.org/D45578
+
extern crate proc_macro;
extern crate syn;
#[macro_use]
extern crate quote;
-use proc_macro::TokenStream;
+use proc_macro::{TokenStream};
+
+/// Attributes required to mark a function as a constructor. This may be exposed in the future if we determine
+/// it to be stable.
+#[doc(hidden)]
+macro_rules! ctor_attributes {
+ () => {
+ quote!(
+ #[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".init_array")]
+ #[cfg_attr(target_os = "freebsd", link_section = ".init_array")]
+ #[cfg_attr(target_os = "netbsd", link_section = ".init_array")]
+ #[cfg_attr(target_os = "openbsd", link_section = ".init_array")]
+ #[cfg_attr(target_os = "dragonfly", link_section = ".init_array")]
+ #[cfg_attr(target_os = "illumos", link_section = ".init_array")]
+ #[cfg_attr(target_os = "haiku", link_section = ".init_array")]
+ #[cfg_attr(any(target_os = "macos", target_os = "ios"), link_section = "__DATA,__mod_init_func")]
+ #[cfg_attr(windows, link_section = ".CRT$XCU")]
+ )
+ };
+}
/// Marks a function or static variable as a library/executable constructor.
/// This uses OS-specific linker sections to call a specific function at
@@ -38,11 +62,13 @@ use proc_macro::TokenStream;
///
/// # Examples
///
-/// Print a startup message:
+/// Print a startup message (using `libc_print` for safety):
///
/// ```rust
/// # extern crate ctor;
/// # use ctor::*;
+/// use libc_print::std_name::println;
+///
/// #[ctor]
/// fn foo() {
/// println!("Hello, world!");
@@ -142,6 +168,7 @@ pub fn ctor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
syn::parse_str::<syn::Ident>(format!("{}___rust_ctor___ctor", ident).as_ref())
.expect("Unable to create identifier");
+ let tokens = ctor_attributes!();
let output = quote!(
#[cfg(not(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", target_os = "macos", target_os = "ios", windows)))]
compile_error!("#[ctor] is not supported on the current target");
@@ -152,15 +179,7 @@ pub fn ctor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
#[used]
#[allow(non_upper_case_globals)]
#[doc(hidden)]
- #[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".init_array")]
- #[cfg_attr(target_os = "freebsd", link_section = ".init_array")]
- #[cfg_attr(target_os = "netbsd", link_section = ".init_array")]
- #[cfg_attr(target_os = "openbsd", link_section = ".init_array")]
- #[cfg_attr(target_os = "dragonfly", link_section = ".init_array")]
- #[cfg_attr(target_os = "illumos", link_section = ".init_array")]
- #[cfg_attr(target_os = "haiku", link_section = ".init_array")]
- #[cfg_attr(any(target_os = "macos", target_os = "ios"), link_section = "__DATA,__mod_init_func")]
- #[cfg_attr(windows, link_section = ".CRT$XCU")]
+ #tokens
static #ctor_ident
:
unsafe extern "C" fn() =
@@ -186,7 +205,7 @@ pub fn ctor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
..
} = var;
- if let Some(_) = mutability {
+ if mutability.is_some() {
panic!("#[ctor]-annotated static objects must not be mutable");
}
@@ -206,6 +225,7 @@ pub fn ctor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
syn::parse_str::<syn::Ident>(format!("{}___rust_ctor___storage", ident).as_ref())
.expect("Unable to create identifier");
+ let tokens = ctor_attributes!();
let output = quote!(
#[cfg(not(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", target_os = "macos", target_os = "ios", windows)))]
compile_error!("#[ctor] is not supported on the current target");
@@ -235,15 +255,7 @@ pub fn ctor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
#[used]
#[allow(non_upper_case_globals)]
- #[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".init_array")]
- #[cfg_attr(target_os = "freebsd", link_section = ".init_array")]
- #[cfg_attr(target_os = "netbsd", link_section = ".init_array")]
- #[cfg_attr(target_os = "openbsd", link_section = ".init_array")]
- #[cfg_attr(target_os = "dragonfly", link_section = ".init_array")]
- #[cfg_attr(target_os = "illumos", link_section = ".init_array")]
- #[cfg_attr(target_os = "haiku", link_section = ".init_array")]
- #[cfg_attr(any(target_os = "macos", target_os = "ios"), link_section = "__DATA,__mod_init_func")]
- #[cfg_attr(windows, link_section = ".CRT$XCU")]
+ #tokens
static #ctor_ident
:
unsafe extern "C" fn() = {
@@ -307,6 +319,7 @@ pub fn dtor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
let dtor_ident = syn::parse_str::<syn::Ident>(format!("{}___rust_dtor___dtor", ident).as_ref())
.expect("Unable to create identifier");
+ let tokens = ctor_attributes!();
let output = quote!(
#[cfg(not(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", target_os = "macos", target_os = "ios", windows)))]
compile_error!("#[dtor] is not supported on the current target");
@@ -314,29 +327,34 @@ pub fn dtor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
#(#attrs)*
#vis #unsafety extern #abi #constness fn #ident() #block
- // Targets that use `atexit`.
- #[cfg(not(any(
- target_os = "macos",
- target_os = "ios",
- )))]
mod #mod_ident {
use super::#ident;
- // Avoid a dep on libc by linking directly
- extern "C" {
- fn atexit(cb: unsafe extern fn());
+ // Note that we avoid a dep on the libc crate by linking directly to atexit functions
+
+ #[cfg(not(any(target_os = "macos", target_os = "ios")))]
+ #[inline(always)]
+ unsafe fn do_atexit(cb: unsafe extern fn()) {
+ extern "C" {
+ fn atexit(cb: unsafe extern fn());
+ }
+ atexit(cb);
+ }
+
+ // For platforms that have __cxa_atexit, we register the dtor as scoped to dso_handle
+ #[cfg(any(target_os = "macos", target_os = "ios"))]
+ #[inline(always)]
+ unsafe fn do_atexit(cb: unsafe extern fn()) {
+ extern "C" {
+ static __dso_handle: *const u8;
+ fn __cxa_atexit(cb: unsafe extern fn(), arg: *const u8, dso_handle: *const u8);
+ }
+ __cxa_atexit(cb, std::ptr::null(), __dso_handle);
}
#[used]
#[allow(non_upper_case_globals)]
- #[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".init_array")]
- #[cfg_attr(target_os = "freebsd", link_section = ".init_array")]
- #[cfg_attr(target_os = "netbsd", link_section = ".init_array")]
- #[cfg_attr(target_os = "openbsd", link_section = ".init_array")]
- #[cfg_attr(target_os = "dragonfly", link_section = ".init_array")]
- #[cfg_attr(target_os = "illumos", link_section = ".init_array")]
- #[cfg_attr(target_os = "haiku", link_section = ".init_array")]
- #[cfg_attr(windows, link_section = ".CRT$XCU")]
+ #tokens
static __dtor_export
:
unsafe extern "C" fn() =
@@ -345,31 +363,11 @@ pub fn dtor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
unsafe extern "C" fn #dtor_ident() { #ident() };
#[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".text.startup")]
unsafe extern fn __dtor_atexit() {
- atexit(#dtor_ident);
+ do_atexit(#dtor_ident);
};
__dtor_atexit
};
}
-
- // Targets that don't rely on `atexit`.
- #[cfg(any(
- target_os = "macos",
- target_os = "ios",
- ))]
- mod #mod_ident {
- use super::#ident;
-
- #[used]
- #[allow(non_upper_case_globals)]
- #[cfg_attr(any(target_os = "macos", target_os = "ios"), link_section = "__DATA,__mod_term_func")]
- static __dtor_export
- :
- unsafe extern "C" fn() =
- {
- unsafe extern fn __dtor() { #ident() };
- __dtor
- };
- }
);
// eprintln!("{}", output);
@@ -387,7 +385,7 @@ fn validate_item(typ: &str, item: &syn::ItemFn) {
}
// No parameters allowed
- if sig.inputs.len() > 0 {
+ if !sig.inputs.is_empty() {
panic!("#[{}] methods may not have parameters", typ);
}