public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/casm-refactoring-v2)] work in progress.
@ 2021-09-16 12:03 Martin Liska
  0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2021-09-16 12:03 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:524a78090dbc9968d61a7c0625329c1bf90561c3

commit 524a78090dbc9968d61a7c0625329c1bf90561c3
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Sep 16 13:37:00 2021 +0200

    work in progress.

Diff:
---
 gcc/dwarf2out.c | 960 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 505 insertions(+), 455 deletions(-)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 863729aea25..f4e13314439 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -152,32 +152,321 @@ static GTY(()) vec<rtx, va_gc> *used_rtx_array;
    it.  */
 static GTY(()) vec<tree, va_gc> *incomplete_types;
 
-/* Pointers to various DWARF2 sections.  */
-static GTY(()) section *debug_info_section;
-static GTY(()) section *debug_skeleton_info_section;
-static GTY(()) section *debug_abbrev_section;
-static GTY(()) section *debug_skeleton_abbrev_section;
-static GTY(()) section *debug_aranges_section;
-static GTY(()) section *debug_addr_section;
-static GTY(()) section *debug_macinfo_section;
-static const char *debug_macinfo_section_name;
-static unsigned macinfo_label_base = 1;
-static GTY(()) section *debug_line_section;
-static GTY(()) section *debug_skeleton_line_section;
-static GTY(()) section *debug_loc_section;
-static GTY(()) section *debug_pubnames_section;
-static GTY(()) section *debug_pubtypes_section;
-static GTY(()) section *debug_str_section;
-static GTY(()) section *debug_line_str_section;
-static GTY(()) section *debug_str_dwo_section;
-static GTY(()) section *debug_str_offsets_section;
-static GTY(()) section *debug_ranges_section;
-static GTY(()) section *debug_ranges_dwo_section;
-static GTY(()) section *debug_frame_section;
-
 /* Maximum size (in bytes) of an artificially generated label.  */
 #define MAX_ARTIFICIAL_LABEL_BYTES	40
 
