Unnamed repository; edit this file 'description' to name the repository.
Merge ref '942ac9ce4116' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: rust-lang/rust@942ac9ce4116d4ea784c9882659372b34978b1f8 Filtered ref: rust-lang/rust-analyzer@104b3c294b910c35efe7a9e0cf8f3c0582c5fd06 Upstream diff: https://github.com/rust-lang/rust/compare/485ec3fbcc12fa14ef6596dabb125ad710499c9e...942ac9ce4116d4ea784c9882659372b34978b1f8 This merge was created using https://github.com/rust-lang/josh-sync.
The rustc-josh-sync Cronjob Bot 3 weeks ago
parent e9f9c7d · parent 104b3c2 · commit a9f0042
-rw-r--r--Cargo.lock34
-rw-r--r--Cargo.toml9
-rw-r--r--crates/proc-macro-srv/Cargo.toml6
-rw-r--r--crates/proc-macro-srv/src/dylib.rs169
-rw-r--r--crates/proc-macro-srv/src/dylib/proc_macros.rs8
-rw-r--r--crates/proc-macro-srv/src/lib.rs3
6 files changed, 12 insertions, 217 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 38aa3050f4..602af6f122 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -90,7 +90,7 @@ dependencies = [
"cfg-if",
"libc",
"miniz_oxide",
- "object 0.37.3",
+ "object",
"rustc-demangle",
"windows-link",
]
@@ -1408,16 +1408,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
[[package]]
-name = "libloading"
-version = "0.8.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
-dependencies = [
- "cfg-if",
- "windows-link",
-]
-
-[[package]]
name = "libmimalloc-sys"
version = "0.1.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1581,15 +1571,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8"
[[package]]
-name = "memmap2"
-version = "0.9.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "714098028fe011992e1c3962653c96b2d578c4b4bce9036e15ff220319b1e0e3"
-dependencies = [
- "libc",
-]
-
-[[package]]
name = "memoffset"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1749,15 +1730,6 @@ checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33"
[[package]]
name = "object"
-version = "0.36.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
-dependencies = [
- "memchr",
-]
-
-[[package]]
-name = "object"
version = "0.37.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe"
@@ -1983,11 +1955,7 @@ version = "0.0.0"
dependencies = [
"expect-test",
"intern",
- "libc",
- "libloading",
"line-index 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "memmap2",
- "object 0.36.7",
"paths",
"proc-macro-test",
"span",
diff --git a/Cargo.toml b/Cargo.toml
index 37e5dbb444..3e2815e875 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -116,17 +116,8 @@ expect-test = "1.5.1"
indexmap = { version = "2.9.0", features = ["serde"] }
itertools = "0.14.0"
libc = "0.2.172"
-libloading = "0.8.8"
-memmap2 = "0.9.5"
nohash-hasher = "0.2.0"
oorandom = "11.1.5"
-object = { version = "0.36.7", default-features = false, features = [
- "std",
- "read_core",
- "elf",
- "macho",
- "pe",
-] }
postcard = { version = "1.1.3", features = ["alloc"] }
process-wrap = { version = "9.1.0", features = ["std"] }
pulldown-cmark-to-cmark = "10.0.4"
diff --git a/crates/proc-macro-srv/Cargo.toml b/crates/proc-macro-srv/Cargo.toml
index 68e0bb6ac8..1b86eac012 100644
--- a/crates/proc-macro-srv/Cargo.toml
+++ b/crates/proc-macro-srv/Cargo.toml
@@ -13,9 +13,6 @@ rust-version.workspace = true
doctest = false
[dependencies]
-object.workspace = true
-libloading.workspace = true
-memmap2.workspace = true
temp-dir.workspace = true
paths.workspace = true
@@ -24,9 +21,6 @@ span = { path = "../span", version = "0.0.0", default-features = false}
intern.workspace = true
-[target.'cfg(unix)'.dependencies]
-libc.workspace = true
-
[dev-dependencies]
expect-test.workspace = true
line-index.workspace = true
diff --git a/crates/proc-macro-srv/src/dylib.rs b/crates/proc-macro-srv/src/dylib.rs
index f654d21cfe..1978a68dd9 100644
--- a/crates/proc-macro-srv/src/dylib.rs
+++ b/crates/proc-macro-srv/src/dylib.rs
@@ -4,22 +4,18 @@ mod proc_macros;
use rustc_codegen_ssa::back::metadata::DefaultMetadataLoader;
use rustc_interface::util::rustc_version_str;
-use rustc_metadata::locator::MetadataError;
use rustc_proc_macro::bridge;
use rustc_session::config::host_tuple;
use rustc_target::spec::{Target, TargetTuple};
use std::path::Path;
-use std::{fmt, fs, io, time::SystemTime};
+use std::{fs, io, time::SystemTime};
use temp_dir::TempDir;
-use libloading::Library;
-use object::Object;
use paths::{Utf8Path, Utf8PathBuf};
use crate::{
PanicMessage, ProcMacroClientHandle, ProcMacroKind, ProcMacroSrvSpan, TrackedEnv,
- dylib::proc_macros::{ProcMacroClients, ProcMacros},
- token_stream::TokenStream,
+ dylib::proc_macros::ProcMacros, token_stream::TokenStream,
};
pub(crate) struct Expander {
@@ -28,10 +24,7 @@ pub(crate) struct Expander {
}
impl Expander {
- pub(crate) fn new(
- temp_dir: &TempDir,
- lib: &Utf8Path,
- ) -> Result<Expander, LoadProcMacroDylibError> {
+ pub(crate) fn new(temp_dir: &TempDir, lib: &Utf8Path) -> io::Result<Expander> {
// Some libraries for dynamic loading require canonicalized path even when it is
// already absolute
let lib = lib.canonicalize_utf8()?;
@@ -78,61 +71,17 @@ impl Expander {
}
}
-#[derive(Debug)]
-pub enum LoadProcMacroDylibError {
- Io(io::Error),
- LibLoading(libloading::Error),
- MetadataError(MetadataError<'static>),
-}
-
-impl fmt::Display for LoadProcMacroDylibError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- Self::Io(e) => e.fmt(f),
- Self::LibLoading(e) => e.fmt(f),
- Self::MetadataError(e) => e.fmt(f),
- }
- }
-}
-
-impl From<io::Error> for LoadProcMacroDylibError {
- fn from(e: io::Error) -> Self {
- LoadProcMacroDylibError::Io(e)
- }
-}
-
-impl From<libloading::Error> for LoadProcMacroDylibError {
- fn from(e: libloading::Error) -> Self {
- LoadProcMacroDylibError::LibLoading(e)
- }
-}
-
-impl From<MetadataError<'_>> for LoadProcMacroDylibError {
- fn from(e: MetadataError<'_>) -> Self {
- LoadProcMacroDylibError::MetadataError(match e {
- MetadataError::NotPresent(path) => MetadataError::NotPresent(path.into_owned().into()),
- MetadataError::LoadFailure(err) => MetadataError::LoadFailure(err),
- MetadataError::VersionMismatch { expected_version, found_version } => {
- MetadataError::VersionMismatch { expected_version, found_version }
- }
- })
- }
-}
-
struct ProcMacroLibrary {
- // this contains references to the library, so make sure this drops before _lib
proc_macros: ProcMacros,
- // Hold on to the library so it doesn't unload
- _lib: Library,
}
impl ProcMacroLibrary {
- fn open(path: &Utf8Path) -> Result<Self, LoadProcMacroDylibError> {
- let proc_macro_kinds = rustc_span::create_default_session_globals_then(|| {
+ fn open(path: &Utf8Path) -> io::Result<Self> {
+ let proc_macros = rustc_span::create_default_session_globals_then(|| {
let (target, _) =
Target::search(&TargetTuple::from_tuple(host_tuple()), Path::new(""), false)
.unwrap();
- rustc_metadata::locator::get_proc_macro_info(
+ rustc_metadata::locator::get_proc_macros(
&target,
path.as_ref(),
&DefaultMetadataLoader,
@@ -140,63 +89,10 @@ impl ProcMacroLibrary {
)
})?;
- let file = fs::File::open(path)?;
- #[allow(clippy::undocumented_unsafe_blocks)] // FIXME
- let file = unsafe { memmap2::Mmap::map(&file) }?;
- let obj = object::File::parse(&*file)
- .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
- let symbol_name =
- find_registrar_symbol(&obj).map_err(invalid_data_err)?.ok_or_else(|| {
- invalid_data_err(format!("Cannot find registrar symbol in file {path}"))
- })?;
-
- // SAFETY: We have verified the validity of the dylib as a proc-macro library
- let lib = unsafe { load_library(path) }.map_err(invalid_data_err)?;
- // SAFETY: We have verified the validity of the dylib as a proc-macro library
- // The 'static lifetime is a lie, it's actually the lifetime of the library but unavoidable
- // due to self-referentiality
- // But we make sure that we do not drop it before the symbol is dropped
- let proc_macros =
- unsafe { lib.get::<&'static &'static ProcMacroClients>(symbol_name.as_bytes()) };
- match proc_macros {
- Ok(proc_macros) => Ok(ProcMacroLibrary {
- proc_macros: ProcMacros::new(*proc_macros, proc_macro_kinds),
- _lib: lib,
- }),
- Err(e) => Err(e.into()),
- }
+ Ok(ProcMacroLibrary { proc_macros: ProcMacros::new(proc_macros) })
}
}
-fn invalid_data_err(e: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> io::Error {
- io::Error::new(io::ErrorKind::InvalidData, e)
-}
-
-fn is_derive_registrar_symbol(symbol: &str) -> bool {
- const NEW_REGISTRAR_SYMBOL: &str = "_rustc_proc_macro_decls_";
- symbol.contains(NEW_REGISTRAR_SYMBOL)
-}
-
-fn find_registrar_symbol(obj: &object::File<'_>) -> object::Result<Option<String>> {
- Ok(obj
- .exports()?
- .into_iter()
- .map(|export| export.name())
- .filter_map(|sym| String::from_utf8(sym.into()).ok())
- .find(|sym| is_derive_registrar_symbol(sym))
- .map(|sym| {
- // From MacOS docs:
- // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dlsym.3.html
- // Unlike other dyld API's, the symbol name passed to dlsym() must NOT be
- // prepended with an underscore.
- if cfg!(target_os = "macos") && sym.starts_with('_') {
- sym[1..].to_owned()
- } else {
- sym
- }
- }))
-}
-
/// Copy the dylib to temp directory to prevent locking in Windows
#[cfg(windows)]
fn ensure_file_with_lock_free_access(
@@ -233,54 +129,3 @@ fn ensure_file_with_lock_free_access(
) -> io::Result<Utf8PathBuf> {
Ok(path.to_owned())
}
-
-/// Loads dynamic library in platform dependent manner.
-///
-/// For unix, you have to use RTLD_DEEPBIND flag to escape problems described
-/// [here](https://github.com/fedochet/rust-proc-macro-panic-inside-panic-expample)
-/// and [here](https://github.com/rust-lang/rust/issues/60593).
-///
-/// Usage of RTLD_DEEPBIND
-/// [here](https://github.com/fedochet/rust-proc-macro-panic-inside-panic-expample/issues/1)
-///
-/// It seems that on Windows that behaviour is default, so we do nothing in that case.
-///
-/// # Safety
-///
-/// The caller is responsible for ensuring that the path is valid proc-macro library
-#[cfg(windows)]
-unsafe fn load_library(file: &Utf8Path) -> Result<Library, libloading::Error> {
- // SAFETY: The caller is responsible for ensuring that the path is valid proc-macro library
- unsafe { Library::new(file) }
-}
-
-/// Loads dynamic library in platform dependent manner.
-///
-/// For unix, you have to use RTLD_DEEPBIND flag to escape problems described
-/// [here](https://github.com/fedochet/rust-proc-macro-panic-inside-panic-expample)
-/// and [here](https://github.com/rust-lang/rust/issues/60593).
-///
-/// Usage of RTLD_DEEPBIND
-/// [here](https://github.com/fedochet/rust-proc-macro-panic-inside-panic-expample/issues/1)
-///
-/// It seems that on Windows that behaviour is default, so we do nothing in that case.
-///
-/// # Safety
-///
-/// The caller is responsible for ensuring that the path is valid proc-macro library
-#[cfg(unix)]
-unsafe fn load_library(file: &Utf8Path) -> Result<Library, libloading::Error> {
- // not defined by POSIX, different values on mips vs other targets
- #[cfg(target_env = "gnu")]
- use libc::RTLD_DEEPBIND;
- use libloading::os::unix::Library as UnixLibrary;
- // defined by POSIX
- use libloading::os::unix::RTLD_NOW;
-
- // MUSL and bionic don't have it..
- #[cfg(not(target_env = "gnu"))]
- const RTLD_DEEPBIND: std::os::raw::c_int = 0x0;
-
- // SAFETY: The caller is responsible for ensuring that the path is valid proc-macro library
- unsafe { UnixLibrary::open(Some(file), RTLD_NOW | RTLD_DEEPBIND).map(|lib| lib.into()) }
-}
diff --git a/crates/proc-macro-srv/src/dylib/proc_macros.rs b/crates/proc-macro-srv/src/dylib/proc_macros.rs
index ef6752d816..4976298d5f 100644
--- a/crates/proc-macro-srv/src/dylib/proc_macros.rs
+++ b/crates/proc-macro-srv/src/dylib/proc_macros.rs
@@ -4,9 +4,6 @@ use crate::{
};
use rustc_proc_macro::bridge;
-#[repr(transparent)]
-pub(crate) struct ProcMacroClients([bridge::client::Client]);
-
impl From<bridge::PanicMessage> for crate::PanicMessage {
fn from(p: bridge::PanicMessage) -> Self {
Self { message: p.into_string() }
@@ -17,10 +14,9 @@ pub(crate) struct ProcMacros(Vec<(bridge::client::Client, rustc_metadata::ProcMa
impl ProcMacros {
pub(super) fn new(
- clients: &ProcMacroClients,
- kinds: Vec<rustc_metadata::ProcMacroKind>,
+ macros: Vec<(bridge::client::Client, rustc_metadata::ProcMacroKind)>,
) -> Self {
- ProcMacros(clients.0.iter().copied().zip(kinds).collect::<Vec<_>>())
+ ProcMacros(macros)
}
pub(crate) fn expand<'a, S: ProcMacroSrvSpan>(
diff --git a/crates/proc-macro-srv/src/lib.rs b/crates/proc-macro-srv/src/lib.rs
index b8cd3621d6..2a3a1bc002 100644
--- a/crates/proc-macro-srv/src/lib.rs
+++ b/crates/proc-macro-srv/src/lib.rs
@@ -10,9 +10,10 @@
#![cfg(feature = "in-rust-tree")]
#![feature(proc_macro_internals, proc_macro_diagnostic, proc_macro_span, rustc_private)]
-#![expect(unreachable_pub, internal_features, clippy::disallowed_types, clippy::print_stderr)]
+#![expect(internal_features, clippy::disallowed_types, clippy::print_stderr)]
#![allow(unused_features, unused_crate_dependencies)]
#![deny(deprecated_safe, clippy::undocumented_unsafe_blocks)]
+#![cfg_attr(test, expect(unreachable_pub))]
extern crate rustc_codegen_ssa;
extern crate rustc_driver as _;