From a9689309ac739efcd3e2491eb8a2bf2787b00e9e Mon Sep 17 00:00:00 2001 From: Pierre Tardy Date: Thu, 23 Oct 2025 10:06:59 +0200 Subject: [PATCH 1/3] fix panic when rustc tries to reduce intermediate filenames length with multi byte chars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The issue cannot be reproduced with the former testcase of creating external crates because rust refuses to use "external crate 28_找出字符串中第一个匹配项的下标" because it is not a valid indentifier (starts with number, and contain non ascii chars) But still using 28_找出字符串中第一个匹配项的下标.rs as a filename is accepted by previous rustc releases So we consider it valid, and add an integration test for it to catch any regression on other code related to non ascii filenames. --- compiler/rustc_session/src/config.rs | 15 ++++++++++++--- tests/run-make/lto-long-filenames/rmake.rs | 2 -- tests/run-make/lto-long-filenames_cn/rmake.rs | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 tests/run-make/lto-long-filenames_cn/rmake.rs diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 484a7d4217211..8ff6d567422b9 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1211,13 +1211,22 @@ fn maybe_strip_file_name(mut path: PathBuf) -> PathBuf { if path.file_name().map_or(0, |name| name.len()) > MAX_FILENAME_LENGTH { let filename = path.file_name().unwrap().to_string_lossy(); let hash_len = 64 / 4; // Hash64 is 64 bits encoded in hex - let stripped_len = filename.len() - MAX_FILENAME_LENGTH + hash_len; + let hyphen_len = 1; // the '-' we insert between hash and suffix + + // number of bytes of suffix we can keep so that "hash-" fits + let allowed_suffix = MAX_FILENAME_LENGTH.saturating_sub(hash_len + hyphen_len); + + // number of bytes to remove from the start + let stripped_bytes = filename.len().saturating_sub(allowed_suffix); + + // ensure we don't cut in a middle of a char + let split_at = filename.ceil_char_boundary(stripped_bytes); let mut hasher = StableHasher::new(); - filename[..stripped_len].hash(&mut hasher); + filename[..split_at].hash(&mut hasher); let hash = hasher.finish::(); - path.set_file_name(format!("{:x}-{}", hash, &filename[stripped_len..])); + path.set_file_name(format!("{:x}-{}", hash, &filename[split_at..])); } path } diff --git a/tests/run-make/lto-long-filenames/rmake.rs b/tests/run-make/lto-long-filenames/rmake.rs index 9e0ba63e9f5b8..98ce54e5efc82 100644 --- a/tests/run-make/lto-long-filenames/rmake.rs +++ b/tests/run-make/lto-long-filenames/rmake.rs @@ -9,8 +9,6 @@ //@ ignore-cross-compile -use std::fs; - use run_make_support::{rfs, rustc}; // This test make sure we don't get such following error: diff --git a/tests/run-make/lto-long-filenames_cn/rmake.rs b/tests/run-make/lto-long-filenames_cn/rmake.rs new file mode 100644 index 0000000000000..e70694e6b0b2a --- /dev/null +++ b/tests/run-make/lto-long-filenames_cn/rmake.rs @@ -0,0 +1,19 @@ +//@ ignore-cross-compile + +use run_make_support::{rfs, rustc}; + +// This test make sure we don't crash when lto creates output files with long names. +// cn characters can be multi-byte and thus trigger the long filename reduction code more easily. +// we need to make sure that the code is properly generating names at char boundaries. +// as reported in issue #147975 +fn main() { + let lto_flags = ["-Clto", "-Clto=yes", "-Clto=off", "-Clto=thin", "-Clto=fat"]; + for prefix_len in 0..4 { + let prefix: String = std::iter::repeat("_").take(prefix_len).collect(); + let main_file = format!("{}ⵅⴻⵎⵎⴻⵎ_ⴷⵉⵎⴰ_ⵖⴻⴼ_ⵢⵉⵙⴻⴽⴽⵉⵍⴻⵏ_ⵏ_ⵡⴰⵟⴰⵙ_ⵏ_ⵢⵉⴱⵢⵜⴻⵏ.rs", prefix); + rfs::write(&main_file, "fn main() {}\n"); + for flag in lto_flags { + rustc().input(&main_file).arg(flag).run(); + } + } +} From 41b4b2f718a536538a10b46d67f0fd1af7e2e382 Mon Sep 17 00:00:00 2001 From: Marijn Schouten Date: Thu, 23 Oct 2025 15:17:44 +0200 Subject: [PATCH 2/3] Add Marijn Schouten to .mailmap --- .mailmap | 1 + 1 file changed, 1 insertion(+) diff --git a/.mailmap b/.mailmap index 0f7bc5e38bd10..fc8e83d6493cd 100644 --- a/.mailmap +++ b/.mailmap @@ -427,6 +427,7 @@ Marcell Pardavi Marco Ieni <11428655+MarcoIeni@users.noreply.github.com> Marcus Klaas de Vries Margaret Meyerhofer +Marijn Schouten Mark Mansi Mark Mansi Mark Rousskov From 9ceb997e040250e0bdb425b324b7662abd1d42a2 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Thu, 23 Oct 2025 17:52:54 +0200 Subject: [PATCH 3/3] Add myself to the review rotation --- triagebot.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/triagebot.toml b/triagebot.toml index fbe29dd182452..a0d0b1892e4fe 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1370,6 +1370,7 @@ compiler = [ "@jackh726", "@jieyouxu", "@jdonszelmann", + "@JonathanBrouwer", "@lcnr", "@madsmtm", "@Nadrieril",