From 29a0ebee3ddc4ba1f6d765ba133cbb2df4068d2c Mon Sep 17 00:00:00 2001
From: rth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 17 Aug 2001 02:33:41 +0000
Subject: [PATCH]         * varasm.c (named_section_flags): Remove align
 parameter.         * varasm.c, dwarf2out.c: Update all callers.         *
 output.h: Update prototypes.

        * target.h (target.asm_out.named_section): Remove align parameter.
        * varasm.c, config/a29k/a29k.c, config/alpha/alpha.c,
        config/arm/arm.c, config/c4x/c4x.c, config/h8300/h8300.c,
        config/i386/i386.c, config/i386/winnt.c, config/m68k/m68k.c,
        config/mcore/mcore.c, config/mips/mips.c, config/rs6000/rs6000.c,
        config/sh/sh.c, config/sparc/sparc.c: Update implementations to match.

        * varasm.c (in_named_entry_eq, in_named_entry_hash): New.
        (get_named_section_flags, set_named_section_flags): New.
        (named_section_flags): Use them.
        (named_section): Do decl vs section flags check here...
        (default_section_type_flags): ... not here.
        (init_varasm_once): Create in_named_htab.
        (resolve_unique_section): Mark reloc unused.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@44953 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog              |  21 +++++
 gcc/config/a29k/a29k.c     |   6 +-
 gcc/config/alpha/alpha.c   |  11 +--
 gcc/config/arm/arm.c       |   4 +-
 gcc/config/c4x/c4x.c       |   6 +-
 gcc/config/h8300/h8300.c   |   6 +-
 gcc/config/i386/i386.c     |  12 ++-
 gcc/config/i386/winnt.c    |   3 +-
 gcc/config/m68k/m68k.c     |   6 +-
 gcc/config/mcore/mcore.c   |   4 +-
 gcc/config/mips/mips.c     |  14 +---
 gcc/config/rs6000/rs6000.c |  12 +--
 gcc/config/sh/sh.c         |   6 +-
 gcc/config/sparc/sparc.c   |   6 +-
 gcc/dwarf2out.c            |  39 +++++-----
 gcc/java/class.c           |   4 +-
 gcc/output.h               |  18 ++---
 gcc/target.h               |   8 +-
 gcc/varasm.c               | 152 ++++++++++++++++++++++++++-----------
 19 files changed, 191 insertions(+), 147 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e0c4c105b134..87a50a6fc393 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,24 @@
+2001-08-16  Richard Henderson  <rth@redhat.com>
+
+	* varasm.c (named_section_flags): Remove align parameter.
+	* varasm.c, dwarf2out.c: Update all callers.
+	* output.h: Update prototypes.
+
+	* target.h (target.asm_out.named_section): Remove align parameter.
+	* varasm.c, config/a29k/a29k.c, config/alpha/alpha.c, 
+	config/arm/arm.c, config/c4x/c4x.c, config/h8300/h8300.c,
+	config/i386/i386.c, config/i386/winnt.c, config/m68k/m68k.c,
+	config/mcore/mcore.c, config/mips/mips.c, config/rs6000/rs6000.c,
+	config/sh/sh.c, config/sparc/sparc.c: Update implementations to match.
+
+	* varasm.c (in_named_entry_eq, in_named_entry_hash): New.
+	(get_named_section_flags, set_named_section_flags): New.
+	(named_section_flags): Use them.
+	(named_section): Do decl vs section flags check here...
+	(default_section_type_flags): ... not here.
+	(init_varasm_once): Create in_named_htab.
+	(resolve_unique_section): Mark reloc unused.
+
 2001-08-16  Richard Henderson  <rth@redhat.com>
 
 	* varasm.c (force_const_mem): Keep pool alignment in bits.
diff --git a/gcc/config/a29k/a29k.c b/gcc/config/a29k/a29k.c
index 8d816b24f4cd..420e2f51dda3 100644
--- a/gcc/config/a29k/a29k.c
+++ b/gcc/config/a29k/a29k.c
@@ -48,8 +48,7 @@ static void compute_regstack_size PARAMS ((void));
 static void check_epilogue_internal_label PARAMS ((FILE *));
 static void output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
 static void output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
-static void a29k_asm_named_section PARAMS ((const char *, unsigned int,
-					    unsigned int));
+static void a29k_asm_named_section PARAMS ((const char *, unsigned int));
 
 #define min(A,B)	((A) < (B) ? (A) : (B))
 
@@ -1572,10 +1571,9 @@ output_function_epilogue (file, size)
 }
 
 static void
