Skip to contentSkip to conversation

kbuild: introduce ccflags-remove-y and asflags-remove-y

PATCH In review Masahiro Yamada 5 participants 10 messages Jul 7, 2020 – Jul 22, 2020

Subsystems (17)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 kbuild: introduce ccflags-remove-y and asflags-remove-y

CFLAGS_REMOVE_<file>.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_<file> adds compiler flags per file.

[5] CFLAGS_REMOVE_<file> 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.

---

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(-)
Documentation/kbuild/makefiles.rst +14 -0
index 6515ebc12b6f..14d8e7d23c04 100644
@@ -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
arch/arm/boot/compressed/Makefile +1 -5
index 00602a6fba04..3d5691b23951 100644
@@ -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
-
 ccflags-y := -fpic $(call cc-option,-mno-single-pic-base,) -fno-builtin \
 	     -I$(obj) $(DISABLE_ARM_SSP_PER_TASK_PLUGIN)
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += -pg
 asflags-y := -DZIMAGE
 
 # Supply kernel BSS size to the decompressor via a linker symbol.
arch/powerpc/xmon/Makefile +1 -2
index 89c76ca35640..eb25d7554ffd 100644
@@ -7,8 +7,7 @@ UBSAN_SANITIZE := n
 KASAN_SANITIZE := n
 
 # Disable ftrace for the entire directory
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
 
 ifdef CONFIG_CC_IS_CLANG
 # clang stores addresses on the stack causing the frame size to blow
arch/sh/boot/compressed/Makefile +1 -4
index ad0e2403e56f..589d2d8a573d 100644
@@ -28,10 +28,7 @@ IMAGE_OFFSET	:= $(shell /bin/bash -c 'printf "0x%08x" \
 			$(CONFIG_BOOT_LINK_OFFSET)]')
 endif
 
-ifeq ($(CONFIG_MCOUNT),y)
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
-endif
+ccflags-remove-$(CONFIG_MCOUNT) += -pg
 
 LDFLAGS_vmlinux := --oformat $(ld-bfd) -Ttext $(IMAGE_OFFSET) -e startup \
 		   -T $(obj)/../../kernel/vmlinux.lds
kernel/trace/Makefile +2 -2
index 6575bb0a0434..7492844a8b1b 100644
@@ -2,9 +2,9 @@
 
 # Do not instrument the tracer itself:
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 ifdef CONFIG_FUNCTION_TRACER
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
 
 # Avoid recursion due to instrumentation.
 KCSAN_SANITIZE := n
lib/842/Makefile +3 -0
index 6f7aad269288..b815e824ae37 100644
@@ -1,3 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
+
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_842_COMPRESS) += 842_compress.o
 obj-$(CONFIG_842_DECOMPRESS) += 842_decompress.o
lib/Makefile +1 -4
index b1c42c10073b..b2ed4beddd68 100644
@@ -3,10 +3,7 @@
 # Makefile for some libs needed in the kernel.
 #
 
-ifdef CONFIG_FUNCTION_TRACER
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
-endif
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
 
 # These files are disabled because they produce lots of non-interesting and/or
 # flaky coverage that is not a function of syscall inputs. For example,
lib/crypto/Makefile +2 -0
index 3a435629d9ce..b557ef0b07c2 100644
@@ -1,5 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 # chacha is used by the /dev/random driver which is always builtin
 obj-y						+= chacha.o
 obj-$(CONFIG_CRYPTO_LIB_CHACHA_GENERIC)		+= libchacha.o
lib/dim/Makefile +2 -0
index 1d6858a108cb..97fc3e89d34e 100644
@@ -2,6 +2,8 @@
 # DIM Dynamic Interrupt Moderation library
 #
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_DIMLIB) += dim.o
 
 dim-y := dim.o net_dim.o rdma_dim.o
lib/fonts/Makefile +2 -0
index ed95070860de..f951750c179e 100644
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 # Font handling
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 font-objs := fonts.o
 
 font-objs-$(CONFIG_FONT_SUN8x16)   += font_sun8x16.o
lib/kunit/Makefile +3 -0
index 724b94311ca3..8c847557ab24 100644
@@ -1,3 +1,6 @@
+
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_KUNIT) +=			kunit.o
 
 kunit-objs +=				test.o \
