diff mbox

[v2] check initializer to be zero in .bss-like sections

Message ID 5776442102000078000FA511@prv-mh.provo.novell.com
State New
Headers show

Commit Message

Jan Beulich July 1, 2016, 8:21 a.m. UTC
Just like gas, which has recently learned to reject such initializers,
gcc shouldn't accept such either.
---
v2: Use dg-require-named-sections.

gcc/
2016-07-01  Jan Beulich  <jbeulich@suse.com>

	* varasm.c (get_variable_section): Validate initializer in
	named .bss-like sections.

gcc/testsuite/
2016-07-01  Jan Beulich  <jbeulich@suse.com>

	* gcc.dg/bss.c: New.

Comments

Bernd Schmidt July 1, 2016, 1:36 p.m. UTC | #1
On 07/01/2016 10:21 AM, Jan Beulich wrote:
> Just like gas, which has recently learned to reject such initializers,
> gcc shouldn't accept such either.
> ---
> v2: Use dg-require-named-sections.
>
> gcc/
> 2016-07-01  Jan Beulich  <jbeulich@suse.com>
>
> 	* varasm.c (get_variable_section): Validate initializer in
> 	named .bss-like sections.
>
> gcc/testsuite/
> 2016-07-01  Jan Beulich  <jbeulich@suse.com>
>
> 	* gcc.dg/bss.c: New.

Looks ok, except why the empty dg-options string in the testcase?


Bernd
Jan Beulich July 1, 2016, 1:42 p.m. UTC | #2
>>> On 01.07.16 at 15:36, <bschmidt@redhat.com> wrote:
> On 07/01/2016 10:21 AM, Jan Beulich wrote:
>> Just like gas, which has recently learned to reject such initializers,
>> gcc shouldn't accept such either.
>> ---
>> v2: Use dg-require-named-sections.
>>
>> gcc/
>> 2016-07-01  Jan Beulich  <jbeulich@suse.com>
>>
>> 	* varasm.c (get_variable_section): Validate initializer in
>> 	named .bss-like sections.
>>
>> gcc/testsuite/
>> 2016-07-01  Jan Beulich  <jbeulich@suse.com>
>>
>> 	* gcc.dg/bss.c: New.
> 
> Looks ok, except why the empty dg-options string in the testcase?

Because I've seen in it that way in various other test cases (and
yes, yet others don't have it). I had to decide for one of the
variants, and if it's not required (nor wanted) I can certainly drop
it.

Jan
Bernd Schmidt July 1, 2016, 1:44 p.m. UTC | #3
On 07/01/2016 03:42 PM, Jan Beulich wrote:
>>>> On 01.07.16 at 15:36, <bschmidt@redhat.com> wrote:

>> Looks ok, except why the empty dg-options string in the testcase?
>
> Because I've seen in it that way in various other test cases (and
> yes, yet others don't have it). I had to decide for one of the
> variants, and if it's not required (nor wanted) I can certainly drop
> it.

Yes, if there's no real reason, drop it.


Bernd
Jan Beulich July 1, 2016, 1:57 p.m. UTC | #4
>>> On 01.07.16 at 15:44, <bschmidt@redhat.com> wrote:
> On 07/01/2016 03:42 PM, Jan Beulich wrote:
>>>>> On 01.07.16 at 15:36, <bschmidt@redhat.com> wrote:
> 
>>> Looks ok, except why the empty dg-options string in the testcase?
>>
>> Because I've seen in it that way in various other test cases (and
>> yes, yet others don't have it). I had to decide for one of the
>> variants, and if it's not required (nor wanted) I can certainly drop
>> it.
> 
> Yes, if there's no real reason, drop it.

Do I need to re-submit, or can I take the above as approved-with-
that-change?

Jan
Bernd Schmidt July 1, 2016, 2:06 p.m. UTC | #5
On 07/01/2016 03:57 PM, Jan Beulich wrote:
> Do I need to re-submit, or can I take the above as approved-with-
> that-change?

Ok with that change.


Bernd
diff mbox

Patch

--- 2016-06-30/gcc/testsuite/gcc.dg/bss.c
+++ 2016-06-30/gcc/testsuite/gcc.dg/bss.c
@@ -0,0 +1,9 @@ 
+/* Test non-zero initializers in .bss-like sections get properly refused.  */
+/* { dg-do compile } */
+/* { dg-require-named-sections "" } */
+/* { 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;
--- 2016-06-30/gcc/varasm.c
+++ 2016-06-30/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)