-a29k_asm_named_section (name, flags, align)
+a29k_asm_named_section (name, flags)
      const char *name;
      unsigned int flags ATTRIBUTE_UNUSED;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   /* ??? Is it really correct to mark all sections as "bss"?  */
   fprintf (asm_out_file, "\t.sect %s, bss\n\t.use %s\n", name, name);
diff --git a/gcc/config/alpha/alpha.c b/gcc/config/alpha/alpha.c
index aa2f979a1b3a..741a5ee97a48 100644
--- a/gcc/config/alpha/alpha.c
+++ b/gcc/config/alpha/alpha.c
@@ -151,8 +151,7 @@ static void alpha_output_function_end_prologue
 #if TARGET_ABI_OPEN_VMS
 static int vms_valid_decl_attribute_p PARAMS ((tree, tree, tree, tree));
 static unsigned int vms_section_type_flags PARAMS ((tree, const char *, int));
-static void vms_asm_named_section PARAMS ((const char *, unsigned int,
-					   unsigned int));
+static void vms_asm_named_section PARAMS ((const char *, unsigned int));
 static void vms_asm_out_constructor PARAMS ((rtx, int));
 static void vms_asm_out_destructor PARAMS ((rtx, int));
 # undef TARGET_VALID_DECL_ATTRIBUTE
@@ -6568,10 +6567,9 @@ vms_section_type_flags (decl, name, reloc)
    the section; 0 if the default should be used.  */
 
 static void
-vms_asm_named_section (name, flags, align)
+vms_asm_named_section (name, flags)
      const char *name;
      unsigned int flags;
-     unsigned int align;
 {
   const char *flag_str = "";
 
@@ -6581,11 +6579,6 @@ vms_asm_named_section (name, flags, align)
     flag_str = ",NOWRT";
 
   fprintf (asm_out_file, ".section\t%s%s\n", name, flag_str);
-
-  /* ??? An indicated alignment of 1 byte is only used by dwarf,
-     and for that we turn off auto-alignment.  */
-  if (align == 1)
-    ASM_OUTPUT_ALIGN (asm_out_file, 0);
 }
 
 /* Record an element in the table of global constructors.  SYMBOL is
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 7f89a3d61ff3..13669b75440c 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -116,7 +116,6 @@ static void	 thumb_output_function_prologue PARAMS ((FILE *,
 static int	 arm_comp_type_attributes	PARAMS ((tree, tree));
 static void	 arm_set_default_type_attributes	PARAMS ((tree));
 static void	 arm_elf_asm_named_section	PARAMS ((const char *,
-							 unsigned int,
 							 unsigned int));
 #undef Hint
 #undef Mmode
@@ -10829,10 +10828,9 @@ aof_dump_imports (f)
    used before the section type.  */
 
 static void
-arm_elf_asm_named_section (name, flags, align)
+arm_elf_asm_named_section (name, flags)
      const char *name;
      unsigned int flags;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   char flagchars[8], *f = flagchars;
   const char *type;
diff --git a/gcc/config/c4x/c4x.c b/gcc/config/c4x/c4x.c
index f6c987b36b5e..71d4c5c9394b 100644
--- a/gcc/config/c4x/c4x.c
+++ b/gcc/config/c4x/c4x.c
@@ -193,8 +193,7 @@ static int c4x_rptb_valid_p PARAMS ((rtx, rtx));
 static int c4x_label_ref_used_p PARAMS ((rtx, rtx));
 static int c4x_valid_type_attribute_p PARAMS ((tree, tree, tree, tree));
 static void c4x_insert_attributes PARAMS ((tree, tree *));
-static void c4x_asm_named_section PARAMS ((const char *, unsigned int,
-					   unsigned int));
+static void c4x_asm_named_section PARAMS ((const char *, unsigned int));
 
 /* Initialize the GCC target structure.  */
 #undef TARGET_VALID_TYPE_ATTRIBUTE
@@ -5183,10 +5182,9 @@ c4x_expand_builtin (exp, target, subtarget, mode, ignore)
 }
 
 static void
-c4x_asm_named_section (name, flags, align)
+c4x_asm_named_section (name, flags)
      const char *name;
      unsigned int flags ATTRIBUTE_UNUSED;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   fprintf (asm_out_file, "\t.sect\t\"%s\"\n", name);
 }
