diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index 7a747a9cdee4e..02ba5c396350d 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -16,7 +16,7 @@ use rustc_errors::{FatalError, Handler}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::bug; use rustc_middle::dep_graph::WorkProduct; -use rustc_middle::middle::exported_symbols::SymbolExportLevel; +use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel}; use rustc_session::cgu_reuse_tracker::CguReuse; use rustc_session::config::{self, CrateType, Lto}; use tracing::{debug, info}; @@ -55,8 +55,8 @@ fn prepare_lto( Lto::No => panic!("didn't request LTO but we're doing LTO"), }; - let symbol_filter = &|&(ref name, level): &(String, SymbolExportLevel)| { - if level.is_below_threshold(export_threshold) { + let symbol_filter = &|&(ref name, info): &(String, SymbolExportInfo)| { + if info.level.is_below_threshold(export_threshold) { Some(CString::new(name.as_str()).unwrap()) } else { None diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index cf32d558d4a51..08b200a900893 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -7,6 +7,7 @@ use rustc_errors::{ErrorGuaranteed, Handler}; use rustc_fs_util::fix_windows_verbatim_for_gcc; use rustc_hir::def_id::CrateNum; use rustc_middle::middle::dependency_format::Linkage; +use rustc_middle::middle::exported_symbols::SymbolExportKind; use rustc_session::config::{self, CFGuard, CrateType, DebugInfo, LdImpl, Strip}; use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, SplitDwarfKind}; use rustc_session::cstore::DllImport; @@ -1655,6 +1656,67 @@ fn add_post_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor } } +/// Add a synthetic object file that contains reference to all symbols that we want to expose to +/// the linker. +/// +/// Background: we implement rlibs as static library (archives). Linkers treat archives +/// differently from object files: all object files participate in linking, while archives will +/// only participate in linking if they can satisfy at least one undefined reference (version +/// scripts doesn't count). This causes `#[no_mangle]` or `#[used]` items to be ignored by the +/// linker, and since they never participate in the linking, using `KEEP` in the linker scripts +/// can't keep them either. This causes #47384. +/// +/// To keep them around, we could use `--whole-archive` and equivalents to force rlib to +/// participate in linking like object files, but this proves to be expensive (#93791). Therefore +/// we instead just introduce an undefined reference to them. This could be done by `-u` command +/// line option to the linker or `EXTERN(...)` in linker scripts, however they does not only +/// introduce an undefined reference, but also make them the GC roots, preventing `--gc-sections` +/// from removing them, and this is especially problematic for embedded programming where every +/// byte counts. +/// +/// This method creates a synthetic object file, which contains undefined references to all symbols +/// that are necessary for the linking. They are only present in symbol table but not actually +/// used in any sections, so the linker will therefore pick relevant rlibs for linking, but +/// unused `#[no_mangle]` or `#[used]` can still be discard by GC sections. +fn add_linked_symbol_object( + cmd: &mut dyn Linker, + sess: &Session, + tmpdir: &Path, + symbols: &[(String, SymbolExportKind)], +) { + if symbols.is_empty() { + return; + } + + let Some(mut file) = super::metadata::create_object_file(sess) else { + return; + }; + + for (sym, kind) in symbols.iter() { + file.add_symbol(object::write::Symbol { + name: sym.clone().into(), + value: 0, + size: 0, + kind: match kind { + SymbolExportKind::Text => object::SymbolKind::Text, + SymbolExportKind::Data => object::SymbolKind::Data, + SymbolExportKind::Tls => object::SymbolKind::Tls, + }, + scope: object::SymbolScope::Unknown, + weak: false, + section: object::write::SymbolSection::Undefined, + flags: object::SymbolFlags::None, + }); + } + + let path = tmpdir.join("symbols.o"); + let result = std::fs::write(&path, file.write().unwrap()); + if let Err(e) = result { + sess.fatal(&format!("failed to write {}: {}", path.display(), e)); + } + cmd.add_object(&path); +} + /// Add object files containing code from the current crate. fn add_local_crate_regular_objects(cmd: &mut dyn Linker, codegen_results: &CodegenResults) { for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) { @@ -1795,6 +1857,13 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( // Pre-link CRT objects. add_pre_link_objects(cmd, sess, link_output_kind, crt_objects_fallback); + add_linked_symbol_object( + cmd, + sess, + tmpdir, + &codegen_results.crate_info.linked_symbols[&crate_type], + ); + // Sanitizer libraries. add_sanitizer_libraries(sess, crate_type, cmd); diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 2c15ed831670c..6e13e0d0e43b1 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -12,6 +12,7 @@ use std::{env, mem, str}; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_middle::middle::dependency_format::Linkage; +use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo, SymbolExportKind}; use rustc_middle::ty::TyCtxt; use rustc_serialize::{json, Encoder}; use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip}; @@ -1518,6 +1519,29 @@ impl<'a> L4Bender<'a> { } } +fn for_each_exported_symbols_include_dep<'tcx>( + tcx: TyCtxt<'tcx>, + crate_type: CrateType, + mut callback: impl FnMut(ExportedSymbol<'tcx>, SymbolExportInfo, CrateNum), +) { + for &(symbol, info) in tcx.exported_symbols(LOCAL_CRATE).iter() { + callback(symbol, info, LOCAL_CRATE); + } + + let formats = tcx.dependency_formats(()); + let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap(); + + for (index, dep_format) in deps.iter().enumerate() { + let cnum = CrateNum::new(index + 1); + // For each dependency that we are linking to statically ... + if *dep_format == Linkage::Static { + for &(symbol, info) in tcx.exported_symbols(cnum).iter() { + callback(symbol, info, cnum); + } + } + } +} + pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec { if let Some(ref exports) = tcx.sess.target.override_export_symbols { return exports.iter().map(ToString::to_string).collect(); @@ -1526,34 +1550,38 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec, + crate_type: CrateType, +) -> Vec<(String, SymbolExportKind)> { + match crate_type { + CrateType::Executable | CrateType::Cdylib => (), + CrateType::Staticlib | CrateType::ProcMacro | CrateType::Rlib | CrateType::Dylib => { + return Vec::new(); } } + let mut symbols = Vec::new(); + + let export_threshold = symbol_export::crates_export_threshold(&[crate_type]); + for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| { + if info.level.is_below_threshold(export_threshold) || info.used { + symbols.push(( + symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum), + info.kind, + )); + } + }); + symbols } diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index c52269805c46f..2e42272805682 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -94,7 +94,7 @@ fn search_for_metadata<'a>( .map_err(|e| format!("failed to read {} section in '{}': {}", section, path.display(), e)) } -fn create_object_file(sess: &Session) -> Option> { +pub(crate) fn create_object_file(sess: &Session) -> Option> { let endianness = match sess.target.options.endian { Endian::Little => Endianness::Little, Endian::Big => Endianness::Big, diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 765bd877db169..56159cc2e08c5 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -9,7 +9,7 @@ use rustc_hir::Node; use rustc_index::vec::IndexVec; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::middle::exported_symbols::{ - metadata_symbol_name, ExportedSymbol, SymbolExportLevel, + metadata_symbol_name, ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel, }; use rustc_middle::ty::query::{ExternProviders, Providers}; use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; @@ -42,7 +42,7 @@ pub fn crates_export_threshold(crate_types: &[CrateType]) -> SymbolExportLevel { } } -fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap { +fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap { assert_eq!(cnum, LOCAL_CRATE); if !tcx.sess.opts.output_types.should_codegen() { @@ -124,17 +124,38 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap< } else { symbol_export_level(tcx, def_id.to_def_id()) }; + let codegen_attrs = tcx.codegen_fn_attrs(def_id.to_def_id()); debug!( "EXPORTED SYMBOL (local): {} ({:?})", tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())), export_level ); - (def_id.to_def_id(), export_level) + (def_id.to_def_id(), SymbolExportInfo { + level: export_level, + kind: if tcx.is_static(def_id.to_def_id()) { + if codegen_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) { + SymbolExportKind::Tls + } else { + SymbolExportKind::Data + } + } else { + SymbolExportKind::Text + }, + used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED) + || codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER), + }) }) .collect(); if let Some(id) = tcx.proc_macro_decls_static(()) { - reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C); + reachable_non_generics.insert( + id.to_def_id(), + SymbolExportInfo { + level: SymbolExportLevel::C, + kind: SymbolExportKind::Data, + used: false, + }, + ); } reachable_non_generics @@ -143,8 +164,8 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap< fn is_reachable_non_generic_provider_local(tcx: TyCtxt<'_>, def_id: DefId) -> bool { let export_threshold = threshold(tcx); - if let Some(&level) = tcx.reachable_non_generics(def_id.krate).get(&def_id) { - level.is_below_threshold(export_threshold) + if let Some(&info) = tcx.reachable_non_generics(def_id.krate).get(&def_id) { + info.level.is_below_threshold(export_threshold) } else { false } @@ -157,7 +178,7 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b fn exported_symbols_provider_local<'tcx>( tcx: TyCtxt<'tcx>, cnum: CrateNum, -) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] { +) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] { assert_eq!(cnum, LOCAL_CRATE); if !tcx.sess.opts.output_types.should_codegen() { @@ -167,13 +188,20 @@ fn exported_symbols_provider_local<'tcx>( let mut symbols: Vec<_> = tcx .reachable_non_generics(LOCAL_CRATE) .iter() - .map(|(&def_id, &level)| (ExportedSymbol::NonGeneric(def_id), level)) + .map(|(&def_id, &info)| (ExportedSymbol::NonGeneric(def_id), info)) .collect(); if tcx.entry_fn(()).is_some() { let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, "main")); - symbols.push((exported_symbol, SymbolExportLevel::C)); + symbols.push(( + exported_symbol, + SymbolExportInfo { + level: SymbolExportLevel::C, + kind: SymbolExportKind::Text, + used: false, + }, + )); } if tcx.allocator_kind(()).is_some() { @@ -181,7 +209,14 @@ fn exported_symbols_provider_local<'tcx>( let symbol_name = format!("__rust_{}", method.name); let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name)); - symbols.push((exported_symbol, SymbolExportLevel::Rust)); + symbols.push(( + exported_symbol, + SymbolExportInfo { + level: SymbolExportLevel::Rust, + kind: SymbolExportKind::Text, + used: false, + }, + )); } } @@ -194,7 +229,14 @@ fn exported_symbols_provider_local<'tcx>( symbols.extend(PROFILER_WEAK_SYMBOLS.iter().map(|sym| { let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym)); - (exported_symbol, SymbolExportLevel::C) + ( + exported_symbol, + SymbolExportInfo { + level: SymbolExportLevel::C, + kind: SymbolExportKind::Data, + used: false, + }, + ) })); } @@ -204,7 +246,14 @@ fn exported_symbols_provider_local<'tcx>( symbols.extend(MSAN_WEAK_SYMBOLS.iter().map(|sym| { let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym)); - (exported_symbol, SymbolExportLevel::C) + ( + exported_symbol, + SymbolExportInfo { + level: SymbolExportLevel::C, + kind: SymbolExportKind::Data, + used: false, + }, + ) })); } @@ -212,7 +261,14 @@ fn exported_symbols_provider_local<'tcx>( let symbol_name = metadata_symbol_name(tcx); let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name)); - symbols.push((exported_symbol, SymbolExportLevel::Rust)); + symbols.push(( + exported_symbol, + SymbolExportInfo { + level: SymbolExportLevel::Rust, + kind: SymbolExportKind::Data, + used: false, + }, + )); } if tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics() { @@ -245,7 +301,14 @@ fn exported_symbols_provider_local<'tcx>( MonoItem::Fn(Instance { def: InstanceDef::Item(def), substs }) => { if substs.non_erasable_generics().next().is_some() { let symbol = ExportedSymbol::Generic(def.did, substs); - symbols.push((symbol, SymbolExportLevel::Rust)); + symbols.push(( + symbol, + SymbolExportInfo { + level: SymbolExportLevel::Rust, + kind: SymbolExportKind::Text, + used: false, + }, + )); } } MonoItem::Fn(Instance { def: InstanceDef::DropGlue(_, Some(ty)), substs }) => { @@ -254,7 +317,14 @@ fn exported_symbols_provider_local<'tcx>( substs.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)) ); - symbols.push((ExportedSymbol::DropGlue(ty), SymbolExportLevel::Rust)); + symbols.push(( + ExportedSymbol::DropGlue(ty), + SymbolExportInfo { + level: SymbolExportLevel::Rust, + kind: SymbolExportKind::Text, + used: false, + }, + )); } _ => { // Any other symbols don't qualify for sharing diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index d5d21775f0abc..98dc5fe8d6424 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -23,7 +23,7 @@ use rustc_incremental::{ }; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; -use rustc_middle::middle::exported_symbols::SymbolExportLevel; +use rustc_middle::middle::exported_symbols::SymbolExportInfo; use rustc_middle::ty::TyCtxt; use rustc_session::cgu_reuse_tracker::CguReuseTracker; use rustc_session::config::{self, CrateType, Lto, OutputFilenames, OutputType}; @@ -304,7 +304,7 @@ pub type TargetMachineFactoryFn = Arc< + Sync, >; -pub type ExportedSymbols = FxHashMap>>; +pub type ExportedSymbols = FxHashMap>>; /// Additional resources used by optimize_and_codegen (not module specific) #[derive(Clone)] diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 7933afb50e8ce..019c9c179d8e1 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -801,6 +801,12 @@ impl CrateInfo { .iter() .map(|&c| (c, crate::back::linker::exported_symbols(tcx, c))) .collect(); + let linked_symbols = tcx + .sess + .crate_types() + .iter() + .map(|&c| (c, crate::back::linker::linked_symbols(tcx, c))) + .collect(); let local_crate_name = tcx.crate_name(LOCAL_CRATE); let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID); let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem); @@ -834,6 +840,7 @@ impl CrateInfo { let mut info = CrateInfo { target_cpu, exported_symbols, + linked_symbols, local_crate_name, compiler_builtins: None, profiler_runtime: None, diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 5273b6cc83725..d430800220930 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -28,6 +28,7 @@ use rustc_hir::def_id::CrateNum; use rustc_hir::LangItem; use rustc_middle::dep_graph::WorkProduct; use rustc_middle::middle::dependency_format::Dependencies; +use rustc_middle::middle::exported_symbols::SymbolExportKind; use rustc_middle::ty::query::{ExternProviders, Providers}; use rustc_serialize::{opaque, Decodable, Decoder, Encoder}; use rustc_session::config::{CrateType, OutputFilenames, OutputType, RUST_CGU_EXT}; @@ -141,6 +142,7 @@ impl From<&cstore::NativeLib> for NativeLib { pub struct CrateInfo { pub target_cpu: String, pub exported_symbols: FxHashMap>, + pub linked_symbols: FxHashMap>, pub local_crate_name: Symbol, pub compiler_builtins: Option, pub profiler_runtime: Option, diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 611694a0d3042..52892707c8646 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -22,7 +22,7 @@ use rustc_hir::lang_items; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::arena::ArenaAllocatable; use rustc_middle::metadata::ModChild; -use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; +use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; use rustc_middle::middle::stability::DeprecationEntry; use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState}; use rustc_middle::thir; @@ -1428,7 +1428,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { fn exported_symbols( self, tcx: TyCtxt<'tcx>, - ) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] { + ) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] { tcx.arena.alloc_from_iter(self.root.exported_symbols.decode((self, tcx))) } diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 63bf929fb8639..b3a7dabdc20b2 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -190,9 +190,9 @@ provide! { <'tcx> tcx, def_id, other, cdata, let reachable_non_generics = tcx .exported_symbols(cdata.cnum) .iter() - .filter_map(|&(exported_symbol, export_level)| { + .filter_map(|&(exported_symbol, export_info)| { if let ExportedSymbol::NonGeneric(def_id) = exported_symbol { - Some((def_id, export_level)) + Some((def_id, export_info)) } else { None } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 6a8d4e037544c..447eaeb73f6e0 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -22,7 +22,7 @@ use rustc_index::vec::Idx; use rustc_middle::hir::nested_filter; use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::exported_symbols::{ - metadata_symbol_name, ExportedSymbol, SymbolExportLevel, + metadata_symbol_name, ExportedSymbol, SymbolExportInfo, }; use rustc_middle::mir::interpret; use rustc_middle::thir; @@ -1865,8 +1865,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { // definition (as that's not defined in this crate). fn encode_exported_symbols( &mut self, - exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportLevel)], - ) -> Lazy<[(ExportedSymbol<'tcx>, SymbolExportLevel)]> { + exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportInfo)], + ) -> Lazy<[(ExportedSymbol<'tcx>, SymbolExportInfo)]> { empty_proc_macro!(self); // The metadata symbol name is special. It should not show up in // downstream crates. diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 43ccfc64e0563..1c389ecf5d046 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -14,7 +14,7 @@ use rustc_hir::definitions::DefKey; use rustc_hir::lang_items; use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec}; use rustc_middle::metadata::ModChild; -use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; +use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; use rustc_middle::mir; use rustc_middle::thir; use rustc_middle::ty::fast_reject::SimplifiedType; @@ -219,7 +219,7 @@ crate struct CrateRoot<'tcx> { tables: LazyTables<'tcx>, - exported_symbols: Lazy!([(ExportedSymbol<'tcx>, SymbolExportLevel)]), + exported_symbols: Lazy!([(ExportedSymbol<'tcx>, SymbolExportInfo)]), syntax_contexts: SyntaxContextTable, expn_data: ExpnDataTable, diff --git a/compiler/rustc_middle/src/middle/exported_symbols.rs b/compiler/rustc_middle/src/middle/exported_symbols.rs index 5ea78e087f845..631fd09ec4cf6 100644 --- a/compiler/rustc_middle/src/middle/exported_symbols.rs +++ b/compiler/rustc_middle/src/middle/exported_symbols.rs @@ -21,6 +21,23 @@ impl SymbolExportLevel { } } +/// Kind of exported symbols. +#[derive(Eq, PartialEq, Debug, Copy, Clone, Encodable, Decodable, HashStable)] +pub enum SymbolExportKind { + Text, + Data, + Tls, +} + +/// The `SymbolExportInfo` of a symbols specifies symbol-related information +/// that is relevant to code generation and linking. +#[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)] +pub struct SymbolExportInfo { + pub level: SymbolExportLevel, + pub kind: SymbolExportKind, + pub used: bool, +} + #[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)] pub enum ExportedSymbol<'tcx> { NonGeneric(DefId), diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 999cb9f30b8aa..2a96e87891db4 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1359,7 +1359,7 @@ rustc_queries! { // Does not include external symbols that don't have a corresponding DefId, // like the compiler-generated `main` function and so on. query reachable_non_generics(_: CrateNum) - -> DefIdMap { + -> DefIdMap { storage(ArenaCacheSelector<'tcx>) desc { "looking up the exported symbols of a crate" } separate_provide_extern @@ -1675,7 +1675,7 @@ rustc_queries! { /// correspond to a publicly visible symbol in `cnum` machine code. /// - The `exported_symbols` sets of different crates do not intersect. query exported_symbols(_: CrateNum) - -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] { + -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] { desc { "exported_symbols" } separate_provide_extern } diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index 9e48c569c253a..6ff061a820ebf 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -3,7 +3,7 @@ use crate::infer::canonical::{self, Canonical}; use crate::lint::LintLevelMap; use crate::metadata::ModChild; use crate::middle::codegen_fn_attrs::CodegenFnAttrs; -use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; +use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; use crate::middle::lib_features::LibFeatures; use crate::middle::privacy::AccessLevels; use crate::middle::region; diff --git a/compiler/rustc_monomorphize/src/partitioning/default.rs b/compiler/rustc_monomorphize/src/partitioning/default.rs index c4ffb19f87a91..02f3efa695c34 100644 --- a/compiler/rustc_monomorphize/src/partitioning/default.rs +++ b/compiler/rustc_monomorphize/src/partitioning/default.rs @@ -5,7 +5,7 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::definitions::DefPathDataName; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use rustc_middle::middle::exported_symbols::SymbolExportLevel; +use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel}; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, Linkage, Visibility}; use rustc_middle::mir::mono::{InstantiationMode, MonoItem}; use rustc_middle::ty::print::characteristic_def_id_of_type; @@ -554,7 +554,7 @@ fn default_visibility(tcx: TyCtxt<'_>, id: DefId, is_generic: bool) -> Visibilit // C-export level items remain at `Default`, all other internal // items become `Hidden`. match tcx.reachable_non_generics(id.krate).get(&id) { - Some(SymbolExportLevel::C) => Visibility::Default, + Some(SymbolExportInfo { level: SymbolExportLevel::C, .. }) => Visibility::Default, _ => Visibility::Hidden, } } diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index b520e5d04eab9..b65e334261325 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -333,6 +333,11 @@ impl CollectPrivateImplItemsVisitor<'_, '_> { let codegen_attrs = self.tcx.codegen_fn_attrs(def_id); if codegen_attrs.contains_extern_indicator() || codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) + // FIXME(nbdd0121): `#[used]` are marked as reachable here so it's picked up by + // `linked_symbols` in cg_ssa. They won't be exported in binary or cdylib due to their + // `SymbolExportLevel::Rust` export level but may end up being exported in dylibs. + || codegen_attrs.flags.contains(CodegenFnAttrFlags::USED) + || codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) { self.worklist.push(def_id); } diff --git a/library/std/src/sys/unix/process/process_common/tests.rs b/library/std/src/sys/unix/process/process_common/tests.rs index 9f1a645372f42..1956b3692a7ea 100644 --- a/library/std/src/sys/unix/process/process_common/tests.rs +++ b/library/std/src/sys/unix/process/process_common/tests.rs @@ -3,7 +3,7 @@ use super::*; use crate::ffi::OsStr; use crate::mem; use crate::ptr; -use crate::sys::cvt; +use crate::sys::{cvt, cvt_nz}; macro_rules! t { ($e:expr) => { @@ -39,7 +39,7 @@ fn test_process_mask() { let mut old_set = mem::MaybeUninit::::uninit(); t!(cvt(sigemptyset(set.as_mut_ptr()))); t!(cvt(sigaddset(set.as_mut_ptr(), libc::SIGINT))); - t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), old_set.as_mut_ptr()))); + t!(cvt_nz(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), old_set.as_mut_ptr()))); cmd.stdin(Stdio::MakePipe); cmd.stdout(Stdio::MakePipe); @@ -48,7 +48,7 @@ fn test_process_mask() { let stdin_write = pipes.stdin.take().unwrap(); let stdout_read = pipes.stdout.take().unwrap(); - t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, old_set.as_ptr(), ptr::null_mut()))); + t!(cvt_nz(libc::pthread_sigmask(libc::SIG_SETMASK, old_set.as_ptr(), ptr::null_mut()))); t!(cvt(libc::kill(cat.id() as libc::pid_t, libc::SIGINT))); // We need to wait until SIGINT is definitely delivered. The diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index 3d305cd7310fd..d48faaa88fb4f 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -328,6 +328,7 @@ impl Command { #[cfg(not(target_os = "emscripten"))] { use crate::mem::MaybeUninit; + use crate::sys::cvt_nz; // Reset signal handling so the child process starts in a // standardized state. libstd ignores SIGPIPE, and signal-handling // libraries often set a mask. Child processes inherit ignored @@ -337,7 +338,7 @@ impl Command { // we're about to run. let mut set = MaybeUninit::::uninit(); cvt(sigemptyset(set.as_mut_ptr()))?; - cvt(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), ptr::null_mut()))?; + cvt_nz(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), ptr::null_mut()))?; #[cfg(target_os = "android")] // see issue #88585 { diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 0276d15a5b472..d688f798956d6 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -364,6 +364,19 @@ impl<'a> ShouldRun<'a> { self } + // single alias, which does not correspond to any on-disk path + pub fn alias(mut self, alias: &str) -> Self { + assert!( + !self.builder.src.join(alias).exists(), + "use `builder.path()` for real paths: {}", + alias + ); + self.paths.insert(PathSet::Set( + std::iter::once(TaskPath { path: alias.into(), kind: Some(self.kind) }).collect(), + )); + self + } + // single, non-aliased path pub fn path(self, path: &str) -> Self { self.paths(&[path]) @@ -372,7 +385,17 @@ impl<'a> ShouldRun<'a> { // multiple aliases for the same job pub fn paths(mut self, paths: &[&str]) -> Self { self.paths.insert(PathSet::Set( - paths.iter().map(|p| TaskPath { path: p.into(), kind: Some(self.kind) }).collect(), + paths + .iter() + .map(|p| { + assert!( + self.builder.src.join(p).exists(), + "`should_run.paths` should correspond to real on-disk paths - use `alias` if there is no relevant path: {}", + p + ); + TaskPath { path: p.into(), kind: Some(self.kind) } + }) + .collect(), )); self } diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index fdd1581d9cd95..e3287e35227b9 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -61,7 +61,7 @@ impl Step for Docs { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = run.builder.config.docs; - run.path("rust-docs").default_condition(default) + run.alias("rust-docs").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -94,7 +94,7 @@ impl Step for RustcDocs { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let builder = run.builder; - run.path("rustc-docs").default_condition(builder.config.compiler_docs) + run.alias("rustc-docs").default_condition(builder.config.compiler_docs) } fn make_run(run: RunConfig<'_>) { @@ -272,7 +272,7 @@ impl Step for Mingw { const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("rust-mingw") + run.alias("rust-mingw") } fn make_run(run: RunConfig<'_>) { @@ -313,7 +313,7 @@ impl Step for Rustc { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("rustc") + run.alias("rustc") } fn make_run(run: RunConfig<'_>) { @@ -456,7 +456,7 @@ impl Step for DebuggerScripts { type Output = (); fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/lldb_batchmode.py") + run.path("src/etc/lldb_batchmode.py") } fn make_run(run: RunConfig<'_>) { @@ -547,7 +547,7 @@ impl Step for Std { const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("rust-std") + run.alias("rust-std") } fn make_run(run: RunConfig<'_>) { @@ -594,7 +594,7 @@ impl Step for RustcDev { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("rustc-dev") + run.alias("rustc-dev") } fn make_run(run: RunConfig<'_>) { @@ -653,7 +653,7 @@ impl Step for Analysis { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "analysis"); - run.path("rust-analysis").default_condition(default) + run.alias("rust-analysis").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -790,7 +790,7 @@ impl Step for Src { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("rust-src") + run.alias("rust-src") } fn make_run(run: RunConfig<'_>) { @@ -848,7 +848,7 @@ impl Step for PlainSourceTarball { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let builder = run.builder; - run.path("rustc-src").default_condition(builder.config.rust_dist_src) + run.alias("rustc-src").default_condition(builder.config.rust_dist_src) } fn make_run(run: RunConfig<'_>) { @@ -942,7 +942,7 @@ impl Step for Cargo { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "cargo"); - run.path("cargo").default_condition(default) + run.alias("cargo").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -998,7 +998,7 @@ impl Step for Rls { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "rls"); - run.path("rls").default_condition(default) + run.alias("rls").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -1045,7 +1045,7 @@ impl Step for RustAnalyzer { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "rust-analyzer"); - run.path("rust-analyzer").default_condition(default) + run.alias("rust-analyzer").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -1101,7 +1101,7 @@ impl Step for Clippy { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "clippy"); - run.path("clippy").default_condition(default) + run.alias("clippy").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -1152,7 +1152,7 @@ impl Step for Miri { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "miri"); - run.path("miri").default_condition(default) + run.alias("miri").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -1212,7 +1212,7 @@ impl Step for Rustfmt { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "rustfmt"); - run.path("rustfmt").default_condition(default) + run.alias("rustfmt").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -1271,7 +1271,7 @@ impl Step for RustDemangler { // we run the step by default when only `extended = true`, and decide whether to actually // run it or not later. let default = run.builder.config.extended; - run.path("rust-demangler").default_condition(default) + run.alias("rust-demangler").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -1324,7 +1324,7 @@ impl Step for Extended { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let builder = run.builder; - run.path("extended").default_condition(builder.config.extended) + run.alias("extended").default_condition(builder.config.extended) } fn make_run(run: RunConfig<'_>) { @@ -1968,7 +1968,8 @@ impl Step for LlvmTools { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let default = should_build_extended_tool(&run.builder, "llvm-tools"); - run.path("llvm-tools").default_condition(default) + // FIXME: allow using the names of the tools themselves? + run.alias("llvm-tools").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -2022,7 +2023,7 @@ impl Step for RustDev { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("rust-dev") + run.alias("rust-dev") } fn make_run(run: RunConfig<'_>) { @@ -2098,7 +2099,7 @@ impl Step for BuildManifest { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("build-manifest") + run.alias("build-manifest") } fn make_run(run: RunConfig<'_>) { @@ -2130,7 +2131,7 @@ impl Step for ReproducibleArtifacts { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("reproducible-artifacts") + run.alias("reproducible-artifacts") } fn make_run(run: RunConfig<'_>) { diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 27b9196d9868e..08e37a1627990 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -93,7 +93,7 @@ fn prepare_dir(mut path: PathBuf) -> String { macro_rules! install { (($sel:ident, $builder:ident, $_config:ident), $($name:ident, - $path:expr, + $condition_name: ident = $path_or_alias: literal, $default_cond:expr, only_hosts: $only_hosts:expr, $run_item:block $(, $c:ident)*;)+) => { @@ -108,7 +108,7 @@ macro_rules! install { #[allow(dead_code)] fn should_build(config: &Config) -> bool { config.extended && config.tools.as_ref() - .map_or(true, |t| t.contains($path)) + .map_or(true, |t| t.contains($path_or_alias)) } } @@ -120,7 +120,7 @@ macro_rules! install { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let $_config = &run.builder.config; - run.path($path).default_condition($default_cond) + run.$condition_name($path_or_alias).default_condition($default_cond) } fn make_run(run: RunConfig<'_>) { @@ -138,11 +138,11 @@ macro_rules! install { } install!((self, builder, _config), - Docs, "src/doc", _config.docs, only_hosts: false, { + Docs, path = "src/doc", _config.docs, only_hosts: false, { let tarball = builder.ensure(dist::Docs { host: self.target }).expect("missing docs"); install_sh(builder, "docs", self.compiler.stage, Some(self.target), &tarball); }; - Std, "library/std", true, only_hosts: false, { + Std, path = "library/std", true, only_hosts: false, { for target in &builder.targets { // `expect` should be safe, only None when host != build, but this // only runs when host == build @@ -153,13 +153,13 @@ install!((self, builder, _config), install_sh(builder, "std", self.compiler.stage, Some(*target), &tarball); } }; - Cargo, "cargo", Self::should_build(_config), only_hosts: true, { + Cargo, alias = "cargo", Self::should_build(_config), only_hosts: true, { let tarball = builder .ensure(dist::Cargo { compiler: self.compiler, target: self.target }) .expect("missing cargo"); install_sh(builder, "cargo", self.compiler.stage, Some(self.target), &tarball); }; - Rls, "rls", Self::should_build(_config), only_hosts: true, { + Rls, alias = "rls", Self::should_build(_config), only_hosts: true, { if let Some(tarball) = builder.ensure(dist::Rls { compiler: self.compiler, target: self.target }) { install_sh(builder, "rls", self.compiler.stage, Some(self.target), &tarball); } else { @@ -168,7 +168,7 @@ install!((self, builder, _config), ); } }; - RustAnalyzer, "rust-analyzer", Self::should_build(_config), only_hosts: true, { + RustAnalyzer, alias = "rust-analyzer", Self::should_build(_config), only_hosts: true, { if let Some(tarball) = builder.ensure(dist::RustAnalyzer { compiler: self.compiler, target: self.target }) { @@ -179,13 +179,13 @@ install!((self, builder, _config), ); } }; - Clippy, "clippy", Self::should_build(_config), only_hosts: true, { + Clippy, alias = "clippy", Self::should_build(_config), only_hosts: true, { let tarball = builder .ensure(dist::Clippy { compiler: self.compiler, target: self.target }) .expect("missing clippy"); install_sh(builder, "clippy", self.compiler.stage, Some(self.target), &tarball); }; - Miri, "miri", Self::should_build(_config), only_hosts: true, { + Miri, alias = "miri", Self::should_build(_config), only_hosts: true, { if let Some(tarball) = builder.ensure(dist::Miri { compiler: self.compiler, target: self.target }) { install_sh(builder, "miri", self.compiler.stage, Some(self.target), &tarball); } else { @@ -194,7 +194,7 @@ install!((self, builder, _config), ); } }; - Rustfmt, "rustfmt", Self::should_build(_config), only_hosts: true, { + Rustfmt, alias = "rustfmt", Self::should_build(_config), only_hosts: true, { if let Some(tarball) = builder.ensure(dist::Rustfmt { compiler: self.compiler, target: self.target @@ -206,7 +206,7 @@ install!((self, builder, _config), ); } }; - RustDemangler, "rust-demangler", Self::should_build(_config), only_hosts: true, { + RustDemangler, alias = "rust-demangler", Self::should_build(_config), only_hosts: true, { // Note: Even though `should_build` may return true for `extended` default tools, // dist::RustDemangler may still return None, unless the target-dependent `profiler` config // is also true, or the `tools` array explicitly includes "rust-demangler". @@ -222,7 +222,7 @@ install!((self, builder, _config), ); } }; - Analysis, "analysis", Self::should_build(_config), only_hosts: false, { + Analysis, alias = "analysis", Self::should_build(_config), only_hosts: false, { // `expect` should be safe, only None with host != build, but this // only uses the `build` compiler let tarball = builder.ensure(dist::Analysis { @@ -234,7 +234,7 @@ install!((self, builder, _config), }).expect("missing analysis"); install_sh(builder, "analysis", self.compiler.stage, Some(self.target), &tarball); }; - Rustc, "src/librustc", true, only_hosts: true, { + Rustc, path = "compiler/rustc", true, only_hosts: true, { let tarball = builder.ensure(dist::Rustc { compiler: builder.compiler(builder.top_stage, self.target), }); diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 6d7ca9a94cfbd..73fb2dad1e3c2 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -122,7 +122,7 @@ impl Step for Llvm { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/llvm-project").path("src/llvm-project/llvm").path("src/llvm") + run.path("src/llvm-project").path("src/llvm-project/llvm") } fn make_run(run: RunConfig<'_>) { @@ -605,7 +605,7 @@ impl Step for Lld { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/llvm-project/lld").path("src/tools/lld") + run.path("src/llvm-project/lld") } fn make_run(run: RunConfig<'_>) { @@ -771,7 +771,7 @@ impl Step for Sanitizers { type Output = Vec; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/llvm-project/compiler-rt").path("src/sanitizers") + run.alias("sanitizers") } fn make_run(run: RunConfig<'_>) { diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index f60766bde726e..835f54936babb 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -2288,7 +2288,7 @@ impl Step for Distcheck { type Output = (); fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("distcheck") + run.alias("distcheck") } fn make_run(run: RunConfig<'_>) { diff --git a/src/bootstrap/toolstate.rs b/src/bootstrap/toolstate.rs index c7ea254c5b1d7..3ee6a42d987a0 100644 --- a/src/bootstrap/toolstate.rs +++ b/src/bootstrap/toolstate.rs @@ -234,7 +234,7 @@ impl Step for ToolStateCheck { } fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("check-tools") + run.alias("check-tools") } fn make_run(run: RunConfig<'_>) { diff --git a/src/doc/book b/src/doc/book index ea90bbaf53ba6..765318b844569 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit ea90bbaf53ba64ef4e2da9ac2352b298aec6bec8 +Subproject commit 765318b844569a642ceef7bf1adab9639cbf6af3 diff --git a/src/doc/nomicon b/src/doc/nomicon index 11f1165e8a2f5..c7d8467ca9158 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit 11f1165e8a2f5840467e748c8108dc53c948ee9a +Subproject commit c7d8467ca9158da58ef295ae65dbf00a308752d9 diff --git a/src/doc/reference b/src/doc/reference index c97d14fa6fed0..b5f6c2362baf9 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit c97d14fa6fed0baa9255432b8a93cb70614f80e3 +Subproject commit b5f6c2362baf932db9440fbfcb509b309237ee85 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index ec954f35eedf5..c2a98d9fc5d29 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit ec954f35eedf592cd173b21c05a7f80a65b61d8a +Subproject commit c2a98d9fc5d29c481d42052fbeccfde15ed03116 diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide index 155126b1d2e2c..eeb5a83c15b6a 160000 --- a/src/doc/rustc-dev-guide +++ b/src/doc/rustc-dev-guide @@ -1 +1 @@ -Subproject commit 155126b1d2e2cb01ddb1d7ba9489b90d7cd173ad +Subproject commit eeb5a83c15b6ae60df3e4f19207376b22c6fbc4c diff --git a/src/etc/htmldocck.py b/src/etc/htmldocck.py index df215f318239e..269b6868e29f9 100644 --- a/src/etc/htmldocck.py +++ b/src/etc/htmldocck.py @@ -423,8 +423,12 @@ def check_snapshot(snapshot_name, actual_tree, normalize_to_text): else: actual_str = flatten(actual_tree) + # Conditions: + # 1. Is --bless + # 2. Are actual and expected tree different + # 3. Are actual and expected text different if not expected_str \ - or (not normalize_to_text and + or (not normalize_to_text and \ not compare_tree(make_xml(actual_str), make_xml(expected_str), stderr)) \ or (normalize_to_text and actual_str != expected_str): diff --git a/src/test/run-make-fulldeps/reproducible-build/linker.rs b/src/test/run-make-fulldeps/reproducible-build/linker.rs index 998d1f328596c..b58614c8b4e1f 100644 --- a/src/test/run-make-fulldeps/reproducible-build/linker.rs +++ b/src/test/run-make-fulldeps/reproducible-build/linker.rs @@ -25,6 +25,12 @@ fn main() { let mut contents = Vec::new(); File::open(path).unwrap().read_to_end(&mut contents).unwrap(); + // This file is produced during linking in a temporary directory. + let arg = if arg.ends_with("/symbols.o") { + "symbols.o" + } else { + &*arg + }; out.push_str(&format!("{}: {}\n", arg, hash(&contents))); } diff --git a/src/test/run-make/issue-47384/Makefile b/src/test/run-make/issue-47384/Makefile new file mode 100644 index 0000000000000..f10365f8c8811 --- /dev/null +++ b/src/test/run-make/issue-47384/Makefile @@ -0,0 +1,12 @@ +-include ../../run-make-fulldeps/tools.mk + +# only-linux +# ignore-cross-compile + +all: main.rs + $(RUSTC) --crate-type lib lib.rs + $(RUSTC) --crate-type cdylib -Clink-args="-Tlinker.ld" main.rs + # Ensure `#[used]` and `KEEP`-ed section is there + objdump -s -j".static" $(TMPDIR)/libmain.so + # Ensure `#[no_mangle]` symbol is there + nm $(TMPDIR)/libmain.so | $(CGREP) bar diff --git a/src/test/run-make/issue-47384/lib.rs b/src/test/run-make/issue-47384/lib.rs new file mode 100644 index 0000000000000..99508bcdaf314 --- /dev/null +++ b/src/test/run-make/issue-47384/lib.rs @@ -0,0 +1,12 @@ +mod foo { + #[link_section = ".rodata.STATIC"] + #[used] + static STATIC: [u32; 10] = [1; 10]; +} + +mod bar { + #[no_mangle] + extern "C" fn bar() -> i32 { + 0 + } +} diff --git a/src/test/run-make/issue-47384/linker.ld b/src/test/run-make/issue-47384/linker.ld new file mode 100644 index 0000000000000..2e70acab3f496 --- /dev/null +++ b/src/test/run-make/issue-47384/linker.ld @@ -0,0 +1,7 @@ +SECTIONS +{ + .static : ALIGN(4) + { + KEEP(*(.rodata.STATIC)); + } +} diff --git a/src/test/run-make/issue-47384/main.rs b/src/test/run-make/issue-47384/main.rs new file mode 100644 index 0000000000000..02572632517ec --- /dev/null +++ b/src/test/run-make/issue-47384/main.rs @@ -0,0 +1 @@ +extern crate lib;