lib/livepatch/Makefile +2 -0
index 295b94bff370..9abdf615b088 100644
@@ -2,6 +2,8 @@
 #
 # Makefile for livepatch test code.
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_TEST_LIVEPATCH) += test_klp_atomic_replace.o \
 				test_klp_callbacks_demo.o \
 				test_klp_callbacks_demo2.o \
lib/lz4/Makefile +1 -0
index 5b42242afaa2..53da4cab7015 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 ccflags-y += -O3
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
 
 obj-$(CONFIG_LZ4_COMPRESS) += lz4_compress.o
 obj-$(CONFIG_LZ4HC_COMPRESS) += lz4hc_compress.o
lib/lzo/Makefile +2 -0
index 2f58fafbbddd..9565a555275b 100644
@@ -1,4 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 lzo_compress-objs := lzo1x_compress.o
 lzo_decompress-objs := lzo1x_decompress_safe.o
 
lib/math/Makefile +2 -0
index be6909e943bd..49aa50e28185 100644
@@ -1,4 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-y += div64.o gcd.o lcm.o int_pow.o int_sqrt.o reciprocal_div.o
 
 obj-$(CONFIG_CORDIC)		+= cordic.o
lib/mpi/Makefile +2 -0
index d5874a7f5ff9..df7883521619 100644
@@ -3,6 +3,8 @@
 # MPI multiprecision maths library (from gpg)
 #
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_MPILIB) = mpi.o
 
 mpi-y = \
lib/raid6/Makefile +3 -0
index b4c0df6d706d..3482d6ae3f3b 100644
@@ -1,4 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
+
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_RAID6_PQ)	+= raid6_pq.o
 
 raid6_pq-y	+= algos.o recov.o tables.o int1.o int2.o int4.o \
lib/reed_solomon/Makefile +2 -0
index 5d4fa68f26cb..a5c9defdac7f 100644
@@ -3,5 +3,7 @@
 # This is a modified version of reed solomon lib,
 #
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_REED_SOLOMON) += reed_solomon.o
 obj-$(CONFIG_REED_SOLOMON_TEST) += test_rslib.o
lib/xz/Makefile +3 -0
index fa6af814a8d1..fae9b6c7c389 100644
@@ -1,4 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
+
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_XZ_DEC) += xz_dec.o
 xz_dec-y := xz_dec_syms.o xz_dec_stream.o xz_dec_lzma2.o
 xz_dec-$(CONFIG_XZ_DEC_BCJ) += xz_dec_bcj.o
lib/zlib_deflate/Makefile +2 -0
index 2622e03c0b94..1fcefe73536f 100644
@@ -7,6 +7,8 @@
 # decompression code.
 #
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate.o
 
 zlib_deflate-objs := deflate.o deftree.o deflate_syms.o
lib/zlib_dfltcc/Makefile +2 -0
index 8e4d5afbbb10..7a8067f6e772 100644
@@ -6,6 +6,8 @@
 # This is the code for s390 zlib hardware support.
 #
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_ZLIB_DFLTCC) += zlib_dfltcc.o
 
 zlib_dfltcc-objs := dfltcc.o dfltcc_deflate.o dfltcc_inflate.o dfltcc_syms.o
lib/zlib_inflate/Makefile +2 -0
index 27327d3e9f54..a451e96f9845 100644
@@ -14,6 +14,8 @@
 # uncompression can be done without blocking on allocation).
 #
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate.o
 
 zlib_inflate-objs := inffast.o inflate.o infutil.o \
lib/zstd/Makefile +1 -0
index f5d778e7e5c7..01be908a2d94 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o
 obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o
 
 ccflags-y += -O3
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
 
 zstd_compress-y := fse_compress.o huf_compress.o compress.o \
 		   entropy_common.o fse_decompress.o zstd_common.o
scripts/Makefile.lib +8 -6
index 916b2f7f7098..3629f66646d7 100644
@@ -111,12 +111,14 @@ basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
 modname_flags  = -DKBUILD_MODNAME=$(call name-fix,$(modname))
 modfile_flags  = -DKBUILD_MODFILE=$(call stringify,$(modfile))
 
