Skip to content

Commit 9f5ff93

Browse files
committed
Auto merge of #136051 - matthiaskrgr:rollup-g2pbn2w, r=<try>
Rollup of 4 pull requests Successful merges: - #135707 (Shorten linker output even more when `--verbose` is not present) - #135764 (Fix tests on LLVM 20) - #135785 (use `PassMode::Direct` for vector types on `s390x`) - #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
2 parents f940188 + 84b9a71 commit 9f5ff93

30 files changed

+567
-127
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3537,6 +3537,7 @@ dependencies = [
35373537
"ar_archive_writer",
35383538
"arrayvec",
35393539
"bitflags",
3540+
"bstr",
35403541
"cc",
35413542
"either",
35423543
"itertools",

compiler/rustc_codegen_ssa/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2021"
88
ar_archive_writer = "0.4.2"
99
arrayvec = { version = "0.7", default-features = false }
1010
bitflags = "2.4.1"
11+
bstr = "1.11.3"
1112
# Pinned so `cargo update` bumps don't cause breakage. Please also update the
1213
# `cc` in `rustc_llvm` if you update the `cc` here.
1314
cc = "=1.2.7"

compiler/rustc_codegen_ssa/src/back/command.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub(crate) struct Command {
1313
args: Vec<OsString>,
1414
env: Vec<(OsString, OsString)>,
1515
env_remove: Vec<OsString>,
16+
env_clear: bool,
1617
}
1718

1819
#[derive(Clone)]
@@ -36,7 +37,13 @@ impl Command {
3637
}
3738

3839
fn _new(program: Program) -> Command {
39-
Command { program, args: Vec::new(), env: Vec::new(), env_remove: Vec::new() }
40+
Command {
41+
program,
42+
args: Vec::new(),
43+
env: Vec::new(),
44+
env_remove: Vec::new(),
45+
env_clear: false,
46+
}
4047
}
4148

4249
pub(crate) fn arg<P: AsRef<OsStr>>(&mut self, arg: P) -> &mut Command {
@@ -79,6 +86,11 @@ impl Command {
7986
self
8087
}
8188

89+
pub(crate) fn env_clear(&mut self) -> &mut Command {
90+
self.env_clear = true;
91+
self
92+
}
93+
8294
fn _env_remove(&mut self, key: &OsStr) {
8395
self.env_remove.push(key.to_owned());
8496
}
@@ -106,6 +118,9 @@ impl Command {
106118
for k in &self.env_remove {
107119
ret.env_remove(k);
108120
}
121+
if self.env_clear {
122+
ret.env_clear();
123+
}
109124
ret
110125
}
111126

compiler/rustc_codegen_ssa/src/back/link.rs

+1
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@ fn link_natively(
991991
command: cmd,
992992
escaped_output,
993993
verbose: sess.opts.verbose,
994+
sysroot_dir: sess.sysroot.clone(),
994995
};
995996
sess.dcx().emit_err(err);
996997
// If MSVC's `link.exe` was expected but the return code

compiler/rustc_codegen_ssa/src/errors.rs

+47-15
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ pub(crate) struct LinkingFailed<'a> {
351351
pub command: Command,
352352
pub escaped_output: String,
353353
pub verbose: bool,
354+
pub sysroot_dir: PathBuf,
354355
}
355356

356357
impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
@@ -364,6 +365,8 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
364365
if self.verbose {
365366
diag.note(format!("{:?}", self.command));
366367
} else {
368+
self.command.env_clear();
369+
367370
enum ArgGroup {
368371
Regular(OsString),
369372
Objects(usize),
@@ -398,26 +401,55 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
398401
args.push(ArgGroup::Regular(arg));
399402
}
400403
}
401-
self.command.args(args.into_iter().map(|arg_group| match arg_group {
402-
ArgGroup::Regular(arg) => arg,
403-
ArgGroup::Objects(n) => OsString::from(format!("<{n} object files omitted>")),
404-
ArgGroup::Rlibs(dir, rlibs) => {
405-
let mut arg = dir.into_os_string();
406-
arg.push("/{");
407-
let mut first = true;
408-
for rlib in rlibs {
409-
if !first {
410-
arg.push(",");
404+
let crate_hash = regex::bytes::Regex::new(r"-[0-9a-f]+\.rlib$").unwrap();
405+
self.command.args(args.into_iter().map(|arg_group| {
406+
match arg_group {
407+
// SAFETY: we are only matching on ASCII, not any surrogate pairs, so any replacements we do will still be valid.
408+
ArgGroup::Regular(arg) => unsafe {
409+
use bstr::ByteSlice;
410+
OsString::from_encoded_bytes_unchecked(
411+
arg.as_encoded_bytes().replace(
412+
self.sysroot_dir.as_os_str().as_encoded_bytes(),
413+
b"<sysroot>",
414+
),
415+
)
416+
},
417+
ArgGroup::Objects(n) => OsString::from(format!("<{n} object files omitted>")),
418+
ArgGroup::Rlibs(mut dir, rlibs) => {
419+
let is_sysroot_dir = match dir.strip_prefix(&self.sysroot_dir) {
420+
Ok(short) => {
421+
dir = Path::new("<sysroot>").join(short);
422+
true
423+
}
424+
Err(_) => false,
425+
};
426+
let mut arg = dir.into_os_string();
427+
arg.push("/{");
428+
let mut first = true;
429+
for mut rlib in rlibs {
430+
if !first {
431+
arg.push(",");
432+
}
433+
first = false;
434+
if is_sysroot_dir {
435+
// SAFETY: Regex works one byte at a type, and our regex will not match surrogate pairs (because it only matches ascii).
436+
rlib = unsafe {
437+
OsString::from_encoded_bytes_unchecked(
438+
crate_hash
439+
.replace(rlib.as_encoded_bytes(), b"-*")
440+
.into_owned(),
441+
)
442+
};
443+
}
444+
arg.push(rlib);
411445
}
412-
first = false;
413-
arg.push(rlib);
446+
arg.push("}.rlib");
447+
arg
414448
}
415-
arg.push("}");
416-
arg
417449
}
418450
}));
419451

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

compiler/rustc_target/src/callconv/s390x.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@ where
3838
}
3939

4040
let size = arg.layout.size;
41-
if size.bits() <= 128 && arg.layout.is_single_vector_element(cx, size) {
42-
arg.cast_to(Reg { kind: RegKind::Vector, size });
43-
return;
41+
if size.bits() <= 128 {
42+
if let BackendRepr::Vector { .. } = arg.layout.backend_repr {
43+
// pass non-wrapped vector types using `PassMode::Direct`
44+
return;
45+
}
46+
47+
if arg.layout.is_single_vector_element(cx, size) {
48+
// pass non-transparant wrappers around a vector as `PassMode::Cast`
49+
arg.cast_to(Reg { kind: RegKind::Vector, size });
50+
return;
51+
}
4452
}
4553
if !arg.layout.is_aggregate() && size.bits() <= 64 {
4654
arg.extend_integer_width_to(64);

src/tools/compiletest/src/runtest/run_make.rs

+2
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ impl TestCx<'_> {
414414
// Provide path to checkout root. This is the top-level directory containing
415415
// rust-lang/rust checkout.
416416
.env("SOURCE_ROOT", &source_root)
417+
// Path to the build directory. This is usually the same as `source_root.join("build").join("host")`.
418+
.env("BUILD_ROOT", &build_root)
417419
// Provide path to stage-corresponding rustc.
418420
.env("RUSTC", &self.config.rustc_path)
419421
// Provide the directory to libraries that are needed to run the *compiler*. This is not

src/tools/run-make-support/src/command.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,15 @@ impl CompletedProcess {
388388
self
389389
}
390390

391+
/// Check the **exit status** of the process. On Unix, this is *not* the **wait status**.
392+
///
393+
/// See [`std::process::ExitStatus::code`]. This is not to be confused with
394+
/// [`std::process::ExitCode`].
391395
#[track_caller]
392396
pub fn assert_exit_code(&self, code: i32) -> &Self {
393-
assert!(self.output.status.code() == Some(code));
397+
// FIXME(jieyouxu): this should really be named `exit_status`, because std has an `ExitCode`
398+
// that means a different thing.
399+
assert_eq!(self.output.status.code(), Some(code));
394400
self
395401
}
396402
}

src/tools/run-make-support/src/external_deps/rustc.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::ffi::{OsStr, OsString};
2-
use std::path::Path;
2+
use std::path::{Path, PathBuf};
3+
use std::str::FromStr as _;
34

45
use crate::command::Command;
56
use crate::env::env_var;
@@ -390,3 +391,10 @@ impl Rustc {
390391
self
391392
}
392393
}
394+
395+
/// Query the sysroot path corresponding `rustc --print=sysroot`.
396+
#[track_caller]
397+
pub fn sysroot() -> PathBuf {
398+
let path = rustc().print("sysroot").run().stdout_utf8();
399+
PathBuf::from_str(path.trim()).unwrap()
400+
}

src/tools/run-make-support/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub use artifact_names::{
9090
/// Path-related helpers.
9191
pub use path_helpers::{
9292
cwd, filename_contains, filename_not_in_denylist, has_extension, has_prefix, has_suffix,
93-
not_contains, path, shallow_find_files, source_root,
93+
not_contains, path, shallow_find_files, build_root, source_root,
9494
};
9595

9696
/// Helpers for scoped test execution where certain properties are attempted to be maintained.

src/tools/run-make-support/src/path_helpers.rs

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ pub fn source_root() -> PathBuf {
3434
env_var("SOURCE_ROOT").into()
3535
}
3636

37+
/// Path to the build directory root.
38+
#[must_use]
39+
pub fn build_root() -> PathBuf {
40+
env_var("BUILD_ROOT").into()
41+
}
42+
3743
/// Browse the directory `path` non-recursively and return all files which respect the parameters
3844
/// outlined by `closure`.
3945
#[track_caller]
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
run-make/split-debuginfo/Makefile
22
run-make/symbol-mangling-hashed/Makefile
3-
run-make/translation/Makefile

src/tools/tidy/src/deps.rs

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
253253
"bitflags",
254254
"blake3",
255255
"block-buffer",
256+
"bstr",
256257
"byteorder", // via ruzstd in object in thorin-dwp
257258
"cc",
258259
"cfg-if",

tests/assembly/x86_64-bigint-helpers.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
//@ assembly-output: emit-asm
33
//@ compile-flags: --crate-type=lib -O -C target-cpu=x86-64-v4
44
//@ compile-flags: -C llvm-args=-x86-asm-syntax=intel
5+
//@ revisions: llvm-pre-20 llvm-20
6+
//@ [llvm-20] min-llvm-version: 20
7+
//@ [llvm-pre-20] max-llvm-major-version: 19
58

69
#![no_std]
710
#![feature(bigint_helper_methods)]
@@ -20,12 +23,16 @@ pub unsafe extern "sysv64" fn bigint_chain_carrying_add(
2023
n: usize,
2124
mut carry: bool,
2225
) -> bool {
23-
// CHECK: mov [[TEMP:r..]], qword ptr [rsi + 8*[[IND:r..]] + 8]
24-
// CHECK: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 8]
25-
// CHECK: mov qword ptr [rdi + 8*[[IND]] + 8], [[TEMP]]
26-
// CHECK: mov [[TEMP]], qword ptr [rsi + 8*[[IND]] + 16]
27-
// CHECK: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 16]
28-
// CHECK: mov qword ptr [rdi + 8*[[IND]] + 16], [[TEMP]]
26+
// llvm-pre-20: mov [[TEMP:r..]], qword ptr [rsi + 8*[[IND:r..]] + 8]
27+
// llvm-pre-20: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 8]
28+
// llvm-pre-20: mov qword ptr [rdi + 8*[[IND]] + 8], [[TEMP]]
29+
// llvm-pre-20: mov [[TEMP]], qword ptr [rsi + 8*[[IND]] + 16]
30+
// llvm-pre-20: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 16]
31+
// llvm-pre-20: mov qword ptr [rdi + 8*[[IND]] + 16], [[TEMP]]
32+
// llvm-20: adc [[TEMP:r..]], qword ptr [rdx + 8*[[IND:r..]]]
33+
// llvm-20: mov qword ptr [rdi + 8*[[IND]]], [[TEMP]]
34+
// llvm-20: mov [[TEMP]], qword ptr [rsi + 8*[[IND]] + 8]
35+
// llvm-20: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 8]
2936
for i in 0..n {
3037
(*dest.add(i), carry) = u64::carrying_add(*src1.add(i), *src2.add(i), carry);
3138
}

0 commit comments

Comments
 (0)