Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1373781 > unrolled thread
| Started by | Emese Revfy <re.emese@gmail.com> |
|---|---|
| First post | 2016-04-07 23:20 +0200 |
| Last post | 2016-04-13 04:40 +0200 |
| Articles | 13 — 5 participants |
Back to article view | Back to linux.kernel
[PATCH v6 0/6] Introduce GCC plugin infrastructure Emese Revfy <re.emese@gmail.com> - 2016-04-07 23:20 +0200
[PATCH v6 3/6] The GCC plugin infrastructure supports the arm and arm64 architectures too Emese Revfy <re.emese@gmail.com> - 2016-04-07 23:20 +0200
[PATCH v6 4/6] Add Cyclomatic complexity GCC plugin Emese Revfy <re.emese@gmail.com> - 2016-04-07 23:20 +0200
[PATCH v6 6/6] Add sancov plugin Emese Revfy <re.emese@gmail.com> - 2016-04-07 23:30 +0200
[PATCH v6 5/6] Documentation for the GCC plugin infrastructure Emese Revfy <re.emese@gmail.com> - 2016-04-07 23:30 +0200
Re: [PATCH v6 0/6] Introduce GCC plugin infrastructure David Brown <david.brown@linaro.org> - 2016-04-12 19:50 +0200
Re: [PATCH v6 0/6] Introduce GCC plugin infrastructure Kees Cook <keescook@chromium.org> - 2016-04-12 20:30 +0200
Re: [PATCH v6 0/6] Introduce GCC plugin infrastructure David Brown <david.brown@linaro.org> - 2016-04-12 20:50 +0200
Re: [PATCH v6 0/6] Introduce GCC plugin infrastructure Kees Cook <keescook@chromium.org> - 2016-04-12 21:50 +0200
Re: [PATCH v6 0/6] Introduce GCC plugin infrastructure "PaX Team" <pageexec@freemail.hu> - 2016-04-12 23:30 +0200
Re: [PATCH v6 0/6] Introduce GCC plugin infrastructure Emese Revfy <re.emese@gmail.com> - 2016-04-12 21:00 +0200
Re: [PATCH v6 0/6] Introduce GCC plugin infrastructure Kees Cook <keescook@chromium.org> - 2016-04-12 21:50 +0200
Re: [PATCH v6 2/6] GCC plugin infrastructure Masahiro Yamada <yamada.masahiro@socionext.com> - 2016-04-13 04:40 +0200
| From | Emese Revfy <re.emese@gmail.com> |
|---|---|
| Date | 2016-04-07 23:20 +0200 |
| Subject | [PATCH v6 0/6] Introduce GCC plugin infrastructure |
| Message-ID | <rlpvj-1uc-3@gated-at.bofh.it> |
This patch set introduce the GCC plugin infrastructure with examples for testing
and documentation.
GCC plugins are loadable modules that provide extra features to the compiler.
They are useful for runtime instrumentation and static analysis.
The infrastructure supports all gcc versions from 4.5 to 6.0, building
out-of-tree modules and building in a separate directory. Cross-compilation
is supported too but currently only the x86, arm and arm64 architectures enables plugins.
This infrastructure was ported from grsecurity/PaX. It is a CII project
supported by the Linux Foundation.
Emese Revfy (6):
Shared library support
GCC plugin infrastructure
The GCC plugin infrastructure supports the arm and arm64 architectures too
Add Cyclomatic complexity plugin
Documentations of the GCC plugin infrastructre
Add sancov plugin
Changes from v5:
* Set important properties on the external fndecl (Add sancov plugin)
* Revert documentation change too (Shared library support)
(Suggested-by: Kees Cook <keescook@chromium.org>)
* The GCC plugin infrastructure now supports the arm and arm64 architectures too
(Signed-off-by: David Brown <david.brown@linaro.org>)
* Simplify the computation of PLUGINCC (GCC plugin infrastructure)
(Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>)
* Simplify the invocation of gcc-plugin.sh (GCC plugin infrastructure)
(Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>)
* Make use of multi-depend (Shared library support)
(Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>)
* Remove unnecessary exports (GCC plugin infrastructure)
(Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>)
* Simplify Makefile by using addprefix (GCC plugin infrastructure)
(Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>)
* Moved the gcc plugins from tools/ to scripts/ (GCC plugin infrastructure)
(Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>)
* Removed plugins from KBUILD_CFLAGS_32 (GCC plugin infrastructure)
* Remove gcc-plugin target everywhere
(Suggested-by and partly Written-by: Masahiro Yamada <yamada.masahiro@socionext.com>)
* There is no leaf gcc attribute in gcc-4.5 (Add sancov plugin)
* Added support to the sancov plugin with kcov (Add sancov plugin)
Changes from v4:
* Moved shared library support from the GCC plugin infrastructure patch into
a different patch
* Update gcc-*.h from PaX
* Fixed gcc-common.h for gcc 6
* Added pass cloning support to the gcc pass generators
* Disable all plugins in vdso because it is userland code
* Add sancov gcc plugin: another use case for gcc plugin support in the kernel
is when there is a feature in the latest gcc version and we would like to use
it with older gcc versions as well (e.g., distros).
Changes from v3:
* Fix some indentation related warnings
(Suggested by checkpatch.pl)
* Add maintainer entries
* Don't run gcc_plugin.sh when the GCC_PLUGINS option is disabled or unsupported
(Reported-by: Fengguang Wu <fengguang.wu@intel.com>)
Changes from v2:
* Fixed incorrectly encoded characters
* Generate the GIMPLE, IPA, SIMPLE_IPA and RTL pass structures
(Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>)
* Write plugin related warning messages to stderr instead of stdout
(Suggested-by: Kees Cook <keescook@chromium.org>)
* Mention the installation of the gcc plugin headers (Documentation)
Changes from v1:
* Move the gcc-plugins make target into a separate Makefile because there may
be a lot of plugins (Suggested-by: Rasmus Villemoes)
* Simplify the dependencies of the plugin related config option
(Suggested-by: Kees Cook <keescook@chromium.org>)
* Removed the unnecessary example plugin
---
Documentation/dontdiff | 1 +
Documentation/gcc-plugins.txt | 83 +++
Documentation/kbuild/makefiles.txt | 39 +-
MAINTAINERS | 8 +
Makefile | 42 +-
arch/Kconfig | 36 +
arch/arm/Kconfig | 1 +
arch/arm64/Kconfig | 1 +
arch/x86/Kconfig | 1 +
arch/x86/entry/vdso/Makefile | 3 +-
init/Makefile | 3 +
lib/Kconfig.debug | 2 +
scripts/Makefile | 2 +-
scripts/Makefile.build | 2 +-
scripts/Makefile.clean | 3 +-
scripts/Makefile.gcc-plugins | 29 +
scripts/Makefile.host | 70 +-
scripts/gcc-plugin.sh | 51 ++
scripts/gcc-plugins/Makefile | 21 +
scripts/gcc-plugins/cyc_complexity_plugin.c | 73 ++
scripts/gcc-plugins/gcc-common.h | 830 +++++++++++++++++++++
scripts/gcc-plugins/gcc-generate-gimple-pass.h | 175 +++++
scripts/gcc-plugins/gcc-generate-ipa-pass.h | 289 +++++++
scripts/gcc-plugins/gcc-generate-rtl-pass.h | 175 +++++
scripts/gcc-plugins/gcc-generate-simple_ipa-pass.h | 175 +++++
scripts/gcc-plugins/sancov_plugin.c | 143 ++++
scripts/link-vmlinux.sh | 2 +-
scripts/package/builddeb | 1 +
28 files changed, 2241 insertions(+), 20 deletions(-)
[toc] | [next] | [standalone]
| From | Emese Revfy <re.emese@gmail.com> |
|---|---|
| Date | 2016-04-07 23:20 +0200 |
| Subject | [PATCH v6 3/6] The GCC plugin infrastructure supports the arm and arm64 architectures too |
| Message-ID | <rlpvk-1uc-13@gated-at.bofh.it> |
| In reply to | #1373781 |
The GCC plugin infrastructure now supports the arm and arm64 architectures too. Signed-off-by: David Brown <david.brown@linaro.org> --- arch/arm/Kconfig | 1 + arch/arm64/Kconfig | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 0846026..8f57eb6 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -55,6 +55,7 @@ config ARM select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL) select HAVE_FUNCTION_TRACER if (!XIP_KERNEL) select HAVE_GENERIC_DMA_COHERENT + select HAVE_GCC_PLUGINS select HAVE_HW_BREAKPOINT if (PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7)) select HAVE_IDE if PCI || ISA || PCMCIA select HAVE_IRQ_TIME_ACCOUNTING diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 4f43622..22c9473 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -72,6 +72,7 @@ config ARM64 select HAVE_FTRACE_MCOUNT_RECORD select HAVE_FUNCTION_TRACER select HAVE_FUNCTION_GRAPH_TRACER + select HAVE_GCC_PLUGINS select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_IRQ_TIME_ACCOUNTING -- 2.4.1
[toc] | [prev] | [next] | [standalone]
| From | Emese Revfy <re.emese@gmail.com> |
|---|---|
| Date | 2016-04-07 23:20 +0200 |
| Subject | [PATCH v6 4/6] Add Cyclomatic complexity GCC plugin |
| Message-ID | <rlpvk-1uc-25@gated-at.bofh.it> |
| In reply to | #1373781 |
Add a very simple plugin to demonstrate the GCC plugin infrastructure. This GCC
plugin computes the cyclomatic complexity of each function.
The complexity M of a function's control flow graph is defined as:
M = E - N + 2P
where
E = the number of edges
N = the number of nodes
P = the number of connected components (exit nodes).
Signed-off-by: Emese Revfy <re.emese@gmail.com>
---
arch/Kconfig | 12 +++++
scripts/Makefile.gcc-plugins | 2 +
scripts/gcc-plugins/Makefile | 4 ++
scripts/gcc-plugins/cyc_complexity_plugin.c | 73 +++++++++++++++++++++++++++++
4 files changed, 91 insertions(+)
create mode 100644 scripts/gcc-plugins/cyc_complexity_plugin.c
diff --git a/arch/Kconfig b/arch/Kconfig
index 7c12571..ddf29b4 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -366,6 +366,18 @@ menuconfig GCC_PLUGINS
GCC plugins are loadable modules that provide extra features to the
compiler. They are useful for runtime instrumentation and static analysis.
+config GCC_PLUGIN_CYC_COMPLEXITY
+ bool "Compute the cyclomatic complexity of a function"
+ depends on GCC_PLUGINS
+ help
+ The complexity M of a function's control flow graph is defined as:
+ M = E - N + 2P
+ where
+
+ E = the number of edges
+ N = the number of nodes
+ P = the number of connected components (exit nodes).
+
config HAVE_CC_STACKPROTECTOR
bool
help
diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
index b981b65..34ad58b 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -2,6 +2,8 @@ ifdef CONFIG_GCC_PLUGINS
__PLUGINCC := $(call cc-ifversion, -ge, 0408, $(HOSTCXX), $(HOSTCC))
PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)")
+ gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so
+
GCC_PLUGINS_CFLAGS := $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y))
ifeq ($(PLUGINCC),)
diff --git a/scripts/gcc-plugins/Makefile b/scripts/gcc-plugins/Makefile
index b2d64af..31c72bf 100644
--- a/scripts/gcc-plugins/Makefile
+++ b/scripts/gcc-plugins/Makefile
@@ -12,4 +12,8 @@ endif
export GCCPLUGINS_DIR HOSTLIBS
+$(HOSTLIBS)-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) := cyc_complexity_plugin.so
+
always := $($(HOSTLIBS)-y)
+
+cyc_complexity_plugin-objs := cyc_complexity_plugin.o
diff --git a/scripts/gcc-plugins/cyc_complexity_plugin.c b/scripts/gcc-plugins/cyc_complexity_plugin.c
new file mode 100644
index 0000000..34df974
--- /dev/null
+++ b/scripts/gcc-plugins/cyc_complexity_plugin.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2011-2016 by Emese Revfy <re.emese@gmail.com>
+ * Licensed under the GPL v2, or (at your option) v3
+ *
+ * Homepage:
+ * https://github.com/ephox-gcc-plugins/cyclomatic_complexity
+ *
+ * http://en.wikipedia.org/wiki/Cyclomatic_complexity
+ * The complexity M is then defined as:
+ * M = E - N + 2P
+ * where
+ *
+ * E = the number of edges of the graph
+ * N = the number of nodes of the graph
+ * P = the number of connected components (exit nodes).
+ *
+ * Usage (4.5 - 5):
+ * $ make clean; make run
+ */
+
+#include "gcc-common.h"
+
+int plugin_is_GPL_compatible;
+
+static struct plugin_info cyc_complexity_plugin_info = {
+ .version = "20160225",
+ .help = "Cyclomatic Complexity\n",
+};
+
+static unsigned int cyc_complexity_execute(void)
+{
+ int complexity;
+ expanded_location xloc;
+
+ /* M = E - N + 2P */
+ complexity = n_edges_for_fn(cfun) - n_basic_blocks_for_fn(cfun) + 2;
+
+ xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
+ fprintf(stderr, "Cyclomatic Complexity %d %s:%s\n", complexity,
+ xloc.file, DECL_NAME_POINTER(current_function_decl));
+
+ return 0;
+}
+
+#define PASS_NAME cyc_complexity
+
+#define NO_GATE
+#define TODO_FLAGS_FINISH TODO_dump_func
+
+#include "gcc-generate-gimple-pass.h"
+
+int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
+{
+ const char * const plugin_name = plugin_info->base_name;
+ struct register_pass_info cyc_complexity_pass_info;
+
+ cyc_complexity_pass_info.pass = make_cyc_complexity_pass();
+ cyc_complexity_pass_info.reference_pass_name = "ssa";
+ cyc_complexity_pass_info.ref_pass_instance_number = 1;
+ cyc_complexity_pass_info.pos_op = PASS_POS_INSERT_AFTER;
+
+ if (!plugin_default_version_check(version, &gcc_version)) {
+ error(G_("incompatible gcc/plugin versions"));
+ return 1;
+ }
+
+ register_callback(plugin_name, PLUGIN_INFO, NULL,
+ &cyc_complexity_plugin_info);
+ register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL,
+ &cyc_complexity_pass_info);
+
+ return 0;
+}
--
2.4.1
[toc] | [prev] | [next] | [standalone]
| From | Emese Revfy <re.emese@gmail.com> |
|---|---|
| Date | 2016-04-07 23:30 +0200 |
| Subject | [PATCH v6 6/6] Add sancov plugin |
| Message-ID | <rlpEZ-1zn-1@gated-at.bofh.it> |
| In reply to | #1373781 |
The sancov gcc plugin inserts a __sanitizer_cov_trace_pc() call
at the start of basic blocks.
This plugin is a helper plugin for the kcov feature. It supports
all gcc versions with plugin support (from gcc-4.5 on).
It is based on the gcc commit "Add fuzzing coverage support" by Dmitry Vyukov
(https://gcc.gnu.org/viewcvs/gcc?limit_changes=0&view=revision&revision=231296).
Signed-off-by: Emese Revfy <re.emese@gmail.com>
---
Makefile | 8 +-
arch/Kconfig | 9 +++
lib/Kconfig.debug | 2 +
scripts/Makefile.gcc-plugins | 9 +++
scripts/gcc-plugins/Makefile | 2 +
scripts/gcc-plugins/sancov_plugin.c | 143 ++++++++++++++++++++++++++++++++++++
6 files changed, 170 insertions(+), 3 deletions(-)
create mode 100644 scripts/gcc-plugins/sancov_plugin.c
diff --git a/Makefile b/Makefile
index 3af7b9e..e079cb4 100644
--- a/Makefile
+++ b/Makefile
@@ -686,10 +686,12 @@ endif
KBUILD_CFLAGS += $(stackp-flag)
ifdef CONFIG_KCOV
- ifeq ($(call cc-option, $(CFLAGS_KCOV)),)
- $(warning Cannot use CONFIG_KCOV: \
+ ifneq ($(CFLAGS_KCOV),)
+ ifeq ($(call cc-option, $(CFLAGS_KCOV)),)
+ $(warning Cannot use CONFIG_KCOV: \
-fsanitize-coverage=trace-pc is not supported by compiler)
- CFLAGS_KCOV =
+ CFLAGS_KCOV =
+ endif
endif
endif
diff --git a/arch/Kconfig b/arch/Kconfig
index e783429..5d856c8 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -380,6 +380,15 @@ config GCC_PLUGIN_CYC_COMPLEXITY
N = the number of nodes
P = the number of connected components (exit nodes).
+config GCC_PLUGIN_SANCOV
+ bool
+ depends on GCC_PLUGINS
+ help
+ This plugin inserts a __sanitizer_cov_trace_pc() call at the start of
+ basic blocks. It supports all gcc versions with plugin support (from
+ gcc-4.5 on). It is based on the commit "Add fuzzing coverage support"
+ by Dmitry Vyukov <dvyukov@google.com>.
+
config HAVE_CC_STACKPROTECTOR
bool
help
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index f4b797a..507d3fc 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -707,6 +707,8 @@ config KCOV
bool "Code coverage for fuzzing"
depends on ARCH_HAS_KCOV
select DEBUG_FS
+ select GCC_PLUGINS
+ select GCC_PLUGIN_SANCOV
help
KCOV exposes kernel code coverage information in a form suitable
for coverage-guided fuzzing (randomized testing).
diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
index 34ad58b..25a70fb 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -4,6 +4,15 @@ ifdef CONFIG_GCC_PLUGINS
gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so
+ ifdef CONFIG_GCC_PLUGIN_SANCOV
+ ifeq ($(call cc-option, $(CFLAGS_KCOV)),)
+ gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so
+ ifneq ($(PLUGINCC),)
+ CFLAGS_KCOV =
+ endif
+ endif
+ endif
+
GCC_PLUGINS_CFLAGS := $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y))
ifeq ($(PLUGINCC),)
diff --git a/scripts/gcc-plugins/Makefile b/scripts/gcc-plugins/Makefile
index 31c72bf..97a923f 100644
--- a/scripts/gcc-plugins/Makefile
+++ b/scripts/gcc-plugins/Makefile
@@ -13,7 +13,9 @@ endif
export GCCPLUGINS_DIR HOSTLIBS
$(HOSTLIBS)-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) := cyc_complexity_plugin.so
+$(HOSTLIBS)-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so
always := $($(HOSTLIBS)-y)
cyc_complexity_plugin-objs := cyc_complexity_plugin.o
+sancov_plugin-objs := sancov_plugin.o
diff --git a/scripts/gcc-plugins/sancov_plugin.c b/scripts/gcc-plugins/sancov_plugin.c
new file mode 100644
index 0000000..1311744
--- /dev/null
+++ b/scripts/gcc-plugins/sancov_plugin.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2011-2016 by Emese Revfy <re.emese@gmail.com>
+ * Licensed under the GPL v2, or (at your option) v3
+ *
+ * Homepage:
+ * https://github.com/ephox-gcc-plugins/sancov
+ *
+ * This plugin inserts a __sanitizer_cov_trace_pc() call at the start of basic blocks.
+ * It supports all gcc versions with plugin support (from gcc-4.5 on).
+ * It is based on the commit "Add fuzzing coverage support" by Dmitry Vyukov <dvyukov@google.com>.
+ *
+ * You can read about it more here:
+ * https://gcc.gnu.org/viewcvs/gcc?limit_changes=0&view=revision&revision=231296
+ * http://lwn.net/Articles/674854/
+ * https://github.com/google/syzkaller
+ * https://lwn.net/Articles/677764/
+ *
+ * Usage:
+ * make run
+ */
+
+#include "gcc-common.h"
+
+int plugin_is_GPL_compatible;
+
+tree sancov_fndecl;
+
+static struct plugin_info sancov_plugin_info = {
+ .version = "20160402",
+ .help = "sancov plugin\n",
+};
+
+static unsigned int sancov_execute(void)
+{
+ basic_block bb;
+
+ /* Remove this line when this plugin and kcov will be in the kernel. */
+ if (!strcmp(DECL_NAME_POINTER(current_function_decl), DECL_NAME_POINTER(sancov_fndecl)))
+ return 0;
+
+ FOR_EACH_BB_FN(bb, cfun) {
+ const_gimple stmt;
+ gcall *gcall;
+ gimple_stmt_iterator gsi = gsi_after_labels(bb);
+
+ if (gsi_end_p(gsi))
+ continue;
+
+ stmt = gsi_stmt(gsi);
+ gcall = as_a_gcall(gimple_build_call(sancov_fndecl, 0));
+ gimple_set_location(gcall, gimple_location(stmt));
+ gsi_insert_before(&gsi, gcall, GSI_SAME_STMT);
+ }
+ return 0;
+}
+
+#define PASS_NAME sancov
+
+#define NO_GATE
+#define TODO_FLAGS_FINISH TODO_dump_func | TODO_verify_stmts | TODO_update_ssa_no_phi | TODO_verify_flow
+
+#include "gcc-generate-gimple-pass.h"
+
+static void sancov_start_unit(void __unused *gcc_data, void __unused *user_data)
+{
+ tree leaf_attr, nothrow_attr;
+ tree BT_FN_VOID = build_function_type_list(void_type_node, NULL_TREE);
+
+ sancov_fndecl = build_fn_decl("__sanitizer_cov_trace_pc", BT_FN_VOID);
+
+ DECL_ASSEMBLER_NAME(sancov_fndecl);
+ TREE_PUBLIC(sancov_fndecl) = 1;
+ DECL_EXTERNAL(sancov_fndecl) = 1;
+ DECL_ARTIFICIAL(sancov_fndecl) = 1;
+ DECL_PRESERVE_P(sancov_fndecl) = 1;
+ DECL_UNINLINABLE(sancov_fndecl) = 1;
+ TREE_USED(sancov_fndecl) = 1;
+
+ nothrow_attr = tree_cons(get_identifier("nothrow"), NULL, NULL);
+ decl_attributes(&sancov_fndecl, nothrow_attr, 0);
+ gcc_assert(TREE_NOTHROW(sancov_fndecl));
+#if BUILDING_GCC_VERSION > 4005
+ leaf_attr = tree_cons(get_identifier("leaf"), NULL, NULL);
+ decl_attributes(&sancov_fndecl, leaf_attr, 0);
+#endif
+}
+
+int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
+{
+ int i;
+ struct register_pass_info sancov_plugin_pass_info;
+ const char * const plugin_name = plugin_info->base_name;
+ const int argc = plugin_info->argc;
+ const struct plugin_argument * const argv = plugin_info->argv;
+ bool enable = true;
+
+ static const struct ggc_root_tab gt_ggc_r_gt_sancov[] = {
+ {
+ .base = &sancov_fndecl,
+ .nelt = 1,
+ .stride = sizeof(sancov_fndecl),
+ .cb = >_ggc_mx_tree_node,
+ .pchw = >_pch_nx_tree_node
+ },
+ LAST_GGC_ROOT_TAB
+ };
+
+ /* BBs can be split afterwards?? */
+ sancov_plugin_pass_info.pass = make_sancov_pass();
+#if BUILDING_GCC_VERSION >= 4009
+ sancov_plugin_pass_info.reference_pass_name = "asan";
+#else
+ sancov_plugin_pass_info.reference_pass_name = "nrv";
+#endif
+ sancov_plugin_pass_info.ref_pass_instance_number = 0;
+ sancov_plugin_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
+
+ if (!plugin_default_version_check(version, &gcc_version)) {
+ error(G_("incompatible gcc/plugin versions"));
+ return 1;
+ }
+
+ for (i = 0; i < argc; ++i) {
+ if (!strcmp(argv[i].key, "no-sancov")) {
+ enable = false;
+ continue;
+ }
+ error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
+ }
+
+ register_callback(plugin_name, PLUGIN_INFO, NULL, &sancov_plugin_info);
+
+ if (!enable)
+ return 0;
+
+#if BUILDING_GCC_VERSION < 6000
+ register_callback(plugin_name, PLUGIN_START_UNIT, &sancov_start_unit, NULL);
+ register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)>_ggc_r_gt_sancov);
+ register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &sancov_plugin_pass_info);
+#endif
+
+ return 0;
+}
--
2.4.1
[toc] | [prev] | [next] | [standalone]
| From | Emese Revfy <re.emese@gmail.com> |
|---|---|
| Date | 2016-04-07 23:30 +0200 |
| Subject | [PATCH v6 5/6] Documentation for the GCC plugin infrastructure |
| Message-ID | <rlpEZ-1zn-3@gated-at.bofh.it> |
| In reply to | #1373781 |
This is the GCC infrastructure documentation about its operation, how to add and use a new plugin with an example. Signed-off-by: Emese Revfy <re.emese@gmail.com> --- Documentation/gcc-plugins.txt | 83 +++++++++++++++++++++++++++++++++++++++++++ arch/Kconfig | 2 ++ 2 files changed, 85 insertions(+) create mode 100644 Documentation/gcc-plugins.txt diff --git a/Documentation/gcc-plugins.txt b/Documentation/gcc-plugins.txt new file mode 100644 index 0000000..9fa9bd2 --- /dev/null +++ b/Documentation/gcc-plugins.txt @@ -0,0 +1,83 @@ +GCC plugin infrastructure +========================= + + +1. Introduction +=============== + +GCC plugins are loadable modules that provide extra features to the +compiler [1]. They are useful for runtime instrumentation and static analysis. +We can analyse, change and add further code during compilation via +callbacks [2], GIMPLE [3], IPA [4] and RTL passes [5]. + +The GCC plugin infrastructure of the kernel supports all gcc versions from +4.5 to 6.0, building out-of-tree modules, cross-compilation and building in a +separate directory. + +Currently the GCC plugin infrastructure supports only the x86, arm and arm64 +architectures. + +This infrastructure was ported from grsecurity [6] and PaX [7]. + +-- +[1] https://gcc.gnu.org/onlinedocs/gccint/Plugins.html +[2] https://gcc.gnu.org/onlinedocs/gccint/Plugin-API.html#Plugin-API +[3] https://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html +[4] https://gcc.gnu.org/onlinedocs/gccint/IPA.html +[5] https://gcc.gnu.org/onlinedocs/gccint/RTL.html +[6] https://grsecurity.net/ +[7] https://pax.grsecurity.net/ + + +2. Files +======== + +$(src)/scripts/gcc-plugins + This is the directory of the GCC plugins. + +$(src)/scripts/gcc-plugins/gcc-common.h + This is a compatibility header for GCC plugins. + It should be always included instead of individual gcc headers. + +$(src)/scripts/gcc-plugin.sh + This script checks the availability of the included headers in + gcc-common.h and chooses the proper host compiler to build the plugins + (gcc-4.7 can be built by either gcc or g++). + +$(src)/scripts/gcc-plugins/gcc-generate-gimple-pass.h +$(src)/scripts/gcc-plugins/gcc-generate-ipa-pass.h +$(src)/scripts/gcc-plugins/gcc-generate-simple_ipa-pass.h +$(src)/scripts/gcc-plugins/gcc-generate-rtl-pass.h + These headers automatically generate the registration structures for + GIMPLE, SIMPLE_IPA, IPA and RTL passes. They support all gcc versions + from 4.5 to 6.0. + They should be preferred to creating the structures by hand. + + +3. Usage +======== + +You must install the gcc plugin headers for your gcc version, +e.g., on Ubuntu for gcc-4.9: + + apt-get install gcc-4.9-plugin-dev + +Enable a GCC plugin based feature in the kernel config: + + CONFIG_GCC_PLUGIN_CYC_COMPLEXITY = y + +To compile only the plugin(s): + + make gcc-plugins + +or just run the kernel make and compile the whole kernel with +the cyclomatic complexity GCC plugin. + + +4. How to add a new GCC plugin +============================== + +The GCC plugins are in $(src)/scripts/gcc-plugins/. You can use a file or a directory +here. It must be added to $(src)/scripts/gcc-plugins/Makefile, +$(src)/scripts/Makefile.gcc-plugins and $(src)/arch/Kconfig. +See the cyc_complexity_plugin.c (CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) GCC plugin. diff --git a/arch/Kconfig b/arch/Kconfig index ddf29b4..e783429 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -366,6 +366,8 @@ menuconfig GCC_PLUGINS GCC plugins are loadable modules that provide extra features to the compiler. They are useful for runtime instrumentation and static analysis. + See Documentation/gcc-plugins.txt for details. + config GCC_PLUGIN_CYC_COMPLEXITY bool "Compute the cyclomatic complexity of a function" depends on GCC_PLUGINS -- 2.4.1
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@linaro.org> |
|---|---|
| Date | 2016-04-12 19:50 +0200 |
| Message-ID | <rnaBQ-2QL-13@gated-at.bofh.it> |
| In reply to | #1373781 |
On Thu, Apr 07, 2016 at 11:10:23PM +0200, Emese Revfy wrote: >This patch set introduce the GCC plugin infrastructure with examples for testing >and documentation. > >GCC plugins are loadable modules that provide extra features to the compiler. >They are useful for runtime instrumentation and static analysis. > >The infrastructure supports all gcc versions from 4.5 to 6.0, building >out-of-tree modules and building in a separate directory. Cross-compilation >is supported too but currently only the x86, arm and arm64 architectures enables plugins. > >This infrastructure was ported from grsecurity/PaX. It is a CII project >supported by the Linux Foundation. > >Emese Revfy (6): > Shared library support > GCC plugin infrastructure > The GCC plugin infrastructure supports the arm and arm64 architectures too > Add Cyclomatic complexity plugin > Documentations of the GCC plugin infrastructre > Add sancov plugin I've tested the v6 patches on arm, and partially on arm64. The arm64 gcc has a bug in make install that doesn't install all necessary headers to build plugins. I believe the patch will work once that version gets out. It does, however, print a helpful message now explaining the likely cause of the failure. Tested-by: David Brown <david.brown@linaro.org>
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@chromium.org> |
|---|---|
| Date | 2016-04-12 20:30 +0200 |
| Message-ID | <rnbez-3s3-19@gated-at.bofh.it> |
| In reply to | #1377049 |
On Tue, Apr 12, 2016 at 10:46 AM, David Brown <david.brown@linaro.org> wrote: > On Thu, Apr 07, 2016 at 11:10:23PM +0200, Emese Revfy wrote: >> >> This patch set introduce the GCC plugin infrastructure with examples for >> testing >> and documentation. >> >> GCC plugins are loadable modules that provide extra features to the >> compiler. >> They are useful for runtime instrumentation and static analysis. >> >> The infrastructure supports all gcc versions from 4.5 to 6.0, building >> out-of-tree modules and building in a separate directory. >> Cross-compilation >> is supported too but currently only the x86, arm and arm64 architectures >> enables plugins. >> >> This infrastructure was ported from grsecurity/PaX. It is a CII project >> supported by the Linux Foundation. >> >> Emese Revfy (6): >> Shared library support >> GCC plugin infrastructure >> The GCC plugin infrastructure supports the arm and arm64 architectures too >> Add Cyclomatic complexity plugin >> Documentations of the GCC plugin infrastructre >> Add sancov plugin > > > I've tested the v6 patches on arm, and partially on arm64. The arm64 > gcc has a bug in make install that doesn't install all necessary > headers to build plugins. I believe the patch will work once that > version gets out. It does, however, print a helpful message now > explaining the likely cause of the failure. > > Tested-by: David Brown <david.brown@linaro.org> Awesome! Thanks for testing this. I still need to finish getting my arm64 environment built... Do you happen to know if there's already a gcc bug open for the make install problem? Masahiro and Michal, does this series look good to you? I'd really like to get this into -next for wider testing. Emese, were you thinking of doing the initify plugin next after this infrastructure lands? -Kees -- Kees Cook Chrome OS & Brillo Security
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@linaro.org> |
|---|---|
| Date | 2016-04-12 20:50 +0200 |
| Message-ID | <rnbxT-3BX-7@gated-at.bofh.it> |
| In reply to | #1377110 |
On Tue, Apr 12, 2016 at 11:27:52AM -0700, Kees Cook wrote: >Awesome! Thanks for testing this. I still need to finish getting my >arm64 environment built... I've been using: http://releases.linaro.org/components/toolchain/binaries/ for most stuff. >Do you happen to know if there's already a gcc bug open for the make >install problem? Linaro toolchain bug: https://bugs.linaro.org/show_bug.cgi?id=2123 Patch to fix it https://gcc.gnu.org/ml/gcc-patches/2016-03/msg00522.html It is supposed to be included in the linaro 5.3-2016.03 snapshot. I've pinged Christophe to see if I can get any insight into when that will be available. It is kind of nice to see that when it fails, it prints a helpful message, though: scripts/Makefile.gcc-plugins:22: *** error, your gcc installation does not support plugins, perhaps the necessary headers are missing?. Stop. I think it is OK to include this, even with the patches still bubbling through gcc releases. It prints a helpful message when it doesn't work, and is only going to be selected if specifically requested. David
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@chromium.org> |
|---|---|
| Date | 2016-04-12 21:50 +0200 |
| Message-ID | <rnctX-4hV-9@gated-at.bofh.it> |
| In reply to | #1377117 |
On Tue, Apr 12, 2016 at 11:41 AM, David Brown <david.brown@linaro.org> wrote: > On Tue, Apr 12, 2016 at 11:27:52AM -0700, Kees Cook wrote: > >> Awesome! Thanks for testing this. I still need to finish getting my >> arm64 environment built... > > > I've been using: > http://releases.linaro.org/components/toolchain/binaries/ > > for most stuff. > >> Do you happen to know if there's already a gcc bug open for the make >> install problem? > > > Linaro toolchain bug: > https://bugs.linaro.org/show_bug.cgi?id=2123 > > Patch to fix it > https://gcc.gnu.org/ml/gcc-patches/2016-03/msg00522.html > > It is supposed to be included in the linaro 5.3-2016.03 snapshot. > I've pinged Christophe to see if I can get any insight into when that > will be available. Looks like it's in the upstream tree: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=bfe972081c3c75019fa5a6e883dcbeb5e03eea18 I'm not sure how GCC does bug fix releases. Is this going to be in 5.4 or 5.3.1? (Is there such a thing as 5.3.1 planned?) I've CCed Jeff in case he's got a moment to peek at this. > It is kind of nice to see that when it fails, it prints a helpful > message, though: > > scripts/Makefile.gcc-plugins:22: *** error, your gcc installation does not > support plugins, perhaps the necessary headers are missing?. Stop. > > I think it is OK to include this, even with the patches still bubbling > through gcc releases. It prints a helpful message when it doesn't > work, and is only going to be selected if specifically requested. Yeah, absolutely. It works on the other architectures, and will soon work on arm64 too. -Kees -- Kees Cook Chrome OS & Brillo Security
[toc] | [prev] | [next] | [standalone]
| From | "PaX Team" <pageexec@freemail.hu> |
|---|---|
| Date | 2016-04-12 23:30 +0200 |
| Message-ID | <rne2M-5Op-49@gated-at.bofh.it> |
| In reply to | #1377135 |
On 12 Apr 2016 at 12:46, Kees Cook wrote: > Looks like it's in the upstream tree: > > https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=bfe972081c3c75019fa5a6e883dcbeb5e03eea18 > > I'm not sure how GCC does bug fix releases. Is this going to be in 5.4 > or 5.3.1? (Is there such a thing as 5.3.1 planned?) I've CCed Jeff in > case he's got a moment to peek at this. gcc-5 will be maintained until gcc-7 (due in a year) so this commit will end up in the next minor release (5.4) eventually.
[toc] | [prev] | [next] | [standalone]
| From | Emese Revfy <re.emese@gmail.com> |
|---|---|
| Date | 2016-04-12 21:00 +0200 |
| Message-ID | <rnbHz-3FG-1@gated-at.bofh.it> |
| In reply to | #1377110 |
On Tue, 12 Apr 2016 11:27:52 -0700 Kees Cook <keescook@chromium.org> wrote: > Emese, were you thinking of doing the initify plugin next after this > infrastructure lands? I already started to work on the entropy plugin but after that I can work on initify. -- Emese
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@chromium.org> |
|---|---|
| Date | 2016-04-12 21:50 +0200 |
| Message-ID | <rnctX-4hV-3@gated-at.bofh.it> |
| In reply to | #1377120 |
On Tue, Apr 12, 2016 at 11:52 AM, Emese Revfy <re.emese@gmail.com> wrote: > On Tue, 12 Apr 2016 11:27:52 -0700 > Kees Cook <keescook@chromium.org> wrote: > >> Emese, were you thinking of doing the initify plugin next after this >> infrastructure lands? > > I already started to work on the entropy plugin but after that I can work on initify. Ah yes, thanks! I'd forgotten you'd mentioned the entropy plugin previously. Great! -Kees -- Kees Cook Chrome OS & Brillo Security
[toc] | [prev] | [next] | [standalone]
| From | Masahiro Yamada <yamada.masahiro@socionext.com> |
|---|---|
| Date | 2016-04-13 04:40 +0200 |
| Subject | Re: [PATCH v6 2/6] GCC plugin infrastructure |
| Message-ID | <rniSJ-1yu-5@gated-at.bofh.it> |
| In reply to | #1373781 |
Hi Emese,
2016-04-08 6:13 GMT+09:00 Emese Revfy <re.emese@gmail.com>:
> diff --git a/Makefile b/Makefile
> index 173437d..3af7b9e 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -418,6 +418,8 @@ export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
> export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
> export KBUILD_ARFLAGS
>
> +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS
> +
> # When compiling out-of-tree modules, put MODVERDIR in the module
> # tree rather than in the kernel tree. The kernel tree might
> # even be read-only.
> @@ -548,7 +550,7 @@ ifeq ($(KBUILD_EXTMOD),)
> # in parallel
> PHONY += scripts
> scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \
> - asm-generic
> + asm-generic gcc-plugins
> $(Q)$(MAKE) $(build)=$(@)
>
> # Objects we will link into vmlinux / subdirs we need to visit
> @@ -623,6 +625,15 @@ endif
> # Tell gcc to never replace conditional load with a non-conditional one
> KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
>
> +PHONY += gcc-plugins
> +gcc-plugins: scripts_basic
> +ifdef CONFIG_GCC_PLUGINS
> + $(Q)$(MAKE) $(build)=scripts/gcc-plugins
> +endif
> + @:
> +
> +include scripts/Makefile.gcc-plugins
> +
> ifdef CONFIG_READABLE_ASM
> # Disable optimizations that make assembler listings hard to read.
> # reorder blocks reorders the control in the function
> @@ -949,6 +960,8 @@ endif
>
> # The actual objects are generated when descending,
> # make sure no implicit rule kicks in
> +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
> +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
> $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
I do not get your intention here.
It looks like you are trying to omit plugin flags for init/ directory.
(Actually this code is not working, though)
Then, you add plug the following lines to init/Makefile
+ccflags-y := $(GCC_PLUGINS_CFLAGS)
+asflags-y := $(GCC_PLUGINS_AFLAGS)
> # Handle descending into subdirectories listed in $(vmlinux-dirs)
> @@ -1001,10 +1014,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
>
> archprepare: archheaders archscripts prepare1 scripts_basic
>
> -prepare0: archprepare FORCE
> +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
> +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
> +prepare0: archprepare gcc-plugins FORCE
> $(Q)$(MAKE) $(build)=.
>
> # All the preparing..
> +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
> prepare: prepare0 prepare-objtool
>
> ifdef CONFIG_STACK_VALIDATION
> @@ -1137,6 +1153,8 @@ all: modules
> # using awk while concatenating to the final file.
>
> PHONY += modules
> +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
> +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
> modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
> $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
> @$(kecho) ' Building modules, stage 2.';
> @@ -1257,7 +1275,7 @@ distclean: mrproper
> @find $(srctree) $(RCS_FIND_IGNORE) \
> \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
> -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
> - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
> + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
> -type f -print | xargs rm -f
>
>
> @@ -1426,6 +1444,8 @@ PHONY += $(module-dirs) modules
> $(module-dirs): crmodverdir $(objtree)/Module.symvers
> $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
>
> +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
> +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
> modules: $(module-dirs)
> @$(kecho) ' Building modules, stage 2.';
> $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
> @@ -1567,10 +1587,14 @@ else
> target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
> endif
>
> +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
> +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
> %.s: %.c prepare scripts FORCE
> $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
> %.i: %.c prepare scripts FORCE
> $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
> +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
> +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
> %.o: %.c prepare scripts FORCE
> $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
> %.lst: %.c prepare scripts FORCE
> @@ -1589,10 +1613,14 @@ endif
> $(build)=$(build-dir)
> # Make sure the latest headers are built for Documentation
> Documentation/: headers_install
> +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
> +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
> %/: prepare scripts FORCE
> $(cmd_crmodverdir)
> $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
> $(build)=$(build-dir)
> +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
> +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
> %.ko: prepare scripts FORCE
> $(cmd_crmodverdir)
> $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
Why do you need to sprinkle "KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)"
here and there?
Unless I am missing something, I think the following should work.
diff --git a/Makefile b/Makefile
index 5d65f4b..f85420b 100644
--- a/Makefile
+++ b/Makefile
@@ -962,8 +962,6 @@ endif
# The actual objects are generated when descending,
# make sure no implicit rule kicks in
-$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
-$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
$(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
# Handle descending into subdirectories listed in $(vmlinux-dirs)
@@ -1016,13 +1014,10 @@ prepare1: prepare2 $(version_h)
include/generated/utsrelease.h
archprepare: archheaders archscripts prepare1 scripts_basic
-prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
-prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
prepare0: archprepare gcc-plugins FORCE
$(Q)$(MAKE) $(build)=.
# All the preparing..
-prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
prepare: prepare0 prepare-objtool
ifdef CONFIG_STACK_VALIDATION
@@ -1155,8 +1150,6 @@ all: modules
# using awk while concatenating to the final file.
PHONY += modules
-modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
-modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
$(Q)$(AWK) '!x[$$0]++'
$(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtre
@$(kecho) ' Building modules, stage 2.';
@@ -1446,8 +1439,6 @@ PHONY += $(module-dirs) modules
$(module-dirs): crmodverdir $(objtree)/Module.symvers
$(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
-modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
-modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
modules: $(module-dirs)
@$(kecho) ' Building modules, stage 2.';
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
@@ -1589,14 +1580,10 @@ else
target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
endif
-%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
-%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
%.s: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.i: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
-%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
-%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
%.o: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.lst: %.c prepare scripts FORCE
@@ -1615,14 +1602,10 @@ endif
$(build)=$(build-dir)
# Make sure the latest headers are built for Documentation
Documentation/: headers_install
-%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
-%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
%/: prepare scripts FORCE
$(cmd_crmodverdir)
$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
$(build)=$(build-dir)
-%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
-%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
%.ko: prepare scripts FORCE
$(cmd_crmodverdir)
$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
index 25a70fb..34d6224 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -26,4 +26,6 @@ ifdef CONFIG_GCC_PLUGINS
endif
endif
+ KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
+
endif
--
Best Regards
Masahiro Yamada
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web