Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1351220 > unrolled thread

[PATCH v5 0/5] Introduce GCC plugin infrastructure

Started byEmese Revfy <re.emese@gmail.com>
First post2016-03-07 00:10 +0100
Last post2016-03-17 05:20 +0100
Articles 20 on this page of 26 — 6 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v5 0/5] Introduce GCC plugin infrastructure Emese Revfy <re.emese@gmail.com> - 2016-03-07 00:10 +0100
    [PATCH v5 3/5] Add Cyclomatic complexity GCC plugin Emese Revfy <re.emese@gmail.com> - 2016-03-07 00:10 +0100
      Re: [PATCH v5 3/5] Add Cyclomatic complexity GCC plugin Masahiro Yamada <yamada.masahiro@socionext.com> - 2016-03-11 07:30 +0100
        Re: [PATCH v5 3/5] Add Cyclomatic complexity GCC plugin Emese Revfy <re.emese@gmail.com> - 2016-03-14 22:10 +0100
    [PATCH v5 5/5] Add sancov plugin Emese Revfy <re.emese@gmail.com> - 2016-03-07 00:10 +0100
      Re: [PATCH v5 5/5] Add sancov plugin Kees Cook <keescook@chromium.org> - 2016-03-07 22:10 +0100
        Re: [PATCH v5 5/5] Add sancov plugin Emese Revfy <re.emese@gmail.com> - 2016-03-07 22:40 +0100
        Re: [PATCH v5 5/5] Add sancov plugin Dmitry Vyukov <dvyukov@google.com> - 2016-03-08 12:00 +0100
    [PATCH v5 1/5] Shared library support Emese Revfy <re.emese@gmail.com> - 2016-03-07 00:10 +0100
      Re: [PATCH v5 1/5] Shared library support Kees Cook <keescook@chromium.org> - 2016-03-07 22:10 +0100
        Re: [PATCH v5 1/5] Shared library support Emese Revfy <re.emese@gmail.com> - 2016-03-07 22:40 +0100
      Re: [PATCH v5 1/5] Shared library support Masahiro Yamada <yamada.masahiro@socionext.com> - 2016-03-11 07:30 +0100
        Re: [PATCH v5 1/5] Shared library support Emese Revfy <re.emese@gmail.com> - 2016-03-14 21:20 +0100
          Re: [PATCH v5 1/5] Shared library support Masahiro Yamada <yamada.masahiro@socionext.com> - 2016-03-16 09:00 +0100
    Re: [kernel-hardening] [PATCH v5 2/5] GCC plugin infrastructure David Brown <david.brown@linaro.org> - 2016-03-09 10:10 +0100
      Re: [kernel-hardening] [PATCH v5 2/5] GCC plugin infrastructure Kees Cook <keescook@chromium.org> - 2016-03-09 22:00 +0100
        Re: [kernel-hardening] [PATCH v5 2/5] GCC plugin infrastructure Emese Revfy <re.emese@gmail.com> - 2016-03-09 23:10 +0100
      Re: [kernel-hardening] [PATCH v5 2/5] GCC plugin infrastructure Emese Revfy <re.emese@gmail.com> - 2016-03-09 23:10 +0100
    Re: [PATCH v5 2/5] GCC plugin infrastructure Masahiro Yamada <yamada.masahiro@socionext.com> - 2016-03-11 07:30 +0100
      Re: [PATCH v5 2/5] GCC plugin infrastructure Emese Revfy <re.emese@gmail.com> - 2016-03-14 22:00 +0100
        Re: [PATCH v5 2/5] GCC plugin infrastructure Masahiro Yamada <yamada.masahiro@socionext.com> - 2016-03-16 08:50 +0100
          Re: [PATCH v5 2/5] GCC plugin infrastructure Emese Revfy <re.emese@gmail.com> - 2016-03-16 22:10 +0100
      Re: [PATCH v5 2/5] GCC plugin infrastructure "PaX Team" <pageexec@freemail.hu> - 2016-03-14 22:30 +0100
        Re: [PATCH v5 2/5] GCC plugin infrastructure Masahiro Yamada <yamada.masahiro@socionext.com> - 2016-03-16 08:40 +0100
          Re: [PATCH v5 2/5] GCC plugin infrastructure "PaX Team" <pageexec@freemail.hu> - 2016-03-16 14:00 +0100
            Re: [PATCH v5 2/5] GCC plugin infrastructure Masahiro Yamada <yamada.masahiro@socionext.com> - 2016-03-17 05:20 +0100

Page 1 of 2  [1] 2  Next page →


#1351220 — [PATCH v5 0/5] Introduce GCC plugin infrastructure

FromEmese Revfy <re.emese@gmail.com>
Date2016-03-07 00:10 +0100
Subject[PATCH v5 0/5] Introduce GCC plugin infrastructure
Message-ID<r9PYe-39m-1@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 architecture enables plugins.

This infrastructure was ported from grsecurity/PaX. It is a CII project
supported by the Linux Foundation.

Emese Revfy (5):
 Shared library support
 GCC plugin infrastructure
 Add Cyclomatic complexity plugin
 Documentations of the GCC plugin infrastructre
 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            |  82 ++++++++++++++++++
 MAINTAINERS                              |   8 ++
 Makefile                                 |  41 ++++++---
 arch/Kconfig                             |  36 ++++++++
 arch/x86/Kconfig                         |   1 +
 arch/x86/entry/vdso/Makefile             |   2 +-
 init/Makefile                            |   3 +
 scripts/Makefile.gcc-plugins             |  35 ++++++++
 scripts/gcc-plugin.sh                    |  51 +++++++++++
 scripts/link-vmlinux.sh                  |   2 +-
 scripts/package/builddeb                 |   1 +
 tools/gcc/Makefile                       |  21 +++++
 tools/gcc/cyc_complexity_plugin.c        |  73 ++++++++++++++++
 tools/gcc/gcc-common.h                   | 830 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/gcc/gcc-generate-gimple-pass.h     | 175 ++++++++++++++++++++++++++++++++++++++
 tools/gcc/gcc-generate-ipa-pass.h        | 289 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/gcc/gcc-generate-rtl-pass.h        | 175 ++++++++++++++++++++++++++++++++++++++
 tools/gcc/gcc-generate-simple_ipa-pass.h | 175 ++++++++++++++++++++++++++++++++++++++
 tools/gcc/sancov_plugin.c                | 133 +++++++++++++++++++++++++++++
 20 files changed, 2121 insertions(+), 13 deletions(-)

[toc] | [next] | [standalone]


#1351221 — [PATCH v5 3/5] Add Cyclomatic complexity GCC plugin

