From patchwork Tue Mar 1 17:17:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emese Revfy X-Patchwork-Id: 8467821 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 E5413C0553 for ; Tue, 1 Mar 2016 17:19:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F2C572014A for ; Tue, 1 Mar 2016 17:19:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E82892027D for ; Tue, 1 Mar 2016 17:19:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751496AbcCARTZ (ORCPT ); Tue, 1 Mar 2016 12:19:25 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34568 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750862AbcCARTY (ORCPT ); Tue, 1 Mar 2016 12:19:24 -0500 Received: by mail-wm0-f68.google.com with SMTP id p65so5248477wmp.1 for ; Tue, 01 Mar 2016 09:19:23 -0800 (PST) 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=Q7mamAqYQ3A0v29Y9s70CJI3qdaZD+x2lsluKgV2Pxc=; b=fH2s6V2O6AerImSWaiiWv49t7qWJ5H2oHfd5obckc1ncZ3eO/9QChchkTPvBidXMmS IqRPfN9zXk6ec6X4eYJ2YVoM/J+YXFfjA0WX3ThaiK0duJNrd9oKRG9k9/a76daYFbmA yEtw8ZjB6NIYSlymp05RVqZ201l1fNYxRP/BCIXot/Taz2ty0GTe4K+H9YZGByXXKp0z xb1SAfr8qkY19RWAWxqJWdRpqUqFdQzrNZCA0bKBbe8tObiBnOnPGwUbJEc0uLCG1oX+ iJIc6VT+W+Cn8oogZY3zY7wohRGAKi9ZIMdWFLxn57/e06W1uTtN+1KvOAXGXZO5+yQ5 HsOA== 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=Q7mamAqYQ3A0v29Y9s70CJI3qdaZD+x2lsluKgV2Pxc=; b=XYmOouchmSVu2Pyatb6+Jw6xQYlmFhJFwRSVP8uhhOP3Q/1NgzsbJE1Te4sZmTxcwf 0dsEU7OQOn6TCw8EuwQEZn8dXMor9BXFtYTZaQ17uBdjmGsDH4WffK4F8gI6WQUtiTON S+541al0NwPP7fIlp0sFzLRIWxXoBL5PeYQMl2AZ5yKFsfesUFLigz2L0M09rzdWlWQ6 XXPshUw6U9TPuSWjUnWq6BNge+wZwztqt6arinzkG8zjTg+oUaynFE91gLVltnzJKsnS alSl32aJj9GeMQBQzFHy30YvT9daqd9FPLqiW5w2t/FIxCsP3+KincmybRqPS+tBmWJh za6Q== X-Gm-Message-State: AD7BkJJKqXK5Pmbjo1WwJ/1i3+ojTtfHCs57iz22g0iBIU6qhomJmCFMqMA47P+arf/xSw== X-Received: by 10.28.60.11 with SMTP id j11mr109095wma.99.1456852763249; Tue, 01 Mar 2016 09:19:23 -0800 (PST) Received: from localhost (beleg.madhouse-project.org. [128.199.36.147]) by smtp.gmail.com with ESMTPSA id v78sm71519wmv.23.2016.03.01.09.19.21 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 01 Mar 2016 09:19:22 -0800 (PST) Date: Tue, 1 Mar 2016 18:17:30 +0100 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 Subject: [PATCH v4 3/3] Documentation for the GCC plugin infrastructure Message-Id: <20160301181730.761d97e13e1cc92ea618e88c@gmail.com> In-Reply-To: <20160301181400.9c623ee9230381da90b89b2a@gmail.com> References: <20160301181400.9c623ee9230381da90b89b2a@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=-6.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 | 82 +++++++++++++++++++++++++++++++++++++++++++ arch/Kconfig | 2 ++ 2 files changed, 84 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..ffb56a3 --- /dev/null +++ b/Documentation/gcc-plugins.txt @@ -0,0 +1,82 @@ +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 architecture. + +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)/tools/gcc + This is the directory of the GCC plugins. + +$(src)/tools/gcc/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)/tools/gcc/gcc-generate-gimple-pass.h +$(src)/tools/gcc/gcc-generate-ipa-pass.h +$(src)/tools/gcc/gcc-generate-simple_ipa-pass.h +$(src)/tools/gcc/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)/tools/gcc/. You can use a file or a directory +here. It must be added to $(src)/tools/gcc/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 fa158b2..dc901d3 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -370,6 +370,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