diff mbox series

[pushed] Darwin : Begin rework of zero-fill sections.

Message ID 173894D1-BB64-4F5F-9212-4F17CCA6604F@sandoe.co.uk
State New
Headers show
Series [pushed] Darwin : Begin rework of zero-fill sections. | expand

Commit Message

Iain Sandoe Oct. 10, 2020, 3:54 p.m. UTC
Hi,

Much of the existing work in the Darwin BSS and common sections
was to accommodate the PowerPC section anchors.  We want to segregate
this, since it might become desirable to support section anchors for
arm64.

First revision (here) is to use the same section conventions as the Xcode
toochains for BSS and COMMON.

We also drop the constraint about putting small items into data/static data
that was a work-around for Java issues (irrelevant for several editions).

tested across the current Darwin range,
pushed to master
thanks
Iain

gcc/ChangeLog:

	* config/darwin.c (darwin_emit_local_bss): Amend section names to
	match system tools. (darwin_output_aligned_bss): Likewise.

gcc/testsuite/ChangeLog:

	* gcc.dg/darwin-sections.c: Adjust test for renamed BSS and common
	sections.  Cater for 64 and 128 bit long doubles.
---
  gcc/config/darwin.c                    | 42 +++++++++-----------------
  gcc/testsuite/gcc.dg/darwin-sections.c | 42 ++++++++++++--------------
  2 files changed, 33 insertions(+), 51 deletions(-)