+/* Section names used to hold DWARF debugging information.  */
+
+#ifndef DEBUG_INFO_SECTION
+#define DEBUG_INFO_SECTION	".debug_info"
+#endif
+#ifndef DEBUG_DWO_INFO_SECTION
+#define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
+#endif
+#ifndef DEBUG_LTO_INFO_SECTION
+#define DEBUG_LTO_INFO_SECTION	".gnu.debuglto_.debug_info"
+#endif
+#ifndef DEBUG_LTO_DWO_INFO_SECTION
+#define DEBUG_LTO_DWO_INFO_SECTION ".gnu.debuglto_.debug_info.dwo"
+#endif
+#ifndef DEBUG_ABBREV_SECTION
+#define DEBUG_ABBREV_SECTION	".debug_abbrev"
+#endif
+#ifndef DEBUG_LTO_ABBREV_SECTION
+#define DEBUG_LTO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev"
+#endif
+#ifndef DEBUG_DWO_ABBREV_SECTION
+#define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
+#endif
+#ifndef DEBUG_LTO_DWO_ABBREV_SECTION
+#define DEBUG_LTO_DWO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev.dwo"
+#endif
+#ifndef DEBUG_ARANGES_SECTION
+#define DEBUG_ARANGES_SECTION	".debug_aranges"
+#endif
+#ifndef DEBUG_ADDR_SECTION
+#define DEBUG_ADDR_SECTION     ".debug_addr"
+#endif
+#ifndef DEBUG_MACINFO_SECTION
+#define DEBUG_MACINFO_SECTION     ".debug_macinfo"
+#endif
+#ifndef DEBUG_LTO_MACINFO_SECTION
+#define DEBUG_LTO_MACINFO_SECTION      ".gnu.debuglto_.debug_macinfo"
+#endif
+#ifndef DEBUG_DWO_MACINFO_SECTION
+#define DEBUG_DWO_MACINFO_SECTION      ".debug_macinfo.dwo"
+#endif
+#ifndef DEBUG_LTO_DWO_MACINFO_SECTION
+#define DEBUG_LTO_DWO_MACINFO_SECTION  ".gnu.debuglto_.debug_macinfo.dwo"
+#endif
+#ifndef DEBUG_MACRO_SECTION
+#define DEBUG_MACRO_SECTION	".debug_macro"
+#endif
+#ifndef DEBUG_LTO_MACRO_SECTION
+#define DEBUG_LTO_MACRO_SECTION ".gnu.debuglto_.debug_macro"
+#endif
+#ifndef DEBUG_DWO_MACRO_SECTION
+#define DEBUG_DWO_MACRO_SECTION        ".debug_macro.dwo"
+#endif
+#ifndef DEBUG_LTO_DWO_MACRO_SECTION
+#define DEBUG_LTO_DWO_MACRO_SECTION    ".gnu.debuglto_.debug_macro.dwo"
+#endif
+#ifndef DEBUG_LINE_SECTION
+#define DEBUG_LINE_SECTION	".debug_line"
+#endif
+#ifndef DEBUG_LTO_LINE_SECTION
+#define DEBUG_LTO_LINE_SECTION ".gnu.debuglto_.debug_line"
+#endif
+#ifndef DEBUG_DWO_LINE_SECTION
+#define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
+#endif
+#ifndef DEBUG_LTO_DWO_LINE_SECTION
+#define DEBUG_LTO_DWO_LINE_SECTION ".gnu.debuglto_.debug_line.dwo"
+#endif
+#ifndef DEBUG_LOC_SECTION
+#define DEBUG_LOC_SECTION	".debug_loc"
+#endif
+#ifndef DEBUG_DWO_LOC_SECTION
+#define DEBUG_DWO_LOC_SECTION  ".debug_loc.dwo"
+#endif
+#ifndef DEBUG_LOCLISTS_SECTION
+#define DEBUG_LOCLISTS_SECTION	".debug_loclists"
+#endif
+#ifndef DEBUG_DWO_LOCLISTS_SECTION
+#define DEBUG_DWO_LOCLISTS_SECTION  ".debug_loclists.dwo"
+#endif
+#ifndef DEBUG_PUBNAMES_SECTION
+#define DEBUG_PUBNAMES_SECTION	\
+  ((debug_generate_pub_sections == 2) \
+   ? ".debug_gnu_pubnames" : ".debug_pubnames")
+#endif
+#ifndef DEBUG_PUBTYPES_SECTION
+#define DEBUG_PUBTYPES_SECTION	\
+  ((debug_generate_pub_sections == 2) \
+   ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
+#endif
+#ifndef DEBUG_STR_OFFSETS_SECTION
+#define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
+#endif
+#ifndef DEBUG_DWO_STR_OFFSETS_SECTION
+#define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
+#endif
+#ifndef DEBUG_LTO_DWO_STR_OFFSETS_SECTION
+#define DEBUG_LTO_DWO_STR_OFFSETS_SECTION ".gnu.debuglto_.debug_str_offsets.dwo"
+#endif
+#ifndef DEBUG_STR_SECTION
+#define DEBUG_STR_SECTION  ".debug_str"
+#endif
+#ifndef DEBUG_LTO_STR_SECTION
+#define DEBUG_LTO_STR_SECTION ".gnu.debuglto_.debug_str"
+#endif
+#ifndef DEBUG_STR_DWO_SECTION
+#define DEBUG_STR_DWO_SECTION   ".debug_str.dwo"
+#endif
+#ifndef DEBUG_LTO_STR_DWO_SECTION
+#define DEBUG_LTO_STR_DWO_SECTION ".gnu.debuglto_.debug_str.dwo"
+#endif
+#ifndef DEBUG_RANGES_SECTION
+#define DEBUG_RANGES_SECTION	".debug_ranges"
+#endif
+#ifndef DEBUG_RNGLISTS_SECTION
+#define DEBUG_RNGLISTS_SECTION	".debug_rnglists"
+#endif
+#ifndef DEBUG_DWO_RNGLISTS_SECTION
+#define DEBUG_DWO_RNGLISTS_SECTION	".debug_rnglists.dwo"
+#endif
+#ifndef DEBUG_LINE_STR_SECTION
+#define DEBUG_LINE_STR_SECTION  ".debug_line_str"
+#endif
+#ifndef DEBUG_LTO_LINE_STR_SECTION
+#define DEBUG_LTO_LINE_STR_SECTION  ".gnu.debuglto_.debug_line_str"
+#endif
+
+/* Standard ELF section names for compiled code and data.  */
+#ifndef TEXT_SECTION_NAME
+#define TEXT_SECTION_NAME	".text"
+#endif
+
+/* Section flags for .debug_str section.  */
+#define DEBUG_STR_SECTION_FLAGS                                 \
+  (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings               \
+   ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1        \
+   : SECTION_DEBUG)
+
+/* Section flags for .debug_str.dwo section.  */
+#define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
+
+/* Attribute used to refer to the macro section.  */
+#define DEBUG_MACRO_ATTRIBUTE (dwarf_version >= 5 ? DW_AT_macros \
+		   : dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros)
+
+/* Labels we insert at beginning sections we can reference instead of
+   the section names themselves.  */
+
+#ifndef TEXT_SECTION_LABEL
+#define TEXT_SECTION_LABEL                 "Ltext"
+#endif
+#ifndef COLD_TEXT_SECTION_LABEL
+#define COLD_TEXT_SECTION_LABEL             "Ltext_cold"
+#endif
+#ifndef DEBUG_LINE_SECTION_LABEL
+#define DEBUG_LINE_SECTION_LABEL           "Ldebug_line"
+#endif
+#ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
+#define DEBUG_SKELETON_LINE_SECTION_LABEL   "Lskeleton_debug_line"
+#endif
+#ifndef DEBUG_INFO_SECTION_LABEL
+#define DEBUG_INFO_SECTION_LABEL           "Ldebug_info"
+#endif
+#ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
+#define DEBUG_SKELETON_INFO_SECTION_LABEL   "Lskeleton_debug_info"
+#endif
+#ifndef DEBUG_ABBREV_SECTION_LABEL
+#define DEBUG_ABBREV_SECTION_LABEL         "Ldebug_abbrev"
+#endif
+#ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
+#define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
+#endif
+#ifndef DEBUG_ADDR_SECTION_LABEL
+#define DEBUG_ADDR_SECTION_LABEL           "Ldebug_addr"
+#endif
+#ifndef DEBUG_LOC_SECTION_LABEL
+#define DEBUG_LOC_SECTION_LABEL                    "Ldebug_loc"
+#endif
+#ifndef DEBUG_RANGES_SECTION_LABEL
+#define DEBUG_RANGES_SECTION_LABEL         "Ldebug_ranges"
+#endif
+#ifndef DEBUG_MACINFO_SECTION_LABEL
+#define DEBUG_MACINFO_SECTION_LABEL         "Ldebug_macinfo"
+#endif
+#ifndef DEBUG_MACRO_SECTION_LABEL
+#define DEBUG_MACRO_SECTION_LABEL          "Ldebug_macro"
+#endif
+#define SKELETON_COMP_DIE_ABBREV 1
+#define SKELETON_TYPE_DIE_ABBREV 2
+
+
+#ifndef TEXT_END_LABEL
+#define TEXT_END_LABEL		"Letext"
+#endif
+#ifndef COLD_END_LABEL
+#define COLD_END_LABEL          "Letext_cold"
+#endif
+#ifndef BLOCK_BEGIN_LABEL
+#define BLOCK_BEGIN_LABEL	"LBB"
+#endif
+#ifndef BLOCK_INLINE_ENTRY_LABEL
+#define BLOCK_INLINE_ENTRY_LABEL "LBI"
+#endif
+#ifndef BLOCK_END_LABEL
+#define BLOCK_END_LABEL		"LBE"
+#endif
+#ifndef LINE_CODE_LABEL
+#define LINE_CODE_LABEL		"LM"
+#endif
+
+struct GTY(()) dwarf_out_state
+{
+  dwarf_out_state (asm_out_state *asm_state):
+    casm (asm_state), sec ({}), debug_macinfo_section_name (NULL),
+       macinfo_label_base (1)
+  {
+    lab.text_end = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.text_section = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.cold_text_section = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.cold_end = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.abbrev_section = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.debug_info_section = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.debug_skeleton_info_section = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.debug_skeleton_abbrev_section = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.debug_line_section = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.debug_addr_section = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.debug_skeleton_line_section = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.macinfo_section = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.loc_section = ggc_vec_alloc <char> (MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.ranges_section = ggc_vec_alloc <char> (2 * MAX_ARTIFICIAL_LABEL_BYTES);
+    lab.ranges_base = ggc_vec_alloc <char> (2 * MAX_ARTIFICIAL_LABEL_BYTES);
+  }
+
+  asm_out_state *casm;
+
+  /* Definitions of defaults for formats and names of various special
+     (artificial) labels which may be generated within this file (when the -g
+     options is used and DWARF2_DEBUGGING_INFO is in effect.
+     If necessary, these may be overridden from within the tm.h file, but
+     typically, overriding these defaults is unnecessary.  */
+
+  struct
+  {
+    char *text_end;
+    char *text_section;
+    char *cold_text_section;
+    char *cold_end;
+    char *abbrev_section;
+    char *debug_info_section;
+    char *debug_skeleton_info_section;
+    char *debug_skeleton_abbrev_section;
+    char *debug_line_section;
+    char *debug_addr_section;
+    char *debug_skeleton_line_section;
+    char *macinfo_section;
+    char *loc_section;
+    char *ranges_section;
+    char *ranges_base;
+  } lab;
+
+  /* Pointers to various DWARF2 sections.  */
+
+  struct
+  {
+    section *debug_info;
+    section *debug_skeleton_info;
+    section *debug_abbrev;
+    section *debug_skeleton_abbrev;
+    section *debug_aranges;
+    section *debug_addr;
+    section *debug_macinfo;
+    section *debug_line;
+    section *debug_skeleton_line;
+    section *debug_loc;
+    section *debug_pubnames;
+    section *debug_pubtypes;
+    section *debug_str;
+    section *debug_line_str;
+    section *debug_str_dwo;
+    section *debug_str_offsets;
+    section *debug_ranges;
+    section *debug_ranges_dwo;
+    section *debug_frame;
+  } sec;
+
+  const char * GTY((skip)) debug_macinfo_section_name;
+  unsigned macinfo_label_base;
+};
+
+static GTY(()) dwarf_out_state *dw_state = NULL;
+
+static vec<dwarf_out_state *> dwarf_stack;
+
+/* Push ASM_STATE as a current casm.  */
+
+void
+push_dwarf_state (dwarf_out_state *state)
+{
+//  push_asm (state->casm);
+  dwarf_stack.safe_push (state);
+  dw_state = state;
+}
+
+/* Return to previous casm state.  */
+
+void
+pop_dwarf_state ()
+{
+  dw_state = dwarf_stack.pop ();
+//  pop_asm ();
+}
+
 /* According to the (draft) DWARF 3 specification, the initial length
    should either be 4 or 12 bytes.  When it's 12 bytes, the first 4
    bytes are 0xffffffff, followed by the length stored in the next 8
@@ -507,10 +796,10 @@ switch_to_frame_table_section (int for_eh, bool back)
     switch_to_eh_frame_section (back);
   else
     {
-      if (!debug_frame_section)
-	debug_frame_section = get_section (DEBUG_FRAME_SECTION,
+      if (!dw_state->sec.debug_frame)
+	dw_state->sec.debug_frame = get_section (DEBUG_FRAME_SECTION,
 					   SECTION_DEBUG, NULL);
-      switch_to_section (debug_frame_section);
+      switch_to_section (dw_state->sec.debug_frame);
     }
 }
 
@@ -622,7 +911,7 @@ output_fde (dw_fde_ref fde, bool for_eh, bool second,
     dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
   else
     dw2_asm_output_offset (dwarf_offset_size, section_start_label,
-			   debug_frame_section, "FDE CIE offset");
+			   dw_state->sec.debug_frame, "FDE CIE offset");
 
   begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
   end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
@@ -2400,7 +2689,7 @@ output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
 		   + HOST_BITS_PER_WIDE_INT / 2 + 2];
 	gcc_assert (val1->val_class == dw_val_class_die_ref);
 	get_ref_die_offset_label (label, val1->v.val_die_ref.die);
-	dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
+	dw2_asm_output_offset (DWARF_REF_SIZE, label, dw_state->sec.debug_info, NULL);
       }
       break;
 
@@ -2411,7 +2700,7 @@ output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
 		   + HOST_BITS_PER_WIDE_INT / 2 + 2];
 	gcc_assert (val1->val_class == dw_val_class_die_ref);
 	get_ref_die_offset_label (label, val1->v.val_die_ref.die);
-	dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
+	dw2_asm_output_offset (DWARF_REF_SIZE, label, dw_state->sec.debug_info, NULL);
 	dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
       }
       break;
@@ -4014,238 +4303,6 @@ new_addr_loc_descr (rtx addr, enum dtprel_bool dtprel)
 
   return ref;
 }
-
-/* Section names used to hold DWARF debugging information.  */
-
-#ifndef DEBUG_INFO_SECTION
-#define DEBUG_INFO_SECTION	".debug_info"
-#endif
-#ifndef DEBUG_DWO_INFO_SECTION
-#define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
-#endif
-#ifndef DEBUG_LTO_INFO_SECTION
-#define DEBUG_LTO_INFO_SECTION	".gnu.debuglto_.debug_info"
-#endif
-#ifndef DEBUG_LTO_DWO_INFO_SECTION
-#define DEBUG_LTO_DWO_INFO_SECTION ".gnu.debuglto_.debug_info.dwo"
-#endif
-#ifndef DEBUG_ABBREV_SECTION
-#define DEBUG_ABBREV_SECTION	".debug_abbrev"
-#endif
-#ifndef DEBUG_LTO_ABBREV_SECTION
-#define DEBUG_LTO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev"
-#endif
-#ifndef DEBUG_DWO_ABBREV_SECTION
-#define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
-#endif
-#ifndef DEBUG_LTO_DWO_ABBREV_SECTION
-#define DEBUG_LTO_DWO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev.dwo"
-#endif
-#ifndef DEBUG_ARANGES_SECTION
-#define DEBUG_ARANGES_SECTION	".debug_aranges"
-#endif
-#ifndef DEBUG_ADDR_SECTION
-#define DEBUG_ADDR_SECTION     ".debug_addr"
-#endif
-#ifndef DEBUG_MACINFO_SECTION
-#define DEBUG_MACINFO_SECTION     ".debug_macinfo"
-#endif
-#ifndef DEBUG_LTO_MACINFO_SECTION
-#define DEBUG_LTO_MACINFO_SECTION      ".gnu.debuglto_.debug_macinfo"
-#endif
-#ifndef DEBUG_DWO_MACINFO_SECTION
-#define DEBUG_DWO_MACINFO_SECTION      ".debug_macinfo.dwo"
-#endif
-#ifndef DEBUG_LTO_DWO_MACINFO_SECTION
-#define DEBUG_LTO_DWO_MACINFO_SECTION  ".gnu.debuglto_.debug_macinfo.dwo"
-#endif
-#ifndef DEBUG_MACRO_SECTION
-#define DEBUG_MACRO_SECTION	".debug_macro"
-#endif
-#ifndef DEBUG_LTO_MACRO_SECTION
-#define DEBUG_LTO_MACRO_SECTION ".gnu.debuglto_.debug_macro"
-#endif
-#ifndef DEBUG_DWO_MACRO_SECTION
-#define DEBUG_DWO_MACRO_SECTION        ".debug_macro.dwo"
-#endif
-#ifndef DEBUG_LTO_DWO_MACRO_SECTION
-#define DEBUG_LTO_DWO_MACRO_SECTION    ".gnu.debuglto_.debug_macro.dwo"
-#endif
-#ifndef DEBUG_LINE_SECTION
-#define DEBUG_LINE_SECTION	".debug_line"
-#endif
-#ifndef DEBUG_LTO_LINE_SECTION
-#define DEBUG_LTO_LINE_SECTION ".gnu.debuglto_.debug_line"
-#endif
-#ifndef DEBUG_DWO_LINE_SECTION
-#define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
-#endif
-#ifndef DEBUG_LTO_DWO_LINE_SECTION
-#define DEBUG_LTO_DWO_LINE_SECTION ".gnu.debuglto_.debug_line.dwo"
-#endif
-#ifndef DEBUG_LOC_SECTION
-#define DEBUG_LOC_SECTION	".debug_loc"
-#endif
-#ifndef DEBUG_DWO_LOC_SECTION
-#define DEBUG_DWO_LOC_SECTION  ".debug_loc.dwo"
-#endif
-#ifndef DEBUG_LOCLISTS_SECTION
-#define DEBUG_LOCLISTS_SECTION	".debug_loclists"
-#endif
-#ifndef DEBUG_DWO_LOCLISTS_SECTION
-#define DEBUG_DWO_LOCLISTS_SECTION  ".debug_loclists.dwo"
-#endif
-#ifndef DEBUG_PUBNAMES_SECTION
-#define DEBUG_PUBNAMES_SECTION	\
-  ((debug_generate_pub_sections == 2) \
-   ? ".debug_gnu_pubnames" : ".debug_pubnames")
-#endif
-#ifndef DEBUG_PUBTYPES_SECTION
-#define DEBUG_PUBTYPES_SECTION	\
-  ((debug_generate_pub_sections == 2) \
-   ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
-#endif
-#ifndef DEBUG_STR_OFFSETS_SECTION
-#define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
-#endif
-#ifndef DEBUG_DWO_STR_OFFSETS_SECTION
-#define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
-#endif
-#ifndef DEBUG_LTO_DWO_STR_OFFSETS_SECTION
-#define DEBUG_LTO_DWO_STR_OFFSETS_SECTION ".gnu.debuglto_.debug_str_offsets.dwo"
-#endif
-#ifndef DEBUG_STR_SECTION
-#define DEBUG_STR_SECTION  ".debug_str"
-#endif
-#ifndef DEBUG_LTO_STR_SECTION
-#define DEBUG_LTO_STR_SECTION ".gnu.debuglto_.debug_str"
-#endif
-#ifndef DEBUG_STR_DWO_SECTION
-#define DEBUG_STR_DWO_SECTION   ".debug_str.dwo"
-#endif
-#ifndef DEBUG_LTO_STR_DWO_SECTION
-#define DEBUG_LTO_STR_DWO_SECTION ".gnu.debuglto_.debug_str.dwo"
-#endif
-#ifndef DEBUG_RANGES_SECTION
-#define DEBUG_RANGES_SECTION	".debug_ranges"
-#endif
-#ifndef DEBUG_RNGLISTS_SECTION
-#define DEBUG_RNGLISTS_SECTION	".debug_rnglists"
-#endif
-#ifndef DEBUG_DWO_RNGLISTS_SECTION
-#define DEBUG_DWO_RNGLISTS_SECTION	".debug_rnglists.dwo"
-#endif
-#ifndef DEBUG_LINE_STR_SECTION
-#define DEBUG_LINE_STR_SECTION  ".debug_line_str"
-#endif
-#ifndef DEBUG_LTO_LINE_STR_SECTION
-#define DEBUG_LTO_LINE_STR_SECTION  ".gnu.debuglto_.debug_line_str"
-#endif
-
-/* Standard ELF section names for compiled code and data.  */
-#ifndef TEXT_SECTION_NAME
-#define TEXT_SECTION_NAME	".text"
-#endif
-
-/* Section flags for .debug_str section.  */
-#define DEBUG_STR_SECTION_FLAGS                                 \
-  (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings               \
-   ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1        \
-   : SECTION_DEBUG)
-
-/* Section flags for .debug_str.dwo section.  */
-#define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
-
-/* Attribute used to refer to the macro section.  */
-#define DEBUG_MACRO_ATTRIBUTE (dwarf_version >= 5 ? DW_AT_macros \
-		   : dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros)
-
-/* Labels we insert at beginning sections we can reference instead of
-   the section names themselves.  */
-
-#ifndef TEXT_SECTION_LABEL
-#define TEXT_SECTION_LABEL                 "Ltext"
-#endif
-#ifndef COLD_TEXT_SECTION_LABEL
-#define COLD_TEXT_SECTION_LABEL             "Ltext_cold"
-#endif
-#ifndef DEBUG_LINE_SECTION_LABEL
-#define DEBUG_LINE_SECTION_LABEL           "Ldebug_line"
-#endif
-#ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
-#define DEBUG_SKELETON_LINE_SECTION_LABEL   "Lskeleton_debug_line"
-#endif
-#ifndef DEBUG_INFO_SECTION_LABEL
-#define DEBUG_INFO_SECTION_LABEL           "Ldebug_info"
-#endif
-#ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
-#define DEBUG_SKELETON_INFO_SECTION_LABEL   "Lskeleton_debug_info"
-#endif
-#ifndef DEBUG_ABBREV_SECTION_LABEL
-#define DEBUG_ABBREV_SECTION_LABEL         "Ldebug_abbrev"
-#endif
-#ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
-#define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
-#endif
-#ifndef DEBUG_ADDR_SECTION_LABEL
-#define DEBUG_ADDR_SECTION_LABEL           "Ldebug_addr"
-#endif
-#ifndef DEBUG_LOC_SECTION_LABEL
-#define DEBUG_LOC_SECTION_LABEL                    "Ldebug_loc"
-#endif
-#ifndef DEBUG_RANGES_SECTION_LABEL
-#define DEBUG_RANGES_SECTION_LABEL         "Ldebug_ranges"
-#endif
-#ifndef DEBUG_MACINFO_SECTION_LABEL
-#define DEBUG_MACINFO_SECTION_LABEL         "Ldebug_macinfo"
-#endif
-#ifndef DEBUG_MACRO_SECTION_LABEL
-#define DEBUG_MACRO_SECTION_LABEL          "Ldebug_macro"
-#endif
-#define SKELETON_COMP_DIE_ABBREV 1
-#define SKELETON_TYPE_DIE_ABBREV 2
-
-/* Definitions of defaults for formats and names of various special
-   (artificial) labels which may be generated within this file (when the -g
-   options is used and DWARF2_DEBUGGING_INFO is in effect.
-   If necessary, these may be overridden from within the tm.h file, but
-   typically, overriding these defaults is unnecessary.  */
-
-static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char debug_skeleton_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char debug_skeleton_abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char debug_addr_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char debug_skeleton_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
-static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
-static char ranges_base_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
-
-#ifndef TEXT_END_LABEL
-#define TEXT_END_LABEL		"Letext"
-#endif
-#ifndef COLD_END_LABEL
-#define COLD_END_LABEL          "Letext_cold"
-#endif
-#ifndef BLOCK_BEGIN_LABEL
-#define BLOCK_BEGIN_LABEL	"LBB"
-#endif
-#ifndef BLOCK_INLINE_ENTRY_LABEL
-#define BLOCK_INLINE_ENTRY_LABEL "LBI"
-#endif
-#ifndef BLOCK_END_LABEL
-#define BLOCK_END_LABEL		"LBE"
-#endif
-#ifndef LINE_CODE_LABEL
-#define LINE_CODE_LABEL		"LM"
-#endif
-
 \f
 /* Return the root of the DIE's built for the current compilation unit.  */
 static dw_die_ref
@@ -4308,12 +4365,12 @@ is_tagged_type (const_tree type)
 	  || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
 }
 
