From patchwork Tue Dec 2 17:56:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Vyukov X-Patchwork-Id: 416958 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 58B3E14013F for ; Wed, 3 Dec 2014 04:57:37 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:cc:content-type; q=dns; s=default; b=FvZ5S3ySDzMjgiYlKyP+ZRzYVhRCx3SN8Dzs51sMlIa x07w/lbO0zka/Y6bcJMLaC3wURoPIAYv1pxJrzxrtJ97uj9GkNaQRGtOofZm8lHA SOLDuepj2BCXRIHrQ0IRrDrlyKLS+Pbwv78L1jEkyYJJlvtkK1ZFGoZrg10SZSI4 = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:cc:content-type; s=default; bh=8e3qZezjovhWalb5e0dkyulXVBA=; b=SP3JZMy1Dvh34AqCv nJ+jiGwQ66z5E/0h0w//GclITWrnJTH7fHgPueehtCybkDJfcb66fZK9fN3ZyzLS SD2WdCWq6Qh7HjYT+4AHgfVJoI9hdXfk265U8WMUR4RcA/8ZOnt/6ML1w2ZVby9e pBU8k3cUFwykqI2XOR99nIGi/4= Received: (qmail 5384 invoked by alias); 2 Dec 2014 17:57:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 5371 invoked by uid 89); 2 Dec 2014 17:57:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SEM_URI, SEM_URIRED, SPF_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mail-lb0-f174.google.com Received: from mail-lb0-f174.google.com (HELO mail-lb0-f174.google.com) (209.85.217.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 02 Dec 2014 17:57:29 +0000 Received: by mail-lb0-f174.google.com with SMTP id w7so10758242lbi.5 for ; Tue, 02 Dec 2014 09:57:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc :content-type; bh=PtPoCfqqjF+l0id4J4OPyMt9juhB1AqKx6jtlo/2Rhk=; b=a3eM4u3ZvMR96JG/eAsCYxwBlY3dYo06DiJxjR81sZlZ8yafejP/CRacjpQ6a7a+If WEg+fB0AafHLkTDdxDQgH0N/5v7bp1H7q0y8v+ZHldFcTT14pOQq16PJTurA7KT2+cFd sM09q+XPp9PBpo2Nk6UVSfJzdxcrrzaCkAh8zCf1gWUUzmojutjEWLviD8vSrPDZB3S3 wyMz0KPedt2HyfzKWKtu2tTa4VVgskxg54Xy+xRA3DGgwUkPwxZyT3Ti8fKaNRULadXy Tlsu+9bwr9xTTq13U7O6+L2K8o7oRS8HOJYjNQmDr+SC/mbJcVtqp0pVharc+5gYoBJ/ eKJQ== X-Gm-Message-State: ALoCoQmiavxtoaEEmWYBnNzFk7h7Mcvj9xjH5Kjh3fzI6cq1QdIZHQk+Gh1oF+FOKg+moaFzmHw+ X-Received: by 10.152.30.39 with SMTP id p7mr474351lah.5.1417543016734; Tue, 02 Dec 2014 09:56:56 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.133.8 with HTTP; Tue, 2 Dec 2014 09:56:36 -0800 (PST) From: Dmitry Vyukov Date: Tue, 2 Dec 2014 21:56:36 +0400 Message-ID: Subject: asan: support for globals in kernel To: Jakub Jelinek , Dodji Seketeli , Andrey Ryabinin , Yury Gribov Cc: GCC Patches , Kostya Serebryany , Dmitry Chernenkov , Andrey Konovalov X-IsSubscribed: yes Hi, The following patch adds support for instrumentation of globals for Linux kernel (-fsanitize=kernel-address). Kernel only supports constructors with default priority, but the rest works fine. OK for trunk? https://codereview.appspot.com/176570043 Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 218280) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2014-12-02 Dmitry Vyukov + + * asan.c: (asan_finish_file): Use default priority for constructors + in kernel mode. + 2014-12-02 Ulrich Weigand PR target/64115 Index: gcc/asan.c =================================================================== --- gcc/asan.c (revision 218280) +++ gcc/asan.c (working copy) @@ -1348,7 +1348,9 @@ the var that is selected by the linker will have padding or not. */ || DECL_ONE_ONLY (decl) - /* Similarly for common vars. People can use -fno-common. */ + /* Similarly for common vars. People can use -fno-common. + Note: Linux kernel is built with -fno-common, so we do instrument + globals there even if it is C. */ || (DECL_COMMON (decl) && TREE_PUBLIC (decl)) /* Don't protect if using user section, often vars placed into user section from multiple TUs are then assumed @@ -2440,6 +2442,7 @@ { varpool_node *vnode; unsigned HOST_WIDE_INT gcount = 0; + int priority; if (shadow_ptr_types[0] == NULL_TREE) asan_init_shadow_ptr_types (); @@ -2448,6 +2451,13 @@ nor after .LASAN* array. */ flag_sanitize &= ~SANITIZE_ADDRESS; + /* For user-space we want asan constructors to run first. + Linux kernel does not support priorities other than default, and the only + other user of constructors is coverage. So we run with the default + priority. */ + priority = flag_sanitize & SANITIZE_USER_ADDRESS ? + MAX_RESERVED_INIT_PRIORITY - 1 : DEFAULT_INIT_PRIORITY; + if (flag_sanitize & SANITIZE_USER_ADDRESS) { tree fn = builtin_decl_implicit (BUILT_IN_ASAN_INIT); @@ -2503,12 +2513,10 @@ build_fold_addr_expr (var), gcount_tree), &dtor_statements); - cgraph_build_static_cdtor ('D', dtor_statements, - MAX_RESERVED_INIT_PRIORITY - 1); + cgraph_build_static_cdtor ('D', dtor_statements, priority); } if (asan_ctor_statements) - cgraph_build_static_cdtor ('I', asan_ctor_statements, - MAX_RESERVED_INIT_PRIORITY - 1); + cgraph_build_static_cdtor ('I', asan_ctor_statements, priority); flag_sanitize |= SANITIZE_ADDRESS; }