diff mbox series

[RFC] Come up with casm state

Message ID 8aa1fb10-334d-aa62-13e4-2ebc24d4ea16@suse.cz
State New
Headers show
Series [RFC] Come up with casm state | expand

Commit Message

Martin Liška Sept. 10, 2021, 9:31 a.m. UTC
Hi.

We're considering with Richi some changes related to how we emit early debug info.
That would probably include changes where the debug info would be streamed to a separate
file (different from normal .o output file).

That said, we would need switching in between output assembly files. The patch I'm sending
is a first step and we would like to receive a comments about the chosen approach?

Richi, do you want to add something?

Cheers,
Martin
diff mbox series

Patch

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 55cb0347149..5bac9beb934 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -2309,7 +2309,7 @@  symbol_table::compile (void)
   timevar_pop (TV_CGRAPHOPT);
 
   /* Output everything.  */
-  switch_to_section (text_section);
+  switch_to_section (casm->sections.text);
   (*debug_hooks->assembly_start) ();
   if (!quiet_flag)
     fprintf (stderr, "Assembling functions:\n");
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 1fbe9e0daa0..3160d2952d5 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -25714,7 +25714,7 @@  aarch64_sls_emit_blr_function_thunks (FILE *out_file)
      would happen in a different section -- leaving an unmatched
      `.cfi_startproc` in the cold text section and an unmatched `.cfi_endproc`
      in the standard text section.  */