-orig_c_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
-                 $(ccflags-y) $(CFLAGS_$(target-stem).o)
-_c_flags       = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), $(orig_c_flags))
-orig_a_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \
-                 $(asflags-y) $(AFLAGS_$(target-stem).o)
-_a_flags       = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), $(orig_a_flags))
+_c_flags       = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
+                     $(filter-out $(ccflags-remove-y), \
+                         $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \
+                     $(CFLAGS_$(target-stem).o))
+_a_flags       = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \
+                     $(filter-out $(asflags-remove-y), \
+                         $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \
+                     $(AFLAGS_$(target-stem).o))
 _cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
 
 #
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 2/2 kbuild: trace functions in subdirectories of lib/

  ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)

exists here in sub-directories of lib/ to keep the behavior of commit 2464a609ded0 ("ftrace: do not trace library functions").

Since that commit, not only the objects in lib/ but also the ones in the sub-directories are excluded from ftrace (although the commit description did not explicitly mention this).

However, most of library functions in sub-directories are not so hot. Re-add them to ftrace.

Going forward, only the objects right under lib/ will be excluded.

---

Changes in v2:
- New patch

 lib/842/Makefile          | 3 ---
 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 -
 17 files changed, 36 deletions(-)
lib/842/Makefile +0 -3
index b815e824ae37..6f7aad269288 100644
@@ -1,6 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0-only
-
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-$(CONFIG_842_COMPRESS) += 842_compress.o
 obj-$(CONFIG_842_DECOMPRESS) += 842_decompress.o
lib/crypto/Makefile +0 -2
index b557ef0b07c2..3a435629d9ce 100644
@@ -1,7 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 # chacha is used by the /dev/random driver which is always builtin
 obj-y						+= chacha.o
 obj-$(CONFIG_CRYPTO_LIB_CHACHA_GENERIC)		+= libchacha.o
lib/dim/Makefile +0 -2
index 97fc3e89d34e..1d6858a108cb 100644
@@ -2,8 +2,6 @@
 # DIM Dynamic Interrupt Moderation library
 #
 
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-$(CONFIG_DIMLIB) += dim.o
 
 dim-y := dim.o net_dim.o rdma_dim.o
lib/fonts/Makefile +0 -2
index f951750c179e..ed95070860de 100644
@@ -1,8 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 # Font handling
 
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 font-objs := fonts.o
 
 font-objs-$(CONFIG_FONT_SUN8x16)   += font_sun8x16.o
lib/kunit/Makefile +0 -3
index 8c847557ab24..724b94311ca3 100644
@@ -1,6 +1,3 @@
-
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-$(CONFIG_KUNIT) +=			kunit.o
 
 kunit-objs +=				test.o \
lib/livepatch/Makefile +0 -2
index 9abdf615b088..295b94bff370 100644
@@ -2,8 +2,6 @@
 #
 # Makefile for livepatch test code.
 
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-$(CONFIG_TEST_LIVEPATCH) += test_klp_atomic_replace.o \
 				test_klp_callbacks_demo.o \
 				test_klp_callbacks_demo2.o \
lib/lz4/Makefile +0 -1
index 53da4cab7015..5b42242afaa2 100644
@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 ccflags-y += -O3
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
 
 obj-$(CONFIG_LZ4_COMPRESS) += lz4_compress.o
 obj-$(CONFIG_LZ4HC_COMPRESS) += lz4hc_compress.o
lib/lzo/Makefile +0 -2
index 9565a555275b..2f58fafbbddd 100644
@@ -1,6 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 lzo_compress-objs := lzo1x_compress.o
 lzo_decompress-objs := lzo1x_decompress_safe.o
 
lib/math/Makefile +0 -2
index 49aa50e28185..be6909e943bd 100644
@@ -1,6 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-y += div64.o gcd.o lcm.o int_pow.o int_sqrt.o reciprocal_div.o
 
 obj-$(CONFIG_CORDIC)		+= cordic.o
lib/mpi/Makefile +0 -2
index df7883521619..d5874a7f5ff9 100644
@@ -3,8 +3,6 @@
 # MPI multiprecision maths library (from gpg)
 #
 
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-$(CONFIG_MPILIB) = mpi.o
 
 mpi-y = \
lib/raid6/Makefile +0 -3
index 3482d6ae3f3b..b4c0df6d706d 100644
@@ -1,7 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
-
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-$(CONFIG_RAID6_PQ)	+= raid6_pq.o
 
 raid6_pq-y	+= algos.o recov.o tables.o int1.o int2.o int4.o \