diff --git a/gcc/config/h8300/h8300.c b/gcc/config/h8300/h8300.c
index 55aef3876f7d..61c255f9cf7e 100644
--- a/gcc/config/h8300/h8300.c
+++ b/gcc/config/h8300/h8300.c
@@ -56,8 +56,7 @@ static const char *cond_string PARAMS ((enum rtx_code));
 static int h8300_valid_decl_attribute PARAMS ((tree, tree, tree, tree));
 static void h8300_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
 static void h8300_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
-static void h8300_asm_named_section PARAMS ((const char *, unsigned int,
-					     unsigned int));
+static void h8300_asm_named_section PARAMS ((const char *, unsigned int));
 
 /* CPU_TYPE, says what cpu we're compiling for.  */
 int cpu_type;
@@ -3329,10 +3328,9 @@ h8300_adjust_insn_length (insn, length)
 }
 
 static void
-h8300_asm_named_section (name, flags, align)
+h8300_asm_named_section (name, flags)
      const char *name;
      unsigned int flags ATTRIBUTE_UNUSED;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   /* ??? Perhaps we should be using default_coff_asm_named_section.  */
   fprintf (asm_out_file, "\t.section %s\n", name);
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 302bd6da5e6d..e952e61b08f2 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -612,8 +612,7 @@ static int ix86_comp_type_attributes PARAMS ((tree, tree));
 static void ix86_svr3_asm_out_constructor PARAMS ((rtx, int));
 #endif
 #if defined(TARGET_ELF) && defined(TARGET_COFF)
-static void sco_asm_named_section PARAMS ((const char *, unsigned int,
-					   unsigned int));
+static void sco_asm_named_section PARAMS ((const char *, unsigned int));
 static void sco_asm_out_constructor PARAMS ((rtx, int));
 #endif
 
@@ -2342,7 +2341,7 @@ ix86_asm_file_end (file)
 			      error_mark_node);
       DECL_ONE_ONLY (decl) = 1;
       UNIQUE_SECTION (decl, 0);
-      named_section (decl, NULL, 0);
+      named_section (decl, NULL);
     }
   else
 #else
@@ -10839,15 +10838,14 @@ ix86_svr3_asm_out_constructor (symbol, priority)
 
 #if defined(TARGET_ELF) && defined(TARGET_COFF)
 static void
-sco_asm_named_section (name, flags, align)
+sco_asm_named_section (name, flags)
      const char *name;
      unsigned int flags;
-     unsigned int align;
 {
   if (TARGET_ELF)
-    default_elf_asm_named_section (name, flags, align);
+    default_elf_asm_named_section (name, flags);
   else
-    default_coff_asm_named_section (name, flags, align);
+    default_coff_asm_named_section (name, flags);
 }
 
 static void
diff --git a/gcc/config/i386/winnt.c b/gcc/config/i386/winnt.c
index ff13c3863b7b..d32224f23821 100644
--- a/gcc/config/i386/winnt.c
+++ b/gcc/config/i386/winnt.c
@@ -523,10 +523,9 @@ i386_pe_section_type_flags (decl, name, reloc)
 }
 
 void
-i386_pe_asm_named_section (name, flags, align)
+i386_pe_asm_named_section (name, flags)
      const char *name;
      unsigned int flags;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   char flagchars[8], *f = flagchars;
 
diff --git a/gcc/config/m68k/m68k.c b/gcc/config/m68k/m68k.c
index 57ddad29d9ed..3a832ffbc4c2 100644
--- a/gcc/config/m68k/m68k.c
+++ b/gcc/config/m68k/m68k.c
@@ -61,8 +61,7 @@ static rtx find_addr_reg PARAMS ((rtx));
 static const char *singlemove_string PARAMS ((rtx *));
 static void m68k_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
 static void m68k_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
-static void m68k_coff_asm_named_section PARAMS ((const char *, unsigned int,
-						 unsigned int));
+static void m68k_coff_asm_named_section PARAMS ((const char *, unsigned int));
 #ifdef CTOR_LIST_BEGIN
 static void m68k_svr3_asm_out_constructor PARAMS ((rtx, int));
 #endif
@@ -4218,10 +4217,9 @@ output_xorsi3 (operands)
 /* Output assembly to switch to section NAME with attribute FLAGS.  */
 
 static void
-m68k_coff_asm_named_section (name, flags, align)
+m68k_coff_asm_named_section (name, flags)
      const char *name;
      unsigned int flags;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   char flagchar;
 
