This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix bss_initializer_p (PR target/83100)


Hi!

As the testcases show, it is essential that bss_initializer_p returns
true for DECL_COMMON vars without initializer, even when they are
TREE_READONLY, otherwise they aren't really common, e.g.
  if (DECL_COMMON (decl))
    {
      /* If the decl has been given an explicit section name, or it resides
         in a non-generic address space, then it isn't common, and shouldn't
         be handled as such.  */
      gcc_assert (DECL_SECTION_NAME (decl) == NULL
                  && ADDR_SPACE_GENERIC_P (as));
      if (DECL_THREAD_LOCAL_P (decl))
        return tls_comm_section;
      else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
        return comm_section;
    }
falls through into non-common code, and on section anchors target sometimes
ICE.

Fixed thusly, bootstrapped/regtested on powerpc64le-linux, bootstrapped
also on {powerpc64,x86_64,i686}-linux, ok for trunk if the pending
regtests on the above 3 targets succeed?

2017-11-24  Jakub Jelinek  <jakub@redhat.com>

	PR target/83100
	* varasm.c (bss_initializer_p): Return true for DECL_COMMON
	TREE_READONLY decls.

	* gcc.dg/pr83100-1.c: New test.
	* gcc.dg/pr83100-2.c: New test.
	* gcc.dg/pr83100-3.c: New test.
	* gcc.dg/pr83100-4.c: New test.

--- gcc/varasm.c.jj	2017-11-21 20:23:02.000000000 +0100
+++ gcc/varasm.c	2017-11-24 21:43:55.616951823 +0100
@@ -986,9 +986,9 @@ decode_reg_name (const char *name)
 bool
 bss_initializer_p (const_tree decl)
 {
-  /* Do not put constants into the .bss section, they belong in a readonly
-     section.  */
-  return (!TREE_READONLY (decl)
+  /* Do not put non-common constants into the .bss section, they belong in
+     a readonly section.  */
+  return ((!TREE_READONLY (decl) || DECL_COMMON (decl))
 	  && (DECL_INITIAL (decl) == NULL
 	      /* In LTO we have no errors in program; error_mark_node is used
 	         to mark offlined constructors.  */
--- gcc/testsuite/gcc.dg/pr83100-1.c.jj	2017-11-24 21:56:52.957497438 +0100
+++ gcc/testsuite/gcc.dg/pr83100-1.c	2017-11-24 22:01:03.433437167 +0100
@@ -0,0 +1,7 @@
+/* PR target/83100 */
+/* { dg-do compile { target *-*-linux* *-*-gnu* } } */
+/* { dg-options "-O2 -fcommon -fdata-sections" } */
+
+const int a;
+
+/* { dg-final { scan-assembler "comm" } } */
--- gcc/testsuite/gcc.dg/pr83100-2.c.jj	2017-11-24 21:58:54.475012758 +0100
+++ gcc/testsuite/gcc.dg/pr83100-2.c	2017-11-24 22:01:09.108367832 +0100
@@ -0,0 +1,15 @@
+/* PR target/83100 */
+/* { dg-do run } */
+/* { dg-options "-O2 -fcommon -fdata-sections" } */
+/* { dg-additional-sources pr83100-3.c } */
+/* { dg-skip-if "-fdata-sections not supported" { hppa*-*-hpux* nvptx-*-* } } */
+
+const int a;
+
+int
+main ()
+{
+  if (a != 7)
+    __builtin_abort ();
+  return 0;
+}
--- gcc/testsuite/gcc.dg/pr83100-3.c.jj	2017-11-24 21:59:57.072247956 +0100
+++ gcc/testsuite/gcc.dg/pr83100-3.c	2017-11-24 22:01:14.344303860 +0100
@@ -0,0 +1,6 @@
+/* PR target/83100 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fcommon -fdata-sections" } */
+/* { dg-skip-if "-fdata-sections not supported" { hppa*-*-hpux* nvptx-*-* } } */
+
+const int a = 7;
--- gcc/testsuite/gcc.dg/pr83100-4.c.jj	2017-11-24 22:00:13.405048405 +0100
+++ gcc/testsuite/gcc.dg/pr83100-4.c	2017-11-24 22:01:20.281231323 +0100
@@ -0,0 +1,7 @@
+/* PR target/83100 */
+/* { dg-do compile { target *-*-linux* *-*-gnu* } } */
+/* { dg-options "-O2 -fno-common -fdata-sections" } */
+
+const int a;
+
+/* { dg-final { scan-assembler "rodata.a" } } */

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]