Skip to content
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

unexpected results when using -MD or -MMD compiler options #134

Closed
jmacfarlane opened this issue Sep 24, 2016 · 9 comments
Closed

unexpected results when using -MD or -MMD compiler options #134

jmacfarlane opened this issue Sep 24, 2016 · 9 comments
Labels
bug Does not work as intended/documented
Milestone

Comments

@jmacfarlane
Copy link

The resulting dependency file is not always correct when specifying the -MD or -MMD options to the compiler.

example:

$ # Make two identical source directories
$ mkdir a
$ touch a/source.c
$ rsync -a a/ b
$
$ # Cache entry added for directory "a"
$ ccache /usr/bin/cc -MMD -c a/source.c && cat source.d
source.o: a/source.c
$
$ # Cache entry added for directory "b"
$ ccache /usr/bin/cc -MMD -c b/source.c && cat source.d
source.o: b/source.c
$
$ # Incorrect cached results used for directory "a"
$ ccache /usr/bin/cc -MMD -c a/source.c && cat source.d
source.o: b/source.c
$
$ # Verify compiler gives different results
$ /usr/bin/cc -MMD -c a/source.c && cat source.d
source.o: a/source.c

The Ninja generator of CMake uses the -MMD compiler option to cache dependencies. This means that anyone using Ninja with a CMake project will encounter this bug if the source code is moved.

@jrosdahl jrosdahl added the bug Does not work as intended/documented label Sep 24, 2016
@tanstafel
Copy link

Is it possible that this issue also causes issue #133? I ask because I see the -MD switch used in the .cmd files the kernel build process creates.

@jrosdahl
Copy link
Member

jrosdahl commented Sep 27, 2016

The resulting dependency file is not always correct when specifying the -MD or -MMD options to the compiler.

Thanks for the bug report and excellent reproduction example!

This is regression introduced as a side effect of #88. First affected ccache version: 3.3.

@jrosdahl
Copy link
Member

Is it possible that this issue also causes issue #133? I ask because I see the -MD switch used in the .cmd files the kernel build process creates.

I haven't had time to look at #133 in detail yet (I have a two weeks old daughter that competes with my spare time), but my current guess is that #133 and #134 are unrelated. I think that your "there is another more hidden issue" problem in #133 might be caused by #134, though.

@jrosdahl jrosdahl added this to the 3.3.2 milestone Sep 27, 2016
jrosdahl added a commit that referenced this issue Sep 27, 2016
5908e65 introduced a regression: If a
source file is compiled in directory A and an identical source file in
directory B results in a preprocessed hit, then the dependency file from
the first compilation will be overwritten by the second compilation.
Since the source path is part of the dependency file, an incorrect
dependency file will be retrieved from the cache when recompiling the
source in directory A.

The solution is to include the source path part in the object hash if a
dependency file is being generated.

Fixes #134.
@jrosdahl
Copy link
Member

Fixed in ccache 3.3.2.

@jrmrjnck
Copy link

jrmrjnck commented Nov 1, 2016

This still doesn't work for situations where the source file stays in the same place, but the include paths change. Consider the following:

$ mkdir inc_a inc_b
$ touch inc_a/source.h inc_b/source.h
$ echo '#include <source.h>' > source.c
$ ccache gcc -MMD -Iinc_a -c source.c && cat source.d
source.o: source.c inc_a/source.h
$ ccache gcc -MMD -Iinc_b -c source.c && cat source.d
source.o: source.c inc_b/source.h
$ ccache gcc -MMD -Iinc_a -c source.c && cat source.d
source.o: source.c inc_b/source.h

@jrmrjnck
Copy link

This is still broken in 3.3.3. Can this bug be reopened?

@jrosdahl
Copy link
Member

jrosdahl commented Feb 4, 2017

Thanks! I hope to find time to have a look at this this weekend.

@amerlyq
Copy link

amerlyq commented Jan 12, 2018

I remember in mailing list of ccache were mentioned problems with kernel having zero hits on second fresh compilation: https://www.mail-archive.com/ccache@lists.samba.org/msg01055.html
Is this issue related to that problem and therefore fixes both of them? Or the problem with kernel persists?

@jrosdahl
Copy link
Member

I remember in mailing list of ccache were mentioned problems with kernel having zero hits on second fresh compilation: https://www.mail-archive.com/ccache@lists.samba.org/msg01055.html
Is this issue related to that problem and therefore fixes both of them?

Don't think so, since this issue was a regression in ccache 3.3, which was released 2016, while the mail thread you refer to is from 2014.

Or the problem with kernel persists?

Don't know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Does not work as intended/documented
Projects
None yet
Development

No branches or pull requests

5 participants