lib/reed_solomon/Makefile +0 -2
index a5c9defdac7f..5d4fa68f26cb 100644
@@ -3,7 +3,5 @@
 # This is a modified version of reed solomon lib,
 #
 
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-$(CONFIG_REED_SOLOMON) += reed_solomon.o
 obj-$(CONFIG_REED_SOLOMON_TEST) += test_rslib.o
lib/xz/Makefile +0 -3
index fae9b6c7c389..fa6af814a8d1 100644
@@ -1,7 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
-
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-$(CONFIG_XZ_DEC) += xz_dec.o
 xz_dec-y := xz_dec_syms.o xz_dec_stream.o xz_dec_lzma2.o
 xz_dec-$(CONFIG_XZ_DEC_BCJ) += xz_dec_bcj.o
lib/zlib_deflate/Makefile +0 -2
index 1fcefe73536f..2622e03c0b94 100644
@@ -7,8 +7,6 @@
 # decompression code.
 #
 
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate.o
 
 zlib_deflate-objs := deflate.o deftree.o deflate_syms.o
lib/zlib_dfltcc/Makefile +0 -2
index 7a8067f6e772..8e4d5afbbb10 100644
@@ -6,8 +6,6 @@
 # This is the code for s390 zlib hardware support.
 #
 
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-$(CONFIG_ZLIB_DFLTCC) += zlib_dfltcc.o
 
 zlib_dfltcc-objs := dfltcc.o dfltcc_deflate.o dfltcc_inflate.o dfltcc_syms.o
lib/zlib_inflate/Makefile +0 -2
index a451e96f9845..27327d3e9f54 100644
@@ -14,8 +14,6 @@
 # uncompression can be done without blocking on allocation).
 #
 
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate.o
 
 zlib_inflate-objs := inffast.o inflate.o infutil.o \
lib/zstd/Makefile +0 -1
index 01be908a2d94..f5d778e7e5c7 100644
@@ -3,7 +3,6 @@ obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o
 obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o
 
 ccflags-y += -O3
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
 
 zstd_compress-y := fse_compress.o huf_compress.o compress.o \
 		   entropy_common.o fse_decompress.o zstd_common.o
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH v2 2/2] kbuild: trace functions in subdirectories of lib/

Quoted 11 lines · On Tue, 7 Jul 2020 18:21:17 +0900 Masahiro Yamada <[email protected]> wrote:
  ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)

exists here in sub-directories of lib/ to keep the behavior of commit 2464a609ded0 ("ftrace: do not trace library functions").

Since that commit, not only the objects in lib/ but also the ones in the sub-directories are excluded from ftrace (although the commit description did not explicitly mention this).

However, most of library functions in sub-directories are not so hot. Re-add them to ftrace.

I'm OK with this change, but note, it wasn't just the hot path that I disabled ftrace on lib for, but some of these calls are done very early at boot up. It may have been PowerPC that I was stumbling over. The issue is that they would call mcount before the kernel was mapped properly, and the system would crash.

My PowerPC box no longer boots so I can't test this anymore. But a lot has changed since 2008, and all this may very well be OK.

-- Steve

#3 lore raw

Re: [PATCH v2 2/2] kbuild: trace functions in subdirectories of lib/

Quoted 22 lines · Steven Rostedt
Quoted 11 lines · On Tue, 7 Jul 2020 18:21:17 +0900 Masahiro Yamada <[email protected]> wrote:
  ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)

exists here in sub-directories of lib/ to keep the behavior of commit 2464a609ded0 ("ftrace: do not trace library functions").

Since that commit, not only the objects in lib/ but also the ones in the sub-directories are excluded from ftrace (although the commit description did not explicitly mention this).

However, most of library functions in sub-directories are not so hot. Re-add them to ftrace.

I'm OK with this change, but note, it wasn't just the hot path that I disabled ftrace on lib for, but some of these calls are done very early at boot up. It may have been PowerPC that I was stumbling over. The issue is that they would call mcount before the kernel was mapped properly, and the system would crash.

Quoted 4 lines

My PowerPC box no longer boots so I can't test this anymore. But a lot has changed since 2008, and all this may very well be OK.

