public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: <gcc-patches@gcc.gnu.org>
Subject: Ping: check initializer to be zero in .bss-like sections
Date: Tue, 12 Jan 2016 10:01:00 -0000	[thread overview]
Message-ID: <5694DD0902000078000C5D71@prv-mh.provo.novell.com> (raw)

>>> 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.
> 
> gcc/
> 2015-12-10  Jan Beulich  <jbeulich@suse.com>
> 
> 	* varasm.c (get_variable_section): Validate initializer in
> 	named .bss-like sections.
> 
> gcc/testsuite/
> 2015-12-10  Jan Beulich  <jbeulich@suse.com>
> 
> 	* gcc.dg/bss.c: New.
> 
> --- 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.  
> */
> +/* { dg-do compile } */
> +/* { dg-options "" } */
> +
> +int __attribute__((section(".bss.local"))) x = 1; /* { dg-error "" "zero 
> init" } */
> +int *__attribute__((section(".bss.local"))) px = &x; /* { dg-error "" "zero 
> init" } */
> +int __attribute__((section(".bss.local"))) y = 0;
> +int *__attribute__((section(".bss.local"))) py = (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
>  
>    resolve_unique_section (decl, reloc, flag_data_sections);
>    if (IN_NAMED_SECTION (decl))
> -    return get_named_section (decl, NULL, reloc);
> +    {
> +      section *sect = 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) = error_mark_node;
> +	}
> +      return sect;
> +    }
>  
>    if (ADDR_SPACE_GENERIC_P (as)
>        && !DECL_THREAD_LOCAL_P (decl)
> 
> 
> 



             reply	other threads:[~2016-01-12 10:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-12 10:01 Jan Beulich [this message]
2016-01-14 22:38 ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5694DD0902000078000C5D71@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).