-/* Set label to debug_info_section_label + die_offset of a DIE reference.  */
+/* Set label to dw_state->lab.debug_info_section + die_offset of a DIE reference.  */
 
 static void
 get_ref_die_offset_label (char *label, dw_die_ref ref)
 {
-  sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
+  sprintf (label, "%s+%ld", dw_state->lab.debug_info_section, ref->die_offset);
 }
 
 /* Return die_offset of a DIE reference to a base type.  */
@@ -4833,7 +4890,7 @@ find_string_form (struct indirect_string_node *node)
      section, only put it into .debug_str if it is worth even in this
      single module.  */
   if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
-      || ((debug_str_section->common.flags & SECTION_MERGE) == 0
+      || ((dw_state->sec.debug_str->common.flags & SECTION_MERGE) == 0
 	  && (len - dwarf_offset_size) * node->refcount <= len))
     return node->form = DW_FORM_string;
 
@@ -8958,7 +9015,7 @@ output_loclists_offsets (dw_die_ref die)
 	if (l->offset_emitted)
 	  continue;
 	dw2_asm_output_delta (dwarf_offset_size, l->ll_symbol,
-			      loc_section_label, NULL);
+			      dw_state->lab.loc_section, NULL);
 	gcc_assert (l->hash == loc_list_idx);
 	loc_list_idx++;
 	l->offset_emitted = true;
@@ -10607,15 +10664,15 @@ output_range_list_offset (dw_attr_node *a)
 	{
 	  dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
 	  dw2_asm_output_offset (dwarf_offset_size, r->label,
-				 debug_ranges_section, "%s", name);
+				 dw_state->sec.debug_ranges, "%s", name);
 	}
       else
 	{
-	  char *p = strchr (ranges_section_label, '\0');
+	  char *p = strchr (dw_state->lab.ranges_section, '\0');
 	  sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
 		   a->dw_attr_val.v.val_offset * 2 * DWARF2_ADDR_SIZE);
