xref: /linux/scripts/gcc-plugins/Makefile (revision be2b34fa9be31c60a95989f984c9a5d40cd781b6)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
26b90bd4bSEmese Revfy
3*be2b34faSKees Cook$(obj)/randomize_layout_plugin.so: $(obj)/randomize_layout_seed.h
4*be2b34faSKees Cookquiet_cmd_create_randomize_layout_seed = SEEDHDR $@
5313dd1b6SKees Cookcmd_create_randomize_layout_seed = \
6*be2b34faSKees Cook	SEED=$$(cat $(filter-out FORCE,$^) </dev/null); \
7*be2b34faSKees Cook	echo '/*' > $@; \
8*be2b34faSKees Cook	echo ' * This file is automatically generated. Keep it private.' >> $@; \
9*be2b34faSKees Cook	echo ' * Exposing this value will expose the layout of randomized structures.' >> $@; \
10*be2b34faSKees Cook	echo ' */' >> $@; \
11*be2b34faSKees Cook	echo "const char *randstruct_seed = \"$$SEED\";" >> $@
12*be2b34faSKees Cook$(obj)/randomize_layout_seed.h: $(objtree)/scripts/basic/randstruct.seed FORCE
13313dd1b6SKees Cook	$(call if_changed,create_randomize_layout_seed)
14*be2b34faSKees 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 \
3167a5a680SValdis Klētnieks		   -I $(GCC_PLUGINS_DIR)/include -I $(obj) -std=gnu++11 \
3242640b13SMasahiro Yamada		   -fno-rtti -fno-exceptions -fasynchronous-unwind-tables \
3367a5a680SValdis Klētnieks		   -ggdb -Wno-narrowing -Wno-unused-variable \
3442640b13SMasahiro Yamada		   -Wno-format-diag
3542640b13SMasahiro Yamada
3642640b13SMasahiro Yamadaplugin_ldflags	= -shared
3742640b13SMasahiro Yamada
3842640b13SMasahiro Yamadaplugin-single	:= $(foreach m, $(GCC_PLUGIN), $(if $($(m:%.so=%-objs)),,$(m)))
3942640b13SMasahiro Yamadaplugin-multi	:= $(filter-out $(plugin-single), $(GCC_PLUGIN))
4042640b13SMasahiro Yamadaplugin-objs	:= $(sort $(foreach m, $(plugin-multi), $($(m:%.so=%-objs))))
4142640b13SMasahiro Yamada
4242640b13SMasahiro Yamadatargets += $(plugin-single) $(plugin-multi) $(plugin-objs)
436b90bd4bSEmese Revfyclean-files += *.so
4442640b13SMasahiro Yamada
4542640b13SMasahiro Yamadaplugin-single	:= $(addprefix $(obj)/, $(plugin-single))
4642640b13SMasahiro Yamadaplugin-multi	:= $(addprefix $(obj)/, $(plugin-multi))
4742640b13SMasahiro Yamadaplugin-objs	:= $(addprefix $(obj)/, $(plugin-objs))
4842640b13SMasahiro Yamada
4942640b13SMasahiro Yamadaquiet_cmd_plugin_cxx_so_c = HOSTCXX $@
5042640b13SMasahiro Yamada      cmd_plugin_cxx_so_c = $(HOSTCXX) $(plugin_cxxflags) $(plugin_ldflags) -o $@ $<
5142640b13SMasahiro Yamada
5242640b13SMasahiro Yamada$(plugin-single): $(obj)/%.so: $(src)/%.c FORCE
5342640b13SMasahiro Yamada	$(call if_changed_dep,plugin_cxx_so_c)
5442640b13SMasahiro Yamada
5542640b13SMasahiro Yamadaquiet_cmd_plugin_ld_so_o = HOSTLD  $@
5642640b13SMasahiro Yamada      cmd_plugin_ld_so_o = $(HOSTCXX) $(plugin_ldflags) -o $@ \
5742640b13SMasahiro Yamada			   $(addprefix $(obj)/, $($(target-stem)-objs))
5842640b13SMasahiro Yamada
5942640b13SMasahiro Yamada$(plugin-multi): FORCE
6042640b13SMasahiro Yamada	$(call if_changed,plugin_ld_so_o)
6142640b13SMasahiro Yamada$(foreach m, $(notdir $(plugin-multi)), $(eval $(obj)/$m: $(addprefix $(obj)/, $($(m:%.so=%-objs)))))
6242640b13SMasahiro Yamada
6342640b13SMasahiro Yamadaquiet_cmd_plugin_cxx_o_c = HOSTCXX $@
6442640b13SMasahiro Yamada      cmd_plugin_cxx_o_c = $(HOSTCXX) $(plugin_cxxflags) -c -o $@ $<
6542640b13SMasahiro Yamada
6642640b13SMasahiro Yamada$(plugin-objs): $(obj)/%.o: $(src)/%.c FORCE
6742640b13SMasahiro Yamada	$(call if_changed_dep,plugin_cxx_o_c)
68