162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci$(obj)/randomize_layout_plugin.so: $(obj)/randomize_layout_seed.h
462306a36Sopenharmony_ciquiet_cmd_create_randomize_layout_seed = SEEDHDR $@
562306a36Sopenharmony_cicmd_create_randomize_layout_seed = \
662306a36Sopenharmony_ci	SEED=$$(cat $(filter-out FORCE,$^) </dev/null); \
762306a36Sopenharmony_ci	echo '/*' > $@; \
862306a36Sopenharmony_ci	echo ' * This file is automatically generated. Keep it private.' >> $@; \
962306a36Sopenharmony_ci	echo ' * Exposing this value will expose the layout of randomized structures.' >> $@; \
1062306a36Sopenharmony_ci	echo ' */' >> $@; \
1162306a36Sopenharmony_ci	echo "const char *randstruct_seed = \"$$SEED\";" >> $@
1262306a36Sopenharmony_ci$(obj)/randomize_layout_seed.h: $(objtree)/scripts/basic/randstruct.seed FORCE
1362306a36Sopenharmony_ci	$(call if_changed,create_randomize_layout_seed)
1462306a36Sopenharmony_citargets += randomize_layout_seed.h
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci# Build rules for plugins
1762306a36Sopenharmony_ci#
1862306a36Sopenharmony_ci# No extra code is needed for single-file plugins.
1962306a36Sopenharmony_ci# For multi-file plugins, use *-objs syntax to list the objects.
2062306a36Sopenharmony_ci#
2162306a36Sopenharmony_ci# If the plugin foo.so is compiled from foo.c and foo2.c, you can do:
2262306a36Sopenharmony_ci#
2362306a36Sopenharmony_ci# foo-objs := foo.o foo2.o
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_cialways-y += $(GCC_PLUGIN)
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ciGCC_PLUGINS_DIR = $(shell $(CC) -print-file-name=plugin)
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ciplugin_cxxflags	= -Wp,-MMD,$(depfile) $(KBUILD_HOSTCXXFLAGS) -fPIC \
3062306a36Sopenharmony_ci		  -include $(srctree)/include/linux/compiler-version.h \
3162306a36Sopenharmony_ci		  -DPLUGIN_VERSION=$(call stringify,$(KERNELVERSION)) \
3262306a36Sopenharmony_ci		  -I $(GCC_PLUGINS_DIR)/include -I $(obj) \
3362306a36Sopenharmony_ci		  -fno-rtti -fno-exceptions -fasynchronous-unwind-tables \
3462306a36Sopenharmony_ci		  -ggdb -Wno-narrowing -Wno-unused-variable \
3562306a36Sopenharmony_ci		  -Wno-format-diag
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ciplugin_ldflags	= -shared
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ciplugin-single	:= $(foreach m, $(GCC_PLUGIN), $(if $($(m:%.so=%-objs)),,$(m)))
4062306a36Sopenharmony_ciplugin-multi	:= $(filter-out $(plugin-single), $(GCC_PLUGIN))
4162306a36Sopenharmony_ciplugin-objs	:= $(sort $(foreach m, $(plugin-multi), $($(m:%.so=%-objs))))
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_citargets += $(plugin-single) $(plugin-multi) $(plugin-objs)
4462306a36Sopenharmony_ciclean-files += *.so
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ciplugin-single	:= $(addprefix $(obj)/, $(plugin-single))
4762306a36Sopenharmony_ciplugin-multi	:= $(addprefix $(obj)/, $(plugin-multi))
4862306a36Sopenharmony_ciplugin-objs	:= $(addprefix $(obj)/, $(plugin-objs))
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ciquiet_cmd_plugin_cxx_so_c = HOSTCXX $@
5162306a36Sopenharmony_ci      cmd_plugin_cxx_so_c = $(HOSTCXX) $(plugin_cxxflags) $(plugin_ldflags) -o $@ $<
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci$(plugin-single): $(obj)/%.so: $(src)/%.c FORCE
5462306a36Sopenharmony_ci	$(call if_changed_dep,plugin_cxx_so_c)
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ciquiet_cmd_plugin_ld_so_o = HOSTLD  $@
5762306a36Sopenharmony_ci      cmd_plugin_ld_so_o = $(HOSTCXX) $(plugin_ldflags) -o $@ \
5862306a36Sopenharmony_ci			   $(addprefix $(obj)/, $($(target-stem)-objs))
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci$(plugin-multi): FORCE
6162306a36Sopenharmony_ci	$(call if_changed,plugin_ld_so_o)
6262306a36Sopenharmony_ci$(foreach m, $(notdir $(plugin-multi)), $(eval $(obj)/$m: $(addprefix $(obj)/, $($(m:%.so=%-objs)))))
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ciquiet_cmd_plugin_cxx_o_c = HOSTCXX $@
6562306a36Sopenharmony_ci      cmd_plugin_cxx_o_c = $(HOSTCXX) $(plugin_cxxflags) -c -o $@ $<
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci$(plugin-objs): $(obj)/%.o: $(src)/%.c FORCE
6862306a36Sopenharmony_ci	$(call if_changed_dep,plugin_cxx_o_c)
69