Message ID | 1507802164-31614-3-git-send-email-yamada.masahiro@socionext.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi Masahiro,
[auto build test WARNING on mmarek/for-next]
[also build test WARNING on next-20171013]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Masahiro-Yamada/kbuild-use-relative-path-from-srctree-instead-of-__FILE__/20171015-012234
base: git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild for-next
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=sparc64
All warnings (new ones prefixed by >>):
lib/dynamic_debug.c: In function 'trim_prefix':
>> lib/dynamic_debug.c:71:13: warning: overflow in implicit constant conversion [-Woverflow]
int skip = strlen(__FILE__) - strlen("lib/dynamic_debug.c");
^~~~~~
vim +71 lib/dynamic_debug.c
e9d376f0 Jason Baron 2009-02-05 67
2b678319 Jim Cromie 2011-12-19 68 /* Return the path relative to source root */
2b678319 Jim Cromie 2011-12-19 69 static inline const char *trim_prefix(const char *path)
2b678319 Jim Cromie 2011-12-19 70 {
2b678319 Jim Cromie 2011-12-19 @71 int skip = strlen(__FILE__) - strlen("lib/dynamic_debug.c");
2b678319 Jim Cromie 2011-12-19 72
2b678319 Jim Cromie 2011-12-19 73 if (strncmp(path, __FILE__, skip))
2b678319 Jim Cromie 2011-12-19 74 skip = 0; /* prefix mismatch, don't skip */
2b678319 Jim Cromie 2011-12-19 75
2b678319 Jim Cromie 2011-12-19 76 return path + skip;
2b678319 Jim Cromie 2011-12-19 77 }
2b678319 Jim Cromie 2011-12-19 78
:::::: The code at line 71 was first introduced by commit
:::::: 2b6783191da7211c88f98eb1a2bd2027bff36e30 dynamic_debug: add trim_prefix() to provide source-root relative paths
:::::: TO: Jim Cromie <jim.cromie@gmail.com>
:::::: CC: Greg Kroah-Hartman <gregkh@suse.de>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
diff --git a/Makefile b/Makefile index 2c4a238..a3e8931 100644 --- a/Makefile +++ b/Makefile @@ -1091,6 +1091,15 @@ ifdef stackp-check endif @: +# If possible, redefne __FILE__ as relative path from $(srctree). +# $$ is needed to expand the following in submake +ifeq ($(call cc-option-yn,-Wno-builtin-macro-redefined),y) +KBUILD_CFLAGS += -Wno-builtin-macro-redefined \ + -D__FILE__=$$(call stringify,$$(src)/$$(notdir $$<)) +endif +# CAUTION: Do not add any reference to KBUILD_CFLAGS below this line. +# Any call of cc-option, etc. will fail. + # Generate some files # ---------------------------------------------------------------------------
Since Kbuild runs in the objtree, __FILE__ can be a very long path depending of $(srctree). Commit 9da0763bdd82 ("kbuild: Use relative path when building in a subdir of the source tree") made the situation better for cases where objtree is a child of srctree. ($(srctree) is "..") For other cases of out-of-tree build, filenames in WARN_ON() etc. are still an absolute path. It also means the kernel image depends on where it was built. Here, the idea is to redefine __FILE__ as the relative path from $(srctree), but doing so causes a compiler warning: warning: "__FILE__" redefined [-Wbuiltin-macro-redefined] The option -Wno-builtin-macro-redefined can suppress it, but it is only recognized by GCC 4.4 or newer. Re-define __FILE__ only when possible. Please note __FILE__ is always an absolute path for external modules. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+)