-- Steve

That's why I split this into two commits
so that we can do git-bisect and
revert the second one in case of a regression.

Anyway, we have some more time to test this in linux-next (and somebody reports an issue, if any).

Signature · 2 lines
Best Regards
Masahiro Yamada
maintainer Acked-by
#4 lore raw

Re: [PATCH v2 2/2] kbuild: trace functions in subdirectories of lib/

Quoted 7 lines · On Wed, 22 Jul 2020 11:08:51 +0900 Masahiro Yamada <[email protected]> wrote:

That's why I split this into two commits
so that we can do git-bisect and
revert the second one in case of a regression.

Anyway, we have some more time to test this in linux-next (and somebody reports an issue, if any).

You can add my

and take it through your tree.

-- Steve

maintainer
#5 lore raw

Re: [PATCH v2 2/2] kbuild: trace functions in subdirectories of lib/

In reply to Masahiro Yamada
Quoted 19 lines · Masahiro Yamada
  ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)

exists here in sub-directories of lib/ to keep the behavior of commit 2464a609ded0 ("ftrace: do not trace library functions").

Since that commit, not only the objects in lib/ but also the ones in the sub-directories are excluded from ftrace (although the commit description did not explicitly mention this).

However, most of library functions in sub-directories are not so hot. Re-add them to ftrace.

Going forward, only the objects right under lib/ will be excluded.

lib/livepatch/Makefile +0 -0
index 9abdf615b088..295b94bff370 100644

lib/livepatch/Makefile line 7

Quoted 8 lines
lib/livepatch/Makefile +0 -2
@@ -2,8 +2,6 @@
 #
 # Makefile for livepatch test code.
 
-ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
-
 obj-$(CONFIG_TEST_LIVEPATCH) += test_klp_atomic_replace.o \
 				test_klp_callbacks_demo.o \
 				test_klp_callbacks_demo2.o \

With this change it might be possible to remove also the last few lines that explicitly added $(CC_FLAGS_FTRACE) for two test modules.

The two modules really needed these flags. But they are fine also for the other modules.

We could do this later as a followup patch but it would be nice to do so here.

Best Regards,
Petr

PS: BTW: The livepatch selftests fail in Linus's master now. But it seems to be for another reason. I am going to dig into it.

maintainer
#6 lore raw

Re: [PATCH v2 2/2] kbuild: trace functions in subdirectories of lib/

Quoted 3 lines · Petr Mladek

PS: BTW: The livepatch selftests fail in Linus's master now. But it seems to be for another reason. I am going to dig into it.

JFYI, the livepatch selftests are actually working. I have messed the testing here. I am sorry for the noise.

Best Regards,
Petr

#7 lore raw

Re: [PATCH v2 2/2] kbuild: trace functions in subdirectories of lib/

Quoted 11 lines · Petr Mladek
Quoted 3 lines · Petr Mladek

PS: BTW: The livepatch selftests fail in Linus's master now. But it seems to be for another reason. I am going to dig into it.

JFYI, the livepatch selftests are actually working. I have messed the testing here. I am sorry for the noise.

Best Regards,
Petr

No worry, thank you for testing this patch.

I deleted the following two lines, otherwise $(CC_FLAGS_FTRACE) would be added twice.

# Target modules to be livepatched require CC_FLAGS_FTRACE
CFLAGS_test_klp_callbacks_busy.o += $(CC_FLAGS_FTRACE)
CFLAGS_test_klp_callbacks_mod.o += $(CC_FLAGS_FTRACE)

Signature · 2 lines
Best Regards
Masahiro Yamada
Acked-by on v2 1/2
#8 lore raw
In reply to Masahiro Yamada
Quoted 51 lines · Masahiro Yamada

CFLAGS_REMOVE_<file>.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_<file> adds compiler flags per file.

[5] CFLAGS_REMOVE_<file> 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

Quoted 8 lines

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.

Tested-by on v2 1/2
#9 lore raw
In reply to Masahiro Yamada
Quoted 51 lines · Masahiro Yamada

CFLAGS_REMOVE_<file>.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_<file> adds compiler flags per file.

[5] CFLAGS_REMOVE_<file> 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

Quoted 8 lines

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.

Quoted 387 lines

