Create a CFLAGS_REMOVE for ftrace
Subsystems (3)
cover Create a CFLAGS_REMOVE for ftrace
Recently David Miller ported ftrace over to the sparc64. When I mentioned to him a way to remove the "notrace" from all the functions in some files done by using a dirty little hack, David (correctly) called it "Makefile turd" and told us to stop doing that.
I then asked if a CFLAGS_REMOVE_foo.o = -pg would be more pleasing, and he agreed.
This patch series starts out by creating a CFLAGS_REMOVE_(basetarget).o that removes options from CFLAGS to compile a target file.
The rest of the patches clean up the Makefile turd with this variant.
Note, I left the turd in the trace directory itself, just because (almost) all the files there should not be traced. But that's a special directory, and this patch series keeps the sewage in one place.
-- Steve
PATCH 1/4 kbuild: Create new CFLAGS_REMOVE_(basename).o option
We currently have a way to add special CFLAGS to code, but we do not have a way to remove them if needed.
With the case of ftrace, some files should simply not be profiled. Adding the -pg flag to these files is simply a waste, and adding "notrace" to each and every function is ugly.
Currently we put in "Makefile turd" [1] to stop the compiler from adding -pg to certain files. This was clumsy and awkward.
This patch now adds the revese of CFLAGS_(basename).o with CFLAGS_REMOVE_(basename).o. This allows developers to prevent certain CFLAGS from being used to compile files. For example, we can now do
CFLAGS_REMOVE_string.o = -pg
to remove the -pg option from the string.o file in the lib directory.
Note: a space delimited list of options may be added to the REMOVE macro.
[1] - what David Miller called the workaronud to remove -pg
--- scripts/Makefile.lib | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/Makefile.lib +2 -1
@@ -96,7 +96,8 @@ basename_flags = -D"KBUILD_BASENAME=KBUI modname_flags = $(if $(filter 1,$(words $(modname))),\ -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") -_c_flags = $(KBUILD_CFLAGS) $(ccflags-y) $(CFLAGS_$(basetarget).o) +orig_c_flags = $(KBUILD_CFLAGS) $(ccflags-y) $(CFLAGS_$(basetarget).o) +_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags)) _a_flags = $(KBUILD_AFLAGS) $(asflags-y) $(AFLAGS_$(basetarget).o) _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
PATCH 2/4 ftrace: use the new kbuild CFLAGS_REMOVE for kernel directory
In reply to Steven RostedtThis patch removes the Makefile turd and uses the nice CFLAGS_REMOVE macro in the kernel directory.
--- kernel/Makefile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
kernel/Makefile +9 -5
@@ -11,12 +11,16 @@ obj-y = sched.o fork.o exec_domain.o hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ notifier.o ksysfs.o pm_qos_params.o sched_clock.o +CFLAGS_REMOVE_sched.o = -pg -mno-spe + ifdef CONFIG_FTRACE -# Do not profile debug utilities -ORIG_CFLAGS := $(KBUILD_CFLAGS) -KBUILD_CFLAGS = $(if $(filter-out lockdep% %debug sched_clock,$(basename $(notdir $@))), \ - $(ORIG_CFLAGS), \ - $(subst -pg,,$(ORIG_CFLAGS))) +# Do not trace debug files and internal ftrace files +CFLAGS_REMOVE_lockdep.o = -pg +CFLAGS_REMOVE_lockdep_proc.o = -pg +CFLAGS_REMOVE_mutex-debug.o = -pg +CFLAGS_REMOVE_rtmutex-debug.o = -pg +CFLAGS_REMOVE_cgroup-debug.o = -pg +CFLAGS_REMOVE_sched_clock.o = -pg endif obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
PATCH 3/4 ftrace: use the new kbuild CFLAGS_REMOVE for lib directory
In reply to Steven RostedtThis patch removes the Makefile turd and uses the nice CFLAGS_REMOVE macro in the lib directory.
--- lib/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
lib/Makefile +4 -4
@@ -10,11 +10,11 @@ lib-y := ctype.o string.o vsprintf.o cmd ifdef CONFIG_FTRACE # Do not profile string.o, since it may be used in early boot or vdso +CFLAGS_REMOVE_string.o = -pg # Also do not profile any debug utilities -ORIG_CFLAGS := $(KBUILD_CFLAGS) -KBUILD_CFLAGS = $(if $(filter-out %debug debug% string%,$(basename $(notdir $@))), \ - $(ORIG_CFLAGS), \ - $(subst -pg,,$(ORIG_CFLAGS))) +CFLAGS_REMOVE_spinlock_debug.o = -pg +CFLAGS_REMOVE_list_debug.o = -pg +CFLAGS_REMOVE_debugobjects.o = -pg endif lib-$(CONFIG_MMU) += ioremap.o
PATCH 4/4 ftrace: use the new kbuild CFLAGS_REMOVE for x86/kernel directory
In reply to Steven RostedtThis patch removes the Makefile turd and uses the nice CFLAGS_REMOVE macro in the x86/kernel directory.
--- arch/x86/kernel/Makefile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
arch/x86/kernel/Makefile +3 -4
@@ -8,10 +8,9 @@ CPPFLAGS_vmlinux.lds += -U$(UTS_MACHINE) ifdef CONFIG_FTRACE # Do not profile debug utilities -ORIG_CFLAGS := $(KBUILD_CFLAGS) -KBUILD_CFLAGS = $(if $(filter-out tsc_64 tsc_32 rtc,$(basename $(notdir $@))), \ - $(ORIG_CFLAGS), \ - $(subst -pg,,$(ORIG_CFLAGS))) +CFLAGS_REMOVE_tsc_64.o = -pg +CFLAGS_REMOVE_tsc_32.o = -pg +CFLAGS_REMOVE_rtc.o = -pg endif #
Quoted 7 lines · Steven Rostedt
Recently David Miller ported ftrace over to the sparc64. When I mentioned to him a way to remove the "notrace" from all the functions in some files done by using a dirty little hack, David (correctly) called it "
Makefileturd" and told us to stop doing that.I then asked if a CFLAGS_REMOVE_foo.o = -pg would be more pleasing, and he agreed.
Very nice. You should use that for the scheduler case to get rid of "-fno-omit-frame-pointer"
-Andi