Skip to content

compiler: hash the input file name for C/C++ compilations - #2974

Merged
sylvestre merged 3 commits into
mozilla:mainfrom
saimskywalker:issue-2959-stt-file-basename
Nov 3, 2026
Merged

sylvestre merged 3 commits into
mozilla:mainfrom
saimskywalker:issue-2959-stt-file-basename

Conversation

@saimskywalker

Copy link
Copy Markdown
Contributor

The source file name, without its directory, is now part of the C/C++ cache key, so two files that preprocess to the same thing no longer share an object that carries only one of their names. The whitespace system test now reformats the same file instead of compiling a second one, since a different name is now a different key.

Closes #2959

The compiler records the source file name in the object (an STT_FILE
symbol on ELF), but the preprocessed output it is hashed from has no
line markers, so two sources that preprocess to the same text, such as
files that are entirely #ifdef'd out, ended up sharing one cache entry
and one of them got an object naming the other.

Hash the file name without its directory, so the same file still hits
across checkouts.

Closes mozilla#2959
@codecov-commenter

codecov-commenter commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.54%. Comparing base (b937482) to head (e2c0d3c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2974      +/-   ##
==========================================
- Coverage   78.54%   78.54%   -0.01%     
==========================================
  Files          74       74              
  Lines       44039    44095      +56     
==========================================
+ Hits        34592    34635      +43     
- Misses       9447     9460      +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

ptxas reads a .ptx file that nvcc names after the source, so identical
device code from two sources stopped sharing a cubin.
Comment thread src/compiler/c.rs Outdated
// after the source, and identical device code from different sources
// is meant to be shared.
let input_file_name = match self.parsed_args.language {
Language::CudaFE | Language::Ptx | Language::Cubin => None,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please add a test showing two sources with the same device code still share the cubin/ptx

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added test_device_code_input_file_name_ignored in e2c0d3c: it checks that cudafe++, PTX and cubin inputs with different names but the same content hash the same, while C and CUDA sources with different names still differ.

… file names

Move the choice of which inputs keep their file name in the hash key into
hashed_input_file_name, and check that cudafe++, PTX and cubin inputs with
the same content but different names hash the same, while C and CUDA
sources with different names still differ.
@drahnr

drahnr commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

If the content is identical, do we want to duplicate the object or strip the filename before posting, and then "re-hydrating" it on the client? In practice this would allow for avoiding recompilation, at the cost of a seek, write and copy operation. Food for thought, don't treat this as direction!

@saimskywalker

Copy link
Copy Markdown
Contributor Author

Thanks, I thought about that too. Putting the name back is more than a seek and write, though: on ELF it lives in .strtab, so a name of a different length moves every later offset, Mach-O and COFF store it their own way, and with -g it is in DWARF/CodeView as well. Getting any of that wrong would break the reproducibility this issue is about. Sources that preprocess the same under different names are almost always empty #ifdef'd units, which compile in milliseconds, so I kept the simple key change here. Happy to open a follow-up issue if you see a case with bigger shared units.

@sylvestre
sylvestre merged commit f4ba08d into mozilla:main Nov 3, 2026
49 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build reproducibility issue related to STT_FILE symbols

4 participants