Skip to content

Commit

Permalink
Auto merge of rust-lang#136049 - matthiaskrgr:rollup-2hfmkoq, r=<try>
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - rust-lang#130808 (Fix linking for symbols starting with ? on i686-pc-windows-msvc)
 - rust-lang#133154 (Reword resolve errors caused by likely missing crate in dep tree)
 - rust-lang#135707 (Shorten linker output even more when `--verbose` is not present)
 - rust-lang#135764 (Fix tests on LLVM 20)
 - rust-lang#135785 (use `PassMode::Direct` for vector types on `s390x`)
 - rust-lang#135818 (tests: Port `translation` to rmake.rs)

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: aarch64-apple
try-job: i686-mingw
try-job: x86_64-gnu-llvm-19-3
  • Loading branch information
bors committed Jan 25, 2025
2 parents 6365178 + 172dcf2 commit a37c61f
Show file tree
Hide file tree
Showing 140 changed files with 1,009 additions and 421 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3537,6 +3537,7 @@ dependencies = [
"ar_archive_writer",
"arrayvec",
"bitflags",
"bstr",
"cc",
"either",
"itertools",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
ar_archive_writer = "0.4.2"
arrayvec = { version = "0.7", default-features = false }
bitflags = "2.4.1"
bstr = "1.11.3"
# Pinned so `cargo update` bumps don't cause breakage. Please also update the
# `cc` in `rustc_llvm` if you update the `cc` here.
cc = "=1.2.7"
Expand Down
17 changes: 16 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) struct Command {
args: Vec<OsString>,
env: Vec<(OsString, OsString)>,
env_remove: Vec<OsString>,
env_clear: bool,
}

#[derive(Clone)]
Expand All @@ -36,7 +37,13 @@ impl Command {
}

fn _new(program: Program) -> Command {
Command { program, args: Vec::new(), env: Vec::new(), env_remove: Vec::new() }
Command {
program,
args: Vec::new(),
env: Vec::new(),
env_remove: Vec::new(),
env_clear: false,
}
}