*/
+/* { dg-final { scan-assembler {.zerofill __DATA,__bss,_sal_256,8,11} } } */
 
  long long foo (int x)
  {
diff mbox series

Patch

diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index b64aaa7b1a7..23116484724 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -2384,11 +2384,7 @@  darwin_emit_local_bss (FILE *fp, tree decl, const  
char *name,
  			unsigned HOST_WIDE_INT size,
  			unsigned int l2align)
  {
-   /* FIXME: We have a fudge to make this work with Java even when the  
target does
-   not use sections anchors -- Java seems to need at least one small item  
in a
-   non-zerofill segment.   */
-   if ((DARWIN_SECTION_ANCHORS && flag_section_anchors && size <  
BYTES_ZFILL)
-       || (size && size <= 2))
+   if (DARWIN_SECTION_ANCHORS && flag_section_anchors && size < BYTES_ZFILL)
      {
        /* Put smaller objects in _static_data, where the section anchors system
  	 can get them.
@@ -2414,16 +2410,13 @@  darwin_emit_local_bss (FILE *fp, tree decl, const  
char *name,
      }
    else
      {
-      /* When we are on a non-section anchor target, we can get zero-sized
-	 items here.  However, all we need to do is to bump them to one byte
-	 and the section alignment will take care of the rest.  */
+      /* When we are on a non-section anchor target (or not using section
+	 anchors, we can get zero-sized items here.  However, all we need to
+	 do is to bump them to one byte and the section alignment will take
+	 care of the rest.  */
        char secnam[64];
-      unsigned int flags ;
-      snprintf (secnam, 64, "__DATA,__%sbss%u", ((size)?"":"zo_"),
-						(unsigned) l2align);
-      /* We can't anchor (yet, if ever) in zerofill sections, because we  
can't
-	 switch to them and emit a label.  */
-      flags = SECTION_BSS|SECTION_WRITE|SECTION_NO_ANCHOR;
+      snprintf (secnam, 64, "__DATA,__bss");
+      unsigned int flags = SECTION_BSS|SECTION_WRITE|SECTION_NO_ANCHOR;
        in_section = get_section (secnam, flags, NULL);
        fprintf (fp, "\t.zerofill %s,", secnam);
        assemble_name (fp, name);
@@ -2434,7 +2427,7 @@  darwin_emit_local_bss (FILE *fp, tree decl, const  
char *name,
  	fprintf (fp, "," HOST_WIDE_INT_PRINT_UNSIGNED",%u\n",
  		 size, (unsigned) l2align);
        else
-	fprintf (fp, "," HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
+	fprintf (fp, "," HOST_WIDE_INT_PRINT_UNSIGNED",0\n", size);
      }
 
    (*targetm.encode_section_info) (decl, DECL_RTL (decl), false);
@@ -2559,9 +2552,8 @@  fprintf (fp, "# albss: %s (%lld,%d) ro %d cst %d stat  
%d com %d"
        return;
      }
 
-  /* So we have a public symbol (small item fudge for Java, see above).  */
-  if ((DARWIN_SECTION_ANCHORS && flag_section_anchors && size < BYTES_ZFILL)
-       || (size && size <= 2))
+  /* So we have a public symbol.  */
+  if (DARWIN_SECTION_ANCHORS && flag_section_anchors && size < BYTES_ZFILL)
      {
        /* Put smaller objects in data, where the section anchors system can get
  	 them.  However, if they are zero-sized punt them to yet a different
@@ -2586,16 +2578,10 @@  fprintf (fp, "# albss: %s (%lld,%d) ro %d cst %d  
stat %d com %d"
      }
    else
      {
+      /* Section anchors not in use.  */
+      unsigned int flags = SECTION_BSS|SECTION_WRITE|SECTION_NO_ANCHOR;
        char secnam[64];
-      unsigned int flags ;
-      /* When we are on a non-section anchor target, we can get zero-sized
-	 items here.  However, all we need to do is to bump them to one byte
-	 and the section alignment will take care of the rest.  */
-      snprintf (secnam, 64, "__DATA,__%spu_bss%u", ((size)?"":"zo_"),  
l2align);
-
-      /* We can't anchor in zerofill sections, because we can't switch
-	 to them and emit a label.  */
-      flags = SECTION_BSS|SECTION_WRITE|SECTION_NO_ANCHOR;
+      snprintf (secnam, 64, "__DATA,__common");
        in_section = get_section (secnam, flags, NULL);
        fprintf (fp, "\t.zerofill %s,", secnam);
        assemble_name (fp, name);
@@ -2605,7 +2591,7 @@  fprintf (fp, "# albss: %s (%lld,%d) ro %d cst %d stat  
%d com %d"
        if (l2align)
  	fprintf (fp, "," HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", size, l2align);
        else
-	fprintf (fp, "," HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
+	fprintf (fp, "," HOST_WIDE_INT_PRINT_UNSIGNED",0\n", size);
      }
    (* targetm.encode_section_info) (decl, DECL_RTL (decl), false);
  }
diff --git a/gcc/testsuite/gcc.dg/darwin-sections.c  
b/gcc/testsuite/gcc.dg/darwin-sections.c
index 276ffa391ed..dbe37027f89 100644
--- a/gcc/testsuite/gcc.dg/darwin-sections.c
+++ b/gcc/testsuite/gcc.dg/darwin-sections.c
@@ -13,45 +13,41 @@  e_s ea;
  /* { dg-final { scan-assembler ".comm\[\t \]_ub,1" } } */
  /* { dg-final { scan-assembler ".comm\[\t \]_ea,1" } } */
 
-/* These should go into .data */
+/* These should go into __DATA,__common */
  char a = 0;
  short b = 0;
-/* { dg-final { scan-assembler ".globl _a.*.data.*.space\[\t \]1" } } */
-/* { dg-final { scan-assembler ".globl _b.*.data.*.space\[\t \]2" } } */
-
-/* These should go into __pu_bssN */
  long long d = 0;
  float e = 0;
  double f = 0;
  long double g = 0.L;
  long long al_256 __attribute__((aligned (256))) = 0;
-/* { dg-final { scan-assembler ".zerofill __DATA,__pu_bss3,_d,8,3" } } */
-/* { dg-final { scan-assembler ".zerofill __DATA,__pu_bss2,_e,4,2" } } */
-/* { dg-final { scan-assembler ".zerofill __DATA,__pu_bss3,_f,8,3" } } */
-/* { dg-final { scan-assembler ".zerofill __DATA,__pu_bss4,_g,16,4" } } */
-/* { dg-final { scan-assembler ".zerofill __DATA,__pu_bss8,_al_256,8,8" }  
} */
+/* { dg-final { scan-assembler {.zerofill __DATA,__common,_a,1,0} } } */
+/* { dg-final { scan-assembler {.zerofill __DATA,__common,_b,2,1} } } */
+/* { dg-final { scan-assembler {.zerofill __DATA,__common,_d,8,3} } } */
+/* { dg-final { scan-assembler {.zerofill __DATA,__common,_e,4,2} } } */
+/* { dg-final { scan-assembler {.zerofill __DATA,__common,_f,8,3} } } */
+/* long double can be 64 or 128 bits depending on the Darwin subtarget.  */
+/* { dg-final { scan-assembler {.zerofill __DATA,__common,_g,(16,4|8,3)} }  
} */
+/* { dg-final { scan-assembler {.zerofill __DATA,__common,_al_256,8,8} } }  
*/
 
-/* This should go into __zo_bss0 */
+/* These should go into __DATA,__bss */
  static e_s sea;
-/* { dg-final { scan-assembler ".zerofill __DATA,__zo_bss0,_sea,1" } } */
-
-/* These should go into .static_data */
  static char sa ;
  static short sb ;
-/* { dg-final { scan-assembler ".static_data.*_sa:.*.space\[\t \]1" } } */
-/* { dg-final { scan-assembler ".static_data.*_sb:.*.space\[\t \]2" } } */
-
-/* These should go into _bssN */
  static long long sd;
  static float se ;
  static double sf ;
  static long double sg;
  static long long sal_256 __attribute__((aligned (2048)));
-/* { dg-final { scan-assembler ".zerofill __DATA,__bss3,_sd,8,3" } } */
-/* { dg-final { scan-assembler ".zerofill __DATA,__bss2,_se,4,2" } } */
-/* { dg-final { scan-assembler ".zerofill __DATA,__bss3,_sf,8,3" } } */
-/* { dg-final { scan-assembler ".zerofill __DATA,__bss4,_sg,16,4" } } */
-/* { dg-final { scan-assembler ".zerofill __DATA,__bss11,_sal_256,8,11" }  
} */
+/* { dg-final { scan-assembler {.zerofill __DATA,__bss,_sea,1,0} } } */
+/* { dg-final { scan-assembler {.zerofill __DATA,__bss,_sa,1,0} } } */
+/* { dg-final { scan-assembler {.zerofill __DATA,__bss,_sb,2,1} } } */
+/* { dg-final { scan-assembler {.zerofill __DATA,__bss,_sd,8,3} } } */
+/* { dg-final { scan-assembler {.zerofill __DATA,__bss,_se,4,2} } } */
+/* { dg-final { scan-assembler {.zerofill __DATA,__bss,_sf,8,3} } } */
+/* long double can be 64 or 128 bits depending on the Darwin subtarget.  */
+/* { dg-final { scan-assembler {.zerofill __DATA,__bss,_sg,(16,4|8,3)} } }