Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ Marcell Pardavi <[email protected]>
Marco Ieni <[email protected]>
Marcus Klaas de Vries <[email protected]>
Margaret Meyerhofer <[email protected]> <mmeyerho@andrew>
Marijn Schouten <[email protected]> <[email protected]>
Mark Mansi <[email protected]>
Mark Mansi <[email protected]> <[email protected]>
Mark Rousskov <[email protected]>
Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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-<suffix>" 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::<Hash64>();

path.set_file_name(format!("{:x}-{}", hash, &filename[stripped_len..]));
path.set_file_name(format!("{:x}-{}", hash, &filename[split_at..]));
}
path
}
Expand Down
2 changes: 0 additions & 2 deletions tests/run-make/lto-long-filenames/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions tests/run-make/lto-long-filenames_cn/rmake.rs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
1 change: 1 addition & 0 deletions triagebot.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,7 @@ compiler = [
"@jackh726",
"@jieyouxu",
"@jdonszelmann",
"@JonathanBrouwer",
"@lcnr",
"@madsmtm",
"@Nadrieril",
Expand Down
Loading