---

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(-)
Documentation/kbuild/makefiles.rst +14 -0
index 6515ebc12b6f..14d8e7d23c04 100644
@@ -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
arch/arm/boot/compressed/Makefile +1 -5
index 00602a6fba04..3d5691b23951 100644
@@ -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
-
 ccflags-y := -fpic $(call cc-option,-mno-single-pic-base,) -fno-builtin \
             -I$(obj) $(DISABLE_ARM_SSP_PER_TASK_PLUGIN)
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += -pg
 asflags-y := -DZIMAGE
 
 # Supply kernel BSS size to the decompressor via a linker symbol.
arch/powerpc/xmon/Makefile +1 -2
index 89c76ca35640..eb25d7554ffd 100644
@@ -7,8 +7,7 @@ UBSAN_SANITIZE := n
 KASAN_SANITIZE := n
 
 # Disable ftrace for the entire directory
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
 
 ifdef CONFIG_CC_IS_CLANG
 # clang stores addresses on the stack causing the frame size to blow
arch/sh/boot/compressed/Makefile +1 -4
index ad0e2403e56f..589d2d8a573d 100644
@@ -28,10 +28,7 @@ IMAGE_OFFSET := $(shell /bin/bash -c 'printf "0x%08x" \
                        $(CONFIG_BOOT_LINK_OFFSET)]')
 endif
 
-ifeq ($(CONFIG_MCOUNT),y)
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
-endif
+ccflags-remove-$(CONFIG_MCOUNT) += -pg
 
 LDFLAGS_vmlinux := --oformat $(ld-bfd) -Ttext $(IMAGE_OFFSET) -e startup \
                   -T $(obj)/../../kernel/vmlinux.lds
kernel/trace/Makefile +2 -2
index 6575bb0a0434..7492844a8b1b 100644
@@ -2,9 +2,9 @@
 
 # Do not instrument the tracer itself:
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 ifdef CONFIG_FUNCTION_TRACER
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
 
 # Avoid recursion due to instrumentation.
 KCSAN_SANITIZE := n
lib/842/Makefile +3 -0
index 6f7aad269288..b815e824ae37 100644
@@ -1,3 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
+
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_842_COMPRESS) += 842_compress.o
 obj-$(CONFIG_842_DECOMPRESS) += 842_decompress.o
lib/Makefile +1 -4
index b1c42c10073b..b2ed4beddd68 100644
@@ -3,10 +3,7 @@
 # Makefile for some libs needed in the kernel.
 #
 
-ifdef CONFIG_FUNCTION_TRACER
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
-endif
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
 
 # These files are disabled because they produce lots of non-interesting and/or
 # flaky coverage that is not a function of syscall inputs. For example,
lib/crypto/Makefile +2 -0
index 3a435629d9ce..b557ef0b07c2 100644
@@ -1,5 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 # chacha is used by the /dev/random driver which is always builtin
 obj-y                                          += chacha.o
 obj-$(CONFIG_CRYPTO_LIB_CHACHA_GENERIC)                += libchacha.o
lib/dim/Makefile +2 -0
index 1d6858a108cb..97fc3e89d34e 100644
@@ -2,6 +2,8 @@
 # DIM Dynamic Interrupt Moderation library
 #
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_DIMLIB) += dim.o
 
 dim-y := dim.o net_dim.o rdma_dim.o
lib/fonts/Makefile +2 -0
index ed95070860de..f951750c179e 100644
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 # Font handling
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 font-objs := fonts.o
 
 font-objs-$(CONFIG_FONT_SUN8x16)   += font_sun8x16.o
lib/kunit/Makefile +3 -0
index 724b94311ca3..8c847557ab24 100644
@@ -1,3 +1,6 @@
+
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_KUNIT) +=                 kunit.o
 
 kunit-objs +=                          test.o \
lib/livepatch/Makefile +2 -0
index 295b94bff370..9abdf615b088 100644
@@ -2,6 +2,8 @@
 #
 # Makefile for livepatch test code.
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_TEST_LIVEPATCH) += test_klp_atomic_replace.o \
                                test_klp_callbacks_demo.o \
                                test_klp_callbacks_demo2.o \
lib/lz4/Makefile +1 -0
index 5b42242afaa2..53da4cab7015 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 ccflags-y += -O3
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
 
 obj-$(CONFIG_LZ4_COMPRESS) += lz4_compress.o
 obj-$(CONFIG_LZ4HC_COMPRESS) += lz4hc_compress.o
