Skip to content

Commit 72fab81

Browse files
committed
Auto merge of #148041 - matthiaskrgr:rollup-ysofz8z, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #148018 (fix panic when rustc tries to reduce intermediate filenames len with utf8) - #148030 (Add Marijn Schouten to .mailmap) - #148039 (Add myself to the review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6501e64 + d569533 commit 72fab81

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ Marcell Pardavi <[email protected]>
427427
Marco Ieni <[email protected]>
428428
Marcus Klaas de Vries <[email protected]>
429429
Margaret Meyerhofer <[email protected]> <mmeyerho@andrew>
430+
430431
Mark Mansi <[email protected]>
431432
432433
Mark Rousskov <[email protected]>

compiler/rustc_session/src/config.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,13 +1211,22 @@ fn maybe_strip_file_name(mut path: PathBuf) -> PathBuf {
12111211
if path.file_name().map_or(0, |name| name.len()) > MAX_FILENAME_LENGTH {
12121212
let filename = path.file_name().unwrap().to_string_lossy();
12131213
let hash_len = 64 / 4; // Hash64 is 64 bits encoded in hex
1214-
let stripped_len = filename.len() - MAX_FILENAME_LENGTH + hash_len;
1214+
let hyphen_len = 1; // the '-' we insert between hash and suffix
1215+
1216+
// number of bytes of suffix we can keep so that "hash-<suffix>" fits
1217+
let allowed_suffix = MAX_FILENAME_LENGTH.saturating_sub(hash_len + hyphen_len);
1218+
1219+
// number of bytes to remove from the start
1220+
let stripped_bytes = filename.len().saturating_sub(allowed_suffix);
1221+
1222+
// ensure we don't cut in a middle of a char
1223+
let split_at = filename.ceil_char_boundary(stripped_bytes);
12151224

12161225
let mut hasher = StableHasher::new();
1217-
filename[..stripped_len].hash(&mut hasher);
1226+
filename[..split_at].hash(&mut hasher);
12181227
let hash = hasher.finish::<Hash64>();
12191228

1220-
path.set_file_name(format!("{:x}-{}", hash, &filename[stripped_len..]));
1229+
path.set_file_name(format!("{:x}-{}", hash, &filename[split_at..]));
12211230
}
12221231
path
12231232
}

tests/run-make/lto-long-filenames/rmake.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
//@ ignore-cross-compile
1111

12-
use std::fs;
13-
1412
use run_make_support::{rfs, rustc};
1513

1614
// This test make sure we don't get such following error:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ ignore-cross-compile
2+
3+
use run_make_support::{rfs, rustc};
4+
5+
// This test make sure we don't crash when lto creates output files with long names.
6+
// cn characters can be multi-byte and thus trigger the long filename reduction code more easily.
7+
// we need to make sure that the code is properly generating names at char boundaries.
8+
// as reported in issue #147975
9+
fn main() {
10+
let lto_flags = ["-Clto", "-Clto=yes", "-Clto=off", "-Clto=thin", "-Clto=fat"];
11+
for prefix_len in 0..4 {
12+
let prefix: String = std::iter::repeat("_").take(prefix_len).collect();
13+
let main_file = format!("{}ⵅⴻⵎⵎⴻⵎ_ⴷⵉⵎⴰ_ⵖⴻⴼ_ⵢⵉⵙⴻⴽⴽⵉⵍⴻⵏ_ⵏ_ⵡⴰⵟⴰⵙ_ⵏ_ⵢⵉⴱⵢⵜⴻⵏ.rs", prefix);
14+
rfs::write(&main_file, "fn main() {}\n");
15+
for flag in lto_flags {
16+
rustc().input(&main_file).arg(flag).run();
17+
}
18+
}
19+
}

triagebot.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,7 @@ compiler = [
13701370
"@jackh726",
13711371
"@jieyouxu",
13721372
"@jdonszelmann",
1373+
"@JonathanBrouwer",
13731374
"@lcnr",
13741375
"@madsmtm",
13751376
"@Nadrieril",

0 commit comments

Comments
 (0)