Re: [PATCH v2 1/2] kbuild: introduce ccflags-remove-y and asflags-remove-y
On Tue, 7 Jul 2020 at 11:21, Masahiro Yamada wrote: > > CFLAGS_REMOVE_.o filters out flags when compiling a particular > object, but there is no convenient way to do that for every object in > a directory. > > Add ccflags-remove-y and asflags-remove-y to make it easily. > > Use ccflags-remove-y to clean up some Makefiles. > > The add/remove order works as follows: > > [1] KBUILD_CFLAGS specifies compiler flags used globally > > [2] ccflags-y adds compiler flags for all objects in the > current Makefile > > [3] ccflags-remove-y removes compiler flags for all objects in the > current Makefile (New feature) > > [4] CFLAGS_ adds compiler flags per file. > > [5] CFLAGS_REMOVE_ removes compiler flags per file. > > Having [3] before [4] allows us to remove flags from most (but not all) > objects in the current Makefile. > > For example, kernel/trace/Makefile removes $(CC_FLAGS_FTRACE) > from all objects in the directory, then adds it back to > trace_selftest_dynamic.o and CFLAGS_trace_kprobe_selftest.o > > Please note ccflags-remove-y has no effect to the sub-directories. > In contrast, the previous notation got rid of compiler flags also from > all the sub-directories. > > arch/arm/boot/compressed/ > arch/powerpc/xmon/ > arch/sh/ > kernel/trace/ > > ... have no sub-directories. > > lib/ > > ... has several sub-directories. > > To keep the behavior, I added ccflags-remove-y to all Makefiles > in subdirectories of lib/, except: > > lib/vdso/Makefile- Kbuild does not descend into this Makefile > lib/raid/test/Makefile - This is not used for the kernel build > > I think commit 2464a609ded0 ("ftrace: do not trace library functions") > excluded too much. In later commit, I will try to remove ccflags-remove-y > from sub-directory Makefiles. > > Suggested-by: Sami Tolvanen > Signed-off-by: Masahiro Yamada > Acked-by: Steven Rostedt (VMware) > Acked-by: Michael Ellerman (powerpc) Tested-by: Anders Roxell > --- > > Changes in v2: > - Swap the order of [3] and [4] to keep the current behavior of > kernel/trace/Makefile. > - Add ccflags-remove-y to subdir Makefiles of lib/ > > Documentation/kbuild/makefiles.rst | 14 ++ > arch/arm/boot/compressed/Makefile | 6 +- > arch/powerpc/xmon/Makefile | 3 +-- > arch/sh/boot/compressed/Makefile | 5 + > kernel/trace/Makefile | 4 ++-- > lib/842/Makefile | 3 +++ > lib/Makefile | 5 + > lib/crypto/Makefile| 2 ++ > lib/dim/Makefile | 2 ++ > lib/fonts/Makefile | 2 ++ > lib/kunit/Makefile | 3 +++ > lib/livepatch/Makefile | 2 ++ > lib/lz4/Makefile | 1 + > lib/lzo/Makefile | 2 ++ > lib/math/Makefile | 2 ++ > lib/mpi/Makefile | 2 ++ > lib/raid6/Makefile | 3 +++ > lib/reed_solomon/Makefile | 2 ++ > lib/xz/Makefile| 3 +++ > lib/zlib_deflate/Makefile | 2 ++ > lib/zlib_dfltcc/Makefile | 2 ++ > lib/zlib_inflate/Makefile | 2 ++ > lib/zstd/Makefile | 1 + > scripts/Makefile.lib | 14 -- > 24 files changed, 64 insertions(+), 23 deletions(-) > > diff --git a/Documentation/kbuild/makefiles.rst > b/Documentation/kbuild/makefiles.rst > index 6515ebc12b6f..14d8e7d23c04 100644 > --- a/Documentation/kbuild/makefiles.rst > +++ b/Documentation/kbuild/makefiles.rst > @@ -368,6 +368,14 @@ more details, with real examples. > > subdir-ccflags-y := -Werror > > +ccflags-remove-y, asflags-remove-y > + These flags are used to remove particular flags for the compiler, > + assembler invocations. > + > + Example:: > + > + ccflags-remove-$(CONFIG_MCOUNT) += -pg > + > CFLAGS_$@, AFLAGS_$@ > CFLAGS_$@ and AFLAGS_$@ only apply to commands in current > kbuild makefile. > @@ -375,6 +383,9 @@ more details, with real examples. > $(CFLAGS_$@) specifies per-file options for $(CC). The $@ > part has a literal value which specifies the file that it is for. > > + CFLAGS_$@ has the higher priority than ccflags-remove-y; CFLAGS_$@ > + can re-add compiler flags that were removed by ccflags-remove-y. > + > Example:: > > # drivers/scsi/Makefile > @@ -387,6 +398,9 @@ more details, with real examples. > $(AFLAGS_$@) is a similar feature for source files in assembly > languages. > > + AFLAGS_$@ has the higher priority than asflags-remove-y; AFLAGS_$@ > + can re-add assembler flags that were removed by asflags-remove-y. > + > Example:: > > # arch/arm/kernel/Makefile > diff --git a/arch/arm/boot/compressed/Makefile > b/arch/arm/boot/compressed/Makefile > index 00602a6fba04..3d5691b23951 100644 > ---
[PATCH v2 1/2] kbuild: introduce ccflags-remove-y and asflags-remove-y
CFLAGS_REMOVE_.o filters out flags when compiling a particular object, but there is no convenient way to do that for every object in a directory. Add ccflags-remove-y and asflags-remove-y to make it easily. Use ccflags-remove-y to clean up some Makefiles. The add/remove order works as follows: [1] KBUILD_CFLAGS specifies compiler flags used globally [2] ccflags-y adds compiler flags for all objects in the current Makefile [3] ccflags-remove-y removes compiler flags for all objects in the current Makefile (New feature) [4] CFLAGS_ adds compiler flags per file. [5] CFLAGS_REMOVE_ removes compiler flags per file. Having [3] before [4] allows us to remove flags from most (but not all) objects in the current Makefile. For example, kernel/trace/Makefile removes $(CC_FLAGS_FTRACE) from all objects in the directory, then adds it back to trace_selftest_dynamic.o and CFLAGS_trace_kprobe_selftest.o Please note ccflags-remove-y has no effect to the sub-directories. In contrast, the previous notation got rid of compiler flags also from all the sub-directories. arch/arm/boot/compressed/ arch/powerpc/xmon/ arch/sh/ kernel/trace/ ... have no sub-directories. lib/ ... has several sub-directories. To keep the behavior, I added ccflags-remove-y to all Makefiles in subdirectories of lib/, except: lib/vdso/Makefile- Kbuild does not descend into this Makefile lib/raid/test/Makefile - This is not used for the kernel build I think commit 2464a609ded0 ("ftrace: do not trace library functions") excluded too much. In later commit, I will try to remove ccflags-remove-y from sub-directory Makefiles. Suggested-by: Sami Tolvanen Signed-off-by: Masahiro Yamada Acked-by: Steven Rostedt (VMware) Acked-by: Michael Ellerman (powerpc) --- Changes in v2: - Swap the order of [3] and [4] to keep the current behavior of kernel/trace/Makefile. - Add ccflags-remove-y to subdir Makefiles of lib/ Documentation/kbuild/makefiles.rst | 14 ++ arch/arm/boot/compressed/Makefile | 6 +- arch/powerpc/xmon/Makefile | 3 +-- arch/sh/boot/compressed/Makefile | 5 + kernel/trace/Makefile | 4 ++-- lib/842/Makefile | 3 +++ lib/Makefile | 5 + lib/crypto/Makefile| 2 ++ lib/dim/Makefile | 2 ++ lib/fonts/Makefile | 2 ++ lib/kunit/Makefile | 3 +++ lib/livepatch/Makefile | 2 ++ lib/lz4/Makefile | 1 + lib/lzo/Makefile | 2 ++ lib/math/Makefile | 2 ++ lib/mpi/Makefile | 2 ++ lib/raid6/Makefile | 3 +++ lib/reed_solomon/Makefile | 2 ++ lib/xz/Makefile| 3 +++ lib/zlib_deflate/Makefile | 2 ++ lib/zlib_dfltcc/Makefile | 2 ++ lib/zlib_inflate/Makefile | 2 ++ lib/zstd/Makefile | 1 + scripts/Makefile.lib | 14 -- 24 files changed, 64 insertions(+), 23 deletions(-) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index 6515ebc12b6f..14d8e7d23c04 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -368,6 +368,14 @@ more details, with real examples. subdir-ccflags-y := -Werror +ccflags-remove-y, asflags-remove-y + These flags are used to remove particular flags for the compiler, + assembler invocations. + + Example:: + + ccflags-remove-$(CONFIG_MCOUNT) += -pg + CFLAGS_$@, AFLAGS_$@ CFLAGS_$@ and AFLAGS_$@ only apply to commands in current kbuild makefile. @@ -375,6 +383,9 @@ more details, with real examples. $(CFLAGS_$@) specifies per-file options for $(CC). The $@ part has a literal value which specifies the file that it is for. + CFLAGS_$@ has the higher priority than ccflags-remove-y; CFLAGS_$@ + can re-add compiler flags that were removed by ccflags-remove-y. + Example:: # drivers/scsi/Makefile @@ -387,6 +398,9 @@ more details, with real examples. $(AFLAGS_$@) is a similar feature for source files in assembly languages. + AFLAGS_$@ has the higher priority than asflags-remove-y; AFLAGS_$@ + can re-add assembler flags that were removed by asflags-remove-y. + Example:: # arch/arm/kernel/Makefile diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile index 00602a6fba04..3d5691b23951 100644 --- a/arch/arm/boot/compressed/Makefile +++ b/arch/arm/boot/compressed/Makefile @@ -103,13 +103,9 @@ clean-files += piggy_data lib1funcs.S ashldi3.S bswapsdi2.S hyp-stub.S KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING -ifeq ($(CONFIG_FUNCTION_TRACER),y) -ORIG_CFLAGS := $(KBUILD_CFLAGS) -KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS)) -endif -