From: Joel Rosdahl Date: Tue, 19 Feb 2019 21:32:14 +0000 (+0100) Subject: Hash CWD when using -gsplit-dwarf X-Git-Tag: v3.7~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1bc408f515dc7e5474ed1ace11ebd231cb59db3;p=thirdparty%2Fccache.git Hash CWD when using -gsplit-dwarf Fixes #356. --- diff --git a/doc/NEWS.adoc b/doc/NEWS.adoc index f724a99e3..0265e5b6a 100644 --- a/doc/NEWS.adoc +++ b/doc/NEWS.adoc @@ -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 ---------- diff --git a/src/ccache.c b/src/ccache.c index 348393544..e972ed1fb 100644 --- a/src/ccache.c +++ b/src/ccache.c @@ -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; diff --git a/test/suites/base.bash b/test/suites/base.bash index 212e148ff..9db521b87 100644 --- a/test/suites/base.bash +++ b/test/suites/base.bash @@ -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" diff --git a/test/suites/debug_prefix_map.bash b/test/suites/debug_prefix_map.bash index d00e65476..e35ce1699 100644 --- a/test/suites/debug_prefix_map.bash +++ b/test/suites/debug_prefix_map.bash @@ -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 }