-	  dw2_asm_output_offset (dwarf_offset_size, ranges_section_label,
-				 debug_ranges_section, "%s", name);
+	  dw2_asm_output_offset (dwarf_offset_size, dw_state->lab.ranges_section,
+				 dw_state->sec.debug_ranges, "%s", name);
 	  *p = '\0';
 	}
     }
@@ -10628,7 +10685,7 @@ output_range_list_offset (dw_attr_node *a)
   else
     dw2_asm_output_data (dwarf_offset_size,
 			 a->dw_attr_val.v.val_offset * 2 * DWARF2_ADDR_SIZE,
-                         "%s (offset from %s)", name, ranges_section_label);
+                         "%s (offset from %s)", name, dw_state->lab.ranges_section);
 }
 
 /* Output the offset into the debug_loc section.  */
@@ -10640,7 +10697,7 @@ output_loc_list_offset (dw_attr_node *a)
 
   gcc_assert (sym);
   if (!dwarf_split_debug_info)
-    dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
+    dw2_asm_output_offset (dwarf_offset_size, sym, dw_state->sec.debug_loc,
                            "%s", dwarf_attr_name (a->dw_attr));
   else if (dwarf_version >= 5)
     {
@@ -10650,7 +10707,7 @@ output_loc_list_offset (dw_attr_node *a)
 				   sym);
     }
   else
-    dw2_asm_output_delta (dwarf_offset_size, sym, loc_section_label,
+    dw2_asm_output_delta (dwarf_offset_size, sym, dw_state->lab.loc_section,
 			  "%s", dwarf_attr_name (a->dw_attr));
 }
 
@@ -10663,10 +10720,10 @@ output_view_list_offset (dw_attr_node *a)
 
   gcc_assert (sym);
   if (dwarf_split_debug_info)
-    dw2_asm_output_delta (dwarf_offset_size, sym, loc_section_label,
+    dw2_asm_output_delta (dwarf_offset_size, sym, dw_state->lab.loc_section,
                           "%s", dwarf_attr_name (a->dw_attr));
   else
-    dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
+    dw2_asm_output_offset (dwarf_offset_size, sym, dw_state->sec.debug_loc,
                            "%s", dwarf_attr_name (a->dw_attr));
 }
 
@@ -10949,9 +11006,9 @@ output_die (dw_die_ref die)
 		     ???  This is the reason for the with_offset flag.  */
 		  if (AT_ref (a)->with_offset)
 		    dw2_asm_output_offset (size, sym, AT_ref (a)->die_offset,
-					   debug_info_section, "%s", name);
+					   dw_state->sec.debug_info, "%s", name);
 		  else
-		    dw2_asm_output_offset (size, sym, debug_info_section, "%s",
+		    dw2_asm_output_offset (size, sym, dw_state->sec.debug_info, "%s",
 					   name);
 		}
 	    }
@@ -10969,7 +11026,7 @@ output_die (dw_die_ref die)
 
 	    ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
 					 a->dw_attr_val.v.val_fde_index * 2);
-	    dw2_asm_output_offset (dwarf_offset_size, l1, debug_frame_section,
+	    dw2_asm_output_offset (dwarf_offset_size, l1, dw_state->sec.debug_frame,
 				   "%s", name);
 	  }
 	  break;
@@ -10992,29 +11049,29 @@ output_die (dw_die_ref die)
 
 	case dw_val_class_lineptr:
 	  dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
-				 debug_line_section, "%s", name);
+				 dw_state->sec.debug_line, "%s", name);
 	  break;
 
 	case dw_val_class_macptr:
 	  dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
-				 debug_macinfo_section, "%s", name);
+				 dw_state->sec.debug_macinfo, "%s", name);
 	  break;
 
 	case dw_val_class_loclistsptr:
 	  dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
-				 debug_loc_section, "%s", name);
+				 dw_state->sec.debug_loc, "%s", name);
 	  break;
 
 	case dw_val_class_str:
           if (a->dw_attr_val.v.val_str->form == DW_FORM_strp)
             dw2_asm_output_offset (dwarf_offset_size,
                                    a->dw_attr_val.v.val_str->label,
-                                   debug_str_section,
+                                   dw_state->sec.debug_str,
                                    "%s: \"%s\"", name, AT_string (a));
 	  else if (a->dw_attr_val.v.val_str->form == DW_FORM_line_strp)
 	    dw2_asm_output_offset (dwarf_offset_size,
 				   a->dw_attr_val.v.val_str->label,
-				   debug_line_str_section,
+				   dw_state->sec.debug_line_str,
 				   "%s: \"%s\"", name, AT_string (a));
           else if (a->dw_attr_val.v.val_str->form == dwarf_FORM (DW_FORM_strx))
             dw2_asm_output_data_uleb128 (AT_index (a),
@@ -11152,8 +11209,8 @@ output_compilation_unit_header (enum dwarf_unit_type ut)
       dw2_asm_output_data (1, ut, "%s", name);
       dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
     }
-  dw2_asm_output_offset (dwarf_offset_size, abbrev_section_label,
-			 debug_abbrev_section,
+  dw2_asm_output_offset (dwarf_offset_size, dw_state->lab.abbrev_section,
+			 dw_state->sec.debug_abbrev,
 			 "Offset Into Abbrev. Section");
   if (dwarf_version < 5)
     dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
@@ -11211,8 +11268,8 @@ output_comp_unit (dw_die_ref die, int output_if_empty,
     }
   else
     {
-      switch_to_section (debug_info_section);
-      ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
+      switch_to_section (dw_state->sec.debug_info);
+      ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.debug_info_section);
       info_section_emitted = true;
     }
 
@@ -11323,7 +11380,7 @@ add_top_level_skeleton_die_attrs (dw_die_ref die)
     add_skeleton_AT_string (die, DW_AT_comp_dir, comp_dir);
   add_AT_pubnames (die);
   if (addr_index_table != NULL && addr_index_table->size () > 0)
-    add_AT_lineptr (die, dwarf_AT (DW_AT_addr_base), debug_addr_section_label);
+    add_AT_lineptr (die, dwarf_AT (DW_AT_addr_base), dw_state->lab.debug_addr_section);
 }
 
 /* Output skeleton debug sections that point to the dwo file.  */
@@ -11336,8 +11393,8 @@ output_skeleton_debug_sections (dw_die_ref comp_unit,
   remove_AT (comp_unit, DW_AT_producer);
   remove_AT (comp_unit, DW_AT_language);
 
-  switch_to_section (debug_skeleton_info_section);
-  ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_info_section_label);
+  switch_to_section (dw_state->sec.debug_skeleton_info);
+  ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.debug_skeleton_info_section);
 
   /* Produce the skeleton compilation-unit header.  This one differs enough from
      a normal CU header that it's better not to call output_compilation_unit
@@ -11358,8 +11415,8 @@ output_skeleton_debug_sections (dw_die_ref comp_unit,
       dw2_asm_output_data (1, DW_UT_skeleton, "DW_UT_skeleton");
       dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
     }
-  dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_abbrev_section_label,
-			 debug_skeleton_abbrev_section,
+  dw2_asm_output_offset (dwarf_offset_size, dw_state->lab.debug_skeleton_abbrev_section,
+			 dw_state->sec.debug_skeleton_abbrev,
                          "Offset Into Abbrev. Section");
   if (dwarf_version < 5)
     dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
@@ -11371,8 +11428,8 @@ output_skeleton_debug_sections (dw_die_ref comp_unit,
   output_die (comp_unit);
 
   /* Build the skeleton debug_abbrev section.  */
-  switch_to_section (debug_skeleton_abbrev_section);
-  ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_abbrev_section_label);
+  switch_to_section (dw_state->sec.debug_skeleton_abbrev);
+  ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.debug_skeleton_abbrev_section);
 
   output_die_abbrevs (SKELETON_COMP_DIE_ABBREV, comp_unit);
 
@@ -11657,12 +11714,12 @@ output_pubnames (vec<pubname_entry, va_gc> *names)
   dw2_asm_output_data (2, 2, "DWARF pubnames/pubtypes version");
 
   if (dwarf_split_debug_info)
-    dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_info_section_label,
-                           debug_skeleton_info_section,
+    dw2_asm_output_offset (dwarf_offset_size, dw_state->lab.debug_skeleton_info_section,
+                           dw_state->sec.debug_skeleton_info,
                            "Offset of Compilation Unit Info");
   else
-    dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
-                           debug_info_section,
+    dw2_asm_output_offset (dwarf_offset_size, dw_state->lab.debug_info_section,
+                           dw_state->sec.debug_info,
                            "Offset of Compilation Unit Info");
   dw2_asm_output_data (dwarf_offset_size, next_die_offset,
 		       "Compilation Unit Length");
@@ -11706,12 +11763,12 @@ output_pubtables (void)
   if (!want_pubnames () || !info_section_emitted)
     return;
 
-  switch_to_section (debug_pubnames_section);
+  switch_to_section (dw_state->sec.debug_pubnames);
   output_pubnames (pubname_table);
   /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
      It shouldn't hurt to emit it always, since pure DWARF2 consumers
      simply won't look for the section.  */
-  switch_to_section (debug_pubtypes_section);
+  switch_to_section (dw_state->sec.debug_pubtypes);
   output_pubnames (pubtype_table);
 }
 
@@ -11738,12 +11795,12 @@ output_aranges (void)
   /* Version number for aranges is still 2, even up to DWARF5.  */
   dw2_asm_output_data (2, 2, "DWARF aranges version");
   if (dwarf_split_debug_info)
-    dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_info_section_label,
-                           debug_skeleton_info_section,
+    dw2_asm_output_offset (dwarf_offset_size, dw_state->lab.debug_skeleton_info_section,
+                           dw_state->sec.debug_skeleton_info,
                            "Offset of Compilation Unit Info");
   else
