All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/3] kbuild: always use relative path for __FILE__
@ 2017-10-13  9:12 Masahiro Yamada
  2017-10-13  9:12 ` [U-Boot] [PATCH 1/3] kbuild: Get rid of KBUILD_STR Masahiro Yamada
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Masahiro Yamada @ 2017-10-13  9:12 UTC (permalink / raw
  To: u-boot


We discussed the __FILE__ problem when U-Boot is built out of tree.
https://www.mail-archive.com/u-boot at lists.denx.de/msg242852.html

The deeper your build directory is located, the larger
your U-Boot image becomes.
If your platform has memory footprint limit, this is a problem.

Recently, I submitted the following patches to Kbuild ML.
(no RFC, this time)
https://patchwork.kernel.org/patch/10001419/
https://patchwork.kernel.org/patch/10001409/

I consider them for Linux 4.15 unless there is
a strong objection or a problem report.

This series is a port for U-Boot.

If Tom wants to pick this up earlier, it is OK.
If not in hurry, you can wait for the activity in Linux.
Either will do.



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

Michal Marek (1):
  kbuild: Get rid of KBUILD_STR

 Makefile               | 9 +++++++++
 scripts/Kbuild.include | 4 ++++
 scripts/Makefile.lib   | 8 ++++----
 3 files changed, 17 insertions(+), 4 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH 1/3] kbuild: Get rid of KBUILD_STR
  2017-10-13  9:12 [U-Boot] [PATCH 0/3] kbuild: always use relative path for __FILE__ Masahiro Yamada
@ 2017-10-13  9:12 ` Masahiro Yamada
  2017-10-13  9:12 ` [U-Boot] [PATCH 2/3] kbuild: add stringify helper to quote a string passed to C files Masahiro Yamada
  2017-10-13  9:12 ` [U-Boot] [PATCH 3/3] kbuild: redefine __FILE__ as relative path from $(srctree) if possible Masahiro Yamada
  2 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2017-10-13  9:12 UTC (permalink / raw
  To: u-boot

From: Michal Marek <mmarek@suse.com>

The compiler can accept -DKBUILD_MODNAME="foo", it's just a matter of
quoting. That way, we reduce the gcc command line a bit.

Signed-off-by: Michal Marek <mmarek@suse.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

[ Linux commit: b42841b7bb6286da56b4fa79835c27166b7e228b ]
---

 scripts/Makefile.lib | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 0d5c529..8934b2f 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -99,10 +99,10 @@ 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 = $(subst $(comma),_,$(subst -,_,$1))
-basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))"
+name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
+basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
 modname_flags  = $(if $(filter 1,$(words $(modname))),\
-                 -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
+                 -DKBUILD_MODNAME=$(call name-fix,$(modname)))
 
 orig_c_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \
                  $(ccflags-y) $(CFLAGS_$(basetarget).o)
@@ -154,7 +154,7 @@ endif
 # Modified for U-Boot: LINUXINCLUDE -> UBOOTINCLUDE
 c_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE)     \
 		 $(__c_flags) $(modkern_cflags)                           \
-		 -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags)
+		 $(basename_flags) $(modname_flags)
 
 a_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE)     \
 		 $(__a_flags) $(modkern_aflags)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH 2/3] kbuild: add stringify helper to quote a string passed to C files
  2017-10-13  9:12 [U-Boot] [PATCH 0/3] kbuild: always use relative path for __FILE__ Masahiro Yamada
  2017-10-13  9:12 ` [U-Boot] [PATCH 1/3] kbuild: Get rid of KBUILD_STR Masahiro Yamada
@ 2017-10-13  9:12 ` Masahiro Yamada
  2017-10-13  9:12 ` [U-Boot] [PATCH 3/3] kbuild: redefine __FILE__ as relative path from $(srctree) if possible Masahiro Yamada
  2 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2017-10-13  9:12 UTC (permalink / raw
  To: u-boot

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 2c7918a..48a641c 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -30,6 +30,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 8934b2f..bd0977e 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -99,7 +99,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] 4+ messages in thread

* [U-Boot] [PATCH 3/3] kbuild: redefine __FILE__ as relative path from $(srctree) if possible
  2017-10-13  9:12 [U-Boot] [PATCH 0/3] kbuild: always use relative path for __FILE__ Masahiro Yamada
  2017-10-13  9:12 ` [U-Boot] [PATCH 1/3] kbuild: Get rid of KBUILD_STR Masahiro Yamada
  2017-10-13  9:12 ` [U-Boot] [PATCH 2/3] kbuild: add stringify helper to quote a string passed to C files Masahiro Yamada
@ 2017-10-13  9:12 ` Masahiro Yamada
  2 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2017-10-13  9:12 UTC (permalink / raw
  To: u-boot

Since Kbuild runs in the objtree, __FILE__ can be a very long path
depending of $(srctree).

If objtree is a child of srctree, the situation is a bit better.
($(srctree) is "..")

For other cases of out-of-tree build, filenames in WARN_ON() etc. are
still an absolute path.  It also means the U-Boot 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.  Redefine __FILE__ only when
possible.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Makefile b/Makefile
index 888486b..ab7775d 100644
--- a/Makefile
+++ b/Makefile
@@ -1334,6 +1334,15 @@ prepare0: archprepare FORCE
 # All the preparing..
 prepare: prepare0
 
+# 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] 4+ messages in thread

end of thread, other threads:[~2017-10-13  9:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-13  9:12 [U-Boot] [PATCH 0/3] kbuild: always use relative path for __FILE__ Masahiro Yamada
2017-10-13  9:12 ` [U-Boot] [PATCH 1/3] kbuild: Get rid of KBUILD_STR Masahiro Yamada
2017-10-13  9:12 ` [U-Boot] [PATCH 2/3] kbuild: add stringify helper to quote a string passed to C files Masahiro Yamada
2017-10-13  9:12 ` [U-Boot] [PATCH 3/3] kbuild: redefine __FILE__ as relative path from $(srctree) if possible Masahiro Yamada

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.