Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #108989

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5b7ab80
Stabilize path_as_mut_os_str
zertosh Dec 20, 2022
52f7a21
Relax ordering rules for `asm!` operands
Amanieu Dec 16, 2022
0f371ca
Support linking to rust dylibs from a staticlib
bjorn3 Dec 28, 2022
7e2f6c1
Support `--print native-static-libs` with rust dylibs
bjorn3 Dec 28, 2022
832fede
Add unstable feature flags
bjorn3 Jan 4, 2023
d3cbedd
Stabilize movbe target feature
calebzulawski Feb 6, 2023
f1cf67b
Fix test for MSVC
bjorn3 Mar 4, 2023
ef807cb
use problem matchers for tidy CI
fee1-dead Dec 23, 2022
a2040de
do not run tidy on x86_64-gnu-llvm-13
fee1-dead Jan 6, 2023
057d6ed
Remove an extraneous include
kazutakahirata Mar 8, 2023
a5258d1
no more do while
lcnr Mar 9, 2023
3abcae2
Document tool lints
clubby789 Mar 8, 2023
9bb87eb
Add soon-to-be-default --no-undefined-version flag
chbaker0 Feb 13, 2023
cb41803
Don't export of __rust_* alloc symbols if not codegened
chbaker0 Feb 13, 2023
e76678e
Rollup merge of #105798 - Amanieu:relax-asm, r=joshtriplett
matthiaskrgr Mar 10, 2023
b4ebfeb
Rollup merge of #105962 - zertosh:stabilize_path_as_mut_os_str, r=dto…
matthiaskrgr Mar 10, 2023
eed1d0c
Rollup merge of #106085 - fee1-dead-contrib:tidy-ci-matchers, r=pietr…
matthiaskrgr Mar 10, 2023
0858a0b
Rollup merge of #106560 - bjorn3:support_staticlib_dylib_linking, r=p…
matthiaskrgr Mar 10, 2023
0f3a0dc
Rollup merge of #107711 - calebzulawski:movbe, r=pnkfelix
matthiaskrgr Mar 10, 2023
c8410d4
Rollup merge of #108017 - chbaker0:fix-105967, r=chbaker0
matthiaskrgr Mar 10, 2023
3b76b32
Rollup merge of #108891 - kazutakahirata:master, r=cuviper
matthiaskrgr Mar 10, 2023
a89ab7e
Rollup merge of #108902 - lcnr:do-while-sus, r=davidtwco,Nilstrieb
matthiaskrgr Mar 10, 2023
2dc5272
Rollup merge of #108912 - clubby789:doc-tool-lints, r=Nilstrieb
matthiaskrgr Mar 10, 2023
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
35 changes: 4 additions & 31 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,6 @@ pub fn parse_asm_args<'a>(
// Validate the order of named, positional & explicit register operands and
// clobber_abi/options. We do this at the end once we have the full span
// of the argument available.
if !args.options_spans.is_empty() {
diag.struct_span_err(span, "arguments are not allowed after options")
.span_labels(args.options_spans.clone(), "previous options")
.span_label(span, "argument")
.emit();
} else if let Some((_, abi_span)) = args.clobber_abis.last() {
diag.struct_span_err(span, "arguments are not allowed after clobber_abi")
.span_label(*abi_span, "clobber_abi")
.span_label(span, "argument")
.emit();
}
if explicit_reg {
if name.is_some() {
diag.struct_span_err(span, "explicit register arguments cannot have names").emit();
Expand All @@ -227,17 +216,6 @@ pub fn parse_asm_args<'a>(
.emit();
continue;
}
if !args.reg_args.is_empty() {
let mut err = diag.struct_span_err(
span,
"named arguments cannot follow explicit register arguments",
);
err.span_label(span, "named argument");
for pos in &args.reg_args {
err.span_label(args.operands[*pos].1, "explicit register argument");
}
err.emit();
}
args.named_args.insert(name, slot);
} else {
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
Expand Down Expand Up @@ -478,15 +456,6 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,

let full_span = span_start.to(p.prev_token.span);

if !args.options_spans.is_empty() {
let mut err = p
.sess
.span_diagnostic
.struct_span_err(full_span, "clobber_abi is not allowed after options");
err.span_labels(args.options_spans.clone(), "options");
return Err(err);
}

match &new_abis[..] {
// should have errored above during parsing
[] => unreachable!(),
Expand Down Expand Up @@ -699,6 +668,10 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
args.operands[idx].1,
"explicit register arguments cannot be used in the asm template",
);
err.span_help(
args.operands[idx].1,
"use the register name directly in the assembly code",
);
}
err.emit();
None
Expand Down
28 changes: 10 additions & 18 deletions compiler/rustc_codegen_cranelift/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::prelude::*;

use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
use rustc_codegen_ssa::base::allocator_kind_for_codegen;
use rustc_session::config::OomStrategy;
use rustc_span::symbol::sym;

