.. | .. |
---|
1 | 1 | # SPDX-License-Identifier: GPL-2.0 |
---|
2 | | -PLUGINCC := $(CONFIG_PLUGIN_HOSTCC:"%"=%) |
---|
3 | | -GCC_PLUGINS_DIR := $(shell $(CC) -print-file-name=plugin) |
---|
4 | 2 | |
---|
5 | | -ifeq ($(PLUGINCC),$(HOSTCC)) |
---|
6 | | - HOSTLIBS := hostlibs |
---|
7 | | - HOST_EXTRACFLAGS += -I$(GCC_PLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb |
---|
8 | | - export HOST_EXTRACFLAGS |
---|
9 | | -else |
---|
10 | | - HOSTLIBS := hostcxxlibs |
---|
11 | | - HOST_EXTRACXXFLAGS += -I$(GCC_PLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti |
---|
12 | | - HOST_EXTRACXXFLAGS += -fno-exceptions -fasynchronous-unwind-tables -ggdb |
---|
13 | | - HOST_EXTRACXXFLAGS += -Wno-narrowing -Wno-unused-variable |
---|
14 | | - HOST_EXTRACXXFLAGS += -Wno-format-diag |
---|
15 | | - export HOST_EXTRACXXFLAGS |
---|
16 | | -endif |
---|
17 | | - |
---|
18 | | -$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h |
---|
| 3 | +$(obj)/randomize_layout_plugin.so: $(objtree)/$(obj)/randomize_layout_seed.h |
---|
19 | 4 | quiet_cmd_create_randomize_layout_seed = GENSEED $@ |
---|
20 | 5 | cmd_create_randomize_layout_seed = \ |
---|
21 | 6 | $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h |
---|
22 | 7 | $(objtree)/$(obj)/randomize_layout_seed.h: FORCE |
---|
23 | 8 | $(call if_changed,create_randomize_layout_seed) |
---|
24 | | -targets = randomize_layout_seed.h randomize_layout_hash.h |
---|
| 9 | +targets += randomize_layout_seed.h randomize_layout_hash.h |
---|
25 | 10 | |
---|
26 | | -$(HOSTLIBS)-y := $(foreach p,$(GCC_PLUGIN),$(if $(findstring /,$(p)),,$(p))) |
---|
27 | | -always := $($(HOSTLIBS)-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 |
---|
28 | 19 | |
---|
29 | | -$(foreach p,$($(HOSTLIBS)-y:%.so=%),$(eval $(p)-objs := $(p).o)) |
---|
| 20 | +always-y += $(GCC_PLUGIN) |
---|
30 | 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++11 \ |
---|
| 26 | + -fno-rtti -fno-exceptions -fasynchronous-unwind-tables \ |
---|
| 27 | + -ggdb -Wno-narrowing -Wno-unused-variable \ |
---|
| 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) |
---|
31 | 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) |
---|