From patchwork Mon Feb 22 19:17:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emese Revfy X-Patchwork-Id: 8382311 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 0DAC1C0553 for ; Mon, 22 Feb 2016 19:19:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0306D205BE for ; Mon, 22 Feb 2016 19:19:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8174204AB for ; Mon, 22 Feb 2016 19:19:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752122AbcBVTTA (ORCPT ); Mon, 22 Feb 2016 14:19:00 -0500 Received: from mail-wm0-f48.google.com ([74.125.82.48]:34168 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752098AbcBVTS7 (ORCPT ); Mon, 22 Feb 2016 14:18:59 -0500 Received: by mail-wm0-f48.google.com with SMTP id b205so169741076wmb.1 for ; Mon, 22 Feb 2016 11:18:58 -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=/lIp814a4lXnfuGUtIuPeGkug5sFjiP/tGt4SKETwDo=; b=o0uj+ZKkeDMx20b/2/x8vqEhLF4kcAInzX6O38aQKXXgq3jYcyasnYgI6QKxxja26A pzC8fwvS9C1VowK6UrW0EFIuZCLkPthaZftJ5mprcNt9TzFOpC9ioblfh6vVS0/jyIgU LPTV4hA91Bem+i0+EpEZMi4jOIdRp1FiSIWC8N3OgLZnEZxASK1KpKaix84uJWZcLbLD TjN54q7D3/+/3OKm4gESsKFix/ODjhJDTXgy7RG6ptaaix5L2u0g2ulIB5lExVrbPGHc 7Rse5ti2VD5vsF/v0/gfFFcUJ0xMAe7hGqFwYNqKiz7ahBdnxLdwDfLcSTo4ndvBAAdY g2MA== 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=/lIp814a4lXnfuGUtIuPeGkug5sFjiP/tGt4SKETwDo=; b=bDJyF1+P2seRgzAJvrLbXMuIwv6rvr5yf0T/SVvtipyCdPYCHVtfv4rz3OWvihgY+T FfbRNu+RvBGoSIXyt5Pg29rsBBBWXbMuPMeLqD/md6zGuPTBWCuag0//HEsZbXpIW+PS qrUxRP5OzhRsjRekQJDm1jXH6wDMnyi7okONKg+C24cZ1SXDDnQTN1fbkaBUqk7x3qiD gb6R9uogt6INXBqPqY6PNk1qWWrpzbDmsKvUKvimCYgbUBVOZq3ieyA+gU3a2c4VY6y1 seIQS/+PdEP1KVV1pMdUl9oPeCKQWvAfViAevhMO+onGYhkpqQWFtz6877w2TDtRyMTi v4Ug== X-Gm-Message-State: AG10YOQjF8b+g3CVv3K1L0Ui2+J0j65LTDywELDBlanNBs0+Y5pLTfDuPQaz1EgzmrCRFg== X-Received: by 10.28.188.138 with SMTP id m132mr14403723wmf.29.1456168738000; Mon, 22 Feb 2016 11:18:58 -0800 (PST) Received: from localhost (beleg.madhouse-project.org. [128.199.36.147]) by smtp.gmail.com with ESMTPSA id c7sm22355739wmd.13.2016.02.22.11.18.56 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 22 Feb 2016 11:18:57 -0800 (PST) Date: Mon, 22 Feb 2016 20:17:06 +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 Subject: [PATCH v3 3/3] Documentation for the GCC plugin infrastructure Message-Id: <20160222201706.be4f5f89a277e5d116f97698@gmail.com> In-Reply-To: <20160222201335.449323716ca4d929f92424d5@gmail.com> References: <20160222201335.449323716ca4d929f92424d5@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. --- 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 b8b1afc..a490f17 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -377,6 +377,8 @@ config GCC_PLUGIN_CYC_COMPLEXITY N = the number of nodes P = the number of connected components (exit nodes). + See Documentation/gcc-plugins.txt for details. + endmenu # "GCC plugins" config HAVE_CC_STACKPROTECTOR