From patchwork Sun Mar 6 23:06: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: 8514231 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 E370AC0553 for ; Sun, 6 Mar 2016 23:08:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D6B9B201C0 for ; Sun, 6 Mar 2016 23:08:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8740E200DC for ; Sun, 6 Mar 2016 23:08:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751531AbcCFXI3 (ORCPT ); Sun, 6 Mar 2016 18:08:29 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34709 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751510AbcCFXI3 (ORCPT ); Sun, 6 Mar 2016 18:08:29 -0500 Received: by mail-wm0-f67.google.com with SMTP id p65so7939369wmp.1; Sun, 06 Mar 2016 15:08:28 -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=k327d8SSIJD9/liDWbgu9uOVdIw4/GQGt8b/9i+fkP4=; b=0sZuuF43gbmiuqvPu8dOavuy0HnH4UwqiyGLacKwQkQ9+hxVnlZaG0i6ofDX99SNwy 1vHxcQyCqDM/q6loOyzx2cQE94NHXRkrsmbkVGaDdGeH+sEG3yxMfqx+7Vv56iAAOYeg qxIOEyw5KIoI8VGMY5JpsJ4x2rxvP+B2n31FOOxJmEelPy2TNrdxe5wsX3J0otWSLzMk ws9zR3MuRnGRoV1N8N0l1PBEQtSnWTSbT0EBuleOn5qu2HGrgL/2Ib5gqM8ZEj60CYja bMEsS91ADf5bMESsxY7oxeiRBZ2HPCDxKJGfviaysjoNaIOj4vQL0DIogowG3+D5BgJ8 Bcsg== 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=k327d8SSIJD9/liDWbgu9uOVdIw4/GQGt8b/9i+fkP4=; b=TRTHJrCAZhQCV+j8w1DFmfXX9Q/p3iHM/zRw3+mVCD0IPzeiXpjB0q4T/NBbJ7a4RG Jeg0Rcd3V4+zLn13TgD6dBfLl85kHrtNWnlD7iW0/ZRzOCQMaKjzYcU3p7eFZLIRms2R 1mdLowHH/5DbGEyhynZKZFWCtoQ3LTWKfM80I7JzXnqEPuqNDfVMZkAZcE/uxdEBy8Wu U8OH1m6F/HUuunXY47slllB88L7/yk5CH91m7JJWyQEiWWhQZBS5ePpWVn5zJ6svj3Ej byhJCRy+2ioS2BNmvKutFsIBxV6h5wW90kYMLb1MhZYIPGEcVvHTkfVQ8PwqDnY+qRmY ENOA== X-Gm-Message-State: AD7BkJJG1VDUFGxUrmmRbYqXl/b7FHsLQ4fdytSQamIx6BA10Th646v1/x3bBeFk9bqoww== X-Received: by 10.194.172.3 with SMTP id ay3mr5057286wjc.155.1457305707531; Sun, 06 Mar 2016 15:08:27 -0800 (PST) Received: from localhost (beleg.madhouse-project.org. [128.199.36.147]) by smtp.gmail.com with ESMTPSA id ls5sm14917733wjb.33.2016.03.06.15.08.25 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 06 Mar 2016 15:08:26 -0800 (PST) Date: Mon, 7 Mar 2016 00:06: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, dvyukov@google.com, linux-kernel@vger.kernel.org Subject: [PATCH v5 4/5] Documentation for the GCC plugin infrastructure Message-Id: <20160307000630.11bd95036594808b6f575f96@gmail.com> In-Reply-To: <20160307000208.1bec3e7dc874489d1b4fcbb4@gmail.com> References: <20160307000208.1bec3e7dc874489d1b4fcbb4@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 59bde9b..32583b7 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