diff --git a/compiler/rustc_attr_ir/src/lint.rs b/compiler/rustc_attr_ir/src/lint.rs index f8f169962ea75..4839412ed59ad 100644 --- a/compiler/rustc_attr_ir/src/lint.rs +++ b/compiler/rustc_attr_ir/src/lint.rs @@ -45,10 +45,12 @@ impl LintCheckKind { pub struct LintCheck { /// The lint's tool name, if present. pub tool: Option, - /// The lint's name. + /// The lint's name, minus the tool name if any. /// - /// With e.g. `clippy::blah` this will be `blah`. - /// Any extra segments are stored in `rest`. + /// For example: + /// - `clippy::blah` -> `blah` + /// - `unstable_imports` -> `unstable_imports` + /// - `custom_tool::blah::bleh` -> `blah::bleh` pub lint_name: Symbol, /// The span of the lint name. /// @@ -66,8 +68,4 @@ pub struct LintCheck { /// inside one attribute are all smooshed and flattened together, so /// multiple `LintCheck`s can have the same `attr_span`. pub attr_span: Span, - /// Any extra segments of the lint name (not including `tool` and `lint_name`), - /// this should be rare and indicates misuse of the attribute as nothing supports - /// 3+ segment lints like `#[allow(tool::two::three)]`. - pub rest: Option>, } diff --git a/compiler/rustc_attr_parsing/src/attributes/lint.rs b/compiler/rustc_attr_parsing/src/attributes/lint.rs index 0c603faa4b5f9..db57b23f6296a 100644 --- a/compiler/rustc_attr_parsing/src/attributes/lint.rs +++ b/compiler/rustc_attr_parsing/src/attributes/lint.rs @@ -1,8 +1,9 @@ +use rustc_ast::join_path_syms; use rustc_attr_ir::AttributeKind; use rustc_attr_ir::lint::{LintCheck, LintCheckKind}; use rustc_attr_ir::target::{AssocCtxt, MethodKind, Target}; use rustc_lint_defs::builtin::UNUSED_ATTRIBUTES; -use rustc_span::sym; +use rustc_span::{Symbol, sym}; use thin_vec::ThinVec; use crate::attributes::{AcceptMapping, AttributeParser, AttributeStability}; @@ -52,20 +53,20 @@ impl LintParser { MetaItemOrLitParser::MetaItemParser(p) => { match p.args() { ArgParser::NoArgs => { - let (tool, lint_name, rest) = match &*p.path().0.segments { + let (tool, lint_name) = match &*p.path().0.segments { [] => unreachable!(), - [lint_name] => (None, lint_name.ident.name, None), - [tool, lint_name] => { - (Some(tool.ident), lint_name.ident.name, None) - } - [tool, lint_name, rest @ ..] => { - let rest = rest - .iter() - .map(|s| s.ident.name) - .collect::>() - .into(); - (Some(tool.ident), lint_name.ident.name, Some(rest)) - } + [lint_name] => (None, lint_name.ident.name), + [tool, lint_name] => (Some(tool.ident), lint_name.ident.name), + // Not reachable for any builtin lints, + // but reachable using `register_tool`. + [tool, multi_segment_lint_name @ ..] => ( + Some(tool.ident), + Symbol::intern(&join_path_syms( + multi_segment_lint_name + .iter() + .map(|seg| seg.ident.name), + )), + ), }; self.lints.push(LintCheck { @@ -76,7 +77,6 @@ impl LintParser { attr_id, reason, attr_span, - rest, }) } // We've found a `reason = "reason"` but we're not the last element. diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index a7540e294ec37..622ac2a905d70 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1349,17 +1349,25 @@ fn link_natively( continue; } - // Detect '-static-pie' used with an older version of gcc or clang not supporting it. - // Fallback from '-static-pie' to '-static' in that case. + // Detect '-static-pie' used with an older version of gcc or clang not supporting it, + // or with glibc that's missing crt objects, e.g. for arches that don't support it. + // Fallback from '-static-pie' to '-static' in either case. + let mut static_pie_message = None; if matches!(flavor, LinkerFlavor::Gnu(Cc::Yes, _)) - && unknown_arg_regex.is_match(&out) - && (out.contains("-static-pie") || out.contains("--no-dynamic-linker")) && cmd.get_args().iter().any(|e| e == "-static-pie") { + if unknown_arg_regex.is_match(&out) + && (out.contains("-static-pie") || out.contains("--no-dynamic-linker")) + { + static_pie_message = + Some("Linker does not support -static-pie command line option."); + } else if Regex::new(r"cannot (find|open) g?rcrt1\.o:").unwrap().is_match(&out) { + static_pie_message = Some("C library is missing static-PIE startup objects."); + } + } + if let Some(message) = static_pie_message { info!("linker output: {:?}", out); - warn!( - "Linker does not support -static-pie command line option. Retrying with -static instead." - ); + warn!("{message} Retrying with -static instead."); // Mirror `add_(pre,post)_link_objects` to replace CRT objects. let self_contained_crt_objects = self_contained_components.is_crt_objects_enabled(); let opts = &sess.target; diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 34ac92faef88c..1e7cdd15d0788 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -639,6 +639,7 @@ fn test_codegen_options_tracking_hash() { tracked!(debuginfo, DebugInfo::Limited); tracked!(dwarf_version, Some(5)); tracked!(embed_bitcode, false); + tracked!(embed_metadata, Some(false)); tracked!(force_frame_pointers, FramePointer::Always); tracked!(force_unwind_tables, Some(true)); tracked!(instrument_coverage, InstrumentCoverage::Yes); @@ -819,7 +820,7 @@ fn test_unstable_options_tracking_hash() { tracked!(direct_access_external_data, Some(true)); tracked!(dual_proc_macros, true); tracked!(dwarf_version, Some(5)); - tracked!(embed_metadata, false); + tracked!(embed_metadata, Some(false)); tracked!(embed_source, true); tracked!(export_executable_symbols, true); tracked!(fewer_names, Some(true)); diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index a9995f6ec5451..c9e58957ebfae 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -1,8 +1,8 @@ use std::fmt::Debug; use rustc_ast as ast; +use rustc_ast::CRATE_NODE_ID; use rustc_ast::attr::AttributeExt; -use rustc_ast::{CRATE_NODE_ID, join_path_syms}; use rustc_attr_ir::lint::{LintCheck, LintCheckKind}; use rustc_attr_ir::target::Target; use rustc_attr_ir::{Attribute, AttributeKind, find_attr}; @@ -753,14 +753,10 @@ where // FIXME: consider performing these checks in attribute parsing instead for (lint_index, lint_check) in lint_checks.into_iter().enumerate() { - let LintCheck { tool, lint_name, lint_span, kind, reason, attr_id, attr_span: _, rest } = + let LintCheck { tool, lint_name, lint_span, kind, reason, attr_id, attr_span: _ } = lint_check; - let full_lint_name = if let Some(rest) = rest { - &join_path_syms([lint_name].into_iter().chain(rest)) - } else { - lint_name.as_str() - }; + let full_lint_name = lint_name.as_str(); let level = match kind { LintCheckKind::Allow => Level::Allow, diff --git a/compiler/rustc_metadata/src/diagnostics.rs b/compiler/rustc_metadata/src/diagnostics.rs index 18796f51375a1..1060423523e5c 100644 --- a/compiler/rustc_metadata/src/diagnostics.rs +++ b/compiler/rustc_metadata/src/diagnostics.rs @@ -325,7 +325,7 @@ impl Diagnostic<'_> for MultipleCandidates { #[derive(Diagnostic)] #[diag( - "only metadata stub found for `{$flavor}` dependency `{$crate_name}` please provide path to the corresponding .rmeta file with full metadata" + "only metadata stub found for `{$flavor}` dependency `{$crate_name}`. Please provide path to the corresponding .rmeta file with full metadata" )] pub(crate) struct FullMetadataNotFound { #[primary_span] diff --git a/compiler/rustc_metadata/src/fs.rs b/compiler/rustc_metadata/src/fs.rs index ed177708facc0..e653522950651 100644 --- a/compiler/rustc_metadata/src/fs.rs +++ b/compiler/rustc_metadata/src/fs.rs @@ -48,13 +48,12 @@ pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> Result CheckAttrVisitor<'tcx> { tool: None, lint_name, lint_span, - rest: None, kind: _, reason: _, attr_id: _, diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 7e274c66f6f75..fd148dccf097c 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2987,6 +2987,10 @@ pub fn build_session_options( .early_warn("using -Z remark-dir without enabling remarks using e.g. -C remark=all"); } + if cg.embed_metadata.is_some() && unstable_opts.embed_metadata.is_some() { + early_dcx.early_fatal("can't use both -Z embed-metadata and -C embed-metadata"); + } + let externs = parse_externs(early_dcx, matches, &unstable_opts); let remap_path_prefix = parse_remap_path_prefix(early_dcx, matches); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index a29309c71e879..e6a9d5e5ebd49 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2251,6 +2251,8 @@ options! { "version of DWARF debug information to emit (default: 2 or 4, depending on platform)"), embed_bitcode: bool = (true, parse_bool, [TRACKED], "emit bitcode in rlibs (default: yes)"), + embed_metadata: Option = (None, parse_opt_bool, [TRACKED], + "embed metadata in rlibs and dylibs (default: yes)"), extra_filename: String = (String::new(), parse_string, [UNTRACKED], "extra data to put in each output filename"), force_frame_pointers: FramePointer = (FramePointer::MayOmit, parse_frame_pointer, [TRACKED], @@ -2514,7 +2516,8 @@ options! { them only if an error has not been emitted"), ehcont_guard: bool = (false, parse_bool, [TRACKED], "generate Windows EHCont Guard tables"), - embed_metadata: bool = (true, parse_bool, [TRACKED], + // FIXME(kobzol): remove in 2027 + embed_metadata: Option = (None, parse_opt_bool, [TRACKED], "embed metadata in rlibs and dylibs (default: yes)"), embed_source: bool = (false, parse_bool, [TRACKED], "embed source text in DWARF debug sections (default: no)"), diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index f068aaa584dce..5e96e48cf7333 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -962,6 +962,11 @@ impl Session { } } } + + /// Should metadata be embedded within .rlib and .dylib files? + pub fn embed_metadata(&self) -> bool { + self.opts.cg.embed_metadata.or(self.opts.unstable_opts.embed_metadata).unwrap_or(true) + } } // JUSTIFICATION: defn of the suggested wrapper fns diff --git a/library/std/src/sys/sync/thread_parking/mod.rs b/library/std/src/sys/sync/thread_parking/mod.rs index f1385ef7bdde6..dffa0ade947ee 100644 --- a/library/std/src/sys/sync/thread_parking/mod.rs +++ b/library/std/src/sys/sync/thread_parking/mod.rs @@ -27,8 +27,7 @@ cfg_select! { mod windows7; pub use windows7::Parker; } - all(target_vendor = "apple", not(miri)) => { - // Doesn't work in Miri, see . + target_vendor = "apple" => { mod darwin; pub use darwin::Parker; } diff --git a/library/std/src/sys/thread_local/destructors/linux_like.rs b/library/std/src/sys/thread_local/destructors/linux_like.rs index d7cbaeb89f42e..5f2e454b99e9e 100644 --- a/library/std/src/sys/thread_local/destructors/linux_like.rs +++ b/library/std/src/sys/thread_local/destructors/linux_like.rs @@ -37,14 +37,17 @@ pub unsafe fn register(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { >; } - if let Some(f) = unsafe { __cxa_thread_atexit_impl } { + if let Some(f) = unsafe { __cxa_thread_atexit_impl } + && let dso = unsafe { __dso_handle } + && !dso.is_null() + { unsafe { f( transmute::( dtor, ), t.cast(), - (&raw const __dso_handle) as *mut _, + dso as *mut _, ); } } else { diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index 0f85e6d00e36b..67c4fd7806933 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -152,6 +152,14 @@ at start-up, because the combination is invalid. > reason for that is that it's how it was for rustc 1.44 and prior. In 1.45 this > option was added to turn off what had always been the default. +## embed-metadata + +This option instructs `rustc` to include the full metadata in `rlib` and `dylib` +crate types. The default value is `yes` (enabled). If disabled (`no`), only stub +metadata will be stored in these files, to reduce their size on disk. When using +`-Cembed-metadata=no`, you will probably want to use `--emit=metadata` to produce +the full metadata into a separate `.rmeta` file. + ## extra-filename This option allows you to put extra data in each output filename. It takes a diff --git a/src/doc/unstable-book/src/compiler-flags/embed-metadata.md b/src/doc/unstable-book/src/compiler-flags/embed-metadata.md index a2a790ee76af3..6ce71f4775232 100644 --- a/src/doc/unstable-book/src/compiler-flags/embed-metadata.md +++ b/src/doc/unstable-book/src/compiler-flags/embed-metadata.md @@ -1,3 +1,5 @@ ## `embed-metadata` This option instructs `rustc` to include the full metadata in `rlib` and `dylib` crate types. The default value is `yes` (enabled). If disabled (`no`), only stub metadata will be stored in these files, to reduce their size on disk. When using `-Zembed-metadata=no`, you will probably want to use `--emit=metadata` to produce the full metadata into a separate `.rmeta` file. + +Note that this flag has been stabilized as `-Cembed-metadata`. The unstable variant of the flag is provided purely for making the migration easier; it will be removed in the future. diff --git a/src/tools/clippy/clippy_lints/src/collapsible_if.rs b/src/tools/clippy/clippy_lints/src/collapsible_if.rs index 5898b2eb267a4..54291d2867dec 100644 --- a/src/tools/clippy/clippy_lints/src/collapsible_if.rs +++ b/src/tools/clippy/clippy_lints/src/collapsible_if.rs @@ -248,7 +248,6 @@ impl CollapsibleIf { lint, LintCheck { tool: Some(Ident { name: sym::clippy, .. }), - rest: None, kind: LintCheckKind::Expect, .. } diff --git a/src/tools/clippy/clippy_lints/src/returns/needless_return.rs b/src/tools/clippy/clippy_lints/src/returns/needless_return.rs index 7e21f1e9b1b5d..37db2fd81c3d2 100644 --- a/src/tools/clippy/clippy_lints/src/returns/needless_return.rs +++ b/src/tools/clippy/clippy_lints/src/returns/needless_return.rs @@ -190,7 +190,6 @@ fn check_final_expr<'tcx>( LintCheck { tool: Some(Ident { name: sym::clippy, .. }), lint_name: sym::needless_return | sym::style | sym::all | sym::warnings, - rest: None, kind: LintCheckKind::Expect, .. } diff --git a/tests/codegen-llvm/swap-large-types.rs b/tests/codegen-llvm/swap-large-types.rs index 08c486affd949..7c32478873e6c 100644 --- a/tests/codegen-llvm/swap-large-types.rs +++ b/tests/codegen-llvm/swap-large-types.rs @@ -99,11 +99,11 @@ pub fn swap_big_aligned(x: &mut BigButHighlyAligned, y: &mut BigButHighlyAligned // CHECK-NOT: load i8 // CHECK-NOT: store i8 - // CHECK-COUNT-2: load <{{2|4}} x i64>{{.+}}align 64, - // CHECK-COUNT-2: store <{{2|4}} x i64>{{.+}}align 64, + // CHECK-COUNT-2: load <{{2|4}} x i64>{{.+}}align 64 + // CHECK-COUNT-2: store <{{2|4}} x i64>{{.+}}align 64 - // CHECK-COUNT-2: load <{{2|4}} x i64>{{.+}}align 32, - // CHECK-COUNT-2: store <{{2|4}} x i64>{{.+}}align 32, + // CHECK-COUNT-2: load <{{2|4}} x i64>{{.+}}align 32 + // CHECK-COUNT-2: store <{{2|4}} x i64>{{.+}}align 32 // CHECK-NOT: load i32 // CHECK-NOT: store i32 diff --git a/tests/run-make/embed-metadata/rmake.rs b/tests/run-make/embed-metadata/rmake.rs index 2de6575feb886..ff80e733c3708 100644 --- a/tests/run-make/embed-metadata/rmake.rs +++ b/tests/run-make/embed-metadata/rmake.rs @@ -1,8 +1,7 @@ //@ ignore-cross-compile //@ needs-crate-type: dylib -// Tests the -Zembed-metadata compiler flag. -// Tracking issue: https://github.com/rust-lang/rust/issues/139165 +// Tests the -Cembed-metadata compiler flag. use run_make_support::rfs::{create_dir, remove_file, rename}; use run_make_support::{Rustc, dynamic_lib_name, path, run_in_tmpdir, rust_lib_name, rustc}; @@ -78,7 +77,7 @@ fn lookup_rmeta_missing(kind: LibraryKind) { fn build_dep_rustc(kind: LibraryKind) -> Rustc { let mut dep_rustc = rustc(); dep_rustc - .arg("-Zembed-metadata=no") + .arg("-Cembed-metadata=no") .crate_type(kind.crate_type()) .input("dep1.rs") .emit("metadata,link"); diff --git a/tests/run-make/metadata-stub-incremental-reuse/rmake.rs b/tests/run-make/metadata-stub-incremental-reuse/rmake.rs index e76433c97d159..adc64d6c38b74 100644 --- a/tests/run-make/metadata-stub-incremental-reuse/rmake.rs +++ b/tests/run-make/metadata-stub-incremental-reuse/rmake.rs @@ -1,6 +1,6 @@ //@ needs-target-std // -// Under `-Zembed-metadata=no` the rlib carries only a metadata stub, which +// Under `-Cembed-metadata=no` the rlib carries only a metadata stub, which // rustc writes as a separate file alongside the full metadata. Recompiling // with `-C incremental` can reuse the full metadata from a work product, and // the stub must still be produced on that path. @@ -13,7 +13,7 @@ fn build(out_dir: &str, incremental: &str) { .crate_name("foo") .crate_type("lib") .emit("dep-info,metadata,link") - .arg("-Zembed-metadata=no") + .arg("-Cembed-metadata=no") .incremental(incremental) .out_dir(out_dir) .run();