pub(crate) fn arg<P: AsRef<OsStr>>(&mut self, arg: P) -> &mut Command {
Expand Down Expand Up @@ -79,6 +86,11 @@ impl Command {
self
}

pub(crate) fn env_clear(&mut self) -> &mut Command {
self.env_clear = true;
self
}

fn _env_remove(&mut self, key: &OsStr) {
self.env_remove.push(key.to_owned());
}
Expand Down Expand Up @@ -106,6 +118,9 @@ impl Command {
for k in &self.env_remove {
ret.env_remove(k);
}
if self.env_clear {
ret.env_clear();
}
ret
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ fn link_natively(
command: cmd,
escaped_output,
verbose: sess.opts.verbose,
sysroot_dir: sess.sysroot.clone(),
};
sess.dcx().emit_err(err);
// If MSVC's `link.exe` was expected but the return code
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,9 @@ pub(crate) fn linking_symbol_name_for_instance_in_crate<'tcx>(
}

let prefix = match &target.arch[..] {
"x86" | "x86_64" if target.is_like_msvc && undecorated.starts_with("?") => {
return undecorated;
}
"x86" => Some('_'),
"x86_64" => None,
"arm64ec" => Some('#'),
Expand Down
62 changes: 47 additions & 15 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ pub(crate) struct LinkingFailed<'a> {
pub command: Command,
pub escaped_output: String,
pub verbose: bool,
pub sysroot_dir: PathBuf,
}

impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
Expand All @@ -364,6 +365,8 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
if self.verbose {
diag.note(format!("{:?}", self.command));
} else {
self.command.env_clear();

enum ArgGroup {
Regular(OsString),
Objects(usize),
Expand Down Expand Up @@ -398,26 +401,55 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
args.push(ArgGroup::Regular(arg));
}
}
self.command.args(args.into_iter().map(|arg_group| match arg_group {
ArgGroup::Regular(arg) => arg,
ArgGroup::Objects(n) => OsString::from(format!("<{n} object files omitted>")),
ArgGroup::Rlibs(dir, rlibs) => {
let mut arg = dir.into_os_string();
arg.push("/{");
let mut first = true;
for rlib in rlibs {
if !first {
arg.push(",");
let crate_hash = regex::bytes::Regex::new(r"-[0-9a-f]+\.rlib$").unwrap();
self.command.args(args.into_iter().map(|arg_group| {
match arg_group {
// SAFETY: we are only matching on ASCII, not any surrogate pairs, so any replacements we do will still be valid.
ArgGroup::Regular(arg) => unsafe {
use bstr::ByteSlice;
OsString::from_encoded_bytes_unchecked(
arg.as_encoded_bytes().replace(
self.sysroot_dir.as_os_str().as_encoded_bytes(),
b"<sysroot>",
),
)
},
ArgGroup::Objects(n) => OsString::from(format!("<{n} object files omitted>")),
ArgGroup::Rlibs(mut dir, rlibs) => {
let is_sysroot_dir = match dir.strip_prefix(&self.sysroot_dir) {
Ok(short) => {
dir = Path::new("<sysroot>").join(short);
true
}
Err(_) => false,
};
let mut arg = dir.into_os_string();
arg.push("/{");
let mut first = true;
for mut rlib in rlibs {
if !first {
arg.push(",");
}
first = false;
if is_sysroot_dir {
// SAFETY: Regex works one byte at a type, and our regex will not match surrogate pairs (because it only matches ascii).
rlib = unsafe {
OsString::from_encoded_bytes_unchecked(
crate_hash
.replace(rlib.as_encoded_bytes(), b"-*")
.into_owned(),
)
};
}
arg.push(rlib);
}
first = false;
arg.push(rlib);
arg.push("}.rlib");
arg
}
arg.push("}");
arg
}
}));

diag.note(format!("{:?}", self.command));
diag.note(format!("{:?}", self.command).trim_start_matches("env -i").to_owned());
diag.note("some arguments are omitted. use `--verbose` to show all linker arguments");
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0433.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ If you've expected to use a crate name:

```compile_fail
use ferris_wheel::BigO;
// error: failed to resolve: use of undeclared crate or module `ferris_wheel`
// error: failed to resolve: use of undeclared module or unlinked crate
```

Make sure the crate has been added as a dependency in `Cargo.toml`.
Expand Down
36 changes: 32 additions & 4 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use rustc_session::lint::builtin::{
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
};
use rustc_session::lint::{AmbiguityErrorDiag, BuiltinLintDiag};
use rustc_session::utils::was_invoked_from_cargo;
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::edition::Edition;
use rustc_span::hygiene::MacroKind;
Expand Down Expand Up @@ -800,7 +801,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
err.multipart_suggestion(msg, suggestions, applicability);
}

if let Some(ModuleOrUniformRoot::Module(module)) = module
&& let Some(module) = module.opt_def_id()
&& let Some(segment) = segment
Expand Down Expand Up @@ -2034,13 +2034,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
(format!("`_` is not a valid crate or module name"), None)
} else if self.tcx.sess.is_rust_2015() {
(
format!("you might be missing crate `{ident}`"),
format!("use of unresolved module or unlinked crate `{ident}`"),
Some((
vec![(
self.current_crate_outer_attr_insert_span,
format!("extern crate {ident};\n"),
)],
format!("consider importing the `{ident}` crate"),
if was_invoked_from_cargo() {
format!(
"if you wanted to use a crate named `{ident}`, use `cargo add {ident}` \
to add it to your `Cargo.toml` and import it in your code",
)
} else {
format!(
"you might be missing a crate named `{ident}`, add it to your \
project and import it in your code",
)
},
Applicability::MaybeIncorrect,
)),
)
Expand Down Expand Up @@ -2219,7 +2229,25 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let descr = binding.res().descr();
(format!("{descr} `{ident}` is not a crate or module"), suggestion)
} else {
(format!("use of undeclared crate or module `{ident}`"), suggestion)
let suggestion = if suggestion.is_some() {
suggestion
} else if was_invoked_from_cargo() {
Some((
vec![],
format!(
"if you wanted to use a crate named `{ident}`, use `cargo add {ident}` \
to add it to your `Cargo.toml`",
),
Applicability::MaybeIncorrect,
))
} else {
Some((
vec![],
format!("you might be missing a crate named `{ident}`",),
Applicability::MaybeIncorrect,
))
};
(format!("use of unresolved module or unlinked crate `{ident}`"), suggestion)
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions compiler/rustc_target/src/callconv/s390x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@ where
}

let size = arg.layout.size;
if size.bits() <= 128 && arg.layout.is_single_vector_element(cx, size) {
arg.cast_to(Reg { kind: RegKind::Vector, size });
return;
if size.bits() <= 128 {
if let BackendRepr::Vector { .. } = arg.layout.backend_repr {
// pass non-wrapped vector types using `PassMode::Direct`
return;
}

if arg.layout.is_single_vector_element(cx, size) {
// pass non-transparant wrappers around a vector as `PassMode::Cast`
arg.cast_to(Reg { kind: RegKind::Vector, size });
return;
}
}
if !arg.layout.is_aggregate() && size.bits() <= 64 {
arg.extend_integer_width_to(64);
Expand Down
2 changes: 2 additions & 0 deletions src/tools/compiletest/src/runtest/run_make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ impl TestCx<'_> {
// Provide path to checkout root. This is the top-level directory containing
// rust-lang/rust checkout.
.env("SOURCE_ROOT", &source_root)
// Path to the build directory. This is usually the same as `source_root.join("build").join("host")`.
.env("BUILD_ROOT", &build_root)
// Provide path to stage-corresponding rustc.
.env("RUSTC", &self.config.rustc_path)
// Provide the directory to libraries that are needed to run the *compiler*. This is not
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/tests/fail/rustc-error2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct Struct<T>(T);
impl<T> std::ops::Deref for Struct<T> {
type Target = dyn Fn(T);
fn deref(&self) -> &assert_mem_uninitialized_valid::Target {
//~^ERROR: undeclared crate or module
//~^ERROR: use of unresolved module or unlinked crate
unimplemented!()
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/tools/miri/tests/fail/rustc-error2.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0433]: failed to resolve: use of undeclared crate or module `assert_mem_uninitialized_valid`
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `assert_mem_uninitialized_valid`
--> tests/fail/rustc-error2.rs:LL:CC
|
LL | fn deref(&self) -> &assert_mem_uninitialized_valid::Target {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `assert_mem_uninitialized_valid`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `assert_mem_uninitialized_valid`
|
= help: you might be missing a crate named `assert_mem_uninitialized_valid`

error: aborting due to 1 previous error

Expand Down
8 changes: 7 additions & 1 deletion src/tools/run-make-support/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,15 @@ impl CompletedProcess {
self
}

/// Check the **exit status** of the process. On Unix, this is *not* the **wait status**.
///
/// See [`std::process::ExitStatus::code`]. This is not to be confused with
/// [`std::process::ExitCode`].
#[track_caller]
pub fn assert_exit_code(&self, code: i32) -> &Self {
assert!(self.output.status.code() == Some(code));
// FIXME(jieyouxu): this should really be named `exit_status`, because std has an `ExitCode`
// that means a different thing.
assert_eq!(self.output.status.code(), Some(code));
self
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/tools/run-make-support/src/external_deps/rustc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::ffi::{OsStr, OsString};
use std::path::Path;
use std::path::{Path, PathBuf};
use std::str::FromStr as _;

use crate::command::Command;
use crate::env::env_var;
Expand Down Expand Up @@ -390,3 +391,10 @@ impl Rustc {
self
}
}

/// Query the sysroot path corresponding `rustc --print=sysroot`.
#[track_caller]
pub fn sysroot() -> PathBuf {
let path = rustc().print("sysroot").run().stdout_utf8();
PathBuf::from_str(path.trim()).unwrap()
}
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub use artifact_names::{
/// Path-related helpers.
pub use path_helpers::{
cwd, filename_contains, filename_not_in_denylist, has_extension, has_prefix, has_suffix,
not_contains, path, shallow_find_files, source_root,
not_contains, path, shallow_find_files, build_root, source_root,
};

/// Helpers for scoped test execution where certain properties are attempted to be maintained.
Expand Down
6 changes: 6 additions & 0 deletions src/tools/run-make-support/src/path_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ pub fn source_root() -> PathBuf {
env_var("SOURCE_ROOT").into()
}

/// Path to the build directory root.
#[must_use]
pub fn build_root() -> PathBuf {
env_var("BUILD_ROOT").into()
}

/// Browse the directory `path` non-recursively and return all files which respect the parameters
/// outlined by `closure`.
#[track_caller]
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
run-make/split-debuginfo/Makefile
run-make/symbol-mangling-hashed/Makefile
run-make/translation/Makefile
1 change: 1 addition & 0 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
"bitflags",
"blake3",
"block-buffer",
"bstr",
"byteorder", // via ruzstd in object in thorin-dwp
"cc",
"cfg-if",
Expand Down
19 changes: 13 additions & 6 deletions tests/assembly/x86_64-bigint-helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
//@ assembly-output: emit-asm
//@ compile-flags: --crate-type=lib -O -C target-cpu=x86-64-v4
//@ compile-flags: -C llvm-args=-x86-asm-syntax=intel
//@ revisions: llvm-pre-20 llvm-20
//@ [llvm-20] min-llvm-version: 20
//@ [llvm-pre-20] max-llvm-major-version: 19

#![no_std]
#![feature(bigint_helper_methods)]
Expand All @@ -20,12 +23,16 @@ pub unsafe extern "sysv64" fn bigint_chain_carrying_add(
n: usize,
mut carry: bool,
) -> bool {
// CHECK: mov [[TEMP:r..]], qword ptr [rsi + 8*[[IND:r..]] + 8]
// CHECK: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 8]
// CHECK: mov qword ptr [rdi + 8*[[IND]] + 8], [[TEMP]]
// CHECK: mov [[TEMP]], qword ptr [rsi + 8*[[IND]] + 16]
// CHECK: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 16]
// CHECK: mov qword ptr [rdi + 8*[[IND]] + 16], [[TEMP]]
// llvm-pre-20: mov [[TEMP:r..]], qword ptr [rsi + 8*[[IND:r..]] + 8]
// llvm-pre-20: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 8]
// llvm-pre-20: mov qword ptr [rdi + 8*[[IND]] + 8], [[TEMP]]
// llvm-pre-20: mov [[TEMP]], qword ptr [rsi + 8*[[IND]] + 16]
// llvm-pre-20: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 16]
// llvm-pre-20: mov qword ptr [rdi + 8*[[IND]] + 16], [[TEMP]]
// llvm-20: adc [[TEMP:r..]], qword ptr [rdx + 8*[[IND:r..]]]
// llvm-20: mov qword ptr [rdi + 8*[[IND]]], [[TEMP]]
// llvm-20: mov [[TEMP]], qword ptr [rsi + 8*[[IND]] + 8]
// llvm-20: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 8]
for i in 0..n {
(*dest.add(i), carry) = u64::carrying_add(*src1.add(i), *src2.add(i), carry);
}
Expand Down
Loading

0 comments on commit a37c61f

Please sign in to comment.