-    dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
-                           debug_info_section,
+    dw2_asm_output_offset (dwarf_offset_size, dw_state->lab.debug_info_section,
+                           dw_state->sec.debug_info,
                            "Offset of Compilation Unit Info");
   dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
   dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
@@ -11766,7 +11823,7 @@ output_aranges (void)
      confused with the terminator.  */
   if (switch_text_ranges)
     {
-      const char *prev_loc = text_section_label;
+      const char *prev_loc = dw_state->lab.text_section;
       const char *loc;
       unsigned idx;
 
@@ -11783,14 +11840,14 @@ output_aranges (void)
       if (prev_loc)
 	{
 	  dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
-	  dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
+	  dw2_asm_output_delta (DWARF2_ADDR_SIZE, dw_state->lab.text_end,
 				prev_loc, "Length");
 	}
     }
 
   if (switch_cold_ranges)
     {
-      const char *prev_loc = cold_text_section_label;
+      const char *prev_loc = dw_state->lab.cold_text_section;
       const char *loc;
       unsigned idx;
 
@@ -11807,7 +11864,7 @@ output_aranges (void)
       if (prev_loc)
 	{
 	  dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
-	  dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
+	  dw2_asm_output_delta (DWARF2_ADDR_SIZE, dw_state->lab.cold_end,
 				prev_loc, "Length");
 	}
     }
@@ -11909,8 +11966,8 @@ output_ranges (void)
   const char *fmt = start_fmt;
   dw_ranges *r;
 
-  switch_to_section (debug_ranges_section);
-  ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
+  switch_to_section (dw_state->sec.debug_ranges);
+  ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.ranges_section);
   FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
     {
       int block_num = r->num;
@@ -11929,10 +11986,10 @@ output_ranges (void)
 	  if (!have_multiple_function_sections)
 	    {
 	      dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
-				    text_section_label,
+				    dw_state->lab.text_section,
 				    fmt, i * 2 * DWARF2_ADDR_SIZE);
 	      dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
-				    text_section_label, NULL);
+				    dw_state->lab.text_section, NULL);
 	    }
 
 	  /* Otherwise, the compilation unit base address is zero,
@@ -11963,11 +12020,11 @@ output_ranges (void)
 		 the #if 0 above.  */
 	      dw2_asm_output_delta (DWARF2_ADDR_SIZE,
 				    (*ranges_by_label)[lab_idx].begin,
-				    text_section_label,
+				    dw_state->lab.text_section,
 				    fmt, i * 2 * DWARF2_ADDR_SIZE);
 	      dw2_asm_output_delta (DWARF2_ADDR_SIZE,
 				    (*ranges_by_label)[lab_idx].end,
-				    text_section_label, NULL);
+				    dw_state->lab.text_section, NULL);
 #endif
 	    }
 	  else
@@ -12118,11 +12175,11 @@ output_rnglists (unsigned generation, bool dwo)
   char basebuf[MAX_ARTIFICIAL_LABEL_BYTES];
 
   if (dwo)
-    switch_to_section (debug_ranges_dwo_section);
+    switch_to_section (dw_state->sec.debug_ranges_dwo);
   else
     {
-      switch_to_section (debug_ranges_section);
-      ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
+      switch_to_section (dw_state->sec.debug_ranges);
+      ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.ranges_section);
     }
   /* There are up to 4 unique ranges labels per generation.
      See also init_sections_and_labels.  */
@@ -12150,11 +12207,11 @@ output_rnglists (unsigned generation, bool dwo)
 		       "Offset Entry Count");
   if (dwo)
     {
-      ASM_OUTPUT_LABEL (asm_out_file, ranges_base_label);
+      ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.ranges_base);
       FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
 	if (r->label && r->idx != DW_RANGES_IDX_SKELETON)
 	  dw2_asm_output_delta (dwarf_offset_size, r->label,
-				ranges_base_label, NULL);
+				dw_state->lab.ranges_base, NULL);
     }
 
   const char *lab = "";
@@ -12202,9 +12259,9 @@ output_rnglists (unsigned generation, bool dwo)
 		{
 		  dw2_asm_output_data (1, DW_RLE_offset_pair,
 				       "DW_RLE_offset_pair (%s)", lab);
-		  dw2_asm_output_delta_uleb128 (blabel, text_section_label,
+		  dw2_asm_output_delta_uleb128 (blabel, dw_state->lab.text_section,
 						"Range begin address (%s)", lab);
-		  dw2_asm_output_delta_uleb128 (elabel, text_section_label,
+		  dw2_asm_output_delta_uleb128 (elabel, dw_state->lab.text_section,
 						"Range end address (%s)", lab);
 		  continue;
 		}
@@ -12475,7 +12532,7 @@ output_line_string (enum dwarf_form form, const char *str,
       set_indirect_string (node);
       node->form = form;
       dw2_asm_output_offset (dwarf_offset_size, node->label,
-			     debug_line_str_section, "%s: %#x: \"%s\"",
+			     dw_state->sec.debug_line_str, "%s: %#x: \"%s\"",
 			     entry_kind, 0, node->str);
       break;
     default:
@@ -17279,7 +17336,7 @@ secname_for_decl (const_tree decl)
   else if (cfun && casm->in_cold_section_p)
     secname = crtl->subsections.cold_section_label;
   else
-    secname = text_section_label;
+    secname = dw_state->lab.text_section;
 
   return secname;
 }
@@ -17656,7 +17713,7 @@ dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
 	      /* If the variable has a location at the last label
 		 it keeps its location until the end of function.  */
 	      else if (!current_function_decl)
-		endname = text_end_label, endview = 0;
+		endname = dw_state->lab.text_end, endview = 0;
 	      else
 		{
 		  ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
@@ -28198,7 +28255,7 @@ set_cur_line_info_table (section *sec)
       if (!table)
 	{
 	  cold_text_section_line_info = table = new_line_info_table ();
-	  table->end_label = cold_end_label;
+	  table->end_label = dw_state->lab.cold_end;
 	}
     }
   else
@@ -28252,7 +28309,7 @@ dwarf2out_begin_function (tree fun)
       gcc_assert (current_function_decl == fun);
       cold_text_section = unlikely_text_section ();
       switch_to_section (cold_text_section);
-      ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
+      ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.cold_text_section);
       switch_to_section (sec);
     }
 
@@ -28713,7 +28770,7 @@ output_macinfo_op (macinfo_entry *ref)
       if ((!dwarf_strict || dwarf_version >= 5)
 	  && len > (size_t) dwarf_offset_size
 	  && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
-	  && (debug_str_section->common.flags & SECTION_MERGE) != 0)
+	  && (dw_state->sec.debug_str->common.flags & SECTION_MERGE) != 0)
 	{
 	  if (dwarf_split_debug_info && dwarf_version >= 5)
 	    ref->code = ref->code == DW_MACINFO_define
@@ -28764,7 +28821,7 @@ output_macinfo_op (macinfo_entry *ref)
 				   (unsigned long) ref->lineno);
       if (node->form == DW_FORM_strp)
         dw2_asm_output_offset (dwarf_offset_size, node->label,
-                               debug_str_section, "The macro: \"%s\"",
+                               dw_state->sec.debug_str, "The macro: \"%s\"",
                                ref->info);
       else
         dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
@@ -28774,7 +28831,7 @@ output_macinfo_op (macinfo_entry *ref)
       dw2_asm_output_data (1, ref->code, "Import");
       ASM_GENERATE_INTERNAL_LABEL (label,
 				   DEBUG_MACRO_SECTION_LABEL,
-				   ref->lineno + macinfo_label_base);
+				   ref->lineno + dw_state->macinfo_label_base);
       dw2_asm_output_offset (dwarf_offset_size, label, NULL, NULL);
       break;
     default:
@@ -28932,7 +28989,7 @@ save_macinfo_strings (void)
 	    if ((!dwarf_strict || dwarf_version >= 5)
                 && len > (unsigned) dwarf_offset_size
                 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
-                && (debug_str_section->common.flags & SECTION_MERGE) != 0)
+                && (dw_state->sec.debug_str->common.flags & SECTION_MERGE) != 0)
               set_indirect_string (find_AT_string (ref->info));
             break;
 	  case DW_MACINFO_start_file:
@@ -28990,7 +29047,7 @@ output_macinfo (const char *debug_line_label, bool early_lto_debug)
       else
 	dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
       dw2_asm_output_offset (dwarf_offset_size, debug_line_label,
-                             debug_line_section, NULL);
+                             dw_state->sec.debug_line, NULL);
     }
 
   /* In the first loop, it emits the primary .debug_macinfo section
@@ -29064,7 +29121,7 @@ output_macinfo (const char *debug_line_label, bool early_lto_debug)
 	  tree comdat_key = get_identifier (ref->info);
 	  /* Terminate the previous .debug_macinfo section.  */
 	  dw2_asm_output_data (1, 0, "End compilation unit");
-	  targetm.asm_out.named_section (debug_macinfo_section_name,
+	  targetm.asm_out.named_section (dw_state->debug_macinfo_section_name,
 					 SECTION_DEBUG
 					 | SECTION_LINKONCE
 					 | (early_lto_debug
@@ -29072,7 +29129,7 @@ output_macinfo (const char *debug_line_label, bool early_lto_debug)
 					 comdat_key);
 	  ASM_GENERATE_INTERNAL_LABEL (label,
 				       DEBUG_MACRO_SECTION_LABEL,
-				       ref->lineno + macinfo_label_base);
+				       ref->lineno + dw_state->macinfo_label_base);
 	  ASM_OUTPUT_LABEL (asm_out_file, label);
 	  ref->code = 0;
 	  ref->info = NULL;
@@ -29094,7 +29151,7 @@ output_macinfo (const char *debug_line_label, bool early_lto_debug)
 	gcc_unreachable ();
       }
 