diff --git a/gcc/config/mcore/mcore.c b/gcc/config/mcore/mcore.c
index 778b734be35d..742875e4f697 100644
--- a/gcc/config/mcore/mcore.c
+++ b/gcc/config/mcore/mcore.c
@@ -133,7 +133,6 @@ static int        mcore_dllimport_p            PARAMS ((tree));
 static int        mcore_valid_decl_attribute   PARAMS ((tree, tree,
 							tree, tree));
 static void	  mcore_asm_named_section      PARAMS ((const char *,
-							unsigned int,
 							unsigned int));
 
 /* Initialize the GCC target structure.  */
@@ -3599,10 +3598,9 @@ mcore_naked_function_p ()
 }
 
 static void
-mcore_asm_named_section (name, flags, align)
+mcore_asm_named_section (name, flags)
      const char *name;
      unsigned int flags ATTRIBUTE_UNUSED;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   fprintf (asm_out_file, "\t.section %s\n", name);
 }
diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c
index 59c7e25d36fd..5e8516059b73 100644
--- a/gcc/config/mips/mips.c
+++ b/gcc/config/mips/mips.c
@@ -116,7 +116,6 @@ static void mips_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
 static void mips_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
 static enum processor_type mips_parse_cpu       PARAMS ((const char *));
 static void iris6_asm_named_section		PARAMS ((const char *,
-							 unsigned int,
 							 unsigned int));
 /* Global variables for machine-dependent things.  */
 
@@ -9754,10 +9753,9 @@ mips_parse_cpu (cpu_string)
 /* Output assembly to switch to section NAME with attribute FLAGS.  */
 
 static void
-iris6_asm_named_section (name, flags, align)
+iris6_asm_named_section (name, flags)
      const char *name;
      unsigned int flags;
-     unsigned int align;
 {
   unsigned int sh_type, sh_flags, sh_entsize;
 
@@ -9785,16 +9783,8 @@ iris6_asm_named_section (name, flags, align)
   else
     sh_entsize = 0;
 
-  if (align == 0)
-    {
-      if (flags & SECTION_CODE)
-	align = 4;
-      else
-	align = 8;
-    }
-
   fprintf (asm_out_file, "\t.section %s,%u,%u,%u,%u\n",
-	   name, sh_type, sh_flags, sh_entsize, align);
+	   name, sh_type, sh_flags, sh_entsize, 0);
 }
 
 /* Cover function for UNIQUE_SECTION.  */
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 0d74876bad70..838315ea7dc1 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -139,8 +139,7 @@ static void rs6000_elf_asm_out_constructor PARAMS ((rtx, int));
 static void rs6000_elf_asm_out_destructor PARAMS ((rtx, int));
 #endif
 #ifdef OBJECT_FORMAT_COFF
-static void xcoff_asm_named_section PARAMS ((const char *, unsigned int,
-					     unsigned int));
+static void xcoff_asm_named_section PARAMS ((const char *, unsigned int));
 #endif
 
 /* Default register names.  */
@@ -8736,7 +8735,8 @@ rs6000_elf_asm_out_constructor (symbol, priority)
       section = buf;
     }
 
-  named_section_flags (section, SECTION_WRITE, POINTER_SIZE / BITS_PER_UNIT);
+  named_section_flags (section, SECTION_WRITE);
+  assemble_align (POINTER_SIZE);
 
   if (TARGET_RELOCATABLE)
     {
@@ -8766,7 +8766,8 @@ rs6000_elf_asm_out_destructor (symbol, priority)
       section = buf;
     }
 
-  named_section_flags (section, SECTION_WRITE, POINTER_SIZE / BITS_PER_UNIT);
+  named_section_flags (section, SECTION_WRITE);
+  assemble_align (POINTER_SIZE);
 
   if (TARGET_RELOCATABLE)
     {
@@ -8781,10 +8782,9 @@ rs6000_elf_asm_out_destructor (symbol, priority)
 
 #ifdef OBJECT_FORMAT_COFF
 static void
-xcoff_asm_named_section (name, flags, align)
+xcoff_asm_named_section (name, flags)
      const char *name;
      unsigned int flags ATTRIBUTE_UNUSED;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   fprintf (asm_out_file, "\t.csect %s\n", name);
 }
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index d643d9288b61..f8d77d416f32 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -157,8 +157,7 @@ static rtx mark_constant_pool_use PARAMS ((rtx));
 static int sh_valid_decl_attribute PARAMS ((tree, tree, tree, tree));
 static void sh_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
 static void sh_insert_attributes PARAMS ((tree, tree *));
-static void sh_asm_named_section PARAMS ((const char *, unsigned int,
-					  unsigned int));
+static void sh_asm_named_section PARAMS ((const char *, unsigned int));
 
 /* Initialize the GCC target structure.  */
 #undef TARGET_VALID_DECL_ATTRIBUTE
