1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 26b90bd4bSEmese Revfy 3be2b34faSKees Cook$(obj)/randomize_layout_plugin.so: $(obj)/randomize_layout_seed.h 4be2b34faSKees Cookquiet_cmd_create_randomize_layout_seed = SEEDHDR $@ 5313dd1b6SKees Cookcmd_create_randomize_layout_seed = \ 6be2b34faSKees Cook SEED=$$(cat $(filter-out FORCE,$^) </dev/null); \ 7be2b34faSKees Cook echo '/*' > $@; \ 8be2b34faSKees Cook echo ' * This file is automatically generated. Keep it private.' >> $@; \ 9be2b34faSKees Cook echo ' * Exposing this value will expose the layout of randomized structures.' >> $@; \ 10be2b34faSKees Cook echo ' */' >> $@; \ 11be2b34faSKees Cook echo "const char *randstruct_seed = \"$$SEED\";" >> $@ 12be2b34faSKees Cook$(obj)/randomize_layout_seed.h: $(objtree)/scripts/basic/randstruct.seed FORCE 13313dd1b6SKees Cook $(call if_changed,create_randomize_layout_seed) 14be2b34faSKees Cooktargets += randomize_layout_seed.h 15313dd1b6SKees Cook 1642640b13SMasahiro Yamada# Build rules for plugins 1742640b13SMasahiro Yamada# 1842640b13SMasahiro Yamada# No extra code is needed for single-file plugins. 1942640b13SMasahiro Yamada# For multi-file plugins, use *-objs syntax to list the objects. 2042640b13SMasahiro Yamada# 2142640b13SMasahiro Yamada# If the plugin foo.so is compiled from foo.c and foo2.c, you can do: 2242640b13SMasahiro Yamada# 2342640b13SMasahiro Yamada# foo-objs := foo.o foo2.o 246b90bd4bSEmese Revfy 2542640b13SMasahiro Yamadaalways-y += $(GCC_PLUGIN) 26543c37cbSEmese Revfy 2742640b13SMasahiro YamadaGCC_PLUGINS_DIR = $(shell $(CC) -print-file-name=plugin) 2842640b13SMasahiro Yamada 2942640b13SMasahiro Yamadaplugin_cxxflags = -Wp,-MMD,$(depfile) $(KBUILD_HOSTCXXFLAGS) -fPIC \ 30ce6ed1c4SMasahiro Yamada -include $(srctree)/include/linux/compiler-version.h \ 31d37aa2efSMasahiro Yamada -DPLUGIN_VERSION=$(call stringify,$(KERNELVERSION)) \ 32*5a6b64adSSam James -I $(GCC_PLUGINS_DIR)/include -I $(obj) \ 3342640b13SMasahiro Yamada -fno-rtti -fno-exceptions -fasynchronous-unwind-tables \ 3467a5a680SValdis Klētnieks -ggdb -Wno-narrowing -Wno-unused-variable \ 3542640b13SMasahiro Yamada -Wno-format-diag 3642640b13SMasahiro Yamada 3742640b13SMasahiro Yamadaplugin_ldflags = -shared 3842640b13SMasahiro Yamada 3942640b13SMasahiro Yamadaplugin-single := $(foreach m, $(GCC_PLUGIN), $(if $($(m:%.so=%-objs)),,$(m))) 4042640b13SMasahiro Yamadaplugin-multi := $(filter-out $(plugin-single), $(GCC_PLUGIN)) 4142640b13SMasahiro Yamadaplugin-objs := $(sort $(foreach m, $(plugin-multi), $($(m:%.so=%-objs)))) 4242640b13SMasahiro Yamada 4342640b13SMasahiro Yamadatargets += $(plugin-single) $(plugin-multi) $(plugin-objs) 446b90bd4bSEmese Revfyclean-files += *.so 4542640b13SMasahiro Yamada 4642640b13SMasahiro Yamadaplugin-single := $(addprefix $(obj)/, $(plugin-single)) 4742640b13SMasahiro Yamadaplugin-multi := $(addprefix $(obj)/, $(plugin-multi)) 4842640b13SMasahiro Yamadaplugin-objs := $(addprefix $(obj)/, $(plugin-objs)) 4942640b13SMasahiro Yamada 5042640b13SMasahiro Yamadaquiet_cmd_plugin_cxx_so_c = HOSTCXX $@ 5142640b13SMasahiro Yamada cmd_plugin_cxx_so_c = $(HOSTCXX) $(plugin_cxxflags) $(plugin_ldflags) -o $@ $< 5242640b13SMasahiro Yamada 5342640b13SMasahiro Yamada$(plugin-single): $(obj)/%.so: $(src)/%.c FORCE 5442640b13SMasahiro Yamada $(call if_changed_dep,plugin_cxx_so_c) 5542640b13SMasahiro Yamada 5642640b13SMasahiro Yamadaquiet_cmd_plugin_ld_so_o = HOSTLD $@ 5742640b13SMasahiro Yamada cmd_plugin_ld_so_o = $(HOSTCXX) $(plugin_ldflags) -o $@ \ 5842640b13SMasahiro Yamada $(addprefix $(obj)/, $($(target-stem)-objs)) 5942640b13SMasahiro Yamada 6042640b13SMasahiro Yamada$(plugin-multi): FORCE 6142640b13SMasahiro Yamada $(call if_changed,plugin_ld_so_o) 6242640b13SMasahiro Yamada$(foreach m, $(notdir $(plugin-multi)), $(eval $(obj)/$m: $(addprefix $(obj)/, $($(m:%.so=%-objs))))) 6342640b13SMasahiro Yamada 6442640b13SMasahiro Yamadaquiet_cmd_plugin_cxx_o_c = HOSTCXX $@ 6542640b13SMasahiro Yamada cmd_plugin_cxx_o_c = $(HOSTCXX) $(plugin_cxxflags) -c -o $@ $< 6642640b13SMasahiro Yamada 6742640b13SMasahiro Yamada$(plugin-objs): $(obj)/%.o: $(src)/%.c FORCE 6842640b13SMasahiro Yamada $(call if_changed_dep,plugin_cxx_o_c) 69