FromEmese Revfy <re.emese@gmail.com>
Date2016-03-07 00:10 +0100
Subject[PATCH v5 3/5] Add Cyclomatic complexity GCC plugin
Message-ID<r9PYe-39m-13@gated-at.bofh.it>
In reply to#1351220
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      |  6 +++-
 tools/gcc/Makefile                |  4 +++
 tools/gcc/cyc_complexity_plugin.c | 73 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 94 insertions(+), 1 deletion(-)
 create mode 100644 tools/gcc/cyc_complexity_plugin.c

diff --git a/arch/Kconfig b/arch/Kconfig
index e090642..59bde9b 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -370,6 +370,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 7c85bf2..dd7b56d 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -5,7 +5,11 @@ else
 PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
 endif
 ifneq ($(PLUGINCC),)
-export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS
+ifdef CONFIG_GCC_PLUGIN_CYC_COMPLEXITY
+GCC_PLUGIN_CYC_COMPLEXITY_CFLAGS := -fplugin=$(objtree)/tools/gcc/cyc_complexity_plugin.so
+endif
+GCC_PLUGINS_CFLAGS := $(GCC_PLUGIN_CYC_COMPLEXITY_CFLAGS)
+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS GCC_PLUGIN_CYC_COMPLEXITY
 ifeq ($(KBUILD_EXTMOD),)
 gcc-plugins:
 	$(Q)$(MAKE) $(build)=tools/gcc
diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
index b2d64af..31c72bf 100644
--- a/tools/gcc/Makefile
+++ b/tools/gcc/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/tools/gcc/cyc_complexity_plugin.c b/tools/gcc/cyc_complexity_plugin.c
new file mode 100644
index 0000000..34df974
--- /dev/null
+++ b/tools/gcc/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]


#1355624 — Re: [PATCH v5 3/5] Add Cyclomatic complexity GCC plugin

FromMasahiro Yamada <yamada.masahiro@socionext.com>
Date2016-03-11 07:30 +0100
SubjectRe: [PATCH v5 3/5] Add Cyclomatic complexity GCC plugin
Message-ID<rboKe-1W9-15@gated-at.bofh.it>
In reply to#1351221
Hi Emese,


2016-03-07 8:05 GMT+09:00 Emese Revfy <re.emese@gmail.com>:
> 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      |  6 +++-
>  tools/gcc/Makefile                |  4 +++
>  tools/gcc/cyc_complexity_plugin.c | 73 +++++++++++++++++++++++++++++++++++++++
>  4 files changed, 94 insertions(+), 1 deletion(-)
>  create mode 100644 tools/gcc/cyc_complexity_plugin.c
>
> diff --git a/arch/Kconfig b/arch/Kconfig
> index e090642..59bde9b 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -370,6 +370,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 7c85bf2..dd7b56d 100644
> --- a/scripts/Makefile.gcc-plugins
> +++ b/scripts/Makefile.gcc-plugins
> @@ -5,7 +5,11 @@ else
>  PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
>  endif
>  ifneq ($(PLUGINCC),)
> -export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS
> +ifdef CONFIG_GCC_PLUGIN_CYC_COMPLEXITY
> +GCC_PLUGIN_CYC_COMPLEXITY_CFLAGS := -fplugin=$(objtree)/tools/gcc/cyc_complexity_plugin.so
> +endif
> +GCC_PLUGINS_CFLAGS := $(GCC_PLUGIN_CYC_COMPLEXITY_CFLAGS)
> +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS GCC_PLUGIN_CYC_COMPLEXITY


Do you need to export "GCC_PLUGIN_CYC_COMPLEXITY"?
I do not see any reference to it.

If we expect more and more plugins in the future,
is it better to do like this?

gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY)  += cyc_complexity_plugin.so
gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV)          += sancov_plugin.so
gcc-plugin-$(CONFIG_GCC_PLUGIN_FOO)             += foo_plugin.so


GCC_PLUGINS_CFLAGS := $(addprefix -fplugin=$(objtree)/tools/gcc/,
$(gcc-plugin-y))








-- 
Best Regards
Masahiro Yamada

[toc] | [prev] | [next] | [standalone]


#1357626 — Re: [PATCH v5 3/5] Add Cyclomatic complexity GCC plugin

FromEmese Revfy <re.emese@gmail.com>
Date2016-03-14 22:10 +0100
SubjectRe: [PATCH v5 3/5] Add Cyclomatic complexity GCC plugin
Message-ID<rcHUt-LG-3@gated-at.bofh.it>
In reply to#1355624
On Fri, 11 Mar 2016 15:26:39 +0900
Masahiro Yamada <yamada.masahiro@socionext.com> wrote:

> > diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
> > index 7c85bf2..dd7b56d 100644
> > --- a/scripts/Makefile.gcc-plugins
> > +++ b/scripts/Makefile.gcc-plugins
> > @@ -5,7 +5,11 @@ else
> >  PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
> >  endif
> >  ifneq ($(PLUGINCC),)
> > -export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS
> > +ifdef CONFIG_GCC_PLUGIN_CYC_COMPLEXITY
> > +GCC_PLUGIN_CYC_COMPLEXITY_CFLAGS := -fplugin=$(objtree)/tools/gcc/cyc_complexity_plugin.so
> > +endif
> > +GCC_PLUGINS_CFLAGS := $(GCC_PLUGIN_CYC_COMPLEXITY_CFLAGS)
> > +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS GCC_PLUGIN_CYC_COMPLEXITY
> 
> 
> Do you need to export "GCC_PLUGIN_CYC_COMPLEXITY"?
> I do not see any reference to it.

This is a demo plugin. I just want to demonstrate how to use this infrastructure but I can remove it.
In my project there would be other plugins which use the export.

> If we expect more and more plugins in the future,
> is it better to do like this?
> 
> gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY)  += cyc_complexity_plugin.so
> gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV)          += sancov_plugin.so
> gcc-plugin-$(CONFIG_GCC_PLUGIN_FOO)             += foo_plugin.so
> 
> 
> GCC_PLUGINS_CFLAGS := $(addprefix -fplugin=$(objtree)/tools/gcc/,
> $(gcc-plugin-y))

Yes, it is better, I will do it.

-- 
Emese

[toc] | [prev] | [next] | [standalone]


#1351224 — [PATCH v5 5/5] Add sancov plugin

FromEmese Revfy <re.emese@gmail.com>
Date2016-03-07 00:10 +0100
Subject[PATCH v5 5/5] Add sancov plugin
Message-ID<r9PYe-39m-21@gated-at.bofh.it>
In reply to#1351220
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>
---
 arch/Kconfig                 |   9 +++
 scripts/Makefile.gcc-plugins |   7 ++-
 tools/gcc/Makefile           |   2 +
 tools/gcc/sancov_plugin.c    | 133 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 149 insertions(+), 2 deletions(-)
 create mode 100644 tools/gcc/sancov_plugin.c

diff --git a/arch/Kconfig b/arch/Kconfig
index 32583b7..30632fa 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -384,6 +384,15 @@ config GCC_PLUGIN_CYC_COMPLEXITY
 	  N = the number of nodes
 	  P = the number of connected components (exit nodes).
 
+config GCC_PLUGIN_SANCOV
+	bool "Helper plugin for the kcov feature"
+	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/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
index dd7b56d..dc11503 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -8,8 +8,11 @@ ifneq ($(PLUGINCC),)
 ifdef CONFIG_GCC_PLUGIN_CYC_COMPLEXITY
 GCC_PLUGIN_CYC_COMPLEXITY_CFLAGS := -fplugin=$(objtree)/tools/gcc/cyc_complexity_plugin.so
 endif
-GCC_PLUGINS_CFLAGS := $(GCC_PLUGIN_CYC_COMPLEXITY_CFLAGS)
-export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS GCC_PLUGIN_CYC_COMPLEXITY
+ifdef CONFIG_GCC_PLUGIN_SANCOV
+GCC_PLUGIN_SANCOV_CFLAGS := -fplugin=$(objtree)/tools/gcc/sancov_plugin.so
+endif
+GCC_PLUGINS_CFLAGS := $(GCC_PLUGIN_CYC_COMPLEXITY_CFLAGS) $(GCC_PLUGIN_SANCOV_CFLAGS)
+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS GCC_PLUGIN_CYC_COMPLEXITY GCC_PLUGIN_SANCOV
 ifeq ($(KBUILD_EXTMOD),)
 gcc-plugins:
 	$(Q)$(MAKE) $(build)=tools/gcc
diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
index 31c72bf..97a923f 100644
--- a/tools/gcc/Makefile
+++ b/tools/gcc/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/tools/gcc/sancov_plugin.c b/tools/gcc/sancov_plugin.c
new file mode 100644
index 0000000..5a9179b
--- /dev/null
+++ b/tools/gcc/sancov_plugin.c
@@ -0,0 +1,133 @@
+/*
+ * 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	= "20160305",
+	.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);
+
+	nothrow_attr = tree_cons(get_identifier("nothrow"), NULL, NULL);
+	decl_attributes(&sancov_fndecl, nothrow_attr, 0);
+	gcc_assert(TREE_NOTHROW(sancov_fndecl));
+	leaf_attr = tree_cons(get_identifier("leaf"), NULL, NULL);
+	decl_attributes(&sancov_fndecl, leaf_attr, 0);
+}
+
+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 = &gt_ggc_mx_tree_node,
+			.pchw = &gt_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 *)&gt_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]


#1351989 — Re: [PATCH v5 5/5] Add sancov plugin

FromKees Cook <keescook@chromium.org>
Date2016-03-07 22:10 +0100
SubjectRe: [PATCH v5 5/5] Add sancov plugin
Message-ID<raazF-899-31@gated-at.bofh.it>
In reply to#1351224
On Sun, Mar 6, 2016 at 3:07 PM, Emese Revfy <re.emese@gmail.com> wrote:
> 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).

Very cool! Dmitry, is this something you could put to good use?

> [...]
> diff --git a/tools/gcc/sancov_plugin.c b/tools/gcc/sancov_plugin.c
> new file mode 100644
> index 0000000..5a9179b
> --- /dev/null
> +++ b/tools/gcc/sancov_plugin.c
> @@ -0,0 +1,133 @@
> +/*
> + * 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

Is this accurate? Wouldn't it just be selected from CONFIGs during kernel build?

-Kees

-- 
Kees Cook
Chrome OS & Brillo Security

[toc] | [prev] | [next] | [standalone]


#1352009 — Re: [PATCH v5 5/5] Add sancov plugin

FromEmese Revfy <re.emese@gmail.com>
Date2016-03-07 22:40 +0100
SubjectRe: [PATCH v5 5/5] Add sancov plugin
Message-ID<rab2G-8kT-27@gated-at.bofh.it>
In reply to#1351989
On Mon, 7 Mar 2016 13:07:32 -0800
Kees Cook <keescook@chromium.org> wrote:

> > diff --git a/tools/gcc/sancov_plugin.c b/tools/gcc/sancov_plugin.c
> > new file mode 100644
> > index 0000000..5a9179b
> > --- /dev/null
> > +++ b/tools/gcc/sancov_plugin.c
> > @@ -0,0 +1,133 @@
> > +/*
> > + * 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
> 
> Is this accurate? Wouldn't it just be selected from CONFIGs during kernel build?

This is just a usage example when someone clones the plugin from github. Every plugin written by me contains this. :)

For now it can be enabled from menuconfig for testing because I'm waiting for the reactions.
Later I think the best way would be when kcov is enabled that it also enables the plugin automatically
if the target gcc version doesn't support the -fsanitize-coverage=trace-pc option but it supports plugins.

-- 
Emese

[toc] | [prev] | [next] | [standalone]


#1352877 — Re: [PATCH v5 5/5] Add sancov plugin

FromDmitry Vyukov <dvyukov@google.com>
Date2016-03-08 12:00 +0100
SubjectRe: [PATCH v5 5/5] Add sancov plugin
Message-ID<ranwS-8b7-3@gated-at.bofh.it>
In reply to#1351989
On Mon, Mar 7, 2016 at 10:07 PM, Kees Cook <keescook@chromium.org> wrote:
> On Sun, Mar 6, 2016 at 3:07 PM, Emese Revfy <re.emese@gmail.com> wrote:
>> 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).
>
> Very cool! Dmitry, is this something you could put to good use?

I am using gcc with sancov as a regular pass, so I don't a good use
for this right now. Maybe it will help with deployment for Android. I
don't know. Though, it will require backporting this plugin support.

[toc] | [prev] | [next] | [standalone]


#1351225 — [PATCH v5 1/5] Shared library support

FromEmese Revfy <re.emese@gmail.com>
Date2016-03-07 00:10 +0100
Subject[PATCH v5 1/5] Shared library support
Message-ID<r9PYf-39m-25@gated-at.bofh.it>
In reply to#1351220
Infrastructure for building independent shared library targets.
This effectively also reverts commit 62e2210798ed38928ab24841e8b4878a
(Masahiro Yamada, kbuild: drop shared library support from Makefile.host).

Signed-off-by: Emese Revfy <re.emese@gmail.com>
---
 scripts/Makefile.build |  2 +-
 scripts/Makefile.clean |  3 ++-
 scripts/Makefile.host  | 69 +++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 130a452..bd2a31e 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -60,7 +60,7 @@ endif
 endif
 
 # Do not include host rules unless needed
-ifneq ($(hostprogs-y)$(hostprogs-m),)
+ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
 include scripts/Makefile.host
 endif
 
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
index 55c96cb..e4e88ab 100644
--- a/scripts/Makefile.clean
+++ b/scripts/Makefile.clean
@@ -38,7 +38,8 @@ subdir-ymn	:= $(addprefix $(obj)/,$(subdir-ymn))
 __clean-files	:= $(extra-y) $(extra-m) $(extra-)       \
 		   $(always) $(targets) $(clean-files)   \
 		   $(host-progs)                         \
-		   $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
+		   $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
+		   $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
 
 __clean-files   := $(filter-out $(no-clean-files), $(__clean-files))
 
diff --git a/scripts/Makefile.host b/scripts/Makefile.host
index 133edfa..4d180d9 100644
--- a/scripts/Makefile.host
+++ b/scripts/Makefile.host
@@ -20,7 +20,25 @@
 # Will compile qconf as a C++ program, and menu as a C program.
 # They are linked as C++ code to the executable qconf
 
+# hostprogs-y := conf
+# conf-objs  := conf.o libkconfig.so
+# libkconfig-objs := expr.o type.o
+# Will create a shared library named libkconfig.so that consists of
+# expr.o and type.o (they are both compiled as C code and the object files
+# are made as position independent code).
+# conf.c is compiled as a C program, and conf.o is linked together with
+# libkconfig.so as the executable conf.
+# Note: Shared libraries consisting of C++ files are not supported
+
+# hostcc-option
+# Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586)
+
+hostcc-option = $(call try-run,\
+	$(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
+
 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
+__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
+__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
 
 # C code
 # Executables compiled from a single .c file
@@ -42,6 +60,19 @@ host-cxxmulti	:= $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
 # C++ Object (.o) files compiled from .cc files
 host-cxxobjs	:= $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
 
+# Shared libaries (only .c supported)
+# Shared libraries (.so) - all .so files referenced in "xxx-objs"
+host-cshlib	:= $(sort $(filter %.so, $(host-cobjs)))
+host-cshlib	+= $(sort $(filter %.so, $(__hostlibs)))
+host-cxxshlib	:= $(sort $(filter %.so, $(__hostcxxlibs)))
+# Remove .so files from "xxx-objs"
+host-cobjs	:= $(filter-out %.so,$(host-cobjs))
+host-cxxobjs	:= $(filter-out %.so,$(host-cxxobjs))
+
+# Object (.o) files used by the shared libaries
+host-cshobjs	:= $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
+host-cxxshobjs	:= $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
+
 # output directory for programs/.o files
 # hostprogs-y := tools/build may have been specified.
 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
@@ -56,6 +87,10 @@ host-cmulti	:= $(addprefix $(obj)/,$(host-cmulti))
 host-cobjs	:= $(addprefix $(obj)/,$(host-cobjs))
 host-cxxmulti	:= $(addprefix $(obj)/,$(host-cxxmulti))
 host-cxxobjs	:= $(addprefix $(obj)/,$(host-cxxobjs))
+host-cshlib	:= $(addprefix $(obj)/,$(host-cshlib))
+host-cxxshlib	:= $(addprefix $(obj)/,$(host-cxxshlib))
+host-cshobjs	:= $(addprefix $(obj)/,$(host-cshobjs))
+host-cxxshobjs	:= $(addprefix $(obj)/,$(host-cxxshobjs))
 host-objdirs    := $(addprefix $(obj)/,$(host-objdirs))
 
 obj-dirs += $(host-objdirs)
@@ -124,5 +159,37 @@ quiet_cmd_host-cxxobjs	= HOSTCXX $@
 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
 	$(call if_changed_dep,host-cxxobjs)
 
+# Compile .c file, create position independent .o file
+# host-cshobjs -> .o
+quiet_cmd_host-cshobjs	= HOSTCC  -fPIC $@
+      cmd_host-cshobjs	= $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
+$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
+	$(call if_changed_dep,host-cshobjs)
+
+# Compile .c file, create position independent .o file
+# host-cxxshobjs -> .o
+quiet_cmd_host-cxxshobjs	= HOSTCXX -fPIC $@
+      cmd_host-cxxshobjs	= $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
+$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
+	$(call if_changed_dep,host-cxxshobjs)
+
+# Link a shared library, based on position independent .o files
+# *.o -> .so shared library (host-cshlib)
+quiet_cmd_host-cshlib	= HOSTLLD -shared $@
+      cmd_host-cshlib	= $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
+			  $(addprefix $(obj)/,$($(@F:.so=-objs))) \
+			  $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
+$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
+	$(call if_changed,host-cshlib)
+
+# Link a shared library, based on position independent .o files
+# *.o -> .so shared library (host-cxxshlib)
+quiet_cmd_host-cxxshlib	= HOSTLLD -shared $@
+      cmd_host-cxxshlib	= $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
+			  $(addprefix $(obj)/,$($(@F:.so=-objs))) \
+			  $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
+$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
+	$(call if_changed,host-cxxshlib)
+
 targets += $(host-csingle)  $(host-cmulti) $(host-cobjs)\
-	   $(host-cxxmulti) $(host-cxxobjs)
+	   $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
-- 
2.4.1

[toc] | [prev] | [next] | [standalone]


#1351988 — Re: [PATCH v5 1/5] Shared library support

FromKees Cook <keescook@chromium.org>
Date2016-03-07 22:10 +0100
SubjectRe: [PATCH v5 1/5] Shared library support
Message-ID<raazE-899-7@gated-at.bofh.it>
In reply to#1351225
On Sun, Mar 6, 2016 at 3:03 PM, Emese Revfy <re.emese@gmail.com> wrote:
> Infrastructure for building independent shared library targets.
> This effectively also reverts commit 62e2210798ed38928ab24841e8b4878a
> (Masahiro Yamada, kbuild: drop shared library support from Makefile.host).

Should this literally be a revert? If so, we'd gain the Documentation
changes back too.

-Kees

>
> Signed-off-by: Emese Revfy <re.emese@gmail.com>
> ---
>  scripts/Makefile.build |  2 +-
>  scripts/Makefile.clean |  3 ++-
>  scripts/Makefile.host  | 69 +++++++++++++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 71 insertions(+), 3 deletions(-)

-- 
Kees Cook
Chrome OS & Brillo Security

[toc] | [prev] | [next] | [standalone]


#1352003 — Re: [PATCH v5 1/5] Shared library support

FromEmese Revfy <re.emese@gmail.com>
Date2016-03-07 22:40 +0100
SubjectRe: [PATCH v5 1/5] Shared library support
Message-ID<rab2F-8kT-11@gated-at.bofh.it>
In reply to#1351988
On Mon, 7 Mar 2016 13:05:16 -0800
Kees Cook <keescook@chromium.org> wrote:

> On Sun, Mar 6, 2016 at 3:03 PM, Emese Revfy <re.emese@gmail.com> wrote:
> > Infrastructure for building independent shared library targets.
> > This effectively also reverts commit 62e2210798ed38928ab24841e8b4878a
> > (Masahiro Yamada, kbuild: drop shared library support from Makefile.host).
> 
> Should this literally be a revert? If so, we'd gain the Documentation
> changes back too.

Sure, I'll do it in the next patch set.

-- 
Emese

[toc] | [prev] | [next] | [standalone]


#1355623 — Re: [PATCH v5 1/5] Shared library support

FromMasahiro Yamada <yamada.masahiro@socionext.com>
Date2016-03-11 07:30 +0100
SubjectRe: [PATCH v5 1/5] Shared library support
Message-ID<rboKd-1W9-11@gated-at.bofh.it>
In reply to#1351225
Hi Emese,

2016-03-07 8:03 GMT+09:00 Emese Revfy <re.emese@gmail.com>:
> Infrastructure for building independent shared library targets.
> This effectively also reverts commit 62e2210798ed38928ab24841e8b4878a
> (Masahiro Yamada, kbuild: drop shared library support from Makefile.host).
>
> Signed-off-by: Emese Revfy <re.emese@gmail.com>
> ---
>  scripts/Makefile.build |  2 +-
>  scripts/Makefile.clean |  3 ++-
>  scripts/Makefile.host  | 69 +++++++++++++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 71 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 130a452..bd2a31e 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -60,7 +60,7 @@ endif
>  endif
>
>  # Do not include host rules unless needed
> -ifneq ($(hostprogs-y)$(hostprogs-m),)
> +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
>  include scripts/Makefile.host
>  endif
>
> diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
> index 55c96cb..e4e88ab 100644
> --- a/scripts/Makefile.clean
> +++ b/scripts/Makefile.clean
> @@ -38,7 +38,8 @@ subdir-ymn    := $(addprefix $(obj)/,$(subdir-ymn))
>  __clean-files  := $(extra-y) $(extra-m) $(extra-)       \
>                    $(always) $(targets) $(clean-files)   \
>                    $(host-progs)                         \
> -                  $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
> +                  $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
> +                  $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
>
>  __clean-files   := $(filter-out $(no-clean-files), $(__clean-files))
>
> diff --git a/scripts/Makefile.host b/scripts/Makefile.host
> index 133edfa..4d180d9 100644
> --- a/scripts/Makefile.host
> +++ b/scripts/Makefile.host
> @@ -20,7 +20,25 @@
>  # Will compile qconf as a C++ program, and menu as a C program.
>  # They are linked as C++ code to the executable qconf
>
> +# hostprogs-y := conf
> +# conf-objs  := conf.o libkconfig.so
> +# libkconfig-objs := expr.o type.o
> +# Will create a shared library named libkconfig.so that consists of
> +# expr.o and type.o (they are both compiled as C code and the object files
> +# are made as position independent code).
> +# conf.c is compiled as a C program, and conf.o is linked together with
> +# libkconfig.so as the executable conf.
> +# Note: Shared libraries consisting of C++ files are not supported

I do not see any use-case for the above.

This series adds cases for "foo.so" as a final target.


As an alternative, you can add needed build rules
into tools/gcc/Makefile, not scripts/Makefile.host

I guess these rule won't be used in other places.



> +# hostcc-option
> +# Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586)
> +
> +hostcc-option = $(call try-run,\
> +       $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
> +
>  __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
> +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
> +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
>
>  # C code
>  # Executables compiled from a single .c file
> @@ -42,6 +60,19 @@ host-cxxmulti        := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
>  # C++ Object (.o) files compiled from .cc files
>  host-cxxobjs   := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
>
> +# Shared libaries (only .c supported)
> +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
> +host-cshlib    := $(sort $(filter %.so, $(host-cobjs)))

useless.

> +host-cshlib    += $(sort $(filter %.so, $(__hostlibs)))
> +host-cxxshlib  := $(sort $(filter %.so, $(__hostcxxlibs)))
> +# Remove .so files from "xxx-objs"
> +host-cobjs     := $(filter-out %.so,$(host-cobjs))
> +host-cxxobjs   := $(filter-out %.so,$(host-cxxobjs))
> +
> +# Object (.o) files used by the shared libaries
> +host-cshobjs   := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
> +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
> +
>  # output directory for programs/.o files
>  # hostprogs-y := tools/build may have been specified.
>  # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
> @@ -56,6 +87,10 @@ host-cmulti  := $(addprefix $(obj)/,$(host-cmulti))
>  host-cobjs     := $(addprefix $(obj)/,$(host-cobjs))
>  host-cxxmulti  := $(addprefix $(obj)/,$(host-cxxmulti))
>  host-cxxobjs   := $(addprefix $(obj)/,$(host-cxxobjs))
> +host-cshlib    := $(addprefix $(obj)/,$(host-cshlib))
> +host-cxxshlib  := $(addprefix $(obj)/,$(host-cxxshlib))
> +host-cshobjs   := $(addprefix $(obj)/,$(host-cshobjs))
> +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
>  host-objdirs    := $(addprefix $(obj)/,$(host-objdirs))
>
>  obj-dirs += $(host-objdirs)
> @@ -124,5 +159,37 @@ quiet_cmd_host-cxxobjs     = HOSTCXX $@
>  $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
>         $(call if_changed_dep,host-cxxobjs)
>
> +# Compile .c file, create position independent .o file
> +# host-cshobjs -> .o
> +quiet_cmd_host-cshobjs = HOSTCC  -fPIC $@
> +      cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
> +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
> +       $(call if_changed_dep,host-cshobjs)
> +
> +# Compile .c file, create position independent .o file
> +# host-cxxshobjs -> .o
> +quiet_cmd_host-cxxshobjs       = HOSTCXX -fPIC $@
> +      cmd_host-cxxshobjs       = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
> +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
> +       $(call if_changed_dep,host-cxxshobjs)
> +
> +# Link a shared library, based on position independent .o files
> +# *.o -> .so shared library (host-cshlib)
> +quiet_cmd_host-cshlib  = HOSTLLD -shared $@
> +      cmd_host-cshlib  = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
> +                         $(addprefix $(obj)/,$($(@F:.so=-objs))) \
> +                         $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
> +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
> +       $(call if_changed,host-cshlib)


Could you use $(call multi-depend, ...)
if you need to handle multi-object please?

Please refer to commit c8589d1e9e01 and commit 97e3226e6e984c8.

But, I still do not see any gcc-plugin that is large enough
to be linked from multiple objects.





-- 
Best Regards
Masahiro Yamada

[toc] | [prev] | [next] | [standalone]


#1357599 — Re: [PATCH v5 1/5] Shared library support

FromEmese Revfy <re.emese@gmail.com>
Date2016-03-14 21:20 +0100
SubjectRe: [PATCH v5 1/5] Shared library support
Message-ID<rcH86-dk-5@gated-at.bofh.it>
In reply to#1355623
On Fri, 11 Mar 2016 15:19:33 +0900
Masahiro Yamada <yamada.masahiro@socionext.com> wrote:

> As an alternative, you can add needed build rules
> into tools/gcc/Makefile, not scripts/Makefile.host
> 
> I guess these rule won't be used in other places.

I think it is better if the rules stay under scripts/ because I expect that there will also be clang and llvm plugins
in the future (e.g., clang plugins can access the frontend that gcc plugins can't do). In this case these rules would
either have to be duplicated or moved back under scripts/ (which makes it difficult to backport).
 
> > +# hostcc-option
> > +# Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586)
> > +
> > +hostcc-option = $(call try-run,\
> > +       $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
> > +
> >  __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
> > +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
> > +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
> >
> >  # C code
> >  # Executables compiled from a single .c file
> > @@ -42,6 +60,19 @@ host-cxxmulti        := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
> >  # C++ Object (.o) files compiled from .cc files
> >  host-cxxobjs   := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
> >
> > +# Shared libaries (only .c supported)
> > +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
> > +host-cshlib    := $(sort $(filter %.so, $(host-cobjs)))
> 
> useless.

Which part do you think is useless and why?
 
> > +host-cshlib    += $(sort $(filter %.so, $(__hostlibs)))
> > +host-cxxshlib  := $(sort $(filter %.so, $(__hostcxxlibs)))
> > +# Remove .so files from "xxx-objs"
> > +host-cobjs     := $(filter-out %.so,$(host-cobjs))
> > +host-cxxobjs   := $(filter-out %.so,$(host-cxxobjs))
> > +
> > +# Object (.o) files used by the shared libaries
> > +host-cshobjs   := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
> > +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
> > +
> >  # output directory for programs/.o files
> >  # hostprogs-y := tools/build may have been specified.
> >  # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
> > @@ -56,6 +87,10 @@ host-cmulti  := $(addprefix $(obj)/,$(host-cmulti))
> >  host-cobjs     := $(addprefix $(obj)/,$(host-cobjs))
> >  host-cxxmulti  := $(addprefix $(obj)/,$(host-cxxmulti))
> >  host-cxxobjs   := $(addprefix $(obj)/,$(host-cxxobjs))
> > +host-cshlib    := $(addprefix $(obj)/,$(host-cshlib))
> > +host-cxxshlib  := $(addprefix $(obj)/,$(host-cxxshlib))
> > +host-cshobjs   := $(addprefix $(obj)/,$(host-cshobjs))
> > +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
> >  host-objdirs    := $(addprefix $(obj)/,$(host-objdirs))
> >
> >  obj-dirs += $(host-objdirs)
> > @@ -124,5 +159,37 @@ quiet_cmd_host-cxxobjs     = HOSTCXX $@
> >  $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
> >         $(call if_changed_dep,host-cxxobjs)
> >
> > +# Compile .c file, create position independent .o file
> > +# host-cshobjs -> .o
> > +quiet_cmd_host-cshobjs = HOSTCC  -fPIC $@
> > +      cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
> > +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
> > +       $(call if_changed_dep,host-cshobjs)
> > +
> > +# Compile .c file, create position independent .o file
> > +# host-cxxshobjs -> .o
> > +quiet_cmd_host-cxxshobjs       = HOSTCXX -fPIC $@
> > +      cmd_host-cxxshobjs       = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
> > +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
> > +       $(call if_changed_dep,host-cxxshobjs)
> > +
> > +# Link a shared library, based on position independent .o files
> > +# *.o -> .so shared library (host-cshlib)
> > +quiet_cmd_host-cshlib  = HOSTLLD -shared $@
> > +      cmd_host-cshlib  = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
> > +                         $(addprefix $(obj)/,$($(@F:.so=-objs))) \
> > +                         $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
> > +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
> > +       $(call if_changed,host-cshlib)
> 
> 
> Could you use $(call multi-depend, ...)
> if you need to handle multi-object please?
> 
> Please refer to commit c8589d1e9e01 and commit 97e3226e6e984c8.

Ok, I will check it out.

> But, I still do not see any gcc-plugin that is large enough
> to be linked from multiple objects.

There will be large plugins later (typically if the plugin has more passes e.g., my size_overflow plugin).

-- 
Emese

[toc] | [prev] | [next] | [standalone]


#1358601 — Re: [PATCH v5 1/5] Shared library support

FromMasahiro Yamada <yamada.masahiro@socionext.com>
Date2016-03-16 09:00 +0100
SubjectRe: [PATCH v5 1/5] Shared library support
Message-ID<rdex4-5QB-1@gated-at.bofh.it>
In reply to#1357599
Hi Emese,


2016-03-15 5:14 GMT+09:00 Emese Revfy <re.emese@gmail.com>:
> On Fri, 11 Mar 2016 15:19:33 +0900
> Masahiro Yamada <yamada.masahiro@socionext.com> wrote:
>
>> As an alternative, you can add needed build rules
>> into tools/gcc/Makefile, not scripts/Makefile.host
>>
>> I guess these rule won't be used in other places.
>
> I think it is better if the rules stay under scripts/ because I expect that there will also be clang and llvm plugins
> in the future (e.g., clang plugins can access the frontend that gcc plugins can't do). In this case these rules would
> either have to be duplicated or moved back under scripts/ (which makes it difficult to backport).
>
>> > +# hostcc-option
>> > +# Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586)
>> > +
>> > +hostcc-option = $(call try-run,\
>> > +       $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
>> > +
>> >  __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
>> > +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
>> > +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
>> >
>> >  # C code
>> >  # Executables compiled from a single .c file
>> > @@ -42,6 +60,19 @@ host-cxxmulti        := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
>> >  # C++ Object (.o) files compiled from .cc files
>> >  host-cxxobjs   := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
>> >
>> > +# Shared libaries (only .c supported)
>> > +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
>> > +host-cshlib    := $(sort $(filter %.so, $(host-cobjs)))
>>
>> useless.
>
> Which part do you think is useless and why?


The line

host-cshlib    := $(sort $(filter %.so, $(host-cobjs)))

is useless because there is no host program that consists of .so files.


Your intention is to generate shared objects as final targets,
not host tools that call shared objects.





-- 
Best Regards
Masahiro Yamada

[toc] | [prev] | [next] | [standalone]


#1353909 — Re: [kernel-hardening] [PATCH v5 2/5] GCC plugin infrastructure

FromDavid Brown <david.brown@linaro.org>
Date2016-03-09 10:10 +0100
SubjectRe: [kernel-hardening] [PATCH v5 2/5] GCC plugin infrastructure
Message-ID<raIhY-5IF-5@gated-at.bofh.it>
In reply to#1351220
On Mon, Mar 07, 2016 at 12:04:27AM +0100, Emese Revfy wrote:

>This patch allows to build the whole kernel with GCC plugins. It was ported from
>grsecurity/PaX. The infrastructure supports building out-of-tree modules and
>building in a separate directory. Cross-compilation is supported too but
>currently only the x86 architecture enables plugins.

I've tested this with both ARM and ARM64.  There are some missing
headers in the arm64 gcc, reported here:
https://bugs.linaro.org/show_bug.cgi?id=2123 (also upstream), but this
should work once that is fixed.

Feel free to fold these into your patch, or, if you prefer, I can send
out separate patches for them.

Signed-off-by: David Brown <david.brown@linaro.org>

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 4f799e5..67ee8e3 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -54,6 +54,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 8cc6228..6d6e4f8 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -70,6 +70,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
-- 

[toc] | [prev] | [next] | [standalone]


#1354444 — Re: [kernel-hardening] [PATCH v5 2/5] GCC plugin infrastructure

FromKees Cook <keescook@chromium.org>
Date2016-03-09 22:00 +0100
SubjectRe: [kernel-hardening] [PATCH v5 2/5] GCC plugin infrastructure
Message-ID<raTn5-4Os-27@gated-at.bofh.it>
In reply to#1353909
On Wed, Mar 9, 2016 at 1:01 AM, David Brown <david.brown@linaro.org> wrote:
> On Mon, Mar 07, 2016 at 12:04:27AM +0100, Emese Revfy wrote:
>
>> This patch allows to build the whole kernel with GCC plugins. It was
>> ported from
>> grsecurity/PaX. The infrastructure supports building out-of-tree modules
>> and
>> building in a separate directory. Cross-compilation is supported too but
>> currently only the x86 architecture enables plugins.
>
>
> I've tested this with both ARM and ARM64.  There are some missing
> headers in the arm64 gcc, reported here:
> https://bugs.linaro.org/show_bug.cgi?id=2123 (also upstream), but this
> should work once that is fixed.
>
> Feel free to fold these into your patch, or, if you prefer, I can send
> out separate patches for them.

Ah-ha, great! Thanks for testing!

Emese, if you're not interested in carrying this, I can add it to my tree.

-Kees

>
> Signed-off-by: David Brown <david.brown@linaro.org>
>
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index 4f799e5..67ee8e3 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -54,6 +54,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 8cc6228..6d6e4f8 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -70,6 +70,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
> --



-- 
Kees Cook
Chrome OS & Brillo Security

[toc] | [prev] | [next] | [standalone]


#1354513 — Re: [kernel-hardening] [PATCH v5 2/5] GCC plugin infrastructure

FromEmese Revfy <re.emese@gmail.com>
Date2016-03-09 23:10 +0100
SubjectRe: [kernel-hardening] [PATCH v5 2/5] GCC plugin infrastructure
Message-ID<raUsQ-5Y7-55@gated-at.bofh.it>
In reply to#1354444
On Wed, 9 Mar 2016 12:50:26 -0800
Kees Cook <keescook@chromium.org> wrote:

> > Feel free to fold these into your patch, or, if you prefer, I can send
> > out separate patches for them.
> 
> Ah-ha, great! Thanks for testing!
> 
> Emese, if you're not interested in carrying this, I can add it to my tree.

I think it is easier if it is in my patch set.

-- 
Emese

[toc] | [prev] | [next] | [standalone]


#1354503 — Re: [kernel-hardening] [PATCH v5 2/5] GCC plugin infrastructure

FromEmese Revfy <re.emese@gmail.com>
Date2016-03-09 23:10 +0100
SubjectRe: [kernel-hardening] [PATCH v5 2/5] GCC plugin infrastructure
Message-ID<raUsP-5Y7-27@gated-at.bofh.it>
In reply to#1353909
On Wed, 9 Mar 2016 02:01:15 -0700
David Brown <david.brown@linaro.org> wrote:

> Feel free to fold these into your patch, or, if you prefer, I can send
> out separate patches for them.

Thanks, I'll take it.

-- 
Emese

[toc] | [prev] | [next] | [standalone]


#1355619 — Re: [PATCH v5 2/5] GCC plugin infrastructure

FromMasahiro Yamada <yamada.masahiro@socionext.com>
Date2016-03-11 07:30 +0100
SubjectRe: [PATCH v5 2/5] GCC plugin infrastructure
Message-ID<rboKd-1W9-1@gated-at.bofh.it>
In reply to#1351220
Hi Emese,

I am not familiar with GCC plugins.

Comments from the view of Kbuild.


2016-03-07 8:04 GMT+09:00 Emese Revfy <re.emese@gmail.com>:
> This patch allows to build the whole kernel with GCC plugins. It was ported from
> grsecurity/PaX. The infrastructure supports building out-of-tree modules and
> building in a separate directory. Cross-compilation is supported too but
> currently only the x86 architecture enables plugins.
>
> The directory of the gcc plugins is tools/gcc. You can use a file or a directory


Maybe scripts/gcc-plugins/ is better than tools/gcc ?

In the directory "scripts/", we have several tools used during
building the kernel image.
We have some optional programs in the directory "tools/", which are not used
for building the kernel image itself.

Please correct me if I am wrong.



You sprinkle "gcc-plugins" target in the top Makefile, which I do not like.

Can you descend into scripts/gcc-plugins from scripts/Makefile?


 subdir-$(CONFIG_MODVERSIONS) += genksyms
 subdir-y                     += mod
 subdir-$(CONFIG_SECURITY_SELINUX) += selinux
 subdir-$(CONFIG_DTC)         += dtc
 subdir-$(CONFIG_GDB_SCRIPTS) += gdb
+subdir-$(CONFIG_GCC_PLUGINS) += gcc-plugins


This is how other host tools do, I think.





>
> +ccflags-y := $(GCC_PLUGINS_CFLAGS)
> +asflags-y := $(GCC_PLUGINS_AFLAGS)
> +
>  obj-y                          := main.o version.o mounts.o
>  ifneq ($(CONFIG_BLK_DEV_INITRD),y)
>  obj-y                          += noinitramfs.o
> diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
> new file mode 100644
> index 0000000..7c85bf2
> --- /dev/null
> +++ b/scripts/Makefile.gcc-plugins
> @@ -0,0 +1,28 @@
> +ifdef CONFIG_GCC_PLUGINS
> +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
> +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
> +else
> +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
> +endif

The difference is only the first argument.

Can you make it as follows?

__HOSTCC := $(call cc-ifversion, -ge, 0408, $(HOSTCXX), $(HOSTCC))

PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh
"$(__HOSTCC)" "$(HOSTCXX)" "$(CC)")


I did not come up with a good name for __HOSTCC.
Feel free to replace it with a better one.





> +ifneq ($(PLUGINCC),)
> +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS
> +ifeq ($(KBUILD_EXTMOD),)
> +gcc-plugins:
> +       $(Q)$(MAKE) $(build)=tools/gcc
> +else
> +gcc-plugins: ;
> +endif
> +else
> +gcc-plugins:
> +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
> +       $(warning warning, your gcc installation does not support plugins, perhaps the necessary headers are missing?)
> +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
> +       $(CONFIG_SHELL) -x $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)"
> +else
> +       $(CONFIG_SHELL) -x $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)"
> +endif
> +else
> +       $(warning warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least)
> +endif
> +endif
> +endif


These ifdef's are really unreadable.
I wondered if it could be a bit simpler.
At least, the deepest one can be resolved with the "__HOSTCC" set above.




> diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
> new file mode 100644
> index 0000000..eaa4fce
> --- /dev/null
> +++ b/scripts/gcc-plugin.sh
> @@ -0,0 +1,51 @@
> +#!/bin/sh
> +srctree=$(dirname "$0")
> +gccplugins_dir=$($3 -print-file-name=plugin)
> +plugincc=$($1 -E -x c++ - -o /dev/null -I"${srctree}"/../tools/gcc -I"${gccplugins_dir}"/include 2>&1 <<EOF
> +#include "gcc-common.h"


Maybe <gcc-common.h> because it is not located at the same directory?



> diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
> new file mode 100644
> index 0000000..172850b
> --- /dev/null
> +++ b/tools/gcc/gcc-common.h
> @@ -0,0 +1,830 @@
> +#ifndef GCC_COMMON_H_INCLUDED
> +#define GCC_COMMON_H_INCLUDED
> +
> +#include "bversion.h"
> +#if BUILDING_GCC_VERSION >= 6000
> +#include "gcc-plugin.h"
> +#else
> +#include "plugin.h"
> +#endif
> +#include "plugin-version.h"
> +#include "config.h"
> +#include "system.h"
> +#include "coretypes.h"
> +#include "tm.h"
> +#include "line-map.h"
> +#include "input.h"
> +#include "tree.h"
> +
> +#include "tree-inline.h"
> +#include "version.h"
> +#include "rtl.h"
> +#include "tm_p.h"
> +#include "flags.h"
> +#include "hard-reg-set.h"
> +#include "output.h"
> +#include "except.h"
> +#include "function.h"
> +#include "toplev.h"
> +#include "basic-block.h"
> +#include "intl.h"
> +#include "ggc.h"
> +#include "timevar.h"
> +
> +#include "params.h"
> +
> +#if BUILDING_GCC_VERSION <= 4009
> +#include "pointer-set.h"
> +#else
> +#include "hash-map.h"
> +#endif
> +
> +#include "emit-rtl.h"
> +#include "debug.h"
> +#include "target.h"
> +#include "langhooks.h"
> +#include "cfgloop.h"
> +#include "cgraph.h"
> +#include "opts.h"

All of these are included by "...", not <...>.


As mentioned above, I want you to use "..." style
when you need to use relative path from the source.

I do not see most of them in tools/gcc/.




-- 
Best Regards
Masahiro Yamada

[toc] | [prev] | [next] | [standalone]


#1357623 — Re: [PATCH v5 2/5] GCC plugin infrastructure

FromEmese Revfy <re.emese@gmail.com>
Date2016-03-14 22:00 +0100
SubjectRe: [PATCH v5 2/5] GCC plugin infrastructure
Message-ID<rcHKO-sV-9@gated-at.bofh.it>
In reply to#1355619
On Fri, 11 Mar 2016 15:25:19 +0900
Masahiro Yamada <yamada.masahiro@socionext.com> wrote:

> Maybe scripts/gcc-plugins/ is better than tools/gcc ?
> 
> In the directory "scripts/", we have several tools used during
> building the kernel image.
> We have some optional programs in the directory "tools/", which are not used
> for building the kernel image itself.
> 
> Please correct me if I am wrong.

I think scripts isn't the right place because there are tools there which don't get used
during the building of vmlinux (e.g., coccinelle, checkpatch). 
The scripts name also doesn't describe gcc plugins well. Plugins take part in the image building process
in a different way than these tools and scripts do.
Since there doesn't seen to be a good place for compiler plugins, maybe we should create a new toplevel directory
called "build". Compiler plugins and other existing build tools could live there. What do you think?

> > +ccflags-y := $(GCC_PLUGINS_CFLAGS)
> > +asflags-y := $(GCC_PLUGINS_AFLAGS)
> > +
> >  obj-y                          := main.o version.o mounts.o
> >  ifneq ($(CONFIG_BLK_DEV_INITRD),y)
> >  obj-y                          += noinitramfs.o
> > diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
> > new file mode 100644
> > index 0000000..7c85bf2
> > --- /dev/null
> > +++ b/scripts/Makefile.gcc-plugins
> > @@ -0,0 +1,28 @@
> > +ifdef CONFIG_GCC_PLUGINS
> > +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
> > +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
> > +else
> > +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
> > +endif
> 
> The difference is only the first argument.
> 
> Can you make it as follows?
> 
> __HOSTCC := $(call cc-ifversion, -ge, 0408, $(HOSTCXX), $(HOSTCC))
> 
> PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh
> "$(__HOSTCC)" "$(HOSTCXX)" "$(CC)")
> 
> 
> I did not come up with a good name for __HOSTCC.
> Feel free to replace it with a better one.

Sure, I will do it.

-- 
Emese

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | linux.kernel


csiph-web