From patchwork Tue Dec 2 18:12:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Vyukov X-Patchwork-Id: 416959 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 E486D14012C for ; Wed, 3 Dec 2014 05:13:04 +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:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=PGqtx5u3geiZvaQ 6TGHTWvTbPPCCubcIyaoM4rTe7S0QvFfBnUxRAK2yJnCptTJ5krOTowbAvRZjn2a Onap8Wh92ccD4KpKmqEjraSa5J6svlrdW6ug83XRojKts4Cue7WXs8+IBBg6Obd6 qt9svvulKRCrbS7sbFvZzCtcts9Q= 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:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; s=default; bh=x8zj8O6zR3HK4Jtis8Czn 08DFY4=; b=GDVvr1WCACEaij8nSJSUHbXJqBWx9yEIBJfkrx9JmGYJ9jdHfFFy8 59QTKb+g3/1nzKtBxZ11lHNyHXZVwtbWvjDFXDyjIpVGAMOoPOLXIlose3MV3iS0 o83BmaShhpMOQn7MHy0u0FuwwZeCIbcaLqPki1s8xGENK8AzWprjdE= Received: (qmail 15908 invoked by alias); 2 Dec 2014 18:12:56 -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 15899 invoked by uid 89); 2 Dec 2014 18:12:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.5 required=5.0 tests=AWL, BAYES_40, RCVD_IN_DNSWL_LOW, SEM_URI, SEM_URIRED, SPF_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mail-la0-f47.google.com Received: from mail-la0-f47.google.com (HELO mail-la0-f47.google.com) (209.85.215.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 02 Dec 2014 18:12:54 +0000 Received: by mail-la0-f47.google.com with SMTP id hz20so10895883lab.20 for ; Tue, 02 Dec 2014 10:12:51 -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:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=H1P9HUf6oPVBZrQJBbqm6GnYZ64kjyrVxSJa9vjuhyo=; b=fJuTgHj13gexPqZi3j50DM3S9UaagKsEc6FHBKS1TC+OoAxfJVrNVodY0JFoIRsQwP N6WfWipRoIdR2wjM8IBaF1gN5tKuLXb/oC81shI1Pbt/48WEDCoCyY0FqcIWPG3Dyieg 6Gv3PtFRoM7ejTMTtJlUHwgfsRpYt32HU0q4LU46SoUxxCZ07ClyVIIL25Irn+oyBQpD XF3VJMXHI3goxezaxqPbcIhRUwvRsyNt5DN0HKTGS8cDSGtIM+19vp27Cmb1ZNt+hAxE VLO5rc6F4lLwoWTDBRUvNjLQp+5hR6qkhE/YixgQrpGHL15MaFOyMCLz2NjmrKMDvwUs sllQ== X-Gm-Message-State: ALoCoQkDWMQGgSoZfLnfSSy4rQ1woKQ3fxecqMyqOzAXB7jouxecE+V1BPXVHQHMCmGjHiTuU7s+ X-Received: by 10.152.8.82 with SMTP id p18mr519488laa.25.1417543970967; Tue, 02 Dec 2014 10:12:50 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.133.8 with HTTP; Tue, 2 Dec 2014 10:12:30 -0800 (PST) In-Reply-To: <20141202180436.GK1860@tucnak.redhat.com> References: <20141202180436.GK1860@tucnak.redhat.com> From: Dmitry Vyukov Date: Tue, 2 Dec 2014 22:12:30 +0400 Message-ID: Subject: Re: asan: support for globals in kernel To: Jakub Jelinek Cc: Dodji Seketeli , Andrey Ryabinin , Yury Gribov , GCC Patches , Kostya Serebryany , Dmitry Chernenkov , Andrey Konovalov X-IsSubscribed: yes On Tue, Dec 2, 2014 at 9:04 PM, Jakub Jelinek wrote: > On Tue, Dec 02, 2014 at 09:56:36PM +0400, Dmitry Vyukov wrote: >> --- 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. > > Seems your MUA is eating tabs, I'll assume they are where I'd expect them to > be. > >> @@ -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 (); > > No need to declare this separately, > >> @@ -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; > > formatting plus declare it here too. This should be > int priority = flag_sanitize & SANITIZE_USER_ADDRESS > ? MAX_RESERVED_INIT_PRIORITY - 1 : DEFAULT_INIT_PRIORITY; > (? should be on the second line and aligned below flag_sanitize). > > Ok for trunk with that change. > > Shall we backport it to 4.9 branch too? If it's doable, it would be nice. Thanks. When do we expect next 4.9 release? Yes, my mail client eats tabs, here is proper version: https://codereview.appspot.com/176570043/diff/20001/gcc/ChangeLog Sorry. And here is updated text version with eaten tabs: 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 @@ -2448,6 +2450,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. */ + int 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 +2512,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; }