mozilla / sccache

Sccache is a ccache-like tool. It is used as a compiler wrapper and avoids compilation when possible. Sccache has the capability to utilize caching in remote storage environments, including various cloud storage options, or alternatively, in local storage.
Apache License 2.0
5.85k stars 552 forks source link

Fix: fix sccache bug for dwo file generate #2271

Closed zhouronghua closed 1 week ago

zhouronghua commented 1 month ago

When output dir changed, and -g -gsplit-dwarf is enabled, because the object file have link to the dwo file (include directories), the new object file should be gererated, but not old cached object. In this patch, we add a new precompile macro, for example, "-D_gsplit_dwarf_path=foo.dwo", to force sccache to generate new object file depend on the output directories.

we can check if it work by this case: case:

echo "int test(){}" > test.cc
mkdir o1 o2
sccache g++ -c -g -gsplit-dwarf test.cc -o o1/test.o
sccache g++ -c -g -gsplit-dwarf test.cc -o o2/test.o
strings o2/test.o |grep o2/test.dwo

The new o2/test.o should contains new link to o2/test.dwo, but not cached o1/test.dwo

codecov-commenter commented 1 month ago

Codecov Report

Attention: Patch coverage is 94.11765% with 3 lines in your changes missing coverage. Please review.

Project coverage is 40.85%. Comparing base (0cc0c62) to head (baca926). Report is 85 commits behind head on main.

Files with missing lines Patch % Lines
src/compiler/gcc.rs 66.66% 0 Missing and 2 partials :warning:
tests/system.rs 97.77% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2271 +/- ## ========================================== + Coverage 30.91% 40.85% +9.94% ========================================== Files 53 54 +1 Lines 20112 20803 +691 Branches 9755 9678 -77 ========================================== + Hits 6217 8499 +2282 - Misses 7922 8153 +231 + Partials 5973 4151 -1822 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

sylvestre commented 1 month ago

Could you please add a test to make sure we don't regress in the future? thanks

zhouronghua commented 1 month ago

"test_parse_arguments_split_dwarf" this case has been modified to make it work all the time

sylvestre commented 1 month ago

this isn't enough. I would like to see a test reproducing:

echo "int test(){}" > test.cc
mkdir o1 o2
sccache g++ -c -g -gsplit-dwarf test.cc -o o1/test.o
sccache g++ -c -g -gsplit-dwarf test.cc -o o2/test.o
strings o2/test.o |grep o2/test.dwo

also, you didn't updated the clang.rs file, is that expected ?

zhouronghua commented 1 month ago

ok, I will add another test for it, but it need time.

parse_arguments in clang.rs will call parse_arguments in gcc.rs, so no need to change them all.

sylvestre commented 1 month ago

see https://github.com/mozilla/sccache/blob/main/tests/system.rs for example

zhouronghua commented 3 weeks ago

thanks, that's really help.

sylvestre commented 3 weeks ago

Needs rustfmt

zhouronghua commented 3 weeks ago

done

sylvestre commented 1 week ago

Thanks