x86-64: REX.W overrides DATA_PREFIX
[binutils-gdb.git] / gas / subsegs.c
index a66af2d3f65c60fb7ebc68ec8872270c875c6500..ae42b4e76d9bf363ce91e9fa99a9ac2bd27fd653 100644 (file)
@@ -1,5 +1,5 @@
 /* subsegs.c - subsegments -
-   Copyright (C) 1987-2019 Free Software Foundation, Inc.
+   Copyright (C) 1987-2023 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
@@ -43,7 +43,27 @@ subsegs_begin (void)
   frchain_now = NULL;          /* Warn new_subseg() that we are booting.  */
   frag_now = &dummy_frag;
 }
+
+void
+subsegs_end (struct obstack **obs)
+{
+  for (; *obs; obs++)
+    _obstack_free (*obs, NULL);
+  _obstack_free (&frchains, NULL);
+  bfd_set_section_userdata (bfd_abs_section_ptr, NULL);
+  bfd_set_section_userdata (bfd_und_section_ptr, NULL);
+}
 \f
+static void
+alloc_seginfo (segT seg)
+{
+  segment_info_type *seginfo;
+
+  seginfo = obstack_alloc (&notes, sizeof (*seginfo));
+  memset (seginfo, 0, sizeof (*seginfo));
+  seginfo->bfd_section = seg;
+  bfd_set_section_userdata (seg, seginfo);
+}
 /*
  *                     subseg_change()
  *
@@ -57,16 +77,11 @@ subsegs_begin (void)
 void
 subseg_change (segT seg, int subseg)
 {
-  segment_info_type *seginfo = seg_info (seg);
   now_seg = seg;
   now_subseg = subseg;
 
-  if (! seginfo)
-    {
-      seginfo = XCNEW (segment_info_type);
-      seginfo->bfd_section = seg;
-      bfd_set_section_userdata (stdoutput, seg, seginfo);
-    }
+  if (!seg_info (seg))
+    alloc_seginfo (seg);
 }
 \f
 static void
@@ -89,6 +104,10 @@ subseg_set_rest (segT seg, subsegT subseg)
 
   seginfo = seg_info (seg);
 
+  /* Should the section symbol be kept?  */
+  if (bfd_keep_unused_section_symbols (stdoutput))
+    seg->symbol->flags |= BSF_SECTION_SYM_USED;
+
   /* Attempt to find or make a frchain for that subsection.
      We keep the list sorted by subsection number.  */
   for (frcP = *(lastPP = &seginfo->frchainP);
@@ -145,10 +164,7 @@ segT
 subseg_get (const char *segname, int force_new)
 {
   segT secptr;
-  segment_info_type *seginfo;
-  const char *now_seg_name = (now_seg
-                             ? bfd_get_section_name (stdoutput, now_seg)
-                             : 0);
+  const char *now_seg_name = now_seg ? bfd_section_name (now_seg) : 0;
 
   if (!force_new
       && now_seg_name
@@ -161,13 +177,10 @@ subseg_get (const char *segname, int force_new)
   else
     secptr = bfd_make_section_anyway (stdoutput, segname);
 
-  seginfo = seg_info (secptr);
-  if (! seginfo)
+  if (!seg_info (secptr))
     {
       secptr->output_section = secptr;
-      seginfo = XCNEW (segment_info_type);
-      seginfo->bfd_section = secptr;
-      bfd_set_section_userdata (stdoutput, secptr, seginfo);
+      alloc_seginfo (secptr);
     }
   return secptr;
 }
@@ -224,7 +237,7 @@ section_symbol (segT sec)
   if (! EMIT_SECTION_SYMBOLS || symbol_table_frozen)
     {
       /* Here we know it won't be going into the symbol table.  */
-      s = symbol_create (sec->symbol->name, sec, 0, &zero_address_frag);
+      s = symbol_create (sec->symbol->name, sec, &zero_address_frag, 0);
     }
   else
     {
@@ -235,7 +248,7 @@ section_symbol (segT sec)
       if (s == NULL
          || ((seg = S_GET_SEGMENT (s)) != sec
              && seg != undefined_section))
-       s = symbol_new (sec->symbol->name, sec, 0, &zero_address_frag);
+       s = symbol_new (sec->symbol->name, sec, &zero_address_frag, 0);
       else if (seg == undefined_section)
        {
          S_SET_SEGMENT (s, sec);
@@ -260,7 +273,7 @@ section_symbol (segT sec)
 int
 subseg_text_p (segT sec)
 {
-  return (bfd_get_section_flags (stdoutput, sec) & SEC_CODE) != 0;
+  return (bfd_section_flags (sec) & SEC_CODE) != 0;
 }
 
 /* Return non zero if SEC has at least one byte of data.  It is