From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 123121 invoked by alias); 12 Jan 2016 10:01:41 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 123013 invoked by uid 89); 12 Jan 2016 10:01:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.0 required=5.0 tests=BAYES_20,SPF_PASS autolearn=ham version=3.3.2 spammy=varasmc, varasm.c, UD:varasm.c, UD:local X-HELO: prv-mh.provo.novell.com Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 12 Jan 2016 10:01:33 +0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Tue, 12 Jan 2016 03:01:31 -0700 Message-Id: <5694DD0902000078000C5D71@prv-mh.provo.novell.com> Date: Tue, 12 Jan 2016 10:01:00 -0000 From: "Jan Beulich" To: Subject: Ping: check initializer to be zero in .bss-like sections Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-SW-Source: 2016-01/txt/msg00678.txt.bz2 >>> On 10.12.15 at 08:21, wrote: > Just like gas, which has recently learned to reject such initializers, > gcc shouldn't accept such either. > --- > The only question really is whether the new test case should be limited > to certain targets - I haven't been able to figure out possible valid > qualifiers to use here. >=20 > gcc/ > 2015-12-10 Jan Beulich >=20 > * varasm.c (get_variable_section): Validate initializer in > named .bss-like sections. >=20 > gcc/testsuite/ > 2015-12-10 Jan Beulich >=20 > * gcc.dg/bss.c: New. >=20 > --- 2015-12-09/gcc/testsuite/gcc.dg/bss.c > +++ 2015-12-09/gcc/testsuite/gcc.dg/bss.c > @@ -0,0 +1,8 @@ > +/* Test non-zero initializers in .bss-like sections get properly refused= .=20=20 > */ > +/* { dg-do compile } */ > +/* { dg-options "" } */ > + > +int __attribute__((section(".bss.local"))) x =3D 1; /* { dg-error "" "ze= ro=20 > init" } */ > +int *__attribute__((section(".bss.local"))) px =3D &x; /* { dg-error "" = "zero=20 > init" } */ > +int __attribute__((section(".bss.local"))) y =3D 0; > +int *__attribute__((section(".bss.local"))) py =3D (void*)0; > --- 2015-12-09/gcc/varasm.c > +++ 2015-12-09/gcc/varasm.c > @@ -1150,7 +1150,18 @@ get_variable_section (tree decl, bool pr >=20=20 > resolve_unique_section (decl, reloc, flag_data_sections); > if (IN_NAMED_SECTION (decl)) > - return get_named_section (decl, NULL, reloc); > + { > + section *sect =3D get_named_section (decl, NULL, reloc); > + > + if ((sect->common.flags & SECTION_BSS) && !bss_initializer_p (decl= )) > + { > + error_at (DECL_SOURCE_LOCATION (decl), > + "only zero initializers are allowed in section %qs", > + sect->named.name); > + DECL_INITIAL (decl) =3D error_mark_node; > + } > + return sect; > + } >=20=20 > if (ADDR_SPACE_GENERIC_P (as) > && !DECL_THREAD_LOCAL_P (decl) >=20 >=20 >=20