// (--serialize-diagnostics)?
static bool generating_diagnostics;
-// Is the compiler being asked to separate dwarf debug info into a separate
-// file (-gsplit-dwarf)"?
-static bool using_split_dwarf;
+// Have we seen -gsplit-dwarf?
+static bool seen_split_dwarf;
// Relocating debuginfo in the format old=new.
static char **debug_prefix_maps = NULL;
args_add(args, i_tmpfile);
}
+ if (seen_split_dwarf) {
+ // Remove any preexisting .dwo since we want to check if the compiler
+ // produced one.
+ x_unlink(output_dwo);
+ }
+
cc_log("Running real compiler");
MTR_BEGIN("execute", "compiler");
char *tmp_stdout;
if (generating_diagnostics) {
result_files_add(result_files, output_dia, ".dia");
}
- if (using_split_dwarf) {
+ if (seen_split_dwarf && stat(output_dwo, &st) == 0) {
+ // Only copy .dwo file if it was created by the compiler (GCC and Clang
+ // behave differently e.g. for "-gsplit-dwarf -g1").
result_files_add(result_files, output_dwo, ".dwo");
}
struct stat orig_dest_st;
}
}
- if (using_split_dwarf) {
+ if (seen_split_dwarf) {
// When using -gsplit-dwarf, object files include a link to the
// corresponding .dwo file based on the target object filename, so we need
// to include the target filename in the hash to avoid handing out an
struct result_files *result_files = result_files_init();
if (!str_eq(output_obj, "/dev/null")) {
result_files_add(result_files, output_obj, ".o");
- if (using_split_dwarf) {
+ if (seen_split_dwarf) {
result_files_add(result_files, output_dwo, ".dwo");
}
}
result_files_free(result_files);
if (!ok) {
cc_log("Failed to get result from cache");
- // TODO: Add new STATS_CORRUPT statistics value and increment here?
tmp_unlink(tmp_stderr);
free(tmp_stderr);
return;
char last_char = argv[i][strlen(argv[i]) - 1];
if (last_char == '0') {
// "-g0", "-ggdb0" or similar: All debug information disabled.
- // "-gsplit-dwarf" is still in effect if given previously, though.
generating_debuginfo = false;
generating_debuginfo_level_3 = false;
} else {
generating_debuginfo_level_3 = true;
}
if (str_eq(argv[i], "-gsplit-dwarf")) {
- using_split_dwarf = true;
+ seen_split_dwarf = true;
}
}
continue;
}
}
- if (found_S_opt) {
- // Even if -gsplit-dwarf is given, the .dwo file is not generated when -S
- // is also given.
- using_split_dwarf = false;
- cc_log("Disabling caching of dwarf files since -S is used");
- }
-
if (!input_file) {
cc_log("No input file found");
stats_update(STATS_NOINPUT);
}
}
- if (using_split_dwarf) {
+ if (seen_split_dwarf) {
char *p = strrchr(output_obj, '.');
if (!p || !p[1]) {
cc_log("Badly formed object filename");
output_is_precompiled_header = false;
conf = conf_create();
- using_split_dwarf = false;
+ seen_split_dwarf = false;
}
// Make a copy of stderr that will not be cached, so things like distcc can
SUITE_split_dwarf_SETUP() {
unset CCACHE_NODIRECT
+ touch test.c
+
mkdir -p dir1/src dir1/include
cat <<EOF >dir1/src/test.c
#include <stdarg.h>
expect_stat 'cache hit (preprocessed)' 0
expect_stat 'cache miss' 1
expect_stat 'files in cache' 2
- if objdump_cmd test.o | grep_cmd "$(pwd)" >/dev/null 2>&1; then
+ if objdump_cmd test.o 2>/dev/null | grep_cmd "$(pwd)" >/dev/null 2>&1; then
test_failed "Source dir ($(pwd)) found in test.o"
fi
expect_stat 'cache hit (preprocessed)' 0
expect_stat 'cache miss' 1
expect_stat 'files in cache' 2
- if objdump_cmd test.o | grep_cmd "$(pwd)" >/dev/null 2>&1; then
+ if objdump_cmd test.o 2>/dev/null | grep_cmd "$(pwd)" >/dev/null 2>&1; then
test_failed "Source dir ($(pwd)) found in test.o"
fi
+
+ # -------------------------------------------------------------------------
+ TEST "-gsplit-dwarf -g1"
+
+ # "gcc -gsplit-dwarf -g1" produces a .dwo file, but "clang -gsplit-dwarf
+ # -g1" doesn't, so test that ccache handles it gracefully either way.
+
+ $REAL_COMPILER -gsplit-dwarf -g1 -c test.c -o reference.o
+
+ $CCACHE_COMPILE -gsplit-dwarf -g1 -c test.c
+ expect_stat 'cache hit (direct)' 0
+ expect_stat 'cache hit (preprocessed)' 0
+ expect_stat 'cache miss' 1
+ rm -f test.dwo
+
+ $CCACHE_COMPILE -gsplit-dwarf -g1 -c test.c
+ expect_stat 'cache hit (direct)' 1
+ expect_stat 'cache hit (preprocessed)' 0
+ expect_stat 'cache miss' 1
+
+ if [ -f reference.dwo ] && [ ! -f test.dwo ]; then
+ test_failed ".dwo missing"
+ elif [ ! -f reference.dwo ] && [ -f test.dwo ]; then
+ test_failed ".dwo not missing"
+ fi
}