Expand All @@ -13,24 +14,15 @@ pub(crate) fn codegen(
module: &mut impl Module,
unwind_context: &mut UnwindContext,
) -> bool {
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
use rustc_middle::middle::dependency_format::Linkage;
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
});
if any_dynamic_crate {
false
} else if let Some(kind) = tcx.allocator_kind(()) {
codegen_inner(
module,
unwind_context,
kind,
tcx.alloc_error_handler_kind(()).unwrap(),
tcx.sess.opts.unstable_opts.oom,
);
true
} else {
false
}
let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
codegen_inner(
module,
unwind_context,
kind,
tcx.alloc_error_handler_kind(()).unwrap(),
tcx.sess.opts.unstable_opts.oom,
);
true
}

fn codegen_inner(
Expand Down
75 changes: 70 additions & 5 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,38 @@ fn link_staticlib<'a>(

ab.build(out_filename);

if !all_native_libs.is_empty() {
if sess.opts.prints.contains(&PrintRequest::NativeStaticLibs) {
print_native_static_libs(sess, &all_native_libs);
let crates = codegen_results.crate_info.used_crates.iter();

let fmts = codegen_results
.crate_info
.dependency_formats
.iter()
.find_map(|&(ty, ref list)| if ty == CrateType::Staticlib { Some(list) } else { None })
.expect("no dependency formats for staticlib");

let mut all_rust_dylibs = vec![];
for &cnum in crates {
match fmts.get(cnum.as_usize() - 1) {
Some(&Linkage::Dynamic) => {}
_ => continue,
}
let crate_name = codegen_results.crate_info.crate_name[&cnum];
let used_crate_source = &codegen_results.crate_info.used_crate_source[&cnum];
if let Some((path, _)) = &used_crate_source.dylib {
all_rust_dylibs.push(&**path);
} else {
if used_crate_source.rmeta.is_some() {
sess.emit_fatal(errors::LinkRlibError::OnlyRmetaFound { crate_name });
} else {
sess.emit_fatal(errors::LinkRlibError::NotFound { crate_name });
}
}
}

if sess.opts.prints.contains(&PrintRequest::NativeStaticLibs) {
print_native_static_libs(sess, &all_native_libs, &all_rust_dylibs);
}

Ok(())
}

Expand Down Expand Up @@ -1289,8 +1315,12 @@ enum RlibFlavor {
StaticlibBase,
}

fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
let lib_args: Vec<_> = all_native_libs
fn print_native_static_libs(
sess: &Session,
all_native_libs: &[NativeLib],
all_rust_dylibs: &[&Path],
) {
let mut lib_args: Vec<_> = all_native_libs
.iter()
.filter(|l| relevant_lib(sess, l))
.filter_map(|lib| {
Expand Down Expand Up @@ -1319,6 +1349,41 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
}
})
.collect();
for path in all_rust_dylibs {
// FIXME deduplicate with add_dynamic_crate

// Just need to tell the linker about where the library lives and
// what its name is
let parent = path.parent();
if let Some(dir) = parent {
let dir = fix_windows_verbatim_for_gcc(dir);
if sess.target.is_like_msvc {
let mut arg = String::from("/LIBPATH:");
arg.push_str(&dir.display().to_string());
lib_args.push(arg);
} else {
lib_args.push("-L".to_owned());
lib_args.push(dir.display().to_string());
}
}
let stem = path.file_stem().unwrap().to_str().unwrap();
// Convert library file-stem into a cc -l argument.
let prefix = if stem.starts_with("lib") && !sess.target.is_like_windows { 3 } else { 0 };
let lib = &stem[prefix..];
let path = parent.unwrap_or_else(|| Path::new(""));
if sess.target.is_like_msvc {
// When producing a dll, the MSVC linker may not actually emit a
// `foo.lib` file if the dll doesn't actually export any symbols, so we
// check to see if the file is there and just omit linking to it if it's
// not present.
let name = format!("{}.dll.lib", lib);
if path.join(&name).exists() {
lib_args.push(name);
}
} else {
lib_args.push(format!("-l{}", lib));
}
}
if !lib_args.is_empty() {
sess.emit_note(errors::StaticLibraryNativeArtifacts);
// Prefix for greppability
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ impl<'a> Linker for GccLinker<'a> {
let mut arg = OsString::from("--version-script=");
arg.push(path);
self.linker_arg(arg);
self.linker_arg("--no-undefined-version");
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::base::allocator_kind_for_codegen;

use std::collections::hash_map::Entry::*;

use rustc_ast::expand::allocator::ALLOCATOR_METHODS;
Expand Down Expand Up @@ -200,7 +202,8 @@ fn exported_symbols_provider_local(
));
}

if tcx.allocator_kind(()).is_some() {
// Mark allocator shim symbols as exported only if they were generated.
if allocator_kind_for_codegen(tcx).is_some() {
for symbol_name in ALLOCATOR_METHODS
.iter()
.map(|method| format!("__rust_{}", method.name))
Expand Down
44 changes: 23 additions & 21 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::mir::place::PlaceRef;
use crate::traits::*;
use crate::{CachedModuleCodegen, CompiledModule, CrateInfo, MemFlags, ModuleCodegen, ModuleKind};

use rustc_ast::expand::allocator::AllocatorKind;
use rustc_attr as attr;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
Expand Down Expand Up @@ -545,6 +546,23 @@ pub fn collect_debugger_visualizers_transitive(
.collect::<BTreeSet<_>>()
}

/// Decide allocator kind to codegen. If `Some(_)` this will be the same as
/// `tcx.allocator_kind`, but it may be `None` in more cases (e.g. if using
/// allocator definitions from a dylib dependency).
pub fn allocator_kind_for_codegen(tcx: TyCtxt<'_>) -> Option<AllocatorKind> {
// If the crate doesn't have an `allocator_kind` set then there's definitely
// no shim to generate. Otherwise we also check our dependency graph for all
// our output crate types. If anything there looks like its a `Dynamic`
// linkage, then it's already got an allocator shim and we'll be using that
// one instead. If nothing exists then it's our job to generate the
// allocator!
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
use rustc_middle::middle::dependency_format::Linkage;
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
});
if any_dynamic_crate { None } else { tcx.allocator_kind(()) }
}

pub fn codegen_crate<B: ExtraBackendMethods>(
backend: B,
tcx: TyCtxt<'_>,
Expand Down Expand Up @@ -615,20 +633,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
);

// Codegen an allocator shim, if necessary.
//
// If the crate doesn't have an `allocator_kind` set then there's definitely
// no shim to generate. Otherwise we also check our dependency graph for all
// our output crate types. If anything there looks like its a `Dynamic`
// linkage, then it's already got an allocator shim and we'll be using that
// one instead. If nothing exists then it's our job to generate the
// allocator!
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
use rustc_middle::middle::dependency_format::Linkage;
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
});
let allocator_module = if any_dynamic_crate {
None
} else if let Some(kind) = tcx.allocator_kind(()) {
if let Some(kind) = allocator_kind_for_codegen(tcx) {
let llmod_id =
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
let module_llvm = tcx.sess.time("write_allocator_module", || {
Expand All @@ -642,13 +647,10 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
)
});

Some(ModuleCodegen { name: llmod_id, module_llvm, kind: ModuleKind::Allocator })
} else {
None
};

