Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kbuild: move host .so build rules to scripts/gcc-plugins/Makefile

The host shared library rules are currently implemented in
scripts/Makefile.host, but actually GCC-plugin is the only user of
them. (The VDSO .so files are built for the target by different
build rules) Hence, they do not need to be treewide available.

Move all the relevant build rules to scripts/gcc-plugins/Makefile.

I also optimized the build steps so *.so is directly built from .c
because every upstream plugin is compiled from a single source file.

I am still keeping the multi-file plugin support, which Kees Cook
mentioned might be needed by out-of-tree plugins.
(https://lkml.org/lkml/2019/1/11/1107)

If the plugin, foo.so, is compiled from two files foo.c and foo2.c,
then you can do like follows:

foo-objs := foo.o foo2.o

Single-file plugins do not need the *-objs notation.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Kees Cook <keescook@chromium.org>

+55 -43
+2 -2
scripts/Makefile.build
··· 45 45 46 46 include scripts/Makefile.lib 47 47 48 - # Do not include host rules unless needed 49 - ifneq ($(hostprogs)$(hostcxxlibs-y)$(hostcxxlibs-m),) 48 + # Do not include hostprogs rules unless needed 49 + ifneq ($(hostprogs),) 50 50 include scripts/Makefile.host 51 51 endif 52 52
+1 -2
scripts/Makefile.clean
··· 29 29 30 30 __clean-files := $(extra-y) $(extra-m) $(extra-) \ 31 31 $(always) $(always-y) $(always-m) $(always-) $(targets) $(clean-files) \ 32 - $(hostprogs) $(hostprogs-y) $(hostprogs-m) $(hostprogs-) $(userprogs) \ 33 - $(hostcxxlibs-y) $(hostcxxlibs-m) 32 + $(hostprogs) $(hostprogs-y) $(hostprogs-m) $(hostprogs-) $(userprogs) 34 33 35 34 __clean-files := $(filter-out $(no-clean-files), $(__clean-files)) 36 35
+2 -28
scripts/Makefile.host
··· 39 39 # They are linked as C++ code to the executable qconf 40 40 41 41 __hostprogs := $(sort $(hostprogs)) 42 - host-cxxshlib := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m)) 43 42 44 43 # C code 45 44 # Executables compiled from a single .c file ··· 60 61 # C++ Object (.o) files compiled from .cc files 61 62 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs))) 62 63 63 - # Object (.o) files used by the shared libaries 64 - host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs)))) 65 - 66 64 host-csingle := $(addprefix $(obj)/,$(host-csingle)) 67 65 host-cmulti := $(addprefix $(obj)/,$(host-cmulti)) 68 66 host-cobjs := $(addprefix $(obj)/,$(host-cobjs)) 69 67 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti)) 70 68 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs)) 71 - host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib)) 72 - host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs)) 73 69 74 70 ##### 75 71 # Handle options to gcc. Support building with separate output directory ··· 130 136 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE 131 137 $(call if_changed_dep,host-cxxobjs) 132 138 133 - # Compile .c file, create position independent .o file 134 - # Note that plugin capable gcc versions can be either C or C++ based 135 - # therefore plugin source files have to be compilable in both C and C++ mode. 136 - # This is why a C++ compiler is invoked on a .c file. 137 - # host-cxxshobjs -> .o 138 - quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@ 139 - cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $< 140 - $(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE 141 - $(call if_changed_dep,host-cxxshobjs) 142 - 143 - # Link a shared library, based on position independent .o files 144 - # *.o -> .so shared library (host-cxxshlib) 145 - quiet_cmd_host-cxxshlib = HOSTLLD -shared $@ 146 - cmd_host-cxxshlib = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \ 147 - $(addprefix $(obj)/, $($(target-stem)-objs)) \ 148 - $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem).so) 149 - $(host-cxxshlib): FORCE 150 - $(call if_changed,host-cxxshlib) 151 - $(call multi_depend, $(host-cxxshlib), .so, -objs) 152 - 153 - targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\ 154 - $(host-cxxmulti) $(host-cxxobjs) $(host-cxxshlib) $(host-cxxshobjs) 139 + targets += $(host-csingle) $(host-cmulti) $(host-cobjs) \ 140 + $(host-cxxmulti) $(host-cxxobjs)
+50 -11
scripts/gcc-plugins/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - GCC_PLUGINS_DIR := $(shell $(CC) -print-file-name=plugin) 3 2 4 - HOST_EXTRACXXFLAGS += -I$(GCC_PLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti 5 - HOST_EXTRACXXFLAGS += -fno-exceptions -fasynchronous-unwind-tables -ggdb 6 - HOST_EXTRACXXFLAGS += -Wno-narrowing -Wno-unused-variable -Wno-c++11-compat 7 - HOST_EXTRACXXFLAGS += -Wno-format-diag 8 - 9 - $(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h 3 + $(obj)/randomize_layout_plugin.so: $(objtree)/$(obj)/randomize_layout_seed.h 10 4 quiet_cmd_create_randomize_layout_seed = GENSEED $@ 11 5 cmd_create_randomize_layout_seed = \ 12 6 $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h 13 7 $(objtree)/$(obj)/randomize_layout_seed.h: FORCE 14 8 $(call if_changed,create_randomize_layout_seed) 15 - targets = randomize_layout_seed.h randomize_layout_hash.h 9 + targets += randomize_layout_seed.h randomize_layout_hash.h 16 10 17 - hostcxxlibs-y := $(GCC_PLUGIN) 18 - always-y := $(hostcxxlibs-y) 11 + # Build rules for plugins 12 + # 13 + # No extra code is needed for single-file plugins. 14 + # For multi-file plugins, use *-objs syntax to list the objects. 15 + # 16 + # If the plugin foo.so is compiled from foo.c and foo2.c, you can do: 17 + # 18 + # foo-objs := foo.o foo2.o 19 19 20 - $(foreach p,$(hostcxxlibs-y:%.so=%),$(eval $(p)-objs := $(p).o)) 20 + always-y += $(GCC_PLUGIN) 21 21 22 + GCC_PLUGINS_DIR = $(shell $(CC) -print-file-name=plugin) 23 + 24 + plugin_cxxflags = -Wp,-MMD,$(depfile) $(KBUILD_HOSTCXXFLAGS) -fPIC \ 25 + -I $(GCC_PLUGINS_DIR)/include -I $(obj) -std=gnu++98 \ 26 + -fno-rtti -fno-exceptions -fasynchronous-unwind-tables \ 27 + -ggdb -Wno-narrowing -Wno-unused-variable -Wno-c++11-compat \ 28 + -Wno-format-diag 29 + 30 + plugin_ldflags = -shared 31 + 32 + plugin-single := $(foreach m, $(GCC_PLUGIN), $(if $($(m:%.so=%-objs)),,$(m))) 33 + plugin-multi := $(filter-out $(plugin-single), $(GCC_PLUGIN)) 34 + plugin-objs := $(sort $(foreach m, $(plugin-multi), $($(m:%.so=%-objs)))) 35 + 36 + targets += $(plugin-single) $(plugin-multi) $(plugin-objs) 22 37 clean-files += *.so 38 + 39 + plugin-single := $(addprefix $(obj)/, $(plugin-single)) 40 + plugin-multi := $(addprefix $(obj)/, $(plugin-multi)) 41 + plugin-objs := $(addprefix $(obj)/, $(plugin-objs)) 42 + 43 + quiet_cmd_plugin_cxx_so_c = HOSTCXX $@ 44 + cmd_plugin_cxx_so_c = $(HOSTCXX) $(plugin_cxxflags) $(plugin_ldflags) -o $@ $< 45 + 46 + $(plugin-single): $(obj)/%.so: $(src)/%.c FORCE 47 + $(call if_changed_dep,plugin_cxx_so_c) 48 + 49 + quiet_cmd_plugin_ld_so_o = HOSTLD $@ 50 + cmd_plugin_ld_so_o = $(HOSTCXX) $(plugin_ldflags) -o $@ \ 51 + $(addprefix $(obj)/, $($(target-stem)-objs)) 52 + 53 + $(plugin-multi): FORCE 54 + $(call if_changed,plugin_ld_so_o) 55 + $(foreach m, $(notdir $(plugin-multi)), $(eval $(obj)/$m: $(addprefix $(obj)/, $($(m:%.so=%-objs))))) 56 + 57 + quiet_cmd_plugin_cxx_o_c = HOSTCXX $@ 58 + cmd_plugin_cxx_o_c = $(HOSTCXX) $(plugin_cxxflags) -c -o $@ $< 59 + 60 + $(plugin-objs): $(obj)/%.o: $(src)/%.c FORCE 61 + $(call if_changed_dep,plugin_cxx_o_c)