]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Hash CWD when using -gsplit-dwarf
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 19 Feb 2019 21:32:14 +0000 (22:32 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 19 Feb 2019 21:32:14 +0000 (22:32 +0100)
Fixes #356.

doc/NEWS.adoc
src/ccache.c
test/suites/base.bash
test/suites/debug_prefix_map.bash

index f724a99e3750d1dede07a6e55396b127969d265c..0265e5b6a12df22890046db2168710c9cf0c245d 100644 (file)
@@ -13,6 +13,10 @@ Changes
 
 * Fixed an issue when printing very large log messages to the debug log.
 
+* Fixed a bug where ccache did not turn on `hash_dir` correctly when using
+  `-gsplit-dwarf`, leading to potentially incorrect file links in debug
+  information when compiling in different directories.
+
 
 ccache 3.6
 ----------
index 34839354404fbabaddc030dbf1161a918756bb9d..e972ed1fb7ce444f4898d80b653ace1eb96e298d 100644 (file)
@@ -2604,12 +2604,6 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
                        continue;
                }
 
-               if (str_eq(argv[i], "-gsplit-dwarf")) {
-                       cc_log("Enabling caching of dwarf files since -gsplit-dwarf is used");
-                       using_split_dwarf = true;
-                       args_add(stripped_args, argv[i]);
-                       continue;
-               }
                if (str_startswith(argv[i], "-fdebug-prefix-map=")
                    || str_startswith(argv[i], "-ffile-prefix-map=")) {
                        debug_prefix_maps = x_realloc(
@@ -2626,6 +2620,9 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
                if (str_startswith(argv[i], "-g")) {
                        generating_debuginfo = true;
                        args_add(stripped_args, argv[i]);
+                       if (str_eq(argv[i], "-gsplit-dwarf")) {
+                               using_split_dwarf = true;
+                       }
                        if (conf->unify && !str_eq(argv[i], "-g0")) {
                                cc_log("%s used; disabling unify mode", argv[i]);
                                conf->unify = false;
index 212e148ff2b821e1d0218435fbeddae2c8777dc9..9db521b87d14cdbe24e389a21d0ab538b11f6498 100644 (file)
@@ -274,6 +274,31 @@ base_tests() {
     expect_stat 'cache hit (preprocessed)' 2
     expect_stat 'cache miss' 1
 
+    # -------------------------------------------------------------------------
+    TEST "Directory is hashed if using -gsplit-dwarf"
+
+    mkdir dir1 dir2
+    cp test1.c dir1
+    cp test1.c dir2
+
+    export CCACHE_DEBUG=1
+
+    cd dir1
+    $CCACHE_COMPILE -c test1.c -gsplit-dwarf
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    $CCACHE_COMPILE -c test1.c -gsplit-dwarf
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 1
+
+    cd ../dir2
+    $CCACHE_COMPILE -c test1.c -gsplit-dwarf
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 2
+    $CCACHE_COMPILE -c test1.c -gsplit-dwarf
+    expect_stat 'cache hit (preprocessed)' 2
+    expect_stat 'cache miss' 2
+
     # -------------------------------------------------------------------------
     TEST "CCACHE_NOHASHDIR"
 
index d00e654767c14b233a4cb53632af21d4fac9a7bd..e35ce16992d233ebb61a9e39f6d450eed103f2fc 100644 (file)
@@ -87,4 +87,27 @@ SUITE_debug_prefix_map() {
     if objdump_cmd test.o | grep_cmd "`pwd`" >/dev/null 2>&1; then
         test_failed "Source dir (`pwd`) found in test.o"
     fi
+
+    # -------------------------------------------------------------------------
+    TEST "-fdebug-prefix-map and -gsplit-dwarf"
+
+    cd dir1
+    CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`/include -gsplit-dwarf -fdebug-prefix-map=`pwd`=dir -c `pwd`/src/test.c -o `pwd`/test.o
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 3
+    if objdump_cmd test.o | grep_cmd "`pwd`" >/dev/null 2>&1; then
+        test_failed "Source dir (`pwd`) found in test.o"
+    fi
+
+    cd ../dir2
+    CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`/include -gsplit-dwarf -fdebug-prefix-map=`pwd`=dir -c `pwd`/src/test.c -o `pwd`/test.o
+    expect_stat 'cache hit (direct)' 1
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 3
+    if objdump_cmd test.o | grep_cmd "`pwd`" >/dev/null 2>&1; then
+        test_failed "Source dir (`pwd`) found in test.o"
+    fi
 }