-  macinfo_label_base += macinfo_label_base_adj;
+  dw_state->macinfo_label_base += macinfo_label_base_adj;
 }
 
 /* As init_sections_and_labels may get called multiple times, have a
@@ -29112,77 +29169,77 @@ init_sections_and_labels (bool early_lto_debug)
     {
       if (!dwarf_split_debug_info)
 	{
-	  debug_info_section = get_section (DEBUG_LTO_INFO_SECTION,
+	  dw_state->sec.debug_info = get_section (DEBUG_LTO_INFO_SECTION,
 					    SECTION_DEBUG | SECTION_EXCLUDE,
 					    NULL);
-	  debug_abbrev_section = get_section (DEBUG_LTO_ABBREV_SECTION,
+	  dw_state->sec.debug_abbrev = get_section (DEBUG_LTO_ABBREV_SECTION,
 					      SECTION_DEBUG | SECTION_EXCLUDE,
 					      NULL);
-	  debug_macinfo_section_name
+	  dw_state->debug_macinfo_section_name
 	    = ((dwarf_strict && dwarf_version < 5)
 	       ? DEBUG_LTO_MACINFO_SECTION : DEBUG_LTO_MACRO_SECTION);
-	  debug_macinfo_section = get_section (debug_macinfo_section_name,
+	  dw_state->sec.debug_macinfo = get_section (dw_state->debug_macinfo_section_name,
 					       SECTION_DEBUG
 					       | SECTION_EXCLUDE, NULL);
 	}
       else
 	{
 	  /* ???  Which of the following do we need early?  */
-	  debug_info_section = get_section (DEBUG_LTO_DWO_INFO_SECTION,
+	  dw_state->sec.debug_info = get_section (DEBUG_LTO_DWO_INFO_SECTION,
 					    SECTION_DEBUG | SECTION_EXCLUDE,
 					    NULL);
-	  debug_abbrev_section = get_section (DEBUG_LTO_DWO_ABBREV_SECTION,
+	  dw_state->sec.debug_abbrev = get_section (DEBUG_LTO_DWO_ABBREV_SECTION,
 					      SECTION_DEBUG | SECTION_EXCLUDE,
 					      NULL);
-	  debug_skeleton_info_section = get_section (DEBUG_LTO_INFO_SECTION,
+	  dw_state->sec.debug_skeleton_info = get_section (DEBUG_LTO_INFO_SECTION,
 						     SECTION_DEBUG
 						     | SECTION_EXCLUDE, NULL);
-	  debug_skeleton_abbrev_section
+	  dw_state->sec.debug_skeleton_abbrev
 	    = get_section (DEBUG_LTO_ABBREV_SECTION,
 			   SECTION_DEBUG | SECTION_EXCLUDE, NULL);
-	  ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
+	  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.debug_skeleton_abbrev_section,
 				       DEBUG_SKELETON_ABBREV_SECTION_LABEL,
 				       init_sections_and_labels_generation);
 
 	  /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
 	     stay in the main .o, but the skeleton_line goes into the split
 	     off dwo.  */
-	  debug_skeleton_line_section
+	  dw_state->sec.debug_skeleton_line
 	    = get_section (DEBUG_LTO_LINE_SECTION,
 			   SECTION_DEBUG | SECTION_EXCLUDE, NULL);
-	  ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
+	  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.debug_skeleton_line_section,
 				       DEBUG_SKELETON_LINE_SECTION_LABEL,
 				       init_sections_and_labels_generation);
-	  debug_str_offsets_section
+	  dw_state->sec.debug_str_offsets
 	    = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION,
 			   SECTION_DEBUG | SECTION_EXCLUDE,
 			   NULL);
-	  ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
+	  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.debug_skeleton_info_section,
 				       DEBUG_SKELETON_INFO_SECTION_LABEL,
 				       init_sections_and_labels_generation);