lib/lzo/Makefile +2 -0
index 2f58fafbbddd..9565a555275b 100644
@@ -1,4 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 lzo_compress-objs := lzo1x_compress.o
 lzo_decompress-objs := lzo1x_decompress_safe.o
 
lib/math/Makefile +2 -0
index be6909e943bd..49aa50e28185 100644
@@ -1,4 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-y += div64.o gcd.o lcm.o int_pow.o int_sqrt.o reciprocal_div.o
 
 obj-$(CONFIG_CORDIC)           += cordic.o
lib/mpi/Makefile +2 -0
index d5874a7f5ff9..df7883521619 100644
@@ -3,6 +3,8 @@
 # MPI multiprecision maths library (from gpg)
 #
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_MPILIB) = mpi.o
 
 mpi-y = \
lib/raid6/Makefile +3 -0
index b4c0df6d706d..3482d6ae3f3b 100644
@@ -1,4 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
+
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_RAID6_PQ) += raid6_pq.o
 
 raid6_pq-y     += algos.o recov.o tables.o int1.o int2.o int4.o \
lib/reed_solomon/Makefile +2 -0
index 5d4fa68f26cb..a5c9defdac7f 100644
@@ -3,5 +3,7 @@
 # This is a modified version of reed solomon lib,
 #
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_REED_SOLOMON) += reed_solomon.o
 obj-$(CONFIG_REED_SOLOMON_TEST) += test_rslib.o
lib/xz/Makefile +3 -0
index fa6af814a8d1..fae9b6c7c389 100644
@@ -1,4 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
+
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_XZ_DEC) += xz_dec.o
 xz_dec-y := xz_dec_syms.o xz_dec_stream.o xz_dec_lzma2.o
 xz_dec-$(CONFIG_XZ_DEC_BCJ) += xz_dec_bcj.o
lib/zlib_deflate/Makefile +2 -0
index 2622e03c0b94..1fcefe73536f 100644
@@ -7,6 +7,8 @@
 # decompression code.
 #
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate.o
 
 zlib_deflate-objs := deflate.o deftree.o deflate_syms.o
lib/zlib_dfltcc/Makefile +2 -0
index 8e4d5afbbb10..7a8067f6e772 100644
@@ -6,6 +6,8 @@
 # This is the code for s390 zlib hardware support.
 #
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_ZLIB_DFLTCC) += zlib_dfltcc.o
 
 zlib_dfltcc-objs := dfltcc.o dfltcc_deflate.o dfltcc_inflate.o dfltcc_syms.o
lib/zlib_inflate/Makefile +2 -0
index 27327d3e9f54..a451e96f9845 100644
@@ -14,6 +14,8 @@
 # uncompression can be done without blocking on allocation).
 #
 
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
 obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate.o
 
 zlib_inflate-objs := inffast.o inflate.o infutil.o \
lib/zstd/Makefile +1 -0
index f5d778e7e5c7..01be908a2d94 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o
 obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o
 
 ccflags-y += -O3
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
 
 zstd_compress-y := fse_compress.o huf_compress.o compress.o \
                   entropy_common.o fse_decompress.o zstd_common.o
scripts/Makefile.lib +8 -7
index 916b2f7f7098..3629f66646d7 100644
@@ -111,12 +111,14 @@ basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
 modname_flags  = -DKBUILD_MODNAME=$(call name-fix,$(modname))
 modfile_flags  = -DKBUILD_MODFILE=$(call stringify,$(modfile))
 
-orig_c_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
-                 $(ccflags-y) $(CFLAGS_$(target-stem).o)
-_c_flags       = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), $(orig_c_flags))
-orig_a_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \
-                 $(asflags-y) $(AFLAGS_$(target-stem).o)
-_a_flags       = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), $(orig_a_flags))
+_c_flags       = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
+                     $(filter-out $(ccflags-remove-y), \
+                         $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \
+                     $(CFLAGS_$(target-stem).o))
+_a_flags       = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \
+                     $(filter-out $(asflags-remove-y), \
+                         $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \
+                     $(AFLAGS_$(target-stem).o))
 _cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
 
 #
--

2.25.1