* [PATCH 2/2] kbuild: simplify GCC plugin build rules
2019-01-11 9:18 [PATCH 1/2] kbuild: clean up hostprogs rules with hostld_flags and hostld_libs Masahiro Yamada
@ 2019-01-11 9:18 ` Masahiro Yamada
2019-01-11 17:20 ` Kees Cook
2019-01-11 17:20 ` [PATCH 1/2] kbuild: clean up hostprogs rules with hostld_flags and hostld_libs Kees Cook
1 sibling, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2019-01-11 9:18 UTC (permalink / raw)
To: linux-kbuild
Cc: Kees Cook, kernel-hardening, Emese Revfy, Masahiro Yamada,
linux-kernel, Michal Marek
GCC-plugin is the only user of the shared library build rules in
scripts/Makefile.host. Hence, those rules do not need to be treewide
available.
The build rules in scripts/Makefile.host are written in a too generic
way. I guess the main reason is because commit 24403874316a ("Shared
library support") revived the code ripped off by commit 62e2210798ed
("kbuild: drop shared library support from Makefile.host").
Currently, every plugin is built from a single C file. So, all we need
is a pattern rule to create %.so from %.c.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
I want Acked-by from GCC plugin folks,
so this series can go into kbuild tree.
scripts/Makefile.build | 2 +-
scripts/Makefile.clean | 4 +---
scripts/Makefile.host | 49 +-------------------------------------------
scripts/gcc-plugins/Makefile | 28 ++++++++++++++-----------
4 files changed, 19 insertions(+), 64 deletions(-)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index fd03d60..d71a4ed 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -44,7 +44,7 @@ include $(kbuild-file)
include scripts/Makefile.lib
# Do not include host rules unless needed
-ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
+ifneq ($(hostprogs-y)$(hostprogs-m),)
include scripts/Makefile.host
endif
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
index 0b80e320..032160a 100644
--- a/scripts/Makefile.clean
+++ b/scripts/Makefile.clean
@@ -38,9 +38,7 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
__clean-files := $(extra-y) $(extra-m) $(extra-) \
$(always) $(targets) $(clean-files) \
- $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
- $(hostlibs-y) $(hostlibs-m) $(hostlibs-) \
- $(hostcxxlibs-y) $(hostcxxlibs-m)
+ $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
__clean-files := $(filter-out $(no-clean-files), $(__clean-files))
diff --git a/scripts/Makefile.host b/scripts/Makefile.host
index f2e15de..0486180 100644
--- a/scripts/Makefile.host
+++ b/scripts/Makefile.host
@@ -22,8 +22,6 @@
# They are linked as C++ code to the executable qconf
__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
-host-cshlib := $(sort $(hostlibs-y) $(hostlibs-m))
-host-cxxshlib := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
# C code
# Executables compiled from a single .c file
@@ -45,19 +43,11 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
# C++ Object (.o) files compiled from .cc files
host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
-# Object (.o) files used by the shared libaries
-host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
-host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
-
host-csingle := $(addprefix $(obj)/,$(host-csingle))
host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
-host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
-host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
-host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
-host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
#####
# Handle options to gcc. Support building with separate output directory
@@ -126,42 +116,5 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
$(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
$(call if_changed_dep,host-cxxobjs)
-# Compile .c file, create position independent .o file
-# host-cshobjs -> .o
-quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
- cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
-$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
- $(call if_changed_dep,host-cshobjs)
-
-# Compile .c file, create position independent .o file
-# Note that plugin capable gcc versions can be either C or C++ based
-# therefore plugin source files have to be compilable in both C and C++ mode.
-# This is why a C++ compiler is invoked on a .c file.
-# host-cxxshobjs -> .o
-quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
- cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
-$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
- $(call if_changed_dep,host-cxxshobjs)
-
-# Link a shared library, based on position independent .o files
-# *.o -> .so shared library (host-cshlib)
-quiet_cmd_host-cshlib = HOSTLLD -shared $@
- cmd_host-cshlib = $(HOSTCC) $(hostld_flags) -shared -o $@ \
- $(addprefix $(obj)/,$($(@F:.so=-objs))) \
- $(hostld_libs)
-$(host-cshlib): FORCE
- $(call if_changed,host-cshlib)
-$(call multi_depend, $(host-cshlib), .so, -objs)
-
-# Link a shared library, based on position independent .o files
-# *.o -> .so shared library (host-cxxshlib)
-quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
- cmd_host-cxxshlib = $(HOSTCXX) $(hostld_flags) -shared -o $@ \
- $(addprefix $(obj)/,$($(@F:.so=-objs))) \
- $(hostld_libs)
-$(host-cxxshlib): FORCE
- $(call if_changed,host-cxxshlib)
-$(call multi_depend, $(host-cxxshlib), .so, -objs)
-
targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
- $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
+ $(host-cxxmulti) $(host-cxxobjs)
diff --git a/scripts/gcc-plugins/Makefile b/scripts/gcc-plugins/Makefile
index aa0d0ec..a09404d 100644
--- a/scripts/gcc-plugins/Makefile
+++ b/scripts/gcc-plugins/Makefile
@@ -3,18 +3,17 @@ PLUGINCC := $(CONFIG_PLUGIN_HOSTCC:"%"=%)
GCC_PLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
ifeq ($(PLUGINCC),$(HOSTCC))
- HOSTLIBS := hostlibs
- HOST_EXTRACFLAGS += -I$(GCC_PLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
- export HOST_EXTRACFLAGS
+ quiet_cmd_plugin = HOSTCC $@
+ pluginc_flags = $(hostc_flags) -std=gnu99
else
- HOSTLIBS := hostcxxlibs
- HOST_EXTRACXXFLAGS += -I$(GCC_PLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti
- HOST_EXTRACXXFLAGS += -fno-exceptions -fasynchronous-unwind-tables -ggdb
- HOST_EXTRACXXFLAGS += -Wno-narrowing -Wno-unused-variable
- export HOST_EXTRACXXFLAGS
+ quiet_cmd_plugin = HOSTCXX $@
+ pluginc_flags = $(hostcxx_flags) -std=gnu++98 -fno-rtti -fno-exceptions \
+ -fasynchronous-unwind-tables -Wno-narrowing -Wno-unused-variable
endif
-$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
+pluginc_flags += -I$(GCC_PLUGINS_DIR)/include -I$(src) -ggdb -fPIC
+
+$(obj)/randomize_layout_plugin.so: $(objtree)/$(obj)/randomize_layout_seed.h
quiet_cmd_create_randomize_layout_seed = GENSEED $@
cmd_create_randomize_layout_seed = \
$(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
@@ -22,9 +21,14 @@ $(objtree)/$(obj)/randomize_layout_seed.h: FORCE
$(call if_changed,create_randomize_layout_seed)
targets = randomize_layout_seed.h randomize_layout_hash.h
-$(HOSTLIBS)-y := $(foreach p,$(GCC_PLUGIN),$(if $(findstring /,$(p)),,$(p)))
-always := $($(HOSTLIBS)-y)
+extra-y := $(GCC_PLUGIN)
+
+cmd_plugin = $(PLUGINCC) $(pluginc_flags) -shared $(hostld_flags) \
+ -o $@ $< $(hostld_libs)
+
+$(obj)/%.so: $(src)/%.c FORCE
+ $(call if_changed_dep,plugin)
-$(foreach p,$($(HOSTLIBS)-y:%.so=%),$(eval $(p)-objs := $(p).o))
+hostprogs-y += dummy_to_include_scripts/Makefile.host
clean-files += *.so
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] kbuild: clean up hostprogs rules with hostld_flags and hostld_libs
2019-01-11 9:18 [PATCH 1/2] kbuild: clean up hostprogs rules with hostld_flags and hostld_libs Masahiro Yamada
2019-01-11 9:18 ` [PATCH 2/2] kbuild: simplify GCC plugin build rules Masahiro Yamada
@ 2019-01-11 17:20 ` Kees Cook
1 sibling, 0 replies; 4+ messages in thread
From: Kees Cook @ 2019-01-11 17:20 UTC (permalink / raw)
To: Masahiro Yamada
Cc: linux-kbuild, Kernel Hardening, Emese Revfy, Michal Marek, LKML
On Fri, Jan 11, 2019 at 1:19 AM Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
>
> Add hostld_flags and hostld_libs shorthands. No function change.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Kees Cook <keescook@chromium.org>
-Kees
> ---
>
> scripts/Makefile.host | 23 +++++++++++++----------
> 1 file changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/scripts/Makefile.host b/scripts/Makefile.host
> index 0393f75..f2e15de 100644
> --- a/scripts/Makefile.host
> +++ b/scripts/Makefile.host
> @@ -78,23 +78,26 @@ endif
> hostc_flags = -Wp,-MD,$(depfile) $(__hostc_flags)
> hostcxx_flags = -Wp,-MD,$(depfile) $(__hostcxx_flags)
>
> +hostld_flags = $(KBUILD_HOSTLDFLAGS)
> +hostld_libs = $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
> +
> #####
> # Compile programs on the host
>
> # Create executable from a single .c file
> # host-csingle -> Executable
> quiet_cmd_host-csingle = HOSTCC $@
> - cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \
> - $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
> + cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(hostld_flags) -o $@ $< \
> + $(hostld_libs)
> $(host-csingle): $(obj)/%: $(src)/%.c FORCE
> $(call if_changed_dep,host-csingle)
>
> # Link an executable based on list of .o files, all plain c
> # host-cmulti -> executable
> quiet_cmd_host-cmulti = HOSTLD $@
> - cmd_host-cmulti = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ \
> + cmd_host-cmulti = $(HOSTCC) $(hostld_flags) -o $@ \
> $(addprefix $(obj)/,$($(@F)-objs)) \
> - $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
> + $(hostld_libs)
> $(host-cmulti): FORCE
> $(call if_changed,host-cmulti)
> $(call multi_depend, $(host-cmulti), , -objs)
> @@ -109,10 +112,10 @@ $(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE
> # Link an executable based on list of .o files, a mixture of .c and .cc
> # host-cxxmulti -> executable
> quiet_cmd_host-cxxmulti = HOSTLD $@
> - cmd_host-cxxmulti = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -o $@ \
> + cmd_host-cxxmulti = $(HOSTCXX) $(hostld_flags) -o $@ \
> $(foreach o,objs cxxobjs,\
> $(addprefix $(obj)/,$($(@F)-$(o)))) \
> - $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
> + $(hostld_libs)
> $(host-cxxmulti): FORCE
> $(call if_changed,host-cxxmulti)
> $(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs)
> @@ -143,9 +146,9 @@ $(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
> # Link a shared library, based on position independent .o files
> # *.o -> .so shared library (host-cshlib)
> quiet_cmd_host-cshlib = HOSTLLD -shared $@
> - cmd_host-cshlib = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \
> + cmd_host-cshlib = $(HOSTCC) $(hostld_flags) -shared -o $@ \
> $(addprefix $(obj)/,$($(@F:.so=-objs))) \
> - $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
> + $(hostld_libs)
> $(host-cshlib): FORCE
> $(call if_changed,host-cshlib)
> $(call multi_depend, $(host-cshlib), .so, -objs)
> @@ -153,9 +156,9 @@ $(call multi_depend, $(host-cshlib), .so, -objs)
> # Link a shared library, based on position independent .o files
> # *.o -> .so shared library (host-cxxshlib)
> quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
> - cmd_host-cxxshlib = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \
> + cmd_host-cxxshlib = $(HOSTCXX) $(hostld_flags) -shared -o $@ \
> $(addprefix $(obj)/,$($(@F:.so=-objs))) \
> - $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
> + $(hostld_libs)
> $(host-cxxshlib): FORCE
> $(call if_changed,host-cxxshlib)
> $(call multi_depend, $(host-cxxshlib), .so, -objs)
> --
> 2.7.4
>
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread