From patchwork Fri Apr 22 18:26:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emese Revfy X-Patchwork-Id: 8915131 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 736E0BF29F for ; Fri, 22 Apr 2016 18:28:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7077520212 for ; Fri, 22 Apr 2016 18:28:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C483201F2 for ; Fri, 22 Apr 2016 18:28:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751595AbcDVS2u (ORCPT ); Fri, 22 Apr 2016 14:28:50 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:37949 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751156AbcDVS2t (ORCPT ); Fri, 22 Apr 2016 14:28:49 -0400 Received: by mail-wm0-f54.google.com with SMTP id u206so39237721wme.1; Fri, 22 Apr 2016 11:28:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xbRZjUKdCys+jKuiU4JzrGXkiuIpNXvJ8tySl1oLyfQ=; b=BPNbzjkYLhcyx7Nu8v1e6UIuPaBuAm7TFg9lID+Dt3iqdTg2bafLCRYD9pk6fLfe2b j22HiY8rCZVL/6u4IxokygcXrIx8qIrhqtG0+C3JGLZfZUMcnHF40RLS5Ll79CfNwifZ qXLPc0l4jt1WziBZ6zMldtPs3wokIXD3hv/+Itv5WFNLaA+ThsOWtimDJCohYpWrA3Nq ivhD3FJJb7thg93GzW6c3kBr6smkWca+Twb2wbYHSIGt0IJ9IIRoNca0YyZ0tNzup8r2 z7+EobyJ2lOG8+UxwOCS9DpF75GDVnBDTW91b8a1V45Hev6IdD/8sJMUzzH+rcgGYrcV 86kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xbRZjUKdCys+jKuiU4JzrGXkiuIpNXvJ8tySl1oLyfQ=; b=W3egtMWkm2m2u++Dhb8POnmRzdNpFYDxmaEwHTD8E4QqtHZdTto1vo/qvxgIEU9Ig5 RBKkb4IrtWZcdJ5KspTUos8RpNJqBT1XUiX/U0Lq460c9E13xDsSX5eqp8nXW98/R+VK RiQqbxkaJZyeZF0WVJq+e5JTrV7Tl8mzq9ztLauSaQtzeKdpN+tw9aljQtS1CwyA1FcJ KuMaGInd/cWDyECOgJGptiPwsH6J2Y36lONqRbSBJ69SEwzhEB64EZ3rQ/Sn6048UvOJ yU4XdP6lM00SGDKwrjvgeoNxhwKI83h0KSN6eoBgOktwgrIkeBMhICa10P4rllDidoeR VFIw== X-Gm-Message-State: AOPr4FVGf3Khf9zCDRJBg0BlAXAgn/cGVug7uZXMRzH5qEJdDtuC7+D3W/hUagyYuHzajw== X-Received: by 10.28.54.224 with SMTP id y93mr5330460wmh.82.1461349727952; Fri, 22 Apr 2016 11:28:47 -0700 (PDT) Received: from localhost (beleg.madhouse-project.org. [128.199.36.147]) by smtp.gmail.com with ESMTPSA id w79sm4564325wme.19.2016.04.22.11.28.46 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Apr 2016 11:28:47 -0700 (PDT) Date: Fri, 22 Apr 2016 20:26:03 +0200 From: Emese Revfy To: linux-kbuild@vger.kernel.org Cc: pageexec@freemail.hu, spender@grsecurity.net, kernel-hardening@lists.openwall.com, mmarek@suse.com, keescook@chromium.org, linux@rasmusvillemoes.dk, fengguang.wu@intel.com, dvyukov@google.com, linux-kernel@vger.kernel.org, david.brown@linaro.org, yamada.masahiro@socionext.com Subject: [PATCH v7 5/6] Documentation for the GCC plugin infrastructure Message-Id: <20160422202603.5daf3b4c09a20a6c515ac70e@gmail.com> In-Reply-To: <20160422201957.97ce16f0e67377d0ce613d19@gmail.com> References: <20160422201957.97ce16f0e67377d0ce613d19@gmail.com> X-Mailer: Sylpheed 3.4.3 (GTK+ 2.24.29; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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