-	  debug_str_dwo_section = get_section (DEBUG_LTO_STR_DWO_SECTION,
+	  dw_state->sec.debug_str_dwo = get_section (DEBUG_LTO_STR_DWO_SECTION,
 					       DEBUG_STR_DWO_SECTION_FLAGS,
 					       NULL);
-	  debug_macinfo_section_name
+	  dw_state->debug_macinfo_section_name
 	    = ((dwarf_strict && dwarf_version < 5)
 	       ? DEBUG_LTO_DWO_MACINFO_SECTION : DEBUG_LTO_DWO_MACRO_SECTION);
-	  debug_macinfo_section = get_section (debug_macinfo_section_name,
+	  dw_state->sec.debug_macinfo = get_section (dw_state->debug_macinfo_section_name,
 					       SECTION_DEBUG | SECTION_EXCLUDE,
 					       NULL);
 	}
       /* For macro info and the file table we have to refer to a
 	 debug_line section.  */
-      debug_line_section = get_section (DEBUG_LTO_LINE_SECTION,
+      dw_state->sec.debug_line = get_section (DEBUG_LTO_LINE_SECTION,
 					SECTION_DEBUG | SECTION_EXCLUDE, NULL);
-      ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
+      ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.debug_line_section,
 				   DEBUG_LINE_SECTION_LABEL,
 				   init_sections_and_labels_generation);
 
-      debug_str_section = get_section (DEBUG_LTO_STR_SECTION,
+      dw_state->sec.debug_str = get_section (DEBUG_LTO_STR_SECTION,
 				       DEBUG_STR_SECTION_FLAGS
 				       | SECTION_EXCLUDE, NULL);
       if (!dwarf_split_debug_info)
-	debug_line_str_section
+	dw_state->sec.debug_line_str
 	  = get_section (DEBUG_LTO_LINE_STR_SECTION,
 			 DEBUG_STR_SECTION_FLAGS | SECTION_EXCLUDE, NULL);
     }
@@ -29190,123 +29247,123 @@ init_sections_and_labels (bool early_lto_debug)
     {
       if (!dwarf_split_debug_info)
 	{
-	  debug_info_section = get_section (DEBUG_INFO_SECTION,
+	  dw_state->sec.debug_info = get_section (DEBUG_INFO_SECTION,
 					    SECTION_DEBUG, NULL);
-	  debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
+	  dw_state->sec.debug_abbrev = get_section (DEBUG_ABBREV_SECTION,
 					      SECTION_DEBUG, NULL);
-	  debug_loc_section = get_section (dwarf_version >= 5
+	  dw_state->sec.debug_loc = get_section (dwarf_version >= 5
 					   ? DEBUG_LOCLISTS_SECTION
 					   : DEBUG_LOC_SECTION,
 					   SECTION_DEBUG, NULL);
-	  debug_macinfo_section_name
+	  dw_state->debug_macinfo_section_name
 	    = ((dwarf_strict && dwarf_version < 5)
 	       ? DEBUG_MACINFO_SECTION : DEBUG_MACRO_SECTION);
-	  debug_macinfo_section = get_section (debug_macinfo_section_name,
+	  dw_state->sec.debug_macinfo = get_section (dw_state->debug_macinfo_section_name,
 					       SECTION_DEBUG, NULL);
 	}
       else
 	{
-	  debug_info_section = get_section (DEBUG_DWO_INFO_SECTION,
+	  dw_state->sec.debug_info = get_section (DEBUG_DWO_INFO_SECTION,
 					    SECTION_DEBUG | SECTION_EXCLUDE,
 					    NULL);
-	  debug_abbrev_section = get_section (DEBUG_DWO_ABBREV_SECTION,
+	  dw_state->sec.debug_abbrev = get_section (DEBUG_DWO_ABBREV_SECTION,
 					      SECTION_DEBUG | SECTION_EXCLUDE,
 					      NULL);
-	  debug_addr_section = get_section (DEBUG_ADDR_SECTION,
+	  dw_state->sec.debug_addr = get_section (DEBUG_ADDR_SECTION,
 					    SECTION_DEBUG, NULL);
-	  debug_skeleton_info_section = get_section (DEBUG_INFO_SECTION,
+	  dw_state->sec.debug_skeleton_info = get_section (DEBUG_INFO_SECTION,
 						     SECTION_DEBUG, NULL);
-	  debug_skeleton_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
+	  dw_state->sec.debug_skeleton_abbrev = get_section (DEBUG_ABBREV_SECTION,
 						       SECTION_DEBUG, NULL);
-	  ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
+	  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.debug_skeleton_abbrev_section,
 				       DEBUG_SKELETON_ABBREV_SECTION_LABEL,
 				       init_sections_and_labels_generation);
 
 	  /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
 	     stay in the main .o, but the skeleton_line goes into the
 	     split off dwo.  */
-	  debug_skeleton_line_section
+	  dw_state->sec.debug_skeleton_line
 	      = get_section (DEBUG_DWO_LINE_SECTION,
 			     SECTION_DEBUG | SECTION_EXCLUDE, NULL);
-	  ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
+	  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.debug_skeleton_line_section,
 				       DEBUG_SKELETON_LINE_SECTION_LABEL,
 				       init_sections_and_labels_generation);
-	  debug_str_offsets_section
+	  dw_state->sec.debug_str_offsets
 	    = get_section (DEBUG_DWO_STR_OFFSETS_SECTION,
 			   SECTION_DEBUG | SECTION_EXCLUDE, NULL);
-	  ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
+	  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.debug_skeleton_info_section,
 				       DEBUG_SKELETON_INFO_SECTION_LABEL,
 				       init_sections_and_labels_generation);
-	  debug_loc_section = get_section (dwarf_version >= 5
+	  dw_state->sec.debug_loc = get_section (dwarf_version >= 5
 					   ? DEBUG_DWO_LOCLISTS_SECTION
 					   : DEBUG_DWO_LOC_SECTION,
 					   SECTION_DEBUG | SECTION_EXCLUDE,
 					   NULL);
-	  debug_str_dwo_section = get_section (DEBUG_STR_DWO_SECTION,
+	  dw_state->sec.debug_str_dwo = get_section (DEBUG_STR_DWO_SECTION,
 					       DEBUG_STR_DWO_SECTION_FLAGS,
 					       NULL);
-	  debug_macinfo_section_name
+	  dw_state->debug_macinfo_section_name
 	    = ((dwarf_strict && dwarf_version < 5)
 	       ? DEBUG_DWO_MACINFO_SECTION : DEBUG_DWO_MACRO_SECTION);
-	  debug_macinfo_section = get_section (debug_macinfo_section_name,
+	  dw_state->sec.debug_macinfo = get_section (dw_state->debug_macinfo_section_name,
 					       SECTION_DEBUG | SECTION_EXCLUDE,
 					       NULL);
 	  if (dwarf_version >= 5)
-	    debug_ranges_dwo_section
+	    dw_state->sec.debug_ranges_dwo
 	      = get_section (DEBUG_DWO_RNGLISTS_SECTION,
 			     SECTION_DEBUG | SECTION_EXCLUDE, NULL);
 	}
-      debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
+      dw_state->sec.debug_aranges = get_section (DEBUG_ARANGES_SECTION,
 					   SECTION_DEBUG, NULL);
-      debug_line_section = get_section (DEBUG_LINE_SECTION,
+      dw_state->sec.debug_line = get_section (DEBUG_LINE_SECTION,
 					SECTION_DEBUG, NULL);
-      debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
+      dw_state->sec.debug_pubnames = get_section (DEBUG_PUBNAMES_SECTION,
 					    SECTION_DEBUG, NULL);
-      debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
+      dw_state->sec.debug_pubtypes = get_section (DEBUG_PUBTYPES_SECTION,
 					    SECTION_DEBUG, NULL);
-      debug_str_section = get_section (DEBUG_STR_SECTION,
+      dw_state->sec.debug_str = get_section (DEBUG_STR_SECTION,
 				       DEBUG_STR_SECTION_FLAGS, NULL);
       if ((!dwarf_split_debug_info && !output_asm_line_debug_info ())
 	  || asm_outputs_debug_line_str ())
-	debug_line_str_section = get_section (DEBUG_LINE_STR_SECTION,
+	dw_state->sec.debug_line_str = get_section (DEBUG_LINE_STR_SECTION,
 					      DEBUG_STR_SECTION_FLAGS, NULL);
 
-      debug_ranges_section = get_section (dwarf_version >= 5
+      dw_state->sec.debug_ranges = get_section (dwarf_version >= 5
 					  ? DEBUG_RNGLISTS_SECTION
 					  : DEBUG_RANGES_SECTION,
 					  SECTION_DEBUG, NULL);
-      debug_frame_section = get_section (DEBUG_FRAME_SECTION,
+      dw_state->sec.debug_frame = get_section (DEBUG_FRAME_SECTION,
 					 SECTION_DEBUG, NULL);
     }
 
-  ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
+  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.abbrev_section,
 			       DEBUG_ABBREV_SECTION_LABEL,
 			       init_sections_and_labels_generation);
-  ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
+  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.debug_info_section,
 			       DEBUG_INFO_SECTION_LABEL,
 			       init_sections_and_labels_generation);
   info_section_emitted = false;
-  ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
+  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.debug_line_section,
 			       DEBUG_LINE_SECTION_LABEL,
 			       init_sections_and_labels_generation);
   /* There are up to 6 unique ranges labels per generation.
      See also output_rnglists.  */
-  ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
+  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.ranges_section,
 			       DEBUG_RANGES_SECTION_LABEL,
 			       init_sections_and_labels_generation * 6);
   if (dwarf_version >= 5 && dwarf_split_debug_info)
-    ASM_GENERATE_INTERNAL_LABEL (ranges_base_label,
+    ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.ranges_base,
 				 DEBUG_RANGES_SECTION_LABEL,
 				 1 + init_sections_and_labels_generation * 6);
-  ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label,
+  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.debug_addr_section,
 			       DEBUG_ADDR_SECTION_LABEL,
 			       init_sections_and_labels_generation);
-  ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
+  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.macinfo_section,
 			       (dwarf_strict && dwarf_version < 5)
 			       ? DEBUG_MACINFO_SECTION_LABEL
 			       : DEBUG_MACRO_SECTION_LABEL,
 			       init_sections_and_labels_generation);
-  ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL,
+  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.loc_section, DEBUG_LOC_SECTION_LABEL,
 			       init_sections_and_labels_generation);
 
   ++init_sections_and_labels_generation;
@@ -29318,6 +29375,8 @@ init_sections_and_labels (bool early_lto_debug)
 static void
 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
 {
+  dw_state = new (ggc_alloc<dwarf_out_state> ()) dwarf_out_state (casm);
+
   /* Allocate the file_table.  */
   file_table = hash_table<dwarf_file_hasher>::create_ggc (50);
 
@@ -29367,19 +29426,19 @@ dwarf2out_assembly_start (void)
     return;
 
 #ifndef DWARF2_LINENO_DEBUGGING_INFO
-  ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
-  ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
-  ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
+  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.text_section, TEXT_SECTION_LABEL, 0);
+  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.text_end, TEXT_END_LABEL, 0);
+  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.cold_text_section,
 			       COLD_TEXT_SECTION_LABEL, 0);
-  ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
+  ASM_GENERATE_INTERNAL_LABEL (dw_state->lab.cold_end, COLD_END_LABEL, 0);
 
   switch_to_section (casm->sec.text);
-  ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
+  ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.text_section);
 #endif
 
   /* Make sure the line number table for .text always exists.  */
   text_section_line_info = new_line_info_table ();
-  text_section_line_info->end_label = text_end_label;
+  text_section_line_info->end_label = dw_state->lab.text_end;
 
 #ifdef DWARF2_LINENO_DEBUGGING_INFO
   cur_line_info_table = text_section_line_info;
@@ -29523,7 +29582,7 @@ output_indirect_string (indirect_string_node **h, enum dwarf_form form)
 static void
 output_indirect_strings (void)
 {
-  switch_to_section (debug_str_section);
+  switch_to_section (dw_state->sec.debug_str);
   if (!dwarf_split_debug_info)
     debug_str_hash->traverse<enum dwarf_form,
 			     output_indirect_string> (DW_FORM_strp);
@@ -29536,7 +29595,7 @@ output_indirect_strings (void)
         skeleton_debug_str_hash->traverse<enum dwarf_form,
 					  output_indirect_string> (DW_FORM_strp);
 
-      switch_to_section (debug_str_offsets_section);
+      switch_to_section (dw_state->sec.debug_str_offsets);
       /* For DWARF5 the .debug_str_offsets[.dwo] section needs a unit
 	 header.  Note that we don't need to generate a label to the
 	 actual index table following the header here, because this is
@@ -29566,7 +29625,7 @@ output_indirect_strings (void)
 	}
       debug_str_hash->traverse_noresize
 	<unsigned int *, output_index_string_offset> (&offset);
-      switch_to_section (debug_str_dwo_section);
+      switch_to_section (dw_state->sec.debug_str_dwo);
       debug_str_hash->traverse_noresize<unsigned int *, output_index_string>
 	(&cur_idx);
     }
@@ -29635,7 +29694,7 @@ output_addr_table (void)
   if (addr_index_table == NULL || addr_index_table->size () == 0)
     return;
 
-  switch_to_section (debug_addr_section);
+  switch_to_section (dw_state->sec.debug_addr);
   /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission
      which GCC uses to implement -gsplit-dwarf as DWARF GNU extension
      before DWARF5, didn't have a header for .debug_addr units.
@@ -29658,7 +29717,7 @@ output_addr_table (void)
       dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
       dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
     }
-  ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label);
+  ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.debug_addr_section);
 
   addr_index_table
     ->traverse_noresize<unsigned int *, output_addr_table_entry> (&index);
@@ -32094,12 +32153,12 @@ dwarf2out_finish (const char *filename)
        && vec_safe_length (switch_text_ranges) < 2)
       || (dwarf_version < 3 && dwarf_strict))
     {
-      const char *end_label = text_end_label;
+      const char *end_label = dw_state->lab.text_end;
       if (vec_safe_length (switch_text_ranges) == 1)
 	end_label = (*switch_text_ranges)[0];
       /* Don't add if the CU has no associated code.  */
       if (switch_text_ranges)
-	add_AT_low_high_pc (main_comp_unit_die, text_section_label,
+	add_AT_low_high_pc (main_comp_unit_die, dw_state->lab.text_section,
 			    end_label, true);
     }
   else
@@ -32109,7 +32168,7 @@ dwarf2out_finish (const char *filename)
       bool range_list_added = false;
       if (switch_text_ranges)
 	{
-	  const char *prev_loc = text_section_label;
+	  const char *prev_loc = dw_state->lab.text_section;
 	  const char *loc;
 	  unsigned idx;
 
@@ -32125,12 +32184,12 @@ dwarf2out_finish (const char *filename)
 
 	  if (prev_loc)
 	    add_ranges_by_labels (main_comp_unit_die, prev_loc,
-				  text_end_label, &range_list_added, true);
+				  dw_state->lab.text_end, &range_list_added, true);
 	}
 
       if (switch_cold_ranges)
 	{
-	  const char *prev_loc = cold_text_section_label;
+	  const char *prev_loc = dw_state->lab.cold_text_section;
 	  const char *loc;
 	  unsigned idx;
 
@@ -32146,7 +32205,7 @@ dwarf2out_finish (const char *filename)
 
 	  if (prev_loc)
 	    add_ranges_by_labels (main_comp_unit_die, prev_loc,
-				  cold_end_label, &range_list_added, true);
+				  dw_state->lab.cold_end, &range_list_added, true);
 	}
 
       FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
@@ -32181,7 +32240,7 @@ dwarf2out_finish (const char *filename)
 
   /* AIX Assembler inserts the length, so adjust the reference to match the
      offset expected by debuggers.  */
-  strcpy (dl_section_ref, debug_line_section_label);
+  strcpy (dl_section_ref, dw_state->lab.debug_line_section);
   if (XCOFF_DEBUGGING_INFO)
     strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
 
@@ -32191,7 +32250,7 @@ dwarf2out_finish (const char *filename)
 
   if (have_macinfo)
     add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE,
-		   macinfo_section_label);
+		   dw_state->lab.macinfo_section);
 
   if (dwarf_split_debug_info)
     {
@@ -32271,7 +32330,7 @@ dwarf2out_finish (const char *filename)
         add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
                         (!dwarf_split_debug_info
                          ? dl_section_ref
-                         : debug_skeleton_line_section_label));
+                         : dw_state->lab.debug_skeleton_line_section));
 
       output_comdat_type_unit (ctnode, false);
       *slot = ctnode;
