With clang, unless -fno-split-dwarf-inlining is used (on trunk, it isn't supported on current 3.9.0), the order between -g* and -gsplit-dwarf matters, see https://github.com/llvm-mirror/clang/blob/master/lib/Driver/Tools.cpp#L4776.
But ccache doesn't preserve the order :
Command line: clang++ -g1 -gsplit-dwarf -c -o test.o test.cpp
...
Executing /usr/bin/clang++ -gsplit-dwarf -g1 -fcolor-diagnostics -E test.cpp
...
Running real compiler
Executing /usr/bin/clang++ -gsplit-dwarf -g1 -fcolor-diagnostics -c -o test.o test.cpp
Compiler didn't produce a split dwarf file
Failed; falling back to running the real compiler
Executing /usr/bin/clang++ -g1 -gsplit-dwarf -c -o test.o test.cpp
In this case, "-g1 -gsplit-dwarf" (same as "-gsplit-dwarf") becomes "-gsplit-dwarf -g1" (same as "-g1"), which doesn't write a dwo.
So when starting from a clean build tree with a clean cache, ccache runs the compiler again with the original arguments like in the traces above.
But later, if the dwo already exists :
- the compiler only writes the .o (not referencing the dwo)
- ccache caches the new .o with the old .dwo
If the user looks at the file dates at this point, he can see the issue (the .dwo is older than the .o).
But after cleaning the build tree, it becomes really confusing, since on the next build ccache restores the cached .o and .dwo, so :
- both files have the same date
- the .o has only limited debug information (-g1)
- the .dwo is perfectly valid, but it isn't loaded by gdb since the .o doesn't reference it
Could ccache do something here ?
If the order was preserved, this specific case would work, but "-gsplit-dwarf -g1" would always fail, re-run the compiler, and nothing would be cached (since clang wouldn't create the dwo).
Perhaps the only solution would be to launch clang with "-###", then parse the cc1 arguments, since the driver handles the conflicting or overlapping options before calling the frontend. But it would be a massive change, and would require clang-specific code, since the cc1 options are different (and could change between versions...).