if let Some(allocator_module) = allocator_module {
ongoing_codegen.submit_pre_codegened_module_to_llvm(tcx, allocator_module);
ongoing_codegen.submit_pre_codegened_module_to_llvm(
tcx,
ModuleCodegen { name: llmod_id, module_llvm, kind: ModuleKind::Allocator },
);
}

// For better throughput during parallel processing by LLVM, we used to sort
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
("fxsr", None),
("gfni", Some(sym::avx512_target_feature)),
("lzcnt", None),
("movbe", Some(sym::movbe_target_feature)),
("movbe", None),
("pclmulqdq", None),
("popcnt", None),
("rdrand", None),
Expand Down Expand Up @@ -394,7 +394,6 @@ pub fn from_target_feature(
Some(sym::sse4a_target_feature) => rust_features.sse4a_target_feature,
Some(sym::tbm_target_feature) => rust_features.tbm_target_feature,
Some(sym::wasm_target_feature) => rust_features.wasm_target_feature,
Some(sym::movbe_target_feature) => rust_features.movbe_target_feature,
Some(sym::rtm_target_feature) => rust_features.rtm_target_feature,
Some(sym::ermsb_target_feature) => rust_features.ermsb_target_feature,
Some(sym::bpf_target_feature) => rust_features.bpf_target_feature,
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ declare_features! (
(accepted, clone_closures, "1.26.0", Some(44490), None),
/// Allows coercing non capturing closures to function pointers.
(accepted, closure_to_fn_coercion, "1.19.0", Some(39817), None),
/// Allows using `cmpxchg16b` from `core::arch::x86_64`.
/// Allows using the CMPXCHG16B target feature.
(accepted, cmpxchg16b_target_feature, "CURRENT_RUSTC_VERSION", Some(44839), None),
/// Allows usage of the `compile_error!` macro.
(accepted, compile_error, "1.20.0", Some(40872), None),
Expand Down Expand Up @@ -238,6 +238,8 @@ declare_features! (
(accepted, min_const_unsafe_fn, "1.33.0", Some(55607), None),
/// Allows using `Self` and associated types in struct expressions and patterns.
(accepted, more_struct_aliases, "1.16.0", Some(37544), None),
/// Allows using the MOVBE target feature.
(accepted, movbe_target_feature, "CURRENT_RUSTC_VERSION", Some(44839), None),
/// Allows patterns with concurrent by-move and by-ref bindings.
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
(accepted, move_ref_pattern, "1.49.0", Some(68354), None),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ declare_features! (
(active, ermsb_target_feature, "1.49.0", Some(44839), None),
(active, hexagon_target_feature, "1.27.0", Some(44839), None),
(active, mips_target_feature, "1.27.0", Some(44839), None),
(active, movbe_target_feature, "1.34.0", Some(44839), None),
(active, powerpc_target_feature, "1.27.0", Some(44839), None),
(active, riscv_target_feature, "1.45.0", Some(44839), None),
(active, rtm_target_feature, "1.35.0", Some(44839), None),
Expand Down
Loading