From patchwork Wed Jun 11 16:08:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 358773 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 131D51400A6 for ; Thu, 12 Jun 2014 02:08:47 +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=upnlIAcitAiJH2CmOcTv2pTq9JLe6r5VyKeHViKdx4162keTPEnsL TqjqukOQ89s/C6hgctLFZt/zISgB71dw7jvTuxSpyOWj+ETfEzKN6b2Gl9TPXzdE pQquVloFu+F0QvrgMLKOGonjo4xX2V5Y+GinqcN+6uZeTokmQPMaH0= 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=9CBZFIfJ9Rb9QWp58kjOXqeLZds=; b=ZUlmbDZJ2nnCENZPjZGM wHvBEIHeC/xWiTZ+DA2+qV9cQocxDErBpzv1UQ7fqyy+j17FR13OzJ9UIjHhHysh 4a7ls+17j88qEONTXRr53W0X9M2Hx1V83UtnGXEOG4bLSCHXndp4xfmew7q1HLXV wq9uF0//OH+u3o8mAUaqPBU= Received: (qmail 14401 invoked by alias); 11 Jun 2014 16:08:39 -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 14380 invoked by uid 89); 11 Jun 2014 16:08:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pb0-f50.google.com Received: from mail-pb0-f50.google.com (HELO mail-pb0-f50.google.com) (209.85.160.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 11 Jun 2014 16:08:37 +0000 Received: by mail-pb0-f50.google.com with SMTP id rp16so2142207pbb.23 for ; Wed, 11 Jun 2014 09:08:35 -0700 (PDT) X-Received: by 10.68.132.9 with SMTP id oq9mr6342466pbb.103.1402502915144; Wed, 11 Jun 2014 09:08:35 -0700 (PDT) Received: from msticlxl57.ims.intel.com ([192.55.54.40]) by mx.google.com with ESMTPSA id be7sm31346794pad.9.2014.06.11.09.08.33 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jun 2014 09:08:34 -0700 (PDT) Date: Wed, 11 Jun 2014 20:08:29 +0400 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH, Pointer Bounds Checker 35/x] Fix object size emitted for structures with flexible arrays Message-ID: <20140611143414.GJ17894@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, This patch fixes problem with size emitted for static structures with flexible array. I found a couple of trackers in guzilla for this problem but all of them are marked as fixed and problem still exists. For a simple testcase struct S { int a; int b[0]; } s = { 1, { 0, 0} }; current trunk produces (no flags): .globl s .data .align 4 .type s, @object .size s, 4 s: .long 1 .long 0 .long 0 which has wrong size for object s. This problem is important for checker because wrong size leads to wrong bounds and false bounds violations. Following patch uses DECL_SIZE_UNIT instead of type size and works well for me. Does it look OK? Bootstrapped and tested on linux-x86_64. Thanks, Ilya --- gcc/ 2014-06-11 Ilya Enkovich * config/elfos.h (ASM_DECLARE_OBJECT_NAME): Use decl size instead of type size. (ASM_FINISH_DECLARE_OBJECT): Likewise. diff --git a/gcc/config/elfos.h b/gcc/config/elfos.h index c1d5553..7929708 100644 --- a/gcc/config/elfos.h +++ b/gcc/config/elfos.h @@ -313,7 +313,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see && (DECL) && DECL_SIZE (DECL)) \ { \ size_directive_output = 1; \ - size = int_size_in_bytes (TREE_TYPE (DECL)); \ + size = tree_to_uhwi (DECL_SIZE_UNIT (DECL)); \ ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size); \ } \ \ @@ -341,7 +341,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see && !size_directive_output) \ { \ size_directive_output = 1; \ - size = int_size_in_bytes (TREE_TYPE (DECL)); \ + size = tree_to_uhwi (DECL_SIZE_UNIT (DECL)); \ ASM_OUTPUT_SIZE_DIRECTIVE (FILE, name, size); \ } \ } \