Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions compiler/rustc_attr_ir/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ impl LintCheckKind {
pub struct LintCheck {
/// The lint's tool name, if present.
pub tool: Option<Ident>,
/// 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.
///
Expand All @@ -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<Box<[Symbol]>>,
}
30 changes: 15 additions & 15 deletions compiler/rustc_attr_parsing/src/attributes/lint.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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::<Vec<_>>()
.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 {
Expand All @@ -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.
Expand Down
22 changes: 15 additions & 7 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_metadata/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> Result<EncodedMetadata, Err
.unwrap_or_else(|err| tcx.dcx().emit_fatal(FailedCreateTempdir { err }));
let metadata_tmpdir = MaybeTempDir::new(metadata_tmpdir, tcx.sess.opts.cg.save_temps);
let metadata_filename = metadata_tmpdir.as_ref().join("full.rmeta");
let metadata_stub_filename = if !tcx.sess.opts.unstable_opts.embed_metadata
&& !tcx.crate_types().contains(&CrateType::ProcMacro)
{
Some(metadata_tmpdir.as_ref().join("stub.rmeta"))
} else {
None
};
let metadata_stub_filename =
if !tcx.sess.embed_metadata() && !tcx.crate_types().contains(&CrateType::ProcMacro) {
Some(metadata_tmpdir.as_ref().join("stub.rmeta"))
} else {
None
};

if tcx.needs_metadata() {
encode_metadata(tcx, &metadata_filename, metadata_stub_filename.as_deref());
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pub(crate) struct CrateHeader {
/// Stubs do not contain the full metadata (it will be typically stored
/// in a separate rmeta file).
///
/// This is used inside rlibs and dylibs when using `-Zembed-metadata=no`.
/// This is used inside rlibs and dylibs when using `-Cembed-metadata=no`.
pub(crate) is_stub: bool,
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
tool: None,
lint_name,
lint_span,
rest: None,
kind: _,
reason: _,
attr_id: _,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> = (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],
Expand Down Expand Up @@ -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<bool> = (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)"),
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions library/std/src/sys/sync/thread_parking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ cfg_select! {
mod windows7;
pub use windows7::Parker;
}
all(target_vendor = "apple", not(miri)) => {
// Doesn't work in Miri, see <https://github.com/rust-lang/miri/issues/2589>.
target_vendor = "apple" => {
mod darwin;
pub use darwin::Parker;
}
Expand Down
7 changes: 5 additions & 2 deletions library/std/src/sys/thread_local/destructors/linux_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<unsafe extern "C" fn(*mut u8), unsafe extern "C" fn(*mut libc::c_void)>(
dtor,
),
t.cast(),
(&raw const __dso_handle) as *mut _,
dso as *mut _,
);
}
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/doc/rustc/src/codegen-options/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/doc/unstable-book/src/compiler-flags/embed-metadata.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 0 additions & 1 deletion src/tools/clippy/clippy_lints/src/collapsible_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ impl CollapsibleIf {
lint,
LintCheck {
tool: Some(Ident { name: sym::clippy, .. }),
rest: None,
kind: LintCheckKind::Expect,
..
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
..
}
Expand Down
8 changes: 4 additions & 4 deletions tests/codegen-llvm/swap-large-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions tests/run-make/embed-metadata/rmake.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/metadata-stub-incremental-reuse/rmake.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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();
Expand Down
Loading