@@ -32303,7 +32362,7 @@ dwarf2out_finish (const char *filename)
 	{
 	  if (dwarf_version < 5)
 	    add_AT_lineptr (main_comp_unit_die, DW_AT_GNU_ranges_base,
-			    ranges_section_label);
+			    dw_state->lab.ranges_section);
 	}
 
       output_addr_table ();
@@ -32320,8 +32379,8 @@ dwarf2out_finish (const char *filename)
   /* Output the abbreviation table.  */
   if (vec_safe_length (abbrev_die_table) != 1)
     {
-      switch_to_section (debug_abbrev_section);
-      ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
+      switch_to_section (dw_state->sec.debug_abbrev);
+      ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.abbrev_section);
       output_abbrev_section ();
     }
 
@@ -32331,7 +32390,7 @@ dwarf2out_finish (const char *filename)
       char l1[MAX_ARTIFICIAL_LABEL_BYTES];
       char l2[MAX_ARTIFICIAL_LABEL_BYTES];
       /* Output the location lists info.  */
-      switch_to_section (debug_loc_section);
+      switch_to_section (dw_state->sec.debug_loc);
       if (dwarf_version >= 5)
 	{
 	  ASM_GENERATE_INTERNAL_LABEL (l1, DEBUG_LOC_SECTION_LABEL, 2);
@@ -32349,7 +32408,7 @@ dwarf2out_finish (const char *filename)
 	  dw2_asm_output_data (4, dwarf_split_debug_info ? loc_list_idx : 0,
 			       "Offset Entry Count");
 	}
-      ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
+      ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.loc_section);
       if (dwarf_version >= 5 && dwarf_split_debug_info)
 	{
 	  unsigned int save_loc_list_idx = loc_list_idx;
@@ -32371,7 +32430,7 @@ dwarf2out_finish (const char *filename)
      generate a table that would have contained data.  */
   if (info_section_emitted)
     {
-      switch_to_section (debug_aranges_section);
+      switch_to_section (dw_state->sec.debug_aranges);
       output_aranges ();
     }
 
@@ -32402,10 +32461,10 @@ dwarf2out_finish (const char *filename)
   /* Have to end the macro section.  */
   if (have_macinfo)
     {
-      switch_to_section (debug_macinfo_section);
-      ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
-      output_macinfo (!dwarf_split_debug_info ? debug_line_section_label
-		      : debug_skeleton_line_section_label, false);
+      switch_to_section (dw_state->sec.debug_macinfo);
+      ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.macinfo_section);
+      output_macinfo (!dwarf_split_debug_info ? dw_state->lab.debug_line_section
+		      : dw_state->lab.debug_skeleton_line_section, false);
       dw2_asm_output_data (1, 0, "End compilation unit");
     }
 
@@ -32415,15 +32474,15 @@ dwarf2out_finish (const char *filename)
      .debug_info section.  IRIX 6.5 `nm' will then complain when
      examining the file.  This is done late so that any filenames
      used by the debug_info section are marked as 'used'.  */
-  switch_to_section (debug_line_section);
-  ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
+  switch_to_section (dw_state->sec.debug_line);
+  ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.debug_line_section);
   if (! output_asm_line_debug_info ())
     output_line_info (false);
 
   if (dwarf_split_debug_info && info_section_emitted)
     {
-      switch_to_section (debug_skeleton_line_section);
-      ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_line_section_label);
+      switch_to_section (dw_state->sec.debug_skeleton_line);
+      ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.debug_skeleton_line_section);
       output_line_info (true);
     }
 
@@ -32432,7 +32491,7 @@ dwarf2out_finish (const char *filename)
     output_indirect_strings ();
   if (debug_line_str_hash)
     {
-      switch_to_section (debug_line_str_section);
+      switch_to_section (dw_state->sec.debug_line_str);
       const enum dwarf_form form = DW_FORM_line_strp;
       debug_line_str_hash->traverse<enum dwarf_form,
 				    output_indirect_string> (form);
@@ -32872,6 +32931,10 @@ dwarf2out_early_finish (const char *filename)
       || TARGET_PECOFF || TARGET_COFF)
     return;
 
+  /* Initialize an early LTO debug output file.  */
+//  lto_debug_asm->out_file = fopen ("/tmp/lto-debug.s", "w");
+//  push_asm (lto_debug_asm);
+
   /* Now as we are going to output for LTO initialize sections and labels
      to the LTO variants.  We don't need a random-seed postfix as other
      LTO sections as linking the LTO debug sections into one in a partial
@@ -32897,7 +32960,7 @@ dwarf2out_early_finish (const char *filename)
 
   /* AIX Assembler inserts the length, so adjust the reference to match the
      offset expected by debuggers.  */
-  strcpy (dl_section_ref, debug_line_section_label);
+  strcpy (dl_section_ref, dw_state->lab.debug_line_section);
   if (XCOFF_DEBUGGING_INFO)
     strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
 
@@ -32906,7 +32969,7 @@ dwarf2out_early_finish (const char *filename)
 
   if (have_macinfo)
     add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE,
-		   macinfo_section_label);
+		   dw_state->lab.macinfo_section);
 
   save_macinfo_strings ();
 
@@ -32936,8 +32999,8 @@ dwarf2out_early_finish (const char *filename)
       if (debug_info_level >= DINFO_LEVEL_TERSE)
         add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
                         (!dwarf_split_debug_info
-                         ? debug_line_section_label
-                         : debug_skeleton_line_section_label));
+                         ? dw_state->lab.debug_line_section
+                         : dw_state->lab.debug_skeleton_line_section));
 
       output_comdat_type_unit (ctnode, true);
       *slot = ctnode;
@@ -32953,8 +33016,8 @@ dwarf2out_early_finish (const char *filename)
   /* Output the abbreviation table.  */
   if (vec_safe_length (abbrev_die_table) != 1)
     {
-      switch_to_section (debug_abbrev_section);
-      ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
+      switch_to_section (dw_state->sec.debug_abbrev);
+      ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.abbrev_section);
       output_abbrev_section ();
     }
 
@@ -32967,9 +33030,9 @@ dwarf2out_early_finish (const char *filename)
       if (flag_fat_lto_objects)
 	macinfo_table = macinfo_table->copy ();
 
-      switch_to_section (debug_macinfo_section);
-      ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
-      output_macinfo (debug_line_section_label, true);
+      switch_to_section (dw_state->sec.debug_macinfo);
+      ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.macinfo_section);
+      output_macinfo (dw_state->lab.debug_line_section, true);
       dw2_asm_output_data (1, 0, "End compilation unit");
 
       if (flag_fat_lto_objects)
@@ -32980,8 +33043,8 @@ dwarf2out_early_finish (const char *filename)
     }
 
   /* Emit a skeleton debug_line section.  */
-  switch_to_section (debug_line_section);
-  ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
+  switch_to_section (dw_state->sec.debug_line);
+  ASM_OUTPUT_LABEL (asm_out_file, dw_state->lab.debug_line_section);
   output_line_info (true);
 
   /* If we emitted any indirect strings, output the string table too.  */
@@ -32989,12 +33052,14 @@ dwarf2out_early_finish (const char *filename)
     output_indirect_strings ();
   if (debug_line_str_hash)
     {
-      switch_to_section (debug_line_str_section);
+      switch_to_section (dw_state->sec.debug_line_str);
       const enum dwarf_form form = DW_FORM_line_strp;
       debug_line_str_hash->traverse<enum dwarf_form,
 				    output_indirect_string> (form);
     }
 
+//  pop_asm ();
+
   /* Switch back to the text section.  */
   switch_to_section (casm->sec.text);
 }
@@ -33005,29 +33070,14 @@ dwarf2out_early_finish (const char *filename)
 void
 dwarf2out_c_finalize (void)
 {
+  if (dw_state != NULL)
+    ggc_free (dw_state);
+  dw_state = NULL;
+
   last_var_location_insn = NULL;
   cached_next_real_insn = NULL;
   used_rtx_array = NULL;
   incomplete_types = NULL;
-  debug_info_section = NULL;
-  debug_skeleton_info_section = NULL;
-  debug_abbrev_section = NULL;
-  debug_skeleton_abbrev_section = NULL;
-  debug_aranges_section = NULL;
-  debug_addr_section = NULL;
-  debug_macinfo_section = NULL;
-  debug_line_section = NULL;
-  debug_skeleton_line_section = NULL;
-  debug_loc_section = NULL;
-  debug_pubnames_section = NULL;
-  debug_pubtypes_section = NULL;
-  debug_str_section = NULL;
-  debug_line_str_section = NULL;
-  debug_str_dwo_section = NULL;
-  debug_str_offsets_section = NULL;
-  debug_ranges_section = NULL;
-  debug_ranges_dwo_section = NULL;
-  debug_frame_section = NULL;
   fde_vec = NULL;
   debug_str_hash = NULL;
   debug_line_str_hash = NULL;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-16 12:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-16 12:03 [gcc(refs/users/marxin/heads/casm-refactoring-v2)] work in progress Martin Liska

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).