@@ -5560,10 +5559,9 @@ sh_can_redirect_branch (branch1, branch2)
 }
 
 static void
-sh_asm_named_section (name, flags, align)
+sh_asm_named_section (name, flags)
      const char *name;
      unsigned int flags ATTRIBUTE_UNUSED;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   /* ??? Perhaps we should be using default_coff_asm_named_section.  */
   fprintf (asm_out_file, "\t.section %s\n", name);
diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c
index d47b985227ae..b0d9ade6ea07 100644
--- a/gcc/config/sparc/sparc.c
+++ b/gcc/config/sparc/sparc.c
@@ -167,8 +167,7 @@ static void sparc_nonflat_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT,
 						     int));
 static void sparc_nonflat_function_prologue PARAMS ((FILE *, HOST_WIDE_INT,
 						     int));
-static void sparc_elf_asm_named_section PARAMS ((const char *, unsigned int,
-						 unsigned int));
+static void sparc_elf_asm_named_section PARAMS ((const char *, unsigned int));
 
 /* Option handling.  */
 
@@ -8695,10 +8694,9 @@ sparc_add_gc_roots ()
 }
 
 static void
-sparc_elf_asm_named_section (name, flags, align)
+sparc_elf_asm_named_section (name, flags)
      const char *name;
      unsigned int flags;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   fprintf (asm_out_file, "\t.section\t\"%s\"", name);
 
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 5ed410a612c8..39861bedfe3d 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -1738,8 +1738,7 @@ output_call_frame_info (for_eh)
   if (for_eh)
     {
 #ifdef EH_FRAME_SECTION_NAME
-      named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE,
-			   DWARF_OFFSET_SIZE);
+      named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
 #else
       tree label = get_file_function_name ('F');
 
@@ -1751,7 +1750,7 @@ output_call_frame_info (for_eh)
       assemble_label ("__FRAME_BEGIN__");
     }
   else
-    named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG, 1);
+    named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
 
   /* Output the CIE.  */
   ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
@@ -6322,7 +6321,7 @@ output_comp_unit (die)
     secname = (const char *) DEBUG_INFO_SECTION;
 
   /* Output debugging information.  */
-  named_section_flags (secname, SECTION_DEBUG, 1);
+  named_section_flags (secname, SECTION_DEBUG);
   output_compilation_unit_header ();
   output_die (die);
 
@@ -11560,7 +11559,7 @@ dwarf2out_start_source_file (lineno, filename)
     }
   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
     {
-      named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG, 1);
+      named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
       dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
       dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
 				   lineno);
@@ -11582,7 +11581,7 @@ dwarf2out_end_source_file (lineno)
     }
   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
     {
-      named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG, 1);
+      named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
       dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
     }
 }
@@ -11604,7 +11603,7 @@ dwarf2out_define (lineno, buffer)
     }
   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
     {
-      named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG, 1);
+      named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
       dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
       dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
       dw2_asm_output_nstring (buffer, -1, "The macro");
@@ -11622,7 +11621,7 @@ dwarf2out_undef (lineno, buffer)
 {
   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
     {
-      named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG, 1);
+      named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
       dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
       dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
       dw2_asm_output_nstring (buffer, -1, "The macro");
@@ -11695,17 +11694,17 @@ dwarf2out_init (main_input_filename)
   ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
 			       DEBUG_LINE_SECTION_LABEL, 0);
   ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0);
-  named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG, 1);
+  named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
   ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
-  named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG, 1);
+  named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
   ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
-  named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG, 1);
+  named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
   ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
-  named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG, 1);
+  named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
   ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
     {
-      named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG, 1);
+      named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
       ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
 				   DEBUG_MACINFO_SECTION_LABEL, 0);
       ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
@@ -11782,7 +11781,7 @@ dwarf2out_finish (input_filename)
      examining the file.  */
   if (! DWARF2_ASM_LINE_DEBUG_INFO)
     {
-      named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG, 1);
+      named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
       output_line_info ();
     }
 
@@ -11813,13 +11812,13 @@ dwarf2out_finish (input_filename)
   output_comp_unit (comp_unit_die);
 
   /* Output the abbreviation table.  */
-  named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG, 1);
+  named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
   output_abbrev_section ();
 
   if (pubname_table_in_use)
     {
       /* Output public names table.  */
-      named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG, 1);
+      named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
       output_pubnames ();
     }
 
@@ -11828,7 +11827,7 @@ dwarf2out_finish (input_filename)
   if (fde_table_in_use)
     {
       /* Output the address range information.  */
-      named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG, 1);
+      named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
       output_aranges ();
     }
 
