Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Emese Revfy | 6b90bd4 | 2016-05-24 00:09:38 +0200 | [diff] [blame] | 2 | |
Masahiro Yamada | 42640b13 | 2020-07-29 12:15:36 +0900 | [diff] [blame] | 3 | $(obj)/randomize_layout_plugin.so: $(objtree)/$(obj)/randomize_layout_seed.h |
Kees Cook | 313dd1b6 | 2017-05-05 23:37:45 -0700 | [diff] [blame] | 4 | quiet_cmd_create_randomize_layout_seed = GENSEED $@ |
| 5 | cmd_create_randomize_layout_seed = \ |
| 6 | $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h |
| 7 | $(objtree)/$(obj)/randomize_layout_seed.h: FORCE |
| 8 | $(call if_changed,create_randomize_layout_seed) |
Masahiro Yamada | 42640b13 | 2020-07-29 12:15:36 +0900 | [diff] [blame] | 9 | targets += randomize_layout_seed.h randomize_layout_hash.h |
Kees Cook | 313dd1b6 | 2017-05-05 23:37:45 -0700 | [diff] [blame] | 10 | |
Masahiro Yamada | 42640b13 | 2020-07-29 12:15:36 +0900 | [diff] [blame] | 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 |
Emese Revfy | 6b90bd4 | 2016-05-24 00:09:38 +0200 | [diff] [blame] | 19 | |
Masahiro Yamada | 42640b13 | 2020-07-29 12:15:36 +0900 | [diff] [blame] | 20 | always-y += $(GCC_PLUGIN) |
Emese Revfy | 543c37c | 2016-05-24 00:11:37 +0200 | [diff] [blame] | 21 | |
Masahiro Yamada | 42640b13 | 2020-07-29 12:15:36 +0900 | [diff] [blame] | 22 | GCC_PLUGINS_DIR = $(shell $(CC) -print-file-name=plugin) |
| 23 | |
| 24 | plugin_cxxflags = -Wp,-MMD,$(depfile) $(KBUILD_HOSTCXXFLAGS) -fPIC \ |
Masahiro Yamada | ce6ed1c | 2021-03-04 20:37:08 +0900 | [diff] [blame] | 25 | -include $(srctree)/include/linux/compiler-version.h \ |
Valdis Klētnieks | 67a5a68 | 2020-12-26 13:21:58 -0500 | [diff] [blame] | 26 | -I $(GCC_PLUGINS_DIR)/include -I $(obj) -std=gnu++11 \ |
Masahiro Yamada | 42640b13 | 2020-07-29 12:15:36 +0900 | [diff] [blame] | 27 | -fno-rtti -fno-exceptions -fasynchronous-unwind-tables \ |
Valdis Klētnieks | 67a5a68 | 2020-12-26 13:21:58 -0500 | [diff] [blame] | 28 | -ggdb -Wno-narrowing -Wno-unused-variable \ |
Masahiro Yamada | 42640b13 | 2020-07-29 12:15:36 +0900 | [diff] [blame] | 29 | -Wno-format-diag |
| 30 | |
| 31 | plugin_ldflags = -shared |
| 32 | |
| 33 | plugin-single := $(foreach m, $(GCC_PLUGIN), $(if $($(m:%.so=%-objs)),,$(m))) |
| 34 | plugin-multi := $(filter-out $(plugin-single), $(GCC_PLUGIN)) |
| 35 | plugin-objs := $(sort $(foreach m, $(plugin-multi), $($(m:%.so=%-objs)))) |
| 36 | |
| 37 | targets += $(plugin-single) $(plugin-multi) $(plugin-objs) |
Emese Revfy | 6b90bd4 | 2016-05-24 00:09:38 +0200 | [diff] [blame] | 38 | clean-files += *.so |
Masahiro Yamada | 42640b13 | 2020-07-29 12:15:36 +0900 | [diff] [blame] | 39 | |
| 40 | plugin-single := $(addprefix $(obj)/, $(plugin-single)) |
| 41 | plugin-multi := $(addprefix $(obj)/, $(plugin-multi)) |
| 42 | plugin-objs := $(addprefix $(obj)/, $(plugin-objs)) |
| 43 | |
| 44 | quiet_cmd_plugin_cxx_so_c = HOSTCXX $@ |
| 45 | cmd_plugin_cxx_so_c = $(HOSTCXX) $(plugin_cxxflags) $(plugin_ldflags) -o $@ $< |
| 46 | |
| 47 | $(plugin-single): $(obj)/%.so: $(src)/%.c FORCE |
| 48 | $(call if_changed_dep,plugin_cxx_so_c) |
| 49 | |
| 50 | quiet_cmd_plugin_ld_so_o = HOSTLD $@ |
| 51 | cmd_plugin_ld_so_o = $(HOSTCXX) $(plugin_ldflags) -o $@ \ |
| 52 | $(addprefix $(obj)/, $($(target-stem)-objs)) |
| 53 | |
| 54 | $(plugin-multi): FORCE |
| 55 | $(call if_changed,plugin_ld_so_o) |
| 56 | $(foreach m, $(notdir $(plugin-multi)), $(eval $(obj)/$m: $(addprefix $(obj)/, $($(m:%.so=%-objs))))) |
| 57 | |
| 58 | quiet_cmd_plugin_cxx_o_c = HOSTCXX $@ |
| 59 | cmd_plugin_cxx_o_c = $(HOSTCXX) $(plugin_cxxflags) -c -o $@ $< |
| 60 | |
| 61 | $(plugin-objs): $(obj)/%.o: $(src)/%.c FORCE |
| 62 | $(call if_changed_dep,plugin_cxx_o_c) |