Skip to content

strip prefix of temporary file names when it exceeds filesystem name length limit #145005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tardyp
Copy link

@tardyp tardyp commented Aug 6, 2025

When doing lto, rustc generates filenames that are concatenating many information.

In the case of this testcase, it is concatenating crate name and rust file name, plus some hash, and the extension. In some other cases it will concatenate even more information reducing the maximum effective crate name to about 110 chars on linux filesystems where filename max length is 255

This commit is ensuring that the temporary file names are limited in size, while still reasonably ensuring the unicity (with hashing of the stripped part)

Fix: #49914

@rustbot
Copy link
Collaborator

rustbot commented Aug 6, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2025
@rustbot

This comment has been minimized.

@bjorn3
Copy link
Member

bjorn3 commented Aug 6, 2025

This method is also used for generating output files in various places. Mangling the name of output files would break cargo and other build tools that pre-generate the expected filenames based on rustc --print file-names or hardcode it.

@tardyp
Copy link
Author

tardyp commented Aug 6, 2025

@bjorn3 would it be more appropriate to put the filename stripping in temp_path_ext_for_cgu ?

those files if I understand correctly are temporary and unlinked after the rustc invocation.

@tardyp tardyp force-pushed the lto_big_filesize branch 2 times, most recently from 4d6eb1e to 3239eeb Compare August 6, 2025 16:54
@lcnr
Copy link
Contributor

lcnr commented Aug 7, 2025

r? bjorn3 feel free to reassign

@rustbot rustbot assigned bjorn3 and unassigned lcnr Aug 7, 2025
filename[..stripped_len].hash(&mut hasher);
let hash = hasher.finish::<Hash64>();

path.set_file_name(format!("{:x}-{}", hash, &filename[stripped_len..]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The start of the filename has more useful information, but we do absolutely need to preserve file extensions (plural: eg .rcgu.o) for correctness and it isn't trivial to distinguish between file extensions and normal dot separated filename components. So I guess the current implementation is good enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This long filename may cause issues on windows where the total path length may not be more than 254 characters unless you use \\?\ prefixed paths, which many programs don't do (including possibly git). Maybe a run-make test which writes the file dynamically would be better? Libstd internally does whatever is necessary to support long paths on Windows.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this thorough review. I updated the test to use run-make.

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Aug 10, 2025
@tardyp tardyp force-pushed the lto_big_filesize branch 2 times, most recently from 4e616be to 63fd877 Compare August 10, 2025 10:37
@rust-log-analyzer

This comment has been minimized.

…length limit

When doing lto, rustc generates filenames that are concatenating many information.

In the case of this testcase, it is concatenating crate name and rust file name, plus some hash, and the extension.
In some other cases it will concatenate even more information reducing the maximum effective crate name to about 110 chars on linux filesystems where
filename max length is 255

This commit is ensuring that the temporary file names are limited in size, while still reasonabily ensuring the unicity (with hashing of the stripped part)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"File name too long" error when compiling files with long names
5 participants