From patchwork Fri Apr 18 04:21:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5p6X5L2c5YGl?= X-Patchwork-Id: 340212 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 DF88D1412D8 for ; Fri, 18 Apr 2014 15:22:13 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=ghBbmG1xWfPEwHxkOGp3KstqHKWPNVng4bJkopUR/VGAtiWMj6L22 r2suzw5M0yitsasn6Vi8vJRn1vBzn47ty5SkcF6iPbBcrUackvtEAXxxQ0t+7WuN cAhdvIwkPRsVL2eXOQCevBmqdj4P1npEvUHjpj56mlOonfJjml/yLo= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=x2Xyohyy/W6kwt3BfmYJ4ef/ZSI=; b=v4avN6bP62COdyk7XHR8 J5QNZPa/8fsSAwC4jgUR5GByNMVCh7zHRjCseZX5THXcE8OuRex1b+gG4LD8BH+U ASxtZpuIAWadEGvMe2X4Ypq7t42IlRBbai4VKWjx0KzOE3jVtcj1o0akwPSIX/hO FlELBeGiBY5kl7vCp2IOLk4= Received: (qmail 16382 invoked by alias); 18 Apr 2014 04:22:08 -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 16361 invoked by uid 89); 18 Apr 2014 04:22:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pb0-f53.google.com Received: from mail-pb0-f53.google.com (HELO mail-pb0-f53.google.com) (209.85.160.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 18 Apr 2014 04:22:02 +0000 Received: by mail-pb0-f53.google.com with SMTP id rp16so1079997pbb.40 for ; Thu, 17 Apr 2014 21:22:00 -0700 (PDT) X-Received: by 10.68.197.99 with SMTP id it3mr19594971pbc.37.1397794920219; Thu, 17 Apr 2014 21:22:00 -0700 (PDT) Received: from ubuntu ([8.37.228.189]) by mx.google.com with ESMTPSA id qw8sm56985821pbb.27.2014.04.17.21.21.57 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 17 Apr 2014 21:21:59 -0700 (PDT) Date: Fri, 18 Apr 2014 12:21:50 +0800 From: lin zuojian To: gcc-patches@gcc.gnu.org, bernd.edlinger@hotmail.de, jakub@redhat.com Subject: [PATCH v8] PR middle-end/60281 Message-ID: <20140418042150.GA13430@ubuntu> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi, Here is the patch after the Jakub's review, and Jakub helps with the coding style. --- * asan.c (asan_emit_stack_protection): Force the base to align to appropriate bits if STRICT_ALIGNMENT. Set shadow_mem align to appropriate bits if STRICT_ALIGNMENT. * cfgexpand.c (expand_stack_vars): Set base_align appropriately when asan is on. (expand_used_vars): Leave a space in the stack frame for alignment if STRICT_ALIGNMENT. --- gcc/ChangeLog | 9 +++++++++ gcc/asan.c | 15 +++++++++++++++ gcc/cfgexpand.c | 18 ++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index da35be8..30a2b33 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2014-04-18 Lin Zuojian + PR middle-end/60281 + * asan.c (asan_emit_stack_protection): Force the base to align to + appropriate bits if STRICT_ALIGNMENT. Set shadow_mem align to + appropriate bits if STRICT_ALIGNMENT. + * cfgexpand.c (expand_stack_vars): Set base_align appropriately + when asan is on. + (expand_used_vars): Leave a space in the stack frame for alignment + if STRICT_ALIGNMENT. 2014-04-17 Jakub Jelinek PR target/60847 diff --git a/gcc/asan.c b/gcc/asan.c index 53992a8..28a476f 100644 --- a/gcc/asan.c +++ b/gcc/asan.c @@ -1017,8 +1017,17 @@ asan_emit_stack_protection (rtx base, rtx pbase, unsigned int alignb, base_align_bias = ((asan_frame_size + alignb - 1) & ~(alignb - HOST_WIDE_INT_1)) - asan_frame_size; } + /* Align base if target is STRICT_ALIGNMENT. */ + if (STRICT_ALIGNMENT) + base = expand_binop (Pmode, and_optab, base, + gen_int_mode (-((GET_MODE_ALIGNMENT (SImode) + << ASAN_SHADOW_SHIFT) + / BITS_PER_UNIT), Pmode), NULL_RTX, + 1, OPTAB_DIRECT); + if (use_after_return_class == -1 && pbase) emit_move_insn (pbase, base); + base = expand_binop (Pmode, add_optab, base, gen_int_mode (base_offset - base_align_bias, Pmode), NULL_RTX, 1, OPTAB_DIRECT); @@ -1097,6 +1106,8 @@ asan_emit_stack_protection (rtx base, rtx pbase, unsigned int alignb, && (ASAN_RED_ZONE_SIZE >> ASAN_SHADOW_SHIFT) == 4); shadow_mem = gen_rtx_MEM (SImode, shadow_base); set_mem_alias_set (shadow_mem, asan_shadow_set); + if (STRICT_ALIGNMENT) + set_mem_align (shadow_mem, (GET_MODE_ALIGNMENT (SImode))); prev_offset = base_offset; for (l = length; l; l -= 2) { @@ -1186,6 +1197,10 @@ asan_emit_stack_protection (rtx base, rtx pbase, unsigned int alignb, shadow_mem = gen_rtx_MEM (BLKmode, shadow_base); set_mem_alias_set (shadow_mem, asan_shadow_set); + + if (STRICT_ALIGNMENT) + set_mem_align (shadow_mem, (GET_MODE_ALIGNMENT (SImode))); + prev_offset = base_offset; last_offset = base_offset; last_size = 0; diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index b7f6360..14511e1 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -1013,10 +1013,19 @@ expand_stack_vars (bool (*pred) (size_t), struct stack_vars_data *data) if (data->asan_base == NULL) data->asan_base = gen_reg_rtx (Pmode); base = data->asan_base; + + if (!STRICT_ALIGNMENT) + base_align = crtl->max_used_stack_slot_alignment; + else + base_align = MAX (crtl->max_used_stack_slot_alignment, + GET_MODE_ALIGNMENT (SImode) + << ASAN_SHADOW_SHIFT); } else - offset = alloc_stack_frame_space (stack_vars[i].size, alignb); - base_align = crtl->max_used_stack_slot_alignment; + { + offset = alloc_stack_frame_space (stack_vars[i].size, alignb); + base_align = crtl->max_used_stack_slot_alignment; + } } else { @@ -1845,6 +1854,11 @@ expand_used_vars (void) = alloc_stack_frame_space (redzonesz, ASAN_RED_ZONE_SIZE); data.asan_vec.safe_push (prev_offset); data.asan_vec.safe_push (offset); + /* Leave space for alignment if STRICT_ALIGNMENT. */ + if (STRICT_ALIGNMENT) + alloc_stack_frame_space ((GET_MODE_ALIGNMENT (SImode) + << ASAN_SHADOW_SHIFT) + / BITS_PER_UNIT, 1); var_end_seq = asan_emit_stack_protection (virtual_stack_vars_rtx,