@@ -11836,7 +11835,7 @@ dwarf2out_finish (input_filename)
   if (have_location_lists)
     {
       /* Output the location lists info.  */
-      named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG, 1);
+      named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
       output_location_lists (die);
       have_location_lists = 0;
     }
@@ -11844,14 +11843,14 @@ dwarf2out_finish (input_filename)
   /* Output ranges section if necessary.  */
   if (ranges_table_in_use)
     {
-      named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG, 1);
+      named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
       output_ranges ();
     }
 
   /* Have to end the primary source file.  */
   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
     { 
-      named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG, 1);
+      named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
       dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
     }
 }
diff --git a/gcc/java/class.c b/gcc/java/class.c
index f7ffe12bc1f4..0f68e5ca75b2 100644
--- a/gcc/java/class.c
+++ b/gcc/java/class.c
@@ -1889,8 +1889,8 @@ emit_register_classes ()
     {
 #ifdef JCR_SECTION_NAME
       tree t;
-      named_section_flags (JCR_SECTION_NAME, SECTION_WRITE,
-			   POINTER_SIZE / BITS_PER_UNIT);
+      named_section_flags (JCR_SECTION_NAME, SECTION_WRITE);
+      assemble_align (POINTER_SIZE);
       for (t = registered_class; t; t = TREE_CHAIN (t))
 	assemble_integer (XEXP (DECL_RTL (t), 0),
 			  POINTER_SIZE / BITS_PER_UNIT, 1);
diff --git a/gcc/output.h b/gcc/output.h
index c2cf497485d5..6b8ffbcd37b3 100644
--- a/gcc/output.h
+++ b/gcc/output.h
@@ -454,21 +454,19 @@ extern void no_asm_to_stream PARAMS ((FILE *));
 #define SECTION_FORGET	   64	/* forget that we've entered the section */
 #define SECTION_MACH_DEP  128	/* subsequent bits reserved for target */
 
-extern void named_section_flags		PARAMS ((const char *, unsigned int,
-						 unsigned int));
+extern unsigned int get_named_section_flags PARAMS ((const char *));
+extern bool set_named_section_flags	PARAMS ((const char *, unsigned int));
+extern void named_section_flags		PARAMS ((const char *, unsigned int));
 
 union tree_node;
 extern unsigned int default_section_type_flags PARAMS ((union tree_node *,
 							const char *, int));
 
-extern void default_no_named_section PARAMS ((const char *, unsigned int,
-					      unsigned int));
-extern void default_elf_asm_named_section PARAMS ((const char *, unsigned int,
-					      unsigned int));
-extern void default_coff_asm_named_section PARAMS ((const char *, unsigned int,
-					      unsigned int));
-extern void default_pe_asm_named_section PARAMS ((const char *, unsigned int,
-					      unsigned int));
+extern void default_no_named_section PARAMS ((const char *, unsigned int));
+extern void default_elf_asm_named_section PARAMS ((const char *, unsigned int));
+extern void default_coff_asm_named_section PARAMS ((const char *,
+						    unsigned int));
+extern void default_pe_asm_named_section PARAMS ((const char *, unsigned int));
 
 extern void default_stabs_asm_out_destructor PARAMS ((struct rtx_def *, int));
 extern void default_named_section_asm_out_destructor PARAMS ((struct rtx_def *,
diff --git a/gcc/target.h b/gcc/target.h
index 3e9b46cb9d0f..bc839c5c8293 100644
--- a/gcc/target.h
+++ b/gcc/target.h
@@ -67,11 +67,9 @@ struct gcc_target
     /* Output the assembler code for function exit.  */
     void (* function_epilogue) PARAMS ((FILE *, HOST_WIDE_INT));
 
-    /* Switch to an arbitrary section NAME with attributes as specified
-       by FLAGS.  ALIGN specifies any known alignment requirements for
-       the section; 0 if the default should be used.  */
-    void (* named_section) PARAMS ((const char *, unsigned int,
-				    unsigned int));
+    /* Switch to an arbitrary section NAME with attributes as
+       specified by FLAGS.  */
+    void (* named_section) PARAMS ((const char *, unsigned int));
 
     /* Output a constructor for a symbol with a given priority.  */
     void (* constructor) PARAMS ((struct rtx_def *, int));
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 4a65020abb77..4e39a8ad08d8 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -165,6 +165,8 @@ static void output_constructor		PARAMS ((tree, int));
 #ifdef ASM_WEAKEN_LABEL
 static void remove_from_pending_weak_list	PARAMS ((const char *));
 #endif
+static int in_named_entry_eq		PARAMS ((const PTR, const PTR));
+static hashval_t in_named_entry_hash	PARAMS ((const PTR));
 #ifdef ASM_OUTPUT_BSS
 static void asm_output_bss		PARAMS ((FILE *, tree, const char *, int, int));
 #endif
@@ -209,6 +211,16 @@ static enum in_section { no_section, in_text, in_data, in_named
 /* Text of section name when in_section == in_named.  */
 static const char *in_named_name;
 
+/* Hash table of flags that have been used for a particular named section.  */
+
+struct in_named_entry
+{
+  const char *name;
+  unsigned int flags;
+};
+
+static htab_t in_named_htab;
+
 /* Define functions like text_section for any extra sections.  */
 #ifdef EXTRA_SECTION_FUNCTIONS
 EXTRA_SECTION_FUNCTIONS
@@ -286,17 +298,86 @@ in_data_section ()
   return in_section == in_data;
 }
 
+/* Helper routines for maintaining in_named_htab.  */
+
+static int
+in_named_entry_eq (p1, p2)
+     const PTR p1;
+     const PTR p2;
+{
+  const struct in_named_entry *old = p1;
+  const char *new = p2;
+
+  return strcmp (old->name, new) == 0;
+}
+
+static hashval_t
+in_named_entry_hash (p)
+     const PTR p;
+{
+  const struct in_named_entry *old = p;
+  return htab_hash_string (old->name);
+}
+
+/* If SECTION has been seen before as a named section, return the flags
+   that were used.  Otherwise, return 0.  Note, that 0 is a perfectly valid
+   set of flags for a section to have, so 0 does not mean that the section
+   has not been seen.  */
+
+unsigned int
+get_named_section_flags (section)
+     const char *section;
+{
+  struct in_named_entry **slot;
+
+  slot = (struct in_named_entry**)
+    htab_find_slot_with_hash (in_named_htab, section,
+			      htab_hash_string (section), NO_INSERT);
+
+  return slot ? (*slot)->flags : 0;
+}
+
+/* Record FLAGS for SECTION.  If SECTION was previously recorded with a
+   different set of flags, return false.  */
+
+bool
+set_named_section_flags (section, flags)
+     const char *section;
+     unsigned int flags;
+{
+  struct in_named_entry **slot, *entry;
+
+  slot = (struct in_named_entry**)
+    htab_find_slot_with_hash (in_named_htab, section,
+			      htab_hash_string (section), INSERT);
+  entry = *slot;
+
+  if (!entry)
+    {
+      entry = (struct in_named_entry *) xmalloc (sizeof (*entry));
+      *slot = entry;
+      entry->name = ggc_strdup (section);
+      entry->flags = flags;
+    }
+  else if (entry->flags != flags)
+    return false;
+
+  return true;
+}
+
 /* Tell assembler to change to section NAME with attributes FLAGS.  */
 
 void
-named_section_flags (name, flags, align)
+named_section_flags (name, flags)
      const char *name;
      unsigned int flags;
-     unsigned int align;
 {
-  if (in_section != in_named || strcmp (name, in_named_name))
+  if (in_section != in_named || strcmp (name, in_named_name) != 0)
     {
-      (* targetm.asm_out.named_section) (name, flags, align);
+      if (! set_named_section_flags (name, flags))
+	abort ();
+
+      (* targetm.asm_out.named_section) (name, flags);
 
       if (flags & SECTION_FORGET)
 	in_section = no_section;
@@ -327,7 +408,16 @@ named_section (decl, name, reloc)
     name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
 
   flags = (* targetm.section_type_flags) (decl, name, reloc);
-  named_section_flags (name, flags, 0);
+
+  /* Sanity check user variables for flag changes.  Non-user
+     section flag changes will abort in named_section_flags.  */
+  if (decl && ! set_named_section_flags (name, flags))
+    {
+      error_with_decl (decl, "%s causes a section type conflict");
+      flags = get_named_section_flags (name);
+    }
+
+  named_section_flags (name, flags);
 }
 
 /* If required, set DECL_SECTION_NAME to a unique name.  */
@@ -335,7 +425,7 @@ named_section (decl, name, reloc)
 static void
 resolve_unique_section (decl, reloc)
      tree decl;
-     int reloc;
+     int reloc ATTRIBUTE_UNUSED;
 {
   if (DECL_SECTION_NAME (decl) == NULL_TREE
       && (flag_function_sections
@@ -855,7 +945,8 @@ default_named_section_asm_out_destructor (symbol, priority)
       section = buf;
     }
 
-  named_section_flags (section, SECTION_WRITE, POINTER_SIZE / BITS_PER_UNIT);
+  named_section_flags (section, SECTION_WRITE);
+  assemble_align (POINTER_SIZE);
   assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, 1);
 }
 
@@ -915,7 +1006,7 @@ default_named_section_asm_out_constructor (symbol, priority)
       section = buf;
     }
 
-  named_section_flags (section, SECTION_WRITE, POINTER_SIZE / BITS_PER_UNIT);
+  named_section_flags (section, SECTION_WRITE);
   assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, 1);
 }
 
@@ -4820,6 +4911,9 @@ init_varasm_once ()
 {
   const_str_htab = htab_create (128, const_str_htab_hash, const_str_htab_eq,
   				const_str_htab_del);
+  in_named_htab = htab_create (31, in_named_entry_hash,
+			       in_named_entry_eq, NULL);
+
   ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
 		mark_const_hash_entry);
   ggc_add_root (&const_str_htab, 1, sizeof const_str_htab,
@@ -4831,12 +4925,7 @@ init_varasm_once ()
    might contain runtime relocations.
 
    We make the section read-only and executable for a function decl,
-   read-only for a const data decl, and writable for a non-const data decl.
-
-   If the section has already been defined, to not allow it to have
-   different attributes, as (1) this is ambiguous since we're not seeing
-   all the declarations up front and (2) some assemblers (e.g. SVR4)
-   do not recoginize section redefinitions.  */
+   read-only for a const data decl, and writable for a non-const data decl.  */
 
 unsigned int
 default_section_type_flags (decl, name, reloc)
@@ -4844,15 +4933,7 @@ default_section_type_flags (decl, name, reloc)
      const char *name;
      int reloc;
 {
-  static htab_t htab;
   unsigned int flags;
-  unsigned int **slot;
-
-  /* The names we put in the hashtable will always be the unique
-     versions gived to us by the stringtable, so we can just use
-     their addresses as the keys.  */
-  if (!htab)
-    htab = htab_create (31, htab_hash_pointer, htab_eq_pointer, NULL);
 
   if (decl && TREE_CODE (decl) == FUNCTION_DECL)
     flags = SECTION_CODE;
@@ -4872,19 +4953,6 @@ default_section_type_flags (decl, name, reloc)
       || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
     flags |= SECTION_BSS;
 
-  /* See if we already have an entry for this section.  */
-  slot = (unsigned int **) htab_find_slot (htab, name, INSERT);
-  if (!*slot)
-    {
-      *slot = (unsigned int *) xmalloc (sizeof (unsigned int));
-      **slot = flags;
-    }
-  else
-    {
-      if (decl && **slot != flags)
-	error_with_decl (decl, "%s causes a section type conflict");
-    }
-
   return flags;
 }
 
@@ -4892,10 +4960,9 @@ default_section_type_flags (decl, name, reloc)
    Four variants for common object file formats.  */
 
 void
-default_no_named_section (name, flags, align)
+default_no_named_section (name, flags)
      const char *name ATTRIBUTE_UNUSED;
      unsigned int flags ATTRIBUTE_UNUSED;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   /* Some object formats don't support named sections at all.  The
      front-end should already have flagged this as an error.  */
@@ -4903,10 +4970,9 @@ default_no_named_section (name, flags, align)
 }
 
 void
-default_elf_asm_named_section (name, flags, align)
+default_elf_asm_named_section (name, flags)
      const char *name;
      unsigned int flags;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   char flagchars[8], *f = flagchars;
   const char *type;
@@ -4931,10 +4997,9 @@ default_elf_asm_named_section (name, flags, align)
 }
 
 void
-default_coff_asm_named_section (name, flags, align)
+default_coff_asm_named_section (name, flags)
      const char *name;
      unsigned int flags;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
   char flagchars[8], *f = flagchars;
 
@@ -4948,12 +5013,11 @@ default_coff_asm_named_section (name, flags, align)
 }
 
 void
-default_pe_asm_named_section (name, flags, align)
+default_pe_asm_named_section (name, flags)
      const char *name;
      unsigned int flags;
-     unsigned int align ATTRIBUTE_UNUSED;
 {
-  default_coff_asm_named_section (name, flags, align);
+  default_coff_asm_named_section (name, flags);
 
   if (flags & SECTION_LINKONCE)
     {
-- 
GitLab