* [PATCH 0/2] kbuild: use relative path from $(srctree) instead of __FILE__
@ 2017-10-12 9:56 Masahiro Yamada
2017-10-12 9:56 ` [PATCH 1/2] kbuild: add stringify helper to quote a string passed to C files Masahiro Yamada
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Masahiro Yamada @ 2017-10-12 9:56 UTC (permalink / raw)
To: linux-kbuild
Cc: Joe Perches, Tom Rini, Geert Uytterhoeven, Masahiro Yamada,
Matthias Kaehlcke, Cao jin, Arnd Bergmann, James Hogan,
linux-kernel, Jan-Simon Möller, Michal Marek,
Douglas Anderson, Josh Poimboeuf, Ingo Molnar, Mark Charlebois
Kbuild works in objtree, not in srctree. So, __FILE__ is prefixed
with $(srctree)/ for out-of-tree build.
For example, WARN_ON() will look as follows if you built your kernel
out of source tree:
WARNING: CPU: 1 PID: 1 at /path/to/build/directory/arch/arm64/kernel/foo.c:...
With this series, it will always look like follows regardless of O= option.
WARNING: CPU: 1 PID: 1 at arch/arm64/kernel/foo.c:...
If GCC does not support -Wno-builtin-macro-redefined (i.e. gcc version < 4.4),
the output is prefixed with absolute path.
Masahiro Yamada (2):
kbuild: add stringify helper to quote a string passed to C files
kbuild: redefine __FILE__ as relative path from $(srctree) if possible
Makefile | 9 +++++++++
scripts/Kbuild.include | 4 ++++
scripts/Makefile.lib | 2 +-
3 files changed, 14 insertions(+), 1 deletion(-)
--
2.7.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] kbuild: add stringify helper to quote a string passed to C files
2017-10-12 9:56 [PATCH 0/2] kbuild: use relative path from $(srctree) instead of __FILE__ Masahiro Yamada
@ 2017-10-12 9:56 ` Masahiro Yamada
2017-10-12 9:56 ` [PATCH 2/2] kbuild: redefine __FILE__ as relative path from $(srctree) if possible Masahiro Yamada
2017-10-14 3:17 ` [PATCH 0/2] kbuild: use relative path from $(srctree) instead of __FILE__ Masahiro Yamada
2 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2017-10-12 9:56 UTC (permalink / raw)
To: linux-kbuild
Cc: Joe Perches, Tom Rini, Geert Uytterhoeven, Masahiro Yamada,
Matthias Kaehlcke, Cao jin, Arnd Bergmann, James Hogan,
linux-kernel, Jan-Simon Möller, Michal Marek,
Douglas Anderson, Josh Poimboeuf, Ingo Molnar, Mark Charlebois
I want to reuse $(squote)$(quote)...$(quote)$(squote) in the next
commit. Move it to a helper.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/Kbuild.include | 4 ++++
scripts/Makefile.lib | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index db81df3..0b97354 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -33,6 +33,10 @@ baseprereq = $(basename $(notdir $<))
escsq = $(subst $(squote),'\$(squote)',$1)
###
+# Quote a string to pass it to C files. foo => '"foo"'
+stringify = $(squote)$(quote)$1$(quote)$(squote)
+
+###
# Easy method for doing a status message
kecho := :
quiet_kecho := echo
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 580e605..9bbb019 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -89,7 +89,7 @@ obj-dirs := $(addprefix $(obj)/,$(obj-dirs))
# Note: Files that end up in two or more modules are compiled without the
# KBUILD_MODNAME definition. The reason is that any made-up name would
# differ in different configs.
-name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
+name-fix = $(call stringify,$(subst $(comma),_,$(subst -,_,$1)))
basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
modname_flags = $(if $(filter 1,$(words $(modname))),\
-DKBUILD_MODNAME=$(call name-fix,$(modname)))
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] kbuild: redefine __FILE__ as relative path from $(srctree) if possible
2017-10-12 9:56 [PATCH 0/2] kbuild: use relative path from $(srctree) instead of __FILE__ Masahiro Yamada
2017-10-12 9:56 ` [PATCH 1/2] kbuild: add stringify helper to quote a string passed to C files Masahiro Yamada
@ 2017-10-12 9:56 ` Masahiro Yamada
2017-10-14 20:15 ` kbuild test robot
2017-10-14 3:17 ` [PATCH 0/2] kbuild: use relative path from $(srctree) instead of __FILE__ Masahiro Yamada
2 siblings, 1 reply; 5+ messages in thread
From: Masahiro Yamada @ 2017-10-12 9:56 UTC (permalink / raw)
To: linux-kbuild
Cc: Joe Perches, Tom Rini, Geert Uytterhoeven, Masahiro Yamada,
Michal Marek, linux-kernel
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(+)
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
# ---------------------------------------------------------------------------
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] kbuild: use relative path from $(srctree) instead of __FILE__
2017-10-12 9:56 [PATCH 0/2] kbuild: use relative path from $(srctree) instead of __FILE__ Masahiro Yamada
2017-10-12 9:56 ` [PATCH 1/2] kbuild: add stringify helper to quote a string passed to C files Masahiro Yamada
2017-10-12 9:56 ` [PATCH 2/2] kbuild: redefine __FILE__ as relative path from $(srctree) if possible Masahiro Yamada
@ 2017-10-14 3:17 ` Masahiro Yamada
2 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2017-10-14 3:17 UTC (permalink / raw)
To: Linux Kbuild mailing list
Cc: Joe Perches, Tom Rini, Geert Uytterhoeven, Masahiro Yamada,
Matthias Kaehlcke, Cao jin, Arnd Bergmann, James Hogan,
Linux Kernel Mailing List, Jan-Simon Möller, Michal Marek,
Douglas Anderson, Josh Poimboeuf, Ingo Molnar, Mark Charlebois
2017-10-12 18:56 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
>
> Kbuild works in objtree, not in srctree. So, __FILE__ is prefixed
> with $(srctree)/ for out-of-tree build.
>
> For example, WARN_ON() will look as follows if you built your kernel
> out of source tree:
>
> WARNING: CPU: 1 PID: 1 at /path/to/build/directory/arch/arm64/kernel/foo.c:...
>
> With this series, it will always look like follows regardless of O= option.
>
> WARNING: CPU: 1 PID: 1 at arch/arm64/kernel/foo.c:...
>
> If GCC does not support -Wno-builtin-macro-redefined (i.e. gcc version < 4.4),
> the output is prefixed with absolute path.
>
I expect to replace __FILE__ with its relative path,
but actually it replaces __FILE__ with relative path of __BASE_FILE__.
This will change the behavior in several places.
I take back this series.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] kbuild: redefine __FILE__ as relative path from $(srctree) if possible
2017-10-12 9:56 ` [PATCH 2/2] kbuild: redefine __FILE__ as relative path from $(srctree) if possible Masahiro Yamada
@ 2017-10-14 20:15 ` kbuild test robot
0 siblings, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2017-10-14 20:15 UTC (permalink / raw)
To: Masahiro Yamada
Cc: kbuild-all, linux-kbuild, Joe Perches, Tom Rini,
Geert Uytterhoeven, Michal Marek, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2229 bytes --]
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
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 48210 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-10-14 20:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-12 9:56 [PATCH 0/2] kbuild: use relative path from $(srctree) instead of __FILE__ Masahiro Yamada
2017-10-12 9:56 ` [PATCH 1/2] kbuild: add stringify helper to quote a string passed to C files Masahiro Yamada
2017-10-12 9:56 ` [PATCH 2/2] kbuild: redefine __FILE__ as relative path from $(srctree) if possible Masahiro Yamada
2017-10-14 20:15 ` kbuild test robot
2017-10-14 3:17 ` [PATCH 0/2] kbuild: use relative path from $(srctree) instead of __FILE__ Masahiro Yamada
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).