-  section *save_text_section = in_section;
+  section *save_text_section = casm->in_section;
   switch_to_section (function_section (current_function_decl));
   for (int regnum = 0; regnum < 30; ++regnum)
     {
diff --git a/gcc/config/alpha/alpha.c b/gcc/config/alpha/alpha.c
index c702e683c31..54a1df4b821 100644
--- a/gcc/config/alpha/alpha.c
+++ b/gcc/config/alpha/alpha.c
@@ -8055,13 +8055,13 @@  alpha_start_function (FILE *file, const char *fnname,
 
 #ifdef TARGET_VMS_CRASH_DEBUG
   /* Support of minimal traceback info.  */
-  switch_to_section (readonly_data_section);
+  switch_to_section (casm->sections.readonly_data);
   fprintf (file, "\t.align 3\n");
   assemble_name (file, fnname); fputs ("..na:\n", file);
   fputs ("\t.ascii \"", file);
   assemble_name (file, fnname);
   fputs ("\\0\"\n", file);
-  switch_to_section (text_section);
+  switch_to_section (casm->sections.text);
 #endif
 #endif /* TARGET_ABI_OPEN_VMS */
 }
@@ -9446,7 +9446,7 @@  alpha_elf_select_rtx_section (machine_mode mode, rtx x,
 {
   if (TARGET_SMALL_DATA && GET_MODE_SIZE (mode) <= g_switch_value)
     /* ??? Consider using mergeable sdata sections.  */
-    return sdata_section;
+    return casm->sections.sdata;
   else
     return default_elf_select_rtx_section (mode, x, align);
 }
@@ -9613,7 +9613,7 @@  alpha_write_linkage (FILE *stream, const char *funname)
 {
   fprintf (stream, "\t.link\n");
   fprintf (stream, "\t.align 3\n");
-  in_section = NULL;
+  casm->in_section = NULL;
 
 #ifdef TARGET_VMS_CRASH_DEBUG
   fputs ("\t.name ", stream);
@@ -9665,7 +9665,7 @@  vms_asm_named_section (const char *name, unsigned int flags,
 static void
 vms_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
 {
-  switch_to_section (ctors_section);
+  switch_to_section (casm->sections.ctors);
   assemble_align (BITS_PER_WORD);
   assemble_integer (symbol, UNITS_PER_WORD, BITS_PER_WORD, 1);
 }
@@ -9673,7 +9673,7 @@  vms_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
 static void
 vms_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
 {
-  switch_to_section (dtors_section);
+  switch_to_section (casm->sections.dtors);
   assemble_align (BITS_PER_WORD);
   assemble_integer (symbol, UNITS_PER_WORD, BITS_PER_WORD, 1);
 }
diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index 92797db96b7..ee763e59312 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -8832,7 +8832,7 @@  arc_asm_output_aligned_decl_local (FILE * stream, tree decl, const char * name,
     switch_to_section (get_named_section (NULL, ".sbss", 0));
   /*    named_section (0,".sbss",0); */
   else
-    switch_to_section (bss_section);
+    switch_to_section (casm->sections.bss);
 
   if (globalize_p)
     (*targetm.asm_out.globalize_label) (stream, name);
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index f1e628253d0..5f7e36234ea 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -17234,7 +17234,7 @@  get_jump_table_size (rtx_jump_table_data *insn)
 {
   /* ADDR_VECs only take room if read-only data does into the text
      section.  */
-  if (JUMP_TABLES_IN_TEXT_SECTION || readonly_data_section == text_section)
+  if (JUMP_TABLES_IN_TEXT_SECTION || casm->sections.readonly_data == casm->sections.text)
     {
       rtx body = PATTERN (insn);
       int elt = GET_CODE (body) == ADDR_DIFF_VEC ? 1 : 0;
@@ -24642,9 +24642,9 @@  arm_elf_asm_cdtor (rtx symbol, int priority, bool is_ctor)
       s = get_section (buf, SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
     }
   else if (is_ctor)
-    s = ctors_section;
+    s = casm->sections.ctors;
   else
-    s = dtors_section;
+    s = casm->sections.dtors;
 
   switch_to_section (s);
   assemble_align (POINTER_SIZE);
@@ -27910,7 +27910,7 @@  thumb_call_via_reg (rtx reg)
   /* If we are in the normal text section we can use a single instance
      per compilation unit.  If we are doing function sections, then we need
      an entry per section, since we can't rely on reachability.  */
-  if (in_section == text_section)
+  if (casm->in_section == casm->sections.text)
     {
       thumb_call_reg_needed = 1;
 
@@ -28302,7 +28302,7 @@  arm_file_end (void)
   if (! thumb_call_reg_needed)
     return;
 
-  switch_to_section (text_section);
+  switch_to_section (casm->sections.text);
   asm_fprintf (asm_out_file, "\t.code 16\n");
   ASM_OUTPUT_ALIGN (asm_out_file, 1);
 
@@ -29752,13 +29752,13 @@  static void
 arm_asm_init_sections (void)
 {
 #if ARM_UNWIND_INFO
-  exception_section = get_unnamed_section (0, output_section_asm_op,
+  casm->sections.exception = get_unnamed_section (0, output_section_asm_op,
 					   "\t.handlerdata");
 #endif /* ARM_UNWIND_INFO */
 
 #ifdef OBJECT_FORMAT_ELF
   if (target_pure_code)
-    text_section->unnamed.data = "\t.section .text,\"0x20000006\",%progbits";
+    casm->sections.text->unnamed.data = "\t.section .text,\"0x20000006\",%progbits";
 #endif
 }
 
diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c
index 200701a583c..9b650bdbf51 100644
--- a/gcc/config/avr/avr.c
+++ b/gcc/config/avr/avr.c
@@ -10085,7 +10085,7 @@  avr_asm_asm_output_aligned_bss (FILE *file, tree decl, const char *name,
 }
 
 
-/* Unnamed section callback for data_section
+/* Unnamed section callback for casm->sections.data
    to track need of __do_copy_data.  */
 
 static void
@@ -10098,7 +10098,7 @@  avr_output_data_section_asm_op (const void *data)
 }
 
 
-/* Unnamed section callback for bss_section
+/* Unnamed section callback for casm->sections.bss
    to track need of __do_clear_bss.  */
 
 static void
@@ -10133,9 +10133,9 @@  avr_asm_init_sections (void)
 #if defined HAVE_LD_AVR_AVRXMEGA3_RODATA_IN_FLASH
   if (avr_arch->flash_pm_offset == 0)
 #endif
-    readonly_data_section->unnamed.callback = avr_output_data_section_asm_op;
-  data_section->unnamed.callback = avr_output_data_section_asm_op;
-  bss_section->unnamed.callback = avr_output_bss_section_asm_op;
+    casm->sections.readonly_data->unnamed.callback = avr_output_data_section_asm_op;
+  casm->sections.data->unnamed.callback = avr_output_data_section_asm_op;
+  casm->sections.bss->unnamed.callback = avr_output_bss_section_asm_op;
 }
 
 
@@ -12567,7 +12567,7 @@  avr_output_addr_vec (rtx_insn *labl, rtx table)
   // Switch back to original section.  As we clobbered the section above,
   // forget the current section before switching back.
 
-  in_section = NULL;
+  casm->in_section = NULL;
   switch_to_section (current_function_section ());
 }
 
diff --git a/gcc/config/c6x/c6x.c b/gcc/config/c6x/c6x.c
index ce4949516cf..b775e518d0c 100644
--- a/gcc/config/c6x/c6x.c
+++ b/gcc/config/c6x/c6x.c
@@ -890,7 +890,7 @@  c6x_select_rtx_section (machine_mode mode, rtx x,
   if (c6x_sdata_mode == C6X_SDATA_ALL
       || (c6x_sdata_mode != C6X_SDATA_NONE && GET_MODE_SIZE (mode) <= 8))
     /* ??? Consider using mergeable sdata sections.  */
-    return sdata_section;
+    return casm->sections.sdata;
   else
     return default_elf_select_rtx_section (mode, x, align);
 }
@@ -5473,7 +5473,7 @@  c6x_asm_emit_except_personality (rtx personality)
 static void
 c6x_asm_init_sections (void)
 {
-  exception_section = get_unnamed_section (0, output_section_asm_op,
+  casm->sections.exception = get_unnamed_section (0, output_section_asm_op,
 					   "\t.handlerdata");
 }
 
diff --git a/gcc/config/csky/csky.c b/gcc/config/csky/csky.c
index e55821fe2ee..c82540abeda 100644
--- a/gcc/config/csky/csky.c
+++ b/gcc/config/csky/csky.c
@@ -958,7 +958,7 @@  get_csky_jump_table_size (rtx insn)
 {
   /* ADDR_VECs only take room if read-only data does into the text
      section.  */
-  if (JUMP_TABLES_IN_TEXT_SECTION || readonly_data_section == text_section)
+  if (JUMP_TABLES_IN_TEXT_SECTION || casm->sections.readonly_data == casm->sections.text)
     {
       rtx body = PATTERN (insn);
       int elt = GET_CODE (body) == ADDR_DIFF_VEC ? 1 : 0;
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 781742fe46f..f6ce2d5d09e 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -143,7 +143,7 @@  output_objc_section_asm_op (const void *directive)
      section is requested.  */
   if (darwin_symbol_stubs && ! been_here)
     {
-      section *saved_in_section = in_section;
+      section *saved_in_section = casm->in_section;
       static const enum darwin_section_enum tomark[] =
 	{
 	  /* written, cold -> hot */
@@ -236,14 +236,14 @@  darwin_init_sections (void)
 #include "config/darwin-sections.def"
 #undef DEF_SECTION
 
-  readonly_data_section = darwin_sections[const_section];
-  exception_section = darwin_sections[darwin_exception_section];
-  eh_frame_section = darwin_sections[darwin_eh_frame_section];
+  casm->sections.readonly_data = darwin_sections[const_section];
+  casm->sections.exception = darwin_sections[darwin_exception_section];
+  casm->sections.eh_frame = darwin_sections[darwin_eh_frame_section];
 
   /* If our linker is new enough to coalesce weak symbols, then we
      can just put picbase_thunks into the text section.  */
   if (! ld_uses_coal_sects )
-    darwin_sections[picbase_thunk_section] = text_section;
+    darwin_sections[picbase_thunk_section] = casm->sections.text;
 }
 
 int
@@ -1071,7 +1071,7 @@  machopic_output_data_section_indirection (machopic_indirection **slot,
   /* The name of the indirection symbol.  */
   const char *ptr_name = p->ptr_name;
 
-  switch_to_section (data_section);
+  switch_to_section (casm->sections.data);
   assemble_align (GET_MODE_ALIGNMENT (Pmode));
   assemble_label (asm_out_file, ptr_name);
   assemble_integer (gen_rtx_SYMBOL_REF (Pmode, sym_name),
@@ -1340,7 +1340,7 @@  darwin_mergeable_string_section (tree exp,
       && TREE_STRING_LENGTH (exp) == 0)
     return darwin_sections[zobj_const_section];
 
-  return readonly_data_section;
+  return casm->sections.readonly_data;
 }
 
 #ifndef HAVE_GAS_LITERAL16
@@ -1362,7 +1362,7 @@  darwin_mergeable_constant_section (tree exp,
       || align < 8
       || align > 256
       || (align & (align -1)) != 0)
-    return readonly_data_section;
+    return casm->sections.readonly_data;
 
   /* This will ICE if the mode is not a constant size, but that is reasonable,
      since one cannot put a variable-sized thing into a constant section, we
@@ -1370,12 +1370,12 @@  darwin_mergeable_constant_section (tree exp,
   const unsigned int modesize = GET_MODE_BITSIZE (mode).to_constant ();
 
   if (modesize > align)
-    return readonly_data_section;
+    return casm->sections.readonly_data;
 
   tree size = TYPE_SIZE_UNIT (TREE_TYPE (exp));
 
   if (TREE_CODE (size) != INTEGER_CST)
-    return readonly_data_section;
+    return casm->sections.readonly_data;
 
   unsigned isize = TREE_INT_CST_LOW (size);
   if (isize == 4)
@@ -1387,7 +1387,7 @@  darwin_mergeable_constant_section (tree exp,
 	   && isize == 16)
     return darwin_sections[literal16_section];
 
-  return readonly_data_section;
+  return casm->sections.readonly_data;
 }
 
 section *
@@ -1443,7 +1443,7 @@  darwin_objc2_section (tree decl ATTRIBUTE_UNUSED, tree meta, section * base)
 
   objc_metadata_seen = 1;
 
-  if (base == data_section)
+  if (base == casm->sections.data)
     base = darwin_sections[objc2_metadata_section];
 
   /* Most of the OBJC2 META-data end up in the base section, so check it
@@ -1494,7 +1494,7 @@  darwin_objc2_section (tree decl ATTRIBUTE_UNUSED, tree meta, section * base)
 
   else if (startswith (p, "V2_EHTY"))
     return ld_uses_coal_sects ? darwin_sections[data_coal_section]
-                              : data_section;
+                              : casm->sections.data;
 
   else if (startswith (p, "V2_CSTR"))
     return darwin_sections[objc2_constant_string_object_section];
@@ -1680,7 +1680,7 @@  machopic_select_section (tree decl,
       else if (ro)
 	base_section = darwin_sections[const_data_section];
       else
-	base_section = data_section;
+	base_section = casm->sections.data;
       break;
     case SECCAT_BSS:
     case SECCAT_SBSS:
@@ -1690,11 +1690,11 @@  machopic_select_section (tree decl,
       else
 	{
 	  if (!TREE_PUBLIC (decl))
-	    base_section = lcomm_section;
-	  else if (bss_noswitch_section)
-	    base_section = bss_noswitch_section;
+	    base_section = casm->sections.lcomm;
+	  else if (casm->sections.bss_noswitch)
+	    base_section = casm->sections.bss_noswitch;
 	  else
-	    base_section = data_section;
+	    base_section = casm->sections.data;
 	}
       break;
 
@@ -2365,8 +2365,8 @@  fprintf (file, "# dadon: %s %s (%llu, %u) local %d weak %d"
       /* Check that we've correctly picked up the zero-sized item and placed it
          properly.  */
       gcc_assert ((!DARWIN_SECTION_ANCHORS || !flag_section_anchors)
-		  || (in_section
-		      && (in_section->common.flags & SECTION_NO_ANCHOR)));
+		  || (casm->in_section
+		      && (casm->in_section->common.flags & SECTION_NO_ANCHOR)));
     }
   else
     ASM_OUTPUT_LABEL (file, xname);
@@ -2386,8 +2386,8 @@  darwin_asm_declare_constant_name (FILE *file, const char *name,
       /* Check that we've correctly picked up the zero-sized item and placed it
          properly.  */
       gcc_assert ((!DARWIN_SECTION_ANCHORS || !flag_section_anchors)
-		  || (in_section
-		      && (in_section->common.flags & SECTION_NO_ANCHOR)));
+		  || (casm->in_section
+		      && (casm->in_section->common.flags & SECTION_NO_ANCHOR)));
     }
 }
 
@@ -2424,7 +2424,7 @@  darwin_emit_weak_or_comdat (FILE *fp, tree decl, const char *name,
 				: darwin_sections[const_data_section]);
   else
     switch_to_section (use_coal ? darwin_sections[data_coal_section]
-				: data_section);
+				: casm->sections.data);
 
   /* To be consistent, we'll allow darwin_asm_declare_object_name to assemble
      the align info for zero-sized items... but do it here otherwise.  */
@@ -2446,7 +2446,7 @@  darwin_emit_objc_zeroed (FILE *fp, tree decl, const char *name,
 				  unsigned HOST_WIDE_INT size,
 				  unsigned int align, tree meta)
 {
-  section *ocs = data_section;
+  section *ocs = casm->sections.data;
 
   if (TREE_PURPOSE (meta) == get_identifier("OBJC2META"))
     ocs = darwin_objc2_section (decl, meta, ocs);
@@ -2488,13 +2488,13 @@  darwin_emit_local_bss (FILE *fp, tree decl, const char *name,
       if (!size)
 	{
 	  fputs ("\t.section\t__DATA,__zobj_bss\n", fp);
-	  in_section = darwin_sections[zobj_bss_section];
+	  casm->in_section = darwin_sections[zobj_bss_section];
 	  size = 1;
 	}
       else
 	{
 	  fputs ("\t.static_data\n", fp);
-	  in_section = darwin_sections[static_data_section];
+	  casm->in_section = darwin_sections[static_data_section];
 	}
 
       if (l2align)
@@ -2512,7 +2512,7 @@  darwin_emit_local_bss (FILE *fp, tree decl, const char *name,
       char secnam[64];
       snprintf (secnam, 64, "__DATA,__bss");
       unsigned int flags = SECTION_BSS|SECTION_WRITE|SECTION_NO_ANCHOR;
-      in_section = get_section (secnam, flags, NULL);
+      casm->in_section = get_section (secnam, flags, NULL);
       fprintf (fp, "\t.zerofill %s,", secnam);
       assemble_name (fp, name);
       if (!size)
@@ -2559,7 +2559,7 @@  darwin_emit_common (FILE *fp, const char *name,
   l2align = floor_log2 (align);
   gcc_assert (l2align <= L2_MAX_OFILE_ALIGNMENT);
 
-  in_section = comm_section;
+  casm->in_section = casm->sections.comm;
   /* We mustn't allow multiple public symbols to share an address when using
      the normal OSX toolchain.  */
   if (!size)
@@ -2567,7 +2567,7 @@  darwin_emit_common (FILE *fp, const char *name,
       /* Put at least one byte.  */
       size = 1;
       /* This section can no longer participate in section anchoring.  */
-      comm_section->common.flags |= SECTION_NO_ANCHOR;
+      casm->sections.comm->common.flags |= SECTION_NO_ANCHOR;
     }
 
   fputs ("\t.comm\t", fp);
@@ -2656,13 +2656,13 @@  fprintf (fp, "# albss: %s (%lld,%d) ro %d cst %d stat %d com %d"
       if (!size)
 	{
 	  fputs ("\t.section\t__DATA,__zobj_data\n", fp);
-	  in_section = darwin_sections[zobj_data_section];
+	  casm->in_section = darwin_sections[zobj_data_section];
 	  size = 1;
 	}
       else
 	{
 	  fputs ("\t.data\n", fp);
-	  in_section = data_section;
+	  casm->in_section = casm->sections.data;
 	}
 
       if (l2align)
@@ -2677,7 +2677,7 @@  fprintf (fp, "# albss: %s (%lld,%d) ro %d cst %d stat %d com %d"
       unsigned int flags = SECTION_BSS|SECTION_WRITE|SECTION_NO_ANCHOR;
       char secnam[64];
       snprintf (secnam, 64, "__DATA,__common");
-      in_section = get_section (secnam, flags, NULL);
+      casm->in_section = get_section (secnam, flags, NULL);
       fprintf (fp, "\t.zerofill %s,", secnam);
       assemble_name (fp, name);
       if (!size)
@@ -3893,7 +3893,7 @@  darwin_function_section (tree decl, enum node_frequency freq,
   /* Otherwise, default to the 'normal' non-reordered sections.  */
 default_function_sections:
   return (use_coal) ? darwin_sections[text_coal_section]
-		    : text_section;
+		    : casm->sections.text;
 }
 
 #include "gt-darwin.h"
diff --git a/gcc/config/frv/frv.c b/gcc/config/frv/frv.c
index a7f7f086d17..74237e93e96 100644
--- a/gcc/config/frv/frv.c
+++ b/gcc/config/frv/frv.c
@@ -9395,7 +9395,7 @@  frv_rtx_costs (rtx x,
 static void
 frv_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
 {
-  switch_to_section (ctors_section);
+  switch_to_section (casm->sections.ctors);
   assemble_align (POINTER_SIZE);
   if (TARGET_FDPIC)
     {
@@ -9410,7 +9410,7 @@  frv_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
 static void
 frv_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
 {
-  switch_to_section (dtors_section);
+  switch_to_section (casm->sections.dtors);
   assemble_align (POINTER_SIZE);
   if (TARGET_FDPIC)
     {
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 7b173bc0beb..600eb2f137d 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -869,7 +869,7 @@  x86_output_aligned_bss (FILE *file, tree decl, const char *name,
       && size > (unsigned int)ix86_section_threshold)
     switch_to_section (get_named_section (decl, ".lbss", 0));
   else
-    switch_to_section (bss_section);
+    switch_to_section (casm->sections.bss);
   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
 #ifdef ASM_DECLARE_OBJECT_NAME
   last_assemble_variable_decl = decl;
@@ -1567,7 +1567,7 @@  ix86_function_naked (const_tree fn)
 /* Write the extra assembler code needed to declare a function properly.  */
 
 void
-ix86_asm_output_function_label (FILE *asm_out_file, const char *fname,
+ix86_asm_output_function_label (FILE *out_file, const char *fname,
 				tree decl)
 {
   bool is_ms_hook = ix86_function_ms_hook_prologue (decl);
@@ -1581,14 +1581,14 @@  ix86_asm_output_function_label (FILE *asm_out_file, const char *fname,
       unsigned int filler_cc = 0xcccccccc;
 
       for (i = 0; i < filler_count; i += 4)
-        fprintf (asm_out_file, ASM_LONG " %#x\n", filler_cc);
+	fprintf (out_file, ASM_LONG " %#x\n", filler_cc);
     }
 
 #ifdef SUBTARGET_ASM_UNWIND_INIT
-  SUBTARGET_ASM_UNWIND_INIT (asm_out_file);
+  SUBTARGET_ASM_UNWIND_INIT (out_file);
 #endif
 
-  ASM_OUTPUT_LABEL (asm_out_file, fname);
+  ASM_OUTPUT_LABEL (out_file, fname);
 
   /* Output magic byte marker, if hot-patch attribute is set.  */
   if (is_ms_hook)
@@ -1597,14 +1597,14 @@  ix86_asm_output_function_label (FILE *asm_out_file, const char *fname,
 	{
 	  /* leaq [%rsp + 0], %rsp  */
 	  fputs (ASM_BYTE "0x48, 0x8d, 0xa4, 0x24, 0x00, 0x00, 0x00, 0x00\n",
-		 asm_out_file);
+		 out_file);
 	}
       else
 	{
           /* movl.s %edi, %edi
 	     push   %ebp
 	     movl.s %esp, %ebp */
-	  fputs (ASM_BYTE "0x8b, 0xff, 0x55, 0x8b, 0xec\n", asm_out_file);
+	  fputs (ASM_BYTE "0x8b, 0xff, 0x55, 0x8b, 0xec\n", out_file);
 	}
     }
 }
@@ -5954,7 +5954,7 @@  output_indirect_thunk_function (enum indirect_thunk_prefix need_prefix,
       }
     else
       {
-	switch_to_section (text_section);
+	switch_to_section (casm->sections.text);
 	ASM_OUTPUT_LABEL (asm_out_file, name);
       }
 
@@ -6074,7 +6074,7 @@  ix86_code_end (void)
 	}
       else
 	{
-	  switch_to_section (text_section);
+	  switch_to_section (casm->sections.text);
 	  ASM_OUTPUT_LABEL (asm_out_file, name);
 	}
 
diff --git a/gcc/config/i386/winnt.c b/gcc/config/i386/winnt.c
index 4158a45ac31..c6b0949da15 100644
--- a/gcc/config/i386/winnt.c
+++ b/gcc/config/i386/winnt.c
@@ -1347,7 +1347,7 @@  void
 i386_pe_seh_init_sections (void)
 {
   if (TARGET_SEH)
-    exception_section = get_unnamed_section (0, output_section_asm_op,
+    casm->sections.exception = get_unnamed_section (0, output_section_asm_op,
 					     "\t.seh_handlerdata");
 }
 
diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c
index 632b9df1761..d9b9fcc5eda 100644
--- a/gcc/config/ia64/ia64.c
+++ b/gcc/config/ia64/ia64.c
@@ -10406,7 +10406,7 @@  ia64_asm_emit_except_personality (rtx personality)
 static void
 ia64_asm_init_sections (void)
 {
-  exception_section = get_unnamed_section (0, output_section_asm_op,
+  casm->sections.exception = get_unnamed_section (0, output_section_asm_op,
 					   "\t.handlerdata");
 }
 
@@ -10858,7 +10858,7 @@  ia64_select_rtx_section (machine_mode mode, rtx x,
   if (GET_MODE_SIZE (mode) > 0
       && GET_MODE_SIZE (mode) <= ia64_section_threshold
       && !TARGET_NO_SDATA)
-    return sdata_section;
+    return casm->sections.sdata;
   else
     return default_elf_select_rtx_section (mode, x, align);
 }
diff --git a/gcc/config/microblaze/microblaze.c b/gcc/config/microblaze/microblaze.c
index 6e8f367c80a..4105df8a480 100644
--- a/gcc/config/microblaze/microblaze.c
+++ b/gcc/config/microblaze/microblaze.c
@@ -2836,9 +2836,9 @@  microblaze_elf_asm_cdtor (rtx symbol, int priority, bool is_ctor)
       s = get_section (buf, SECTION_WRITE, NULL_TREE);
     }
   else if (is_ctor)
-    s = ctors_section;
+    s = casm->sections.ctors;
   else
-    s = dtors_section;
+    s = casm->sections.dtors;
 
   switch_to_section (s);
   assemble_align (POINTER_SIZE);
@@ -3261,7 +3261,7 @@  microblaze_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
          relaxation/relocation. Currently, turning mergeable sections 
          into regular readonly sections.  */
 
-      return readonly_data_section;
+      return casm->sections.readonly_data;
     default:
       return default_elf_select_section (decl, reloc, align);
     }
diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c
index ade5d7041f0..50dd99ff0b3 100644
--- a/gcc/config/mips/mips.c
+++ b/gcc/config/mips/mips.c
@@ -9718,7 +9718,7 @@  mips_output_aligned_decl_common (FILE *stream, tree decl, const char *name,
       if (TREE_PUBLIC (decl) && DECL_NAME (decl))
 	targetm.asm_out.globalize_label (stream, name);
 
-      switch_to_section (readonly_data_section);
+      switch_to_section (casm->sections.readonly_data);
       ASM_OUTPUT_ALIGN (stream, floor_log2 (align / BITS_PER_UNIT));
       mips_declare_object (stream, name, "",
 			   ":\n\t.space\t" HOST_WIDE_INT_PRINT_UNSIGNED "\n",
diff --git a/gcc/config/mmix/mmix.c b/gcc/config/mmix/mmix.c
index 010cd4773ea..5522535e0ab 100644
--- a/gcc/config/mmix/mmix.c
+++ b/gcc/config/mmix/mmix.c
@@ -1321,7 +1321,7 @@  mmix_file_start (void)
   fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file);
 
   /* Make sure each file starts with the text section.  */
-  switch_to_section (text_section);
+  switch_to_section (casm->sections.text);
 }
 
 /* TARGET_ASM_FILE_END.  */
@@ -1330,7 +1330,7 @@  static void
 mmix_file_end (void)
 {
   /* Make sure each file ends with the data section.  */
-  switch_to_section (data_section);
+  switch_to_section (casm->sections.data);
 }
 
 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME.  */
@@ -1510,7 +1510,7 @@  mmix_asm_output_aligned_local (FILE *stream,
 			       int size,
 			       int align)
 {
-  switch_to_section (data_section);
+  switch_to_section (casm->sections.data);
 
   ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
   assemble_name (stream, name);
diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
index 1cdacb7f480..d9ae7e2d912 100644
--- a/gcc/config/msp430/msp430.c
+++ b/gcc/config/msp430/msp430.c
@@ -2398,22 +2398,22 @@  msp430_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
     {
     case SECCAT_TEXT:
       if (!prefix)
-	return text_section;
+	return casm->sections.text;
       base_sec_name = ".text";
       break;
     case SECCAT_DATA:
       if (!prefix)
-	return data_section;
+	return casm->sections.data;
       base_sec_name = ".data";
       break;
     case SECCAT_BSS:
       if (!prefix)
-	return bss_section;
+	return casm->sections.bss;
       base_sec_name = ".bss";
       break;
     case SECCAT_RODATA:
       if (!prefix)
-	return readonly_data_section;
+	return casm->sections.readonly_data;
       base_sec_name = ".rodata";
       break;
 
diff --git a/gcc/config/pa/pa.c b/gcc/config/pa/pa.c
index 06143023b46..2f01884cea2 100644
--- a/gcc/config/pa/pa.c
+++ b/gcc/config/pa/pa.c
@@ -4444,7 +4444,7 @@  pa_output_function_epilogue (FILE *file)
       /* We are done with this subspace except possibly for some additional
 	 debug information.  Forget that we are in this subspace to ensure
 	 that the next function is output in its own subspace.  */
-      in_section = NULL;
+      casm->in_section = NULL;
       cfun->machine->in_nsubspa = 2;
     }
 
@@ -4693,7 +4693,7 @@  output_deferred_profile_counters (void)
   if (funcdef_nos.is_empty ())
    return;
 
-  switch_to_section (data_section);
+  switch_to_section (casm->sections.data);
   align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
   ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
 
@@ -5863,7 +5863,7 @@  output_deferred_plabels (void)
      before outputting the deferred plabels.  */
   if (n_deferred_plabels)
     {
-      switch_to_section (flag_pic ? data_section : readonly_data_section);
+      switch_to_section (flag_pic ? casm->sections.data : casm->sections.readonly_data);
       ASM_OUTPUT_ALIGN (asm_out_file, TARGET_64BIT ? 3 : 2);
     }
 
@@ -8872,7 +8872,7 @@  pa_asm_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
 
   if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
     {
-      switch_to_section (data_section);
+      switch_to_section (casm->sections.data);
       output_asm_insn (".align 4", xoperands);
       ASM_OUTPUT_LABEL (file, label);
       output_asm_insn (".word P'%0", xoperands);
@@ -9047,7 +9047,7 @@  pa_asm_output_aligned_bss (FILE *stream,
 			   unsigned HOST_WIDE_INT size,
 			   unsigned int align)
 {
-  switch_to_section (bss_section);
+  switch_to_section (casm->sections.bss);
 
 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
   ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "object");
@@ -9084,7 +9084,7 @@  pa_asm_output_aligned_common (FILE *stream,
       align = max_common_align;
     }
 
-  switch_to_section (bss_section);
+  switch_to_section (casm->sections.bss);
 
   assemble_name (stream, name);
   fprintf (stream, "\t.comm " HOST_WIDE_INT_PRINT_UNSIGNED"\n",
@@ -9104,7 +9104,7 @@  pa_asm_output_aligned_local (FILE *stream,
 			     unsigned HOST_WIDE_INT size,
 			     unsigned int align)
 {
-  switch_to_section (bss_section);
+  switch_to_section (casm->sections.bss);
   fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
 
 #ifdef LOCAL_ASM_OP
@@ -10030,10 +10030,10 @@  som_output_text_section_asm_op (const void *data ATTRIBUTE_UNUSED)
 	     function has been completed.  So, we are changing to the
 	     text section to output debugging information.  Thus, we
 	     need to forget that we are in the text section so that
-	     varasm.c will call us when text_section is selected again.  */
+	     varasm.c will call us when casm->sections.text is selected again.  */
 	  gcc_assert (!cfun || !cfun->machine
 		      || cfun->machine->in_nsubspa == 2);
-	  in_section = NULL;
+	  casm->in_section = NULL;
 	}
       output_section_asm_op ("\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$");
       return;
@@ -10047,7 +10047,7 @@  som_output_text_section_asm_op (const void *data ATTRIBUTE_UNUSED)
 static void
 som_output_comdat_data_section_asm_op (const void *data)
 {
-  in_section = NULL;
+  casm->in_section = NULL;
   output_section_asm_op (data);
 }
 
@@ -10056,7 +10056,7 @@  som_output_comdat_data_section_asm_op (const void *data)
 static void
 pa_som_asm_init_sections (void)
 {
-  text_section
+  casm->sections.text
     = get_unnamed_section (0, som_output_text_section_asm_op, NULL);
 
   /* SOM puts readonly data in the default $LIT$ subspace when PIC code
@@ -10104,14 +10104,14 @@  pa_som_asm_init_sections (void)
      when generating PIC code.  This reduces sharing, but it works
      correctly.  Now we rely on pa_reloc_rw_mask() for section selection.
      This puts constant data not needing relocation into the $TEXT$ space.  */
-  readonly_data_section = som_readonly_data_section;
+  casm->sections.readonly_data = som_readonly_data_section;
 
   /* We must not have a reference to an external symbol defined in a
      shared library in a readonly section, else the SOM linker will
      complain.
 
      So, we force exception information into the data section.  */
-  exception_section = data_section;
+  casm->sections.exception = casm->sections.data;
 }
 
 /* Implement TARGET_ASM_TM_CLONE_TABLE_SECTION.  */
@@ -10144,18 +10144,18 @@  pa_select_section (tree exp, int reloc,
 	  && !DECL_WEAK (exp))
 	return som_one_only_readonly_data_section;
       else
-	return readonly_data_section;
+	return casm->sections.readonly_data;
     }
   else if (CONSTANT_CLASS_P (exp)
 	   && !(reloc & pa_reloc_rw_mask ()))
-    return readonly_data_section;
+    return casm->sections.readonly_data;
   else if (TARGET_SOM
 	   && TREE_CODE (exp) == VAR_DECL
 	   && DECL_ONE_ONLY (exp)
 	   && !DECL_WEAK (exp))
     return som_one_only_data_section;
   else
-    return data_section;
+    return casm->sections.data;
 }
 
 /* Implement pa_elf_select_rtx_section.  If X is a function label operand
@@ -10648,7 +10648,7 @@  pa_function_section (tree decl, enum node_frequency freq,
 {
   /* Put functions in text section if target doesn't have named sections.  */
   if (!targetm_common.have_named_sections)
-    return text_section;
+    return casm->sections.text;
 
   /* Force nested functions into the same section as the containing
      function.  */
diff --git a/gcc/config/pdp11/pdp11.c b/gcc/config/pdp11/pdp11.c
index ced653116a4..0cb38926edc 100644
--- a/gcc/config/pdp11/pdp11.c
+++ b/gcc/config/pdp11/pdp11.c
@@ -743,7 +743,7 @@  void
 pdp11_asm_output_var (FILE *file, const char *name, int size,
 		      int align, bool global)
 {
-  switch_to_section (data_section);
+  switch_to_section (casm->sections.data);
   if (align > 8)
     fprintf (file, "\t.even\n");
   if (TARGET_DEC_ASM)
@@ -2323,11 +2323,11 @@  pdp11_asm_init_sections (void)
 {
   if (TARGET_DEC_ASM)
     {
-      bss_section = data_section;
+      casm->sections.bss = casm->sections.data;
     }
   else if (TARGET_GNU_ASM)
     {
-      bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
+      casm->sections.bss = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
 					 output_section_asm_op,
 					 ".bss");
     }
diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index 576960bb37c..66bb05b0e43 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -3615,8 +3615,8 @@  riscv_elf_select_rtx_section (machine_mode mode, rtx x,
 	  return get_section (name, s->named.common.flags, NULL);
 	}
 
-      if (s == data_section)
-	return sdata_section;
+      if (s == casm->sections.data)
+	return casm->sections.sdata;
     }
 
   return s;
diff --git a/gcc/config/rl78/rl78.c b/gcc/config/rl78/rl78.c
index 4c34949a97f..30d81f9d41f 100644
--- a/gcc/config/rl78/rl78.c
+++ b/gcc/config/rl78/rl78.c
@@ -4644,14 +4644,14 @@  rl78_select_section (tree decl,
     }
 
   if (readonly)
-    return TARGET_ES0 ? frodata_section : readonly_data_section;
+    return TARGET_ES0 ? frodata_section : casm->sections.readonly_data;
 
   switch (categorize_decl_for_section (decl, reloc))
     {
-    case SECCAT_TEXT:   return text_section;
-    case SECCAT_DATA:   return data_section;
-    case SECCAT_BSS:    return bss_section;
-    case SECCAT_RODATA: return TARGET_ES0 ? frodata_section : readonly_data_section;
+    case SECCAT_TEXT:   return casm->sections.text;
+    case SECCAT_DATA:   return casm->sections.data;
+    case SECCAT_BSS:    return casm->sections.bss;
+    case SECCAT_RODATA: return TARGET_ES0 ? frodata_section : casm->sections.readonly_data;
     default:
       return default_select_section (decl, reloc, align);
     }
@@ -4786,7 +4786,7 @@  rl78_asm_ctor_dtor (rtx symbol, int priority, bool is_ctor)
       sec = get_section (buf, 0, NULL);
     }
   else
-    sec = is_ctor ? ctors_section : dtors_section;
+    sec = is_ctor ? casm->sections.ctors : casm->sections.dtors;
 
   assemble_addr_to_section (symbol, sec);
 }
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index b7ea1483da5..d194d23fa8d 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -14392,7 +14392,7 @@  rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
 	 section.  */
       if (DEFAULT_ABI == ABI_V4
 	  && (TARGET_RELOCATABLE || flag_pic > 1)
-	  && in_section != toc_section
+	  && casm->in_section != toc_section
 	  && !recurse
 	  && !CONST_SCALAR_INT_P (x)
 	  && CONSTANT_P (x))
@@ -20941,7 +20941,7 @@  rs6000_elf_file_end (void)
       /* We have expanded a CPU builtin, so we need to emit a reference to
 	 the special symbol that LIBC uses to declare it supports the
 	 AT_PLATFORM and AT_HWCAP/AT_HWCAP2 in the TCB feature.  */
-      switch_to_section (data_section);
+      switch_to_section (casm->sections.data);
       fprintf (asm_out_file, "\t.align %u\n", TARGET_32BIT ? 2 : 3);
       fprintf (asm_out_file, "\t%s %s\n",
 	       TARGET_32BIT ? ".long" : ".quad", tcb_verification_symbol);
@@ -21066,7 +21066,7 @@  rs6000_xcoff_asm_init_sections (void)
   toc_section
     = get_unnamed_section (0, rs6000_xcoff_output_toc_section_asm_op, NULL);
 
-  readonly_data_section = read_only_data_section;
+  casm->sections.readonly_data = read_only_data_section;
 }
 
 static int
@@ -21144,7 +21144,7 @@  rs6000_xcoff_select_section (tree decl, int reloc,
       if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
 	{
 	  if (bss_initializer_p (decl))
-	    return tls_comm_section;
+	    return casm->sections.tls_comm;
 	  else if (TREE_PUBLIC (decl))
 	    return tls_data_section;
 	  else
@@ -21153,7 +21153,7 @@  rs6000_xcoff_select_section (tree decl, int reloc,
       else
 #endif
 	if (TREE_PUBLIC (decl))
-	return data_section;
+	return casm->sections.data;
       else
 	return private_data_section;
     }
@@ -21258,7 +21258,7 @@  rs6000_xcoff_file_start (void)
   if (write_symbols != NO_DEBUG)
     switch_to_section (private_data_section);
   switch_to_section (toc_section);
-  switch_to_section (text_section);
+  switch_to_section (casm->sections.text);
   if (profile_flag)
     fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
   rs6000_file_start ();
@@ -21270,9 +21270,9 @@  rs6000_xcoff_file_start (void)
 static void
 rs6000_xcoff_file_end (void)
 {
-  switch_to_section (text_section);
+  switch_to_section (casm->sections.text);
   fputs ("_section_.text:\n", asm_out_file);
-  switch_to_section (data_section);
+  switch_to_section (casm->sections.data);
   fputs (TARGET_32BIT
 	 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
 	 asm_out_file);
@@ -21392,7 +21392,7 @@  rs6000_xcoff_visibility (tree decl)
    Dollar signs are converted to underscores.
 
    The csect for the function will have already been created when
-   text_section was selected.  We do have to go back to that csect, however.
+   casm->sections.text was selected.  We do have to go back to that csect, however.
 
    The third and fourth parameters to the .function pseudo-op (16 and 044)
    are placeholders which no longer have any use.
@@ -21454,7 +21454,7 @@  rs6000_xcoff_declare_function_name (FILE *file, const char *name, tree decl)
   RS6000_OUTPUT_BASENAME (file, buffer);
   fputs (", TOC[tc0], 0\n", file);
 
-  in_section = NULL;
+  casm->in_section = NULL;
   switch_to_section (function_section (decl));
   putc ('.', file);
   ASM_OUTPUT_LABEL (file, buffer);
@@ -21514,7 +21514,7 @@  rs6000_xcoff_asm_output_aligned_decl_common (FILE *stream,
   if (! DECL_COMMON (decl))
     {
       /* Forget section.  */
-      in_section = NULL;
+      casm->in_section = NULL;
 
       /* Globalize TLS BSS.  */
       if (TREE_PUBLIC (decl) && DECL_THREAD_LOCAL_P (decl))
@@ -26509,7 +26509,7 @@  rs6000_code_end (void)
   else
 #endif
     {
-      switch_to_section (text_section);
+      switch_to_section (casm->sections.text);
       ASM_OUTPUT_LABEL (asm_out_file, name);
     }
 
diff --git a/gcc/config/rx/rx.c b/gcc/config/rx/rx.c
index af54ccc2588..3cb495f5c4d 100644
--- a/gcc/config/rx/rx.c
+++ b/gcc/config/rx/rx.c
@@ -2305,7 +2305,7 @@  rx_select_rtx_section (machine_mode mode,
   if (rx_small_data_limit > 0
       && GET_MODE_SIZE (mode) <= rx_small_data_limit
       && align <= (unsigned HOST_WIDE_INT) rx_small_data_limit * BITS_PER_UNIT)
-    return sdata_section;
+    return casm->sections.sdata;
 
   return default_elf_select_rtx_section (mode, x, align);
 }
@@ -2319,8 +2319,8 @@  rx_select_section (tree decl,
     {
       switch (categorize_decl_for_section (decl, reloc))
 	{
-	case SECCAT_SDATA:	return sdata_section;
-	case SECCAT_SBSS:	return sbss_section;
+	case SECCAT_SDATA:	return casm->sections.sdata;
+	case SECCAT_SBSS:	return casm->sections.sbss;
 	case SECCAT_SRODATA:
 	  /* Fall through.  We do not put small, read only
 	     data into the C_2 section because we are not
@@ -2342,7 +2342,7 @@  rx_select_section (tree decl,
       case SECCAT_RODATA_MERGE_CONST:
       case SECCAT_RODATA_MERGE_STR_INIT:
       case SECCAT_RODATA_MERGE_STR:
-	return readonly_data_section;
+	return casm->sections.readonly_data;
 
       default:
 	break;
@@ -2690,9 +2690,9 @@  rx_elf_asm_cdtor (rtx symbol, int priority, bool is_ctor)
       s = get_section (buf, SECTION_WRITE, NULL_TREE);
     }
   else if (is_ctor)
-    s = ctors_section;
+    s = casm->sections.ctors;
   else
-    s = dtors_section;
+    s = casm->sections.dtors;
 
   switch_to_section (s);
   assemble_align (POINTER_SIZE);
diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 54dd6332c3a..244e97bbbca 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -16612,7 +16612,7 @@  s390_output_indirect_thunk_function (unsigned int regno, bool z10_p)
     }
   else
     {
-      switch_to_section (text_section);
+      switch_to_section (casm->sections.text);
       ASM_OUTPUT_LABEL (asm_out_file, thunk_label);
     }
 
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index 1564109c942..07d18406ea1 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -2828,7 +2828,7 @@  sh_file_start (void)
   else
     /* Switch to the data section so that the coffsem symbol
        isn't in the text section.  */
-    switch_to_section (data_section);
+    switch_to_section (casm->sections.data);
 
   if (TARGET_LITTLE_ENDIAN)
     fputs ("\t.little\n", asm_out_file);
diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c
index 06f41d7bb53..53fca1f4b5c 100644
--- a/gcc/config/sparc/sparc.c
+++ b/gcc/config/sparc/sparc.c
@@ -12499,7 +12499,7 @@  sparc_file_end (void)
       else
 	{
 	  const int align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
-          switch_to_section (text_section);
+          switch_to_section (casm->sections.text);
 	  if (align > 0)
 	    ASM_OUTPUT_ALIGN (asm_out_file, align);
 	  ASM_OUTPUT_LABEL (asm_out_file, name);
diff --git a/gcc/config/v850/v850.c b/gcc/config/v850/v850.c
index 4978faf9318..2d1c8dca2ea 100644
--- a/gcc/config/v850/v850.c
+++ b/gcc/config/v850/v850.c
@@ -2398,7 +2398,7 @@  v850_output_aligned_bss (FILE * file,
       break;
 
     case DATA_AREA_SDA:
-      switch_to_section (sbss_section);
+      switch_to_section (casm->sections.sbss);
       break;
 
     case DATA_AREA_TDA:
@@ -2406,7 +2406,7 @@  v850_output_aligned_bss (FILE * file,
       break;
       
     default:
-      switch_to_section (bss_section);
+      switch_to_section (casm->sections.bss);
       break;
     }
   
@@ -2882,13 +2882,13 @@  v850_select_section (tree exp,
 	  return tdata_section;
 
         case DATA_AREA_SDA:
-	  return is_const ? rosdata_section : sdata_section;
+	  return is_const ? rosdata_section : casm->sections.sdata;
 
         default:
-	  return is_const ? readonly_data_section : data_section;
+	  return is_const ? casm->sections.readonly_data : casm->sections.data;
         }
     }
-  return readonly_data_section;
+  return casm->sections.readonly_data;
 }
 
 /* Worker function for TARGET_FUNCTION_VALUE_REGNO_P.  */
diff --git a/gcc/dbxout.c b/gcc/dbxout.c
index 6be282714cf..0ad57ab35bd 100644
--- a/gcc/dbxout.c
+++ b/gcc/dbxout.c
@@ -934,7 +934,7 @@  dbxout_function_end (tree decl ATTRIBUTE_UNUSED)
   if (crtl->has_bb_partition)
     {
       dbxout_begin_empty_stabs (N_FUN);
-      if (in_cold_section_p)
+      if (casm->in_cold_section_p)
 	dbxout_stab_value_label_diff (crtl->subsections.cold_section_end_label,
 				      crtl->subsections.cold_section_label);
       else
@@ -1042,7 +1042,7 @@  dbxout_init (const char *input_file_name)
 
   if (used_ltext_label_name)
     {
-      switch_to_section (text_section);
+      switch_to_section (casm->sections.text);
       targetm.asm_out.internal_label (asm_out_file, "Ltext", 0);
     }
 
@@ -1244,7 +1244,7 @@  dbxout_source_file (const char *filename)
     {
       /* Don't change section amid function.  */
       if (current_function_decl == NULL_TREE)
-	switch_to_section (text_section);
+	switch_to_section (casm->sections.text);
 
       dbxout_begin_simple_stabs (remap_debug_filename (filename), N_SOL);
       dbxout_stab_value_internal_label ("Ltext", &source_label_number);
@@ -1314,12 +1314,12 @@  dbxout_switch_text_section (void)
   /* The N_FUN tag at the end of the function is a GNU extension,
      which may be undesirable, and is unnecessary if we do not have
      named sections.  */
-  in_cold_section_p = !in_cold_section_p;
+  casm->in_cold_section_p = !casm->in_cold_section_p;
   switch_to_section (current_function_section ());
   dbxout_block (DECL_INITIAL (current_function_decl), 0,
 		DECL_ARGUMENTS (current_function_decl), -1);
   dbxout_function_end (current_function_decl);
-  in_cold_section_p = !in_cold_section_p;
+  casm->in_cold_section_p = !casm->in_cold_section_p;
 
   switch_to_section (current_function_section ());
 
@@ -1432,7 +1432,7 @@  dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
   DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename);
 #elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
  {
-   switch_to_section (text_section);
+   switch_to_section (casm->sections.text);
    dbxout_begin_empty_stabs (N_SO);
    dbxout_stab_value_internal_label ("Letext", 0);
  }
@@ -3114,7 +3114,7 @@  dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
 	    {
 	      /* Ultrix `as' seems to need this.  */
 #ifdef DBX_STATIC_STAB_DATA_SECTION
-	      switch_to_section (data_section);
+	      switch_to_section (casm->sections.data);
 #endif
 	      code = N_STSYM;
 	    }
@@ -3776,7 +3776,7 @@  dbxout_block (tree block, int depth, tree args, int parent_blocknum)
 
   /* If called for the second partition, ignore blocks that don't have
      any children in the second partition.  */
-  if (crtl->has_bb_partition && in_cold_section_p && depth == 0)
+  if (crtl->has_bb_partition && casm->in_cold_section_p && depth == 0)
     dbx_block_with_cold_children (block);
 
   for (; block; block = BLOCK_CHAIN (block))
@@ -3801,7 +3801,7 @@  dbxout_block (tree block, int depth, tree args, int parent_blocknum)
 	     the assembler symbols LBBn and LBEn
 	     that final will define around the code in this block.  */
 	  if (did_output
-	      && BLOCK_IN_COLD_SECTION_P (block) == in_cold_section_p)
+	      && BLOCK_IN_COLD_SECTION_P (block) == casm->in_cold_section_p)
 	    {
 	      char buf[20];
 	      const char *scope_start;
@@ -3829,7 +3829,7 @@  dbxout_block (tree block, int depth, tree args, int parent_blocknum)
 
 	  /* Refer to the marker for the end of the block.  */
 	  if (did_output
-	      && BLOCK_IN_COLD_SECTION_P (block) == in_cold_section_p)
+	      && BLOCK_IN_COLD_SECTION_P (block) == casm->in_cold_section_p)
 	    {
 	      char buf[100];
 	      if (depth == 0)
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 9876750e4f9..cdfdee3cd9a 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -438,14 +438,14 @@  should_emit_struct_debug (tree type, enum debug_info_usage usage)
   return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
 }
 
-/* Switch [BACK] to eh_frame_section.  If we don't have an eh_frame_section,
+/* Switch [BACK] to casm->sections.eh_frame.  If we don't have an casm->sections.eh_frame,
    switch to the data section instead, and write out a synthetic start label
    for collect2 the first time around.  */
 
 static void
 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED)
 {
-  if (eh_frame_section == 0)
+  if (casm->sections.eh_frame == 0)
     {
       int flags;
 
@@ -474,14 +474,14 @@  switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED)
 	flags = SECTION_WRITE;
 
 #ifdef EH_FRAME_SECTION_NAME
-      eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
+      casm->sections.eh_frame = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
 #else
-      eh_frame_section = ((flags == SECTION_WRITE)
-			  ? data_section : readonly_data_section);
+      casm->sections.eh_frame = ((flags == SECTION_WRITE)
+			  ? casm->sections.data : casm->sections.readonly_data);
 #endif /* EH_FRAME_SECTION_NAME */
     }
 
-  switch_to_section (eh_frame_section);
+  switch_to_section (casm->sections.eh_frame);
 
 #ifdef EH_FRAME_THROUGH_COLLECT2
   /* We have no special eh_frame section.  Emit special labels to guide
@@ -1113,10 +1113,10 @@  dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
   /* Initialize the bits of CURRENT_FDE that were not available earlier.  */
   fde->dw_fde_begin = dup_label;
   fde->dw_fde_current_label = dup_label;
-  fde->in_std_section = (fnsec == text_section
+  fde->in_std_section = (fnsec == casm->sections.text
 			 || (cold_text_section && fnsec == cold_text_section));
   fde->ignored_debug = DECL_IGNORED_P (current_function_decl);
-  in_text_section_p = fnsec == text_section;
+  in_text_section_p = fnsec == casm->sections.text;
 
   /* We only want to output line number information for the genuine dwarf2
      prologue case, not the eh frame case.  */
@@ -1295,7 +1295,7 @@  dwarf2out_switch_text_section (void)
 			       current_function_funcdef_no);
 
   fde->dw_fde_second_begin = ggc_strdup (label);
-  if (!in_cold_section_p)
+  if (!casm->in_cold_section_p)
     {
       fde->dw_fde_end = crtl->subsections.cold_section_end_label;
       fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
@@ -1317,9 +1317,9 @@  dwarf2out_switch_text_section (void)
   switch_to_section (sect);
 
   fde->second_in_std_section
-    = (sect == text_section
+    = (sect == casm->sections.text
        || (cold_text_section && sect == cold_text_section));
-  in_text_section_p = sect == text_section;
+  in_text_section_p = sect == casm->sections.text;
 
   if (dwarf2out_do_cfi_asm ())
     dwarf2out_do_cfi_startproc (true);
@@ -17268,7 +17268,7 @@  secname_for_decl (const_tree decl)
     secname = DECL_SECTION_NAME (decl);
   else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
     {
-      if (in_cold_section_p)
+      if (casm->in_cold_section_p)
 	{
 	  section *sec = current_function_section ();
 	  if (sec->common.flags & SECTION_NAMED)
@@ -17276,7 +17276,7 @@  secname_for_decl (const_tree decl)
 	}
       secname = DECL_SECTION_NAME (current_function_decl);
     }
-  else if (cfun && in_cold_section_p)
+  else if (cfun && casm->in_cold_section_p)
     secname = crtl->subsections.cold_section_label;
   else
     secname = text_section_label;
@@ -17597,12 +17597,12 @@  dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
 
   if (cfun && crtl->has_bb_partition)
     {
-      bool save_in_cold_section_p = in_cold_section_p;
-      in_cold_section_p = first_function_block_is_cold;
+      bool save_in_cold_section_p = casm->in_cold_section_p;
+      casm->in_cold_section_p = first_function_block_is_cold;
       if (loc_list->last_before_switch == NULL)
-	in_cold_section_p = !in_cold_section_p;
+	casm->in_cold_section_p = !casm->in_cold_section_p;
       secname = secname_for_decl (decl);
-      in_cold_section_p = save_in_cold_section_p;
+      casm->in_cold_section_p = save_in_cold_section_p;
     }
   else
     secname = secname_for_decl (decl);
@@ -17680,10 +17680,10 @@  dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
 	  && crtl->has_bb_partition
 	  && node == loc_list->last_before_switch)
 	{
-	  bool save_in_cold_section_p = in_cold_section_p;
-	  in_cold_section_p = !first_function_block_is_cold;
+	  bool save_in_cold_section_p = casm->in_cold_section_p;
+	  casm->in_cold_section_p = !first_function_block_is_cold;
 	  secname = secname_for_decl (decl);
-	  in_cold_section_p = save_in_cold_section_p;
+	  casm->in_cold_section_p = save_in_cold_section_p;
 	}
 
       if (range_across_switch)
@@ -27851,7 +27851,7 @@  create_label:
      last_{,postcall_}label so that they are not reused this time.  */
   if (last_var_location_insn == NULL_RTX
       || last_var_location_insn != next_real
-      || last_in_cold_section_p != in_cold_section_p)
+      || last_in_cold_section_p != casm->in_cold_section_p)
     {
       last_label = NULL;
       last_postcall_label = NULL;
@@ -28022,7 +28022,7 @@  create_label:
     }
 
   last_var_location_insn = next_real;
-  last_in_cold_section_p = in_cold_section_p;
+  last_in_cold_section_p = casm->in_cold_section_p;
 }
 
 /* Check whether BLOCK, a lexical block, is nested within OUTER, or is
@@ -28190,7 +28190,7 @@  set_cur_line_info_table (section *sec)
 {
   dw_line_info_table *table;
 
-  if (sec == text_section)
+  if (sec == casm->sections.text)
     table = text_section_line_info;
   else if (sec == cold_text_section)
     {
@@ -28207,7 +28207,7 @@  set_cur_line_info_table (section *sec)
 
       if (crtl->has_bb_partition)
 	{
-	  if (in_cold_section_p)
+	  if (casm->in_cold_section_p)
 	    end_label = crtl->subsections.cold_section_end_label;
 	  else
 	    end_label = crtl->subsections.hot_section_end_label;
@@ -28244,7 +28244,7 @@  dwarf2out_begin_function (tree fun)
 {
   section *sec = function_section (fun);
 
-  if (sec != text_section)
+  if (sec != casm->sections.text)
     have_multiple_function_sections = true;
 
   if (crtl->has_bb_partition && !cold_text_section)
@@ -29373,7 +29373,7 @@  dwarf2out_assembly_start (void)
 			       COLD_TEXT_SECTION_LABEL, 0);
   ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
 
-  switch_to_section (text_section);
+  switch_to_section (casm->sections.text);
   ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
 #endif
 
@@ -32080,7 +32080,7 @@  dwarf2out_finish (const char *filename)
     main_comp_unit_die = comp_unit_die ();
 
   /* Output a terminator label for the .text section.  */
-  switch_to_section (text_section);
+  switch_to_section (casm->sections.text);
   targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
   if (cold_text_section)
     {
@@ -32996,7 +32996,7 @@  dwarf2out_early_finish (const char *filename)
     }
 
   /* Switch back to the text section.  */
-  switch_to_section (text_section);
+  switch_to_section (casm->sections.text);
 }
 
 /* Reset all state within dwarf2out.c so that we can rerun the compiler
diff --git a/gcc/except.c b/gcc/except.c
index 8e905a30939..db6a2b9e14c 100644
--- a/gcc/except.c
+++ b/gcc/except.c
@@ -2906,8 +2906,8 @@  switch_to_exception_section (const char * ARG_UNUSED (fnname))
 {
   section *s;
 
-  if (exception_section)
-    s = exception_section;
+  if (casm->sections.exception)
+    s = casm->sections.exception;
   else
     {
       int flags;
@@ -2924,7 +2924,7 @@  switch_to_exception_section (const char * ARG_UNUSED (fnname))
       else
 	flags = SECTION_WRITE;
 
-      /* Compute the section and cache it into exception_section,
+      /* Compute the section and cache it into casm->sections.exception,
 	 unless it depends on the function name.  */
       if (targetm_common.have_named_sections)
 	{
@@ -2943,12 +2943,12 @@  switch_to_exception_section (const char * ARG_UNUSED (fnname))
 	    }
 	  else
 #endif
-	    exception_section
+	    casm->sections.exception
 	      = s = get_section (".gcc_except_table", flags, NULL);
 	}
       else
-	exception_section
-	  = s = flags == SECTION_WRITE ? data_section : readonly_data_section;
+	casm->sections.exception
+	  = s = flags == SECTION_WRITE ? casm->sections.data: casm->sections.readonly_data;
     }
 
   switch_to_section (s);
diff --git a/gcc/final.c b/gcc/final.c
index ac6892d041c..6515f00875c 100644
--- a/gcc/final.c
+++ b/gcc/final.c
@@ -885,7 +885,7 @@  shorten_branches (rtx_insn *first)
 	  /* ADDR_VECs only take room if read-only data goes into the text
 	     section.  */
 	  if ((JUMP_TABLES_IN_TEXT_SECTION
-	       || readonly_data_section == text_section)
+	       || casm->sections.readonly_data == casm->sections.text)
 	      && table)
 	    {
 	      align_flags alignment = align_flags (ADDR_VEC_ALIGN (table));
@@ -1051,7 +1051,7 @@  shorten_branches (rtx_insn *first)
 	  /* This only takes room if read-only data goes into the text
 	     section.  */
 	  if (JUMP_TABLES_IN_TEXT_SECTION
-	      || readonly_data_section == text_section)
+	      || casm->sections.readonly_data == casm->sections.text)
 	    insn_lengths[uid] = (XVECLEN (body,
 					  GET_CODE (body) == ADDR_DIFF_VEC)
 				 * GET_MODE_SIZE (table->get_data_mode ()));
@@ -1143,7 +1143,7 @@  shorten_branches (rtx_insn *first)
 		 may need to update the alignment of this label.  */
 
 	      if (JUMP_TABLES_IN_TEXT_SECTION
-		  || readonly_data_section == text_section)
+		  || casm->sections.readonly_data == casm->sections.text)
 		{
 		  rtx_jump_table_data *table = jump_table_for_label (label);
 		  if (table)
@@ -1284,7 +1284,7 @@  shorten_branches (rtx_insn *first)
 		      >= GET_MODE_SIZE (table->get_data_mode ())))
 		PUT_MODE (body, vec_mode);
 	      if (JUMP_TABLES_IN_TEXT_SECTION
-		  || readonly_data_section == text_section)
+		  || casm->sections.readonly_data == casm->sections.text)
 		{
 		  insn_lengths[uid]
 		    = (XVECLEN (body, 1)
@@ -1836,7 +1836,7 @@  profile_function (FILE *file ATTRIBUTE_UNUSED)
   if (! NO_PROFILE_COUNTERS)
     {
       int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
-      switch_to_section (data_section);
+      switch_to_section (casm->sections.data);
       ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
       targetm.asm_out.internal_label (file, "LP", current_function_funcdef_no);
       assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, align, 1);
@@ -2189,10 +2189,10 @@  final_scan_insn_1 (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED,
 	  if (targetm.asm_out.unwind_emit)
 	    targetm.asm_out.unwind_emit (asm_out_file, insn);
 
-	  in_cold_section_p = !in_cold_section_p;
+	  casm->in_cold_section_p = !casm->in_cold_section_p;
 
-	  gcc_checking_assert (in_cold_section_p);
-	  if (in_cold_section_p)
+	  gcc_checking_assert (casm->in_cold_section_p);
+	  if (casm->in_cold_section_p)
 	    cold_function_name
 	      = clone_function_name (current_function_decl, "cold");
 
@@ -2213,10 +2213,10 @@  final_scan_insn_1 (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED,
 	  switch_to_section (current_function_section ());
 	  targetm.asm_out.function_switched_text_sections (asm_out_file,
 							   current_function_decl,
-							   in_cold_section_p);
+							   casm->in_cold_section_p);
 	  /* Emit a label for the split cold section.  Form label name by
 	     suffixing "cold" to the original function's name.  */
-	  if (in_cold_section_p)
+	  if (casm->in_cold_section_p)
 	    {
 #ifdef ASM_DECLARE_COLD_FUNCTION_NAME
 	      ASM_DECLARE_COLD_FUNCTION_NAME (asm_out_file,
@@ -2323,7 +2323,7 @@  final_scan_insn_1 (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED,
 
 	      /* Mark this block as output.  */
 	      TREE_ASM_WRITTEN (NOTE_BLOCK (insn)) = 1;
-	      BLOCK_IN_COLD_SECTION_P (NOTE_BLOCK (insn)) = in_cold_section_p;
+	      BLOCK_IN_COLD_SECTION_P (NOTE_BLOCK (insn)) = casm->in_cold_section_p;
 	    }
 	  if (write_symbols == DBX_DEBUG)
 	    {
@@ -2358,7 +2358,7 @@  final_scan_insn_1 (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED,
 	      if (!DECL_IGNORED_P (current_function_decl))
 		debug_hooks->end_block (high_block_linenum, n);
 	      gcc_assert (BLOCK_IN_COLD_SECTION_P (NOTE_BLOCK (insn))
-			  == in_cold_section_p);
+			  == casm->in_cold_section_p);
 	    }
 	  if (write_symbols == DBX_DEBUG)
 	    {
diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c
index 32ba5be42b2..c383605f813 100644
--- a/gcc/ggc-common.c
+++ b/gcc/ggc-common.c
@@ -30,6 +30,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "hosthooks.h"
 #include "plugin.h"
 #include "options.h"
+#include "output.h"
 
 /* When true, protect the contents of the identifier hash table.  */
 bool ggc_protect_identifiers = true;
@@ -589,6 +590,9 @@  gt_pch_restore (FILE *f)
   struct mmap_info mmi;
   int result;
 
+  /* Hide ASM state object as we don't want it to be streamed.  */
+  FILE *saved_casm_out_file = casm->out_file;
+
   /* Delete any deletable objects.  This makes ggc_pch_read much
      faster, as it can be sure that no GCable objects remain other
      than the ones just read in.  */
@@ -629,6 +633,8 @@  gt_pch_restore (FILE *f)
   ggc_pch_read (f, mmi.preferred_base);
 
   gt_pch_restore_stringpool ();
+
+  casm->out_file = saved_casm_out_file;
 }
 
 /* Default version of HOST_HOOKS_GT_PCH_GET_ADDRESS when mmap is not present.
diff --git a/gcc/langhooks.c b/gcc/langhooks.c
index 48c72377778..a25a4f84eba 100644
--- a/gcc/langhooks.c
+++ b/gcc/langhooks.c
@@ -803,9 +803,9 @@  lhd_begin_section (const char *name)
 
   /* Save the old section so we can restore it in lto_end_asm_section.  */
   gcc_assert (!saved_section);
-  saved_section = in_section;
+  saved_section = casm->in_section;
   if (!saved_section)
-    saved_section = text_section;
+    saved_section = casm->sections.text;
 
   /* Create a new section and switch to it.  */
   section = get_section (name, SECTION_DEBUG | SECTION_EXCLUDE, NULL, true);
diff --git a/gcc/output.h b/gcc/output.h
index 73ca4545f4f..3fdc559fec5 100644
--- a/gcc/output.h
+++ b/gcc/output.h
@@ -313,9 +313,78 @@  extern rtx_sequence *final_sequence;
 
 /* File in which assembler code is being written.  */
 
-#ifdef BUFSIZ
-extern FILE *asm_out_file;
-#endif
+struct section_hasher : ggc_ptr_hash<section>
+{
+  typedef const char *compare_type;
+
+  static hashval_t hash (section *);
+  static bool equal (section *, const char *);
+};
+
+/* Assembly output state.  */
+
+struct GTY(()) asm_out_state
+{
+  asm_out_state (): out_file (NULL), in_section (NULL),
+    sections ({}), anchor_labelno (0), in_cold_section_p (false)
+  {
+    section_htab = hash_table<section_hasher>::create_ggc (31);
+  }
+
+  /* Assembly output stream.  */
+  FILE * GTY((skip)) out_file;
+
+  /* Hash table of named sections.  */
+  hash_table<section_hasher> *section_htab;
+
+  /* asm_out_file's current section.  This is NULL if no section has yet
+     been selected or if we lose track of what the current section is.  */
+  section *in_section;
+
+  /* Well-known sections, each one associated with some sort of *_ASM_OP.  */
+  struct
+  {
+    section *text;
+    section *data;
+    section *readonly_data;
+    section *sdata;
+    section *ctors;
+    section *dtors;
+    section *bss;
+    section *sbss;
+
+    /* Various forms of common section.  All are guaranteed to be nonnull.  */
+    section *tls_comm;
+    section *comm;
+    section *lcomm;
+
+    /* A SECTION_NOSWITCH section used for declaring global BSS variables.
+       May be null.  */
+    section *bss_noswitch;
+
+    /* The section that holds the main exception table, when known.  The section
+       is set either by the target's init_sections hook or by the first call to
+       switch_to_exception_section.  */
+    section *exception;
+
+    /* The section that holds the DWARF2 frame unwind information, when known.
+       The section is set either by the target's init_sections hook or by the
+       first call to switch_to_eh_frame_section.  */
+    section *eh_frame;
+  } sections;
+
+  /* The next number to use for internal anchor labels.  */
+  int anchor_labelno;
+
+  /* True if code for the current function is currently being directed
+     at the cold section.  */
+  bool in_cold_section_p;
+};
+
+extern GTY(()) asm_out_state *casm;
+
+/* Helper macro for commonly used accesses.  */
+#define asm_out_file casm->out_file
 
 /* The first global object in the file.  */
 extern const char *first_global_object_name;
@@ -511,24 +580,6 @@  union GTY ((desc ("SECTION_STYLE (&(%h))"), for_user)) section {
 struct object_block;
 
 /* Special well-known sections.  */
-extern GTY(()) section *text_section;
-extern GTY(()) section *data_section;
-extern GTY(()) section *readonly_data_section;
-extern GTY(()) section *sdata_section;
-extern GTY(()) section *ctors_section;
-extern GTY(()) section *dtors_section;
-extern GTY(()) section *bss_section;
-extern GTY(()) section *sbss_section;
-extern GTY(()) section *exception_section;
-extern GTY(()) section *eh_frame_section;
-extern GTY(()) section *tls_comm_section;
-extern GTY(()) section *comm_section;
-extern GTY(()) section *lcomm_section;
-extern GTY(()) section *bss_noswitch_section;
-
-extern GTY(()) section *in_section;
-extern GTY(()) bool in_cold_section_p;
-
 extern section *get_unnamed_section (unsigned int, void (*) (const void *),
 				     const void *);
 extern section *get_section (const char *, unsigned int, tree,
diff --git a/gcc/run-rtl-passes.c b/gcc/run-rtl-passes.c
index 37a02813f22..e49b75bf7f9 100644
--- a/gcc/run-rtl-passes.c
+++ b/gcc/run-rtl-passes.c
@@ -46,7 +46,7 @@  run_rtl_passes (char *initial_pass_name)
   max_regno = max_reg_num ();
 
   /* cgraphunit.c normally handles this.  */
-  switch_to_section (text_section);
+  switch_to_section (casm->sections.text);
   (*debug_hooks->assembly_start) ();
 
   if (initial_pass_name)
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index c9b5208853d..68660186ec5 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -1962,7 +1962,7 @@  default_print_patchable_function_entry_1 (FILE *file,
     {
       char buf[256];
       static int patch_area_number;
-      section *previous_section = in_section;
+      section *previous_section = casm->in_section;
       const char *asm_op = integer_asm_op (POINTER_SIZE_UNITS, false);
 
       gcc_assert (asm_op != NULL);
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 14d1335e79e..fcc7b39f624 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -172,7 +172,8 @@  const char *user_label_prefix;
 /* Output files for assembler code (real compiler output)
    and debugging dumps.  */
 
-FILE *asm_out_file;
+asm_out_state *casm;
+
 FILE *aux_info_file;
 FILE *callgraph_info_file = NULL;
 static bitmap callgraph_info_external_printed;
@@ -552,13 +553,13 @@  compile_file (void)
   if (flag_generate_lto && !flag_fat_lto_objects)
     {
 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
-      ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE, "__gnu_lto_slim",
+      ASM_OUTPUT_ALIGNED_DECL_COMMON (casm->out_file, NULL_TREE, "__gnu_lto_slim",
 				      HOST_WIDE_INT_1U, 8);
 #elif defined ASM_OUTPUT_ALIGNED_COMMON
-      ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_slim",
+      ASM_OUTPUT_ALIGNED_COMMON (casm->out_file, "__gnu_lto_slim",
 				 HOST_WIDE_INT_1U, 8);
 #else
-      ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_slim",
+      ASM_OUTPUT_COMMON (casm->out_file, "__gnu_lto_slim",
 			 HOST_WIDE_INT_1U,
 			 HOST_WIDE_INT_1U);
 #endif
@@ -696,7 +697,7 @@  static void
 init_asm_output (const char *name)
 {
   if (name == NULL && asm_file_name == 0)
-    asm_out_file = stdout;
+    casm->out_file = stdout;
   else
     {
       if (asm_file_name == 0)
@@ -710,17 +711,17 @@  init_asm_output (const char *name)
 	  asm_file_name = dumpname;
 	}
       if (!strcmp (asm_file_name, "-"))
-	asm_out_file = stdout;
+	casm->out_file = stdout;
       else if (!canonical_filename_eq (asm_file_name, name)
 	       || !strcmp (asm_file_name, HOST_BIT_BUCKET))
-	asm_out_file = fopen (asm_file_name, "w");
+	casm->out_file = fopen (asm_file_name, "w");
       else
 	/* Use UNKOWN_LOCATION to prevent gcc from printing the first
 	   line in the current file. */
 	fatal_error (UNKNOWN_LOCATION,
 		     "input file %qs is the same as output file",
 		     asm_file_name);
-      if (asm_out_file == 0)
+      if (casm->out_file == 0)
 	fatal_error (UNKNOWN_LOCATION,
 		     "cannot open %qs for writing: %m", asm_file_name);
     }
@@ -747,14 +748,14 @@  init_asm_output (const char *name)
 
       if (flag_verbose_asm)
 	{
-	  print_version (asm_out_file, ASM_COMMENT_START, true);
-	  fputs (ASM_COMMENT_START, asm_out_file);
-	  fputs (" options passed: ", asm_out_file);
+	  print_version (casm->out_file, ASM_COMMENT_START, true);
+	  fputs (ASM_COMMENT_START, casm->out_file);
+	  fputs (" options passed: ", casm->out_file);
 	  char *cmdline = gen_command_line_string (save_decoded_options,
 						   save_decoded_options_count);
-	  fputs (cmdline, asm_out_file);
+	  fputs (cmdline, casm->out_file);
 	  free (cmdline);
-	  fputc ('\n', asm_out_file);
+	  fputc ('\n', casm->out_file);
 	}
     }
 }
@@ -1112,6 +1113,9 @@  general_init (const char *argv0, bool init_signals)
 
   symtab = new (ggc_alloc <symbol_table> ()) symbol_table ();
 
+  /* Initialize ASM out state.  */
+  casm = new (ggc_alloc<asm_out_state> ()) asm_out_state ();
+
   statistics_early_init ();
   debuginfo_early_init ();
 }
@@ -2083,13 +2087,13 @@  finalize (bool no_backend)
      whether fclose returns an error, since the pages might still be on the
      buffer chain while the file is open.  */
 
-  if (asm_out_file)
+  if (casm->out_file)
     {
-      if (ferror (asm_out_file) != 0)
+      if (ferror (casm->out_file) != 0)
 	fatal_error (input_location, "error writing to %s: %m", asm_file_name);
-      if (fclose (asm_out_file) != 0)
+      if (fclose (casm->out_file) != 0)
 	fatal_error (input_location, "error closing %s: %m", asm_file_name);
-      asm_out_file = NULL;
+      casm->out_file = NULL;
     }
 
   if (stack_usage_file)
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 53cf6dea3f3..61064df9dc8 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -130,43 +130,6 @@  static void mark_weak (tree);
 static void output_constant_pool (const char *, tree);
 static void handle_vtv_comdat_section (section *, const_tree);
 
-/* Well-known sections, each one associated with some sort of *_ASM_OP.  */
-section *text_section;
-section *data_section;
-section *readonly_data_section;
-section *sdata_section;
-section *ctors_section;
-section *dtors_section;
-section *bss_section;
-section *sbss_section;
-
-/* Various forms of common section.  All are guaranteed to be nonnull.  */
-section *tls_comm_section;
-section *comm_section;
-section *lcomm_section;
-
-/* A SECTION_NOSWITCH section used for declaring global BSS variables.
-   May be null.  */
-section *bss_noswitch_section;
-
-/* The section that holds the main exception table, when known.  The section
-   is set either by the target's init_sections hook or by the first call to
-   switch_to_exception_section.  */
-section *exception_section;
-
-/* The section that holds the DWARF2 frame unwind information, when known.
-   The section is set either by the target's init_sections hook or by the
-   first call to switch_to_eh_frame_section.  */
-section *eh_frame_section;
-
-/* asm_out_file's current section.  This is NULL if no section has yet
-   been selected or if we lose track of what the current section is.  */
-section *in_section;
-
-/* True if code for the current function is currently being directed
-   at the cold section.  */
-bool in_cold_section_p;
-
 /* The following global holds the "function name" for the code in the
    cold section of a function, if hot/cold function splitting is enabled
    and there was actually code that went into the cold section.  A
@@ -181,17 +144,6 @@  static GTY(()) section *unnamed_sections;
 #define IN_NAMED_SECTION(DECL) \
   (VAR_OR_FUNCTION_DECL_P (DECL) && DECL_SECTION_NAME (DECL) != NULL)
 
-struct section_hasher : ggc_ptr_hash<section>
-{
-  typedef const char *compare_type;
-
-  static hashval_t hash (section *);
-  static bool equal (section *, const char *);
-};
-
-/* Hash table of named sections.  */
-static GTY(()) hash_table<section_hasher> *section_htab;
-
 struct object_block_hasher : ggc_ptr_hash<object_block>
 {
   typedef const section *compare_type;
@@ -203,9 +155,6 @@  struct object_block_hasher : ggc_ptr_hash<object_block>
 /* A table of object_blocks, indexed by section.  */
 static GTY(()) hash_table<object_block_hasher> *object_block_htab;
 
-/* The next number to use for internal anchor labels.  */
-static GTY(()) int anchor_labelno;
-
 /* A pool of constants that can be shared between functions.  */
 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
 
@@ -294,8 +243,8 @@  get_section (const char *name, unsigned int flags, tree decl,
 {
   section *sect, **slot;
 
-  slot = section_htab->find_slot_with_hash (name, htab_hash_string (name),
-					    INSERT);
+  slot = casm->section_htab->find_slot_with_hash (name, htab_hash_string (name),
+						  INSERT);
   flags |= SECTION_NAMED;
   if (decl != nullptr
       && DECL_P (decl)
@@ -510,7 +459,7 @@  asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
 			const char *name, unsigned HOST_WIDE_INT size,
 			int align)
 {
-  switch_to_section (bss_section);
+  switch_to_section (casm->sections.bss);
   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
 #ifdef ASM_DECLARE_OBJECT_NAME
   last_assemble_variable_decl = decl;
@@ -527,7 +476,7 @@  asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
 #endif /* BSS_SECTION_ASM_OP */
 
 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
-/* Return the hot section for function DECL.  Return text_section for
+/* Return the hot section for function DECL.  Return casm->sections.text for
    null DECLs.  */
 
 static section *
@@ -538,7 +487,7 @@  hot_function_section (tree decl)
       && targetm_common.have_named_sections)
     return get_named_section (decl, NULL, 0);
   else
-    return text_section;
+    return casm->sections.text;
 }
 #endif
 
@@ -718,7 +667,7 @@  function_section (tree decl)
 section *
 current_function_section (void)
 {
-  return function_section_1 (current_function_decl, in_cold_section_p);
+  return function_section_1 (current_function_decl, casm->in_cold_section_p);
 }
 
 /* Tell assembler to switch to unlikely-to-be-executed text section.  */
@@ -746,7 +695,7 @@  unlikely_text_section_p (section *sect)
 void
 switch_to_other_text_partition (void)
 {
-  in_cold_section_p = !in_cold_section_p;
+  casm->in_cold_section_p = !casm->in_cold_section_p;
   switch_to_section (current_function_section ());
 }
 
@@ -831,7 +780,7 @@  default_function_rodata_section (tree decl, bool relocatable)
   if (relocatable)
     return get_section (sname, flags, decl);
   else
-    return readonly_data_section;
+    return casm->sections.readonly_data;
 }
 
 /* Return the read-only data section associated with function DECL
@@ -841,7 +790,7 @@  default_function_rodata_section (tree decl, bool relocatable)
 section *
 default_no_function_rodata_section (tree, bool)
 {
-  return readonly_data_section;
+  return casm->sections.readonly_data;
 }
 
 /* A subroutine of mergeable_string_section and mergeable_constant_section.  */
@@ -890,7 +839,7 @@  mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
 	    align = modesize;
 
 	  if (!HAVE_LD_ALIGNED_SHF_MERGE && align > 8)
-	    return readonly_data_section;
+	    return casm->sections.readonly_data;
 
 	  str = TREE_STRING_POINTER (decl);
 	  unit = GET_MODE_SIZE (mode);
@@ -914,7 +863,7 @@  mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
 	}
     }
 
-  return readonly_data_section;
+  return casm->sections.readonly_data;
 }
 
 /* Return the section to use for constant merging.  */
@@ -940,7 +889,7 @@  mergeable_constant_section (machine_mode mode ATTRIBUTE_UNUSED,
       flags |= (align / 8) | SECTION_MERGE;
       return get_section (name, flags, NULL);
     }
-  return readonly_data_section;
+  return casm->sections.readonly_data;
 }
 
 /* Given NAME, a putative register name, discard any customary prefixes.  */
@@ -1253,9 +1202,9 @@  get_variable_section (tree decl, bool prefer_noswitch_p)
       gcc_assert (DECL_SECTION_NAME (decl) == NULL
 		  && ADDR_SPACE_GENERIC_P (as));
       if (DECL_THREAD_LOCAL_P (decl))
-	return tls_comm_section;
+	return casm->sections.tls_comm;
       else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
-	return comm_section;
+	return casm->sections.comm;
     }
 
   reloc = compute_reloc_for_var (decl);
@@ -1285,9 +1234,9 @@  get_variable_section (tree decl, bool prefer_noswitch_p)
       if (!TREE_PUBLIC (decl)
 	  && !((flag_sanitize & SANITIZE_ADDRESS)
 	       && asan_protect_global (decl)))
-	return lcomm_section;
-      if (bss_noswitch_section)
-	return bss_noswitch_section;
+	return casm->sections.lcomm;
+      if (casm->sections.bss_noswitch)
+	return casm->sections.bss_noswitch;
     }
 
   return targetm.asm_out.select_section (decl, reloc,
@@ -1733,7 +1682,7 @@  void
 default_dtor_section_asm_out_destructor (rtx symbol,
 					 int priority ATTRIBUTE_UNUSED)
 {
-  assemble_addr_to_section (symbol, dtors_section);
+  assemble_addr_to_section (symbol, casm->sections.dtors);
 }
 #endif
 
@@ -1756,7 +1705,7 @@  void
 default_ctor_section_asm_out_constructor (rtx symbol,
 					  int priority ATTRIBUTE_UNUSED)
 {
-  assemble_addr_to_section (symbol, ctors_section);
+  assemble_addr_to_section (symbol, casm->sections.ctors);
 }
 #endif
 
@@ -1824,7 +1773,7 @@  decide_function_section (tree decl)
 				      == NODE_FREQUENCY_UNLIKELY_EXECUTED);
     }
 
-  in_cold_section_p = first_function_block_is_cold;
+  casm->in_cold_section_p = first_function_block_is_cold;
 }
 
 /* Get the function's name, as described by its RTL.  This may be
@@ -1900,13 +1849,13 @@  assemble_start_function (tree decl, const char *fnname)
       if (!cfun->is_thunk
 	  && BB_PARTITION (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb) == BB_COLD_PARTITION)
 	{
-	  switch_to_section (text_section);
+	  switch_to_section (casm->sections.text);
 	  assemble_align (align);
 	  ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
 	  hot_label_written = true;
 	  first_function_block_is_cold = true;
 	}
-      in_cold_section_p = first_function_block_is_cold;
+      casm->in_cold_section_p = first_function_block_is_cold;
     }
 
 
@@ -2020,7 +1969,7 @@  assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
     {
       section *save_text_section;
 
-      save_text_section = in_section;
+      save_text_section = casm->in_section;
       switch_to_section (unlikely_text_section ());
 #ifdef ASM_DECLARE_COLD_FUNCTION_SIZE
       if (cold_function_name != NULL_TREE)
@@ -2030,7 +1979,7 @@  assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
 #endif
       ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
       if (first_function_block_is_cold)
-	switch_to_section (text_section);
+	switch_to_section (casm->sections.text);
       else
 	switch_to_section (function_section (decl));
       ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
@@ -2050,7 +1999,7 @@  assemble_zeros (unsigned HOST_WIDE_INT size)
 #ifdef ASM_NO_SKIP_IN_TEXT
   /* The `space' pseudo in the text section outputs nop insns rather than 0s,
      so we must output 0s explicitly in the text section.  */
-  if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
+  if (ASM_NO_SKIP_IN_TEXT && (casm->in_section->common.flags & SECTION_CODE) != 0)
     {
       unsigned HOST_WIDE_INT i;
       for (i = 0; i < size; i++)
@@ -2097,7 +2046,7 @@  assemble_string (const char *p, int size)
 }
 
 
-/* A noswitch_section_callback for lcomm_section.  */
+/* A noswitch_section_callback for casm->sections.lcomm.  */
 
 static bool
 emit_local (tree decl ATTRIBUTE_UNUSED,
@@ -2120,7 +2069,7 @@  emit_local (tree decl ATTRIBUTE_UNUSED,
 #endif
 }
 
-/* A noswitch_section_callback for bss_noswitch_section.  */
+/* A noswitch_section_callback for casm->sections.bss_noswitch.  */
 
 #if defined ASM_OUTPUT_ALIGNED_BSS
 static bool
@@ -2135,7 +2084,7 @@  emit_bss (tree decl ATTRIBUTE_UNUSED,
 }
 #endif
 
-/* A noswitch_section_callback for comm_section.  */
+/* A noswitch_section_callback for casm->sections.comm.  */
 
 static bool
 emit_common (tree decl ATTRIBUTE_UNUSED,
@@ -2157,7 +2106,7 @@  emit_common (tree decl ATTRIBUTE_UNUSED,
 #endif
 }
 
-/* A noswitch_section_callback for tls_comm_section.  */
+/* A noswitch_section_callback for casm->sections.tls_comm.  */
 
 static bool
 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
@@ -2774,7 +2723,7 @@  assemble_trampoline_template (void)
 #ifdef TRAMPOLINE_SECTION
   switch_to_section (TRAMPOLINE_SECTION);
 #else
-  switch_to_section (readonly_data_section);
+  switch_to_section (casm->sections.readonly_data);
 #endif
 
   /* Write the assembler code to define one.  */
@@ -4192,8 +4141,8 @@  output_constant_pool_1 (class constant_descriptor_rtx *desc,
   /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
      sections have proper size.  */
   if (align > GET_MODE_BITSIZE (desc->mode)
-      && in_section
-      && (in_section->common.flags & SECTION_MERGE))
+      && casm->in_section
+      && (casm->in_section->common.flags & SECTION_MERGE))
     assemble_align (align);
 
 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
@@ -6596,70 +6545,69 @@  make_decl_one_only (tree decl, tree comdat_group)
 void
 init_varasm_once (void)
 {
-  section_htab = hash_table<section_hasher>::create_ggc (31);
   object_block_htab = hash_table<object_block_hasher>::create_ggc (31);
   const_desc_htab = hash_table<tree_descriptor_hasher>::create_ggc (1009);
 
   shared_constant_pool = create_constant_pool ();
 
 #ifdef TEXT_SECTION_ASM_OP
-  text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
+  casm->sections.text = get_unnamed_section (SECTION_CODE, output_section_asm_op,
 				      TEXT_SECTION_ASM_OP);
 #endif
 
 #ifdef DATA_SECTION_ASM_OP
-  data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
-				      DATA_SECTION_ASM_OP);
+  casm->sections.data = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
+					     DATA_SECTION_ASM_OP);
 #endif
 
 #ifdef SDATA_SECTION_ASM_OP
-  sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
+  casm->sections.sdata = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
 				       SDATA_SECTION_ASM_OP);
 #endif
 
 #ifdef READONLY_DATA_SECTION_ASM_OP
-  readonly_data_section = get_unnamed_section (0, output_section_asm_op,
-					       READONLY_DATA_SECTION_ASM_OP);
+  casm->sections.readonly_data = get_unnamed_section (0, output_section_asm_op,
+						      READONLY_DATA_SECTION_ASM_OP);
 #endif
 
 #ifdef CTORS_SECTION_ASM_OP
-  ctors_section = get_unnamed_section (0, output_section_asm_op,
+  casm->sections.ctors = get_unnamed_section (0, output_section_asm_op,
 				       CTORS_SECTION_ASM_OP);
 #endif
 
 #ifdef DTORS_SECTION_ASM_OP
-  dtors_section = get_unnamed_section (0, output_section_asm_op,
+  casm->sections.dtors = get_unnamed_section (0, output_section_asm_op,
 				       DTORS_SECTION_ASM_OP);
 #endif
 
 #ifdef BSS_SECTION_ASM_OP
-  bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
-				     output_section_asm_op,
-				     BSS_SECTION_ASM_OP);
+  casm->sections.bss = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
+					    output_section_asm_op,
+					    BSS_SECTION_ASM_OP);
 #endif
 
 #ifdef SBSS_SECTION_ASM_OP
-  sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
+  casm->sections.sbss = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
 				      output_section_asm_op,
 				      SBSS_SECTION_ASM_OP);
 #endif
 
-  tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
-					   | SECTION_COMMON, emit_tls_common);
-  lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
-					| SECTION_COMMON, emit_local);
-  comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
-				       | SECTION_COMMON, emit_common);
+  casm->sections.tls_comm = get_noswitch_section (SECTION_WRITE | SECTION_BSS
+						  | SECTION_COMMON, emit_tls_common);
+  casm->sections.lcomm = get_noswitch_section (SECTION_WRITE | SECTION_BSS
+					       | SECTION_COMMON, emit_local);
+  casm->sections.comm = get_noswitch_section (SECTION_WRITE | SECTION_BSS
+					      | SECTION_COMMON, emit_common);
 
 #if defined ASM_OUTPUT_ALIGNED_BSS
-  bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
-					       emit_bss);
+  casm->sections.bss_noswitch = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
+						      emit_bss);
 #endif
 
   targetm.asm_out.init_sections ();
 
-  if (readonly_data_section == NULL)
-    readonly_data_section = text_section;
+  if (casm->sections.readonly_data == NULL)
+    casm->sections.readonly_data = casm->sections.text;
 
 #ifdef ASM_OUTPUT_EXTERNAL
   pending_assemble_externals_set = new hash_set<tree>;
@@ -6784,13 +6732,13 @@  default_section_type_flags (tree decl, const char *name, int reloc)
 }
 
 /* Return true if the target supports some form of global BSS,
-   either through bss_noswitch_section, or by selecting a BSS
+   either through casm->sections.bss_noswitch, or by selecting a BSS
    section in TARGET_ASM_SELECT_SECTION.  */
 
 bool
 have_global_bss_p (void)
 {
-  return bss_noswitch_section || targetm.have_switchable_bss_sections;
+  return casm->sections.bss_noswitch || targetm.have_switchable_bss_sections;
 }
 
 /* Output assembly to switch to section NAME with attribute FLAGS.
@@ -6952,7 +6900,7 @@  default_select_section (tree decl, int reloc,
   if (DECL_P (decl))
     {
       if (decl_readonly_section (decl, reloc))
-	return readonly_data_section;
+	return casm->sections.readonly_data;
     }
   else if (TREE_CODE (decl) == CONSTRUCTOR)
     {
@@ -6960,14 +6908,14 @@  default_select_section (tree decl, int reloc,
 	     || !TREE_READONLY (decl)
 	     || TREE_SIDE_EFFECTS (decl)
 	     || !TREE_CONSTANT (decl)))
-	return readonly_data_section;
+	return casm->sections.readonly_data;
     }
   else if (TREE_CODE (decl) == STRING_CST)
-    return readonly_data_section;
+    return casm->sections.readonly_data;
   else if (! (flag_pic && reloc))
-    return readonly_data_section;
+    return casm->sections.readonly_data;
 
-  return data_section;
+  return casm->sections.data;
 }
 
 enum section_category
@@ -7106,7 +7054,7 @@  default_elf_select_section (tree decl, int reloc,
       /* We're not supposed to be called on FUNCTION_DECLs.  */
       gcc_unreachable ();
     case SECCAT_RODATA:
-      return readonly_data_section;
+      return casm->sections.readonly_data;
     case SECCAT_RODATA_MERGE_STR:
       return mergeable_string_section (decl, align, 0);
     case SECCAT_RODATA_MERGE_STR_INIT:
@@ -7122,7 +7070,7 @@  default_elf_select_section (tree decl, int reloc,
 	  sname = ".persistent";
 	  break;
 	}
-      return data_section;
+      return casm->sections.data;
     case SECCAT_DATA_REL:
       sname = ".data.rel";
       break;
@@ -7147,8 +7095,8 @@  default_elf_select_section (tree decl, int reloc,
 	  sname = ".noinit";
 	  break;
 	}
-      if (bss_section)
-	return bss_section;
+      if (casm->sections.bss)
+	return casm->sections.bss;
       sname = ".bss";
       break;
     case SECCAT_SBSS:
@@ -7298,9 +7246,9 @@  default_select_rtx_section (machine_mode mode ATTRIBUTE_UNUSED,
 			    unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
 {
   if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
-    return data_section;
+    return casm->sections.data;
   else
-    return readonly_data_section;
+    return casm->sections.readonly_data;
 }
 
 section *
@@ -7818,13 +7766,13 @@  switch_to_section (section *new_section, tree decl)
 		  "%qD was declared here", used_decl);
 	}
     }
-  else if (in_section == new_section)
+  else if (casm->in_section == new_section)
     return;
 
   if (new_section->common.flags & SECTION_FORGET)
-    in_section = NULL;
+    casm->in_section = NULL;
   else
-    in_section = new_section;
+    casm->in_section = new_section;
 
   switch (SECTION_STYLE (new_section))
     {
@@ -8000,7 +7948,7 @@  get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
     }
 
   /* Create a new anchor with a unique label.  */
-  ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
+  ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", casm->anchor_labelno++);
   anchor = create_block_symbol (ggc_strdup (label), block, offset);
   SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
   SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
@@ -8469,7 +8417,7 @@  handle_vtv_comdat_section (section *sect, const_tree decl ATTRIBUTE_UNUSED)
 				 sect->named.common.flags
 				 | SECTION_LINKONCE,
 				 DECL_NAME (decl));
-  in_section = sect;
+  casm->in_section = sect;
 #else
   /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here.
      Therefore the following check is used.
@@ -8495,7 +8443,7 @@  handle_vtv_comdat_section (section *sect, const_tree decl ATTRIBUTE_UNUSED)
 				     sect->named.common.flags
 				     | SECTION_LINKONCE,
 				     DECL_NAME (decl));
-      in_section = sect;
+      casm->in_section = sect;
     }
   else
     switch_to_section (sect);
diff --git a/gcc/vmsdbgout.c b/gcc/vmsdbgout.c
index 05fadce075e..48e1ca9fb25 100644
--- a/gcc/vmsdbgout.c
+++ b/gcc/vmsdbgout.c
@@ -1583,7 +1583,7 @@  vmsdbgout_finish (const char *filename ATTRIBUTE_UNUSED)
     return;
 
   /* Output a terminator label for the .text section.  */
-  switch_to_section (text_section);
+  switch_to_section (casm->sections.text);
   targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
 
   /* Output debugging information.