Re: ubsan: undefined shift in frag_align_code
[binutils-gdb.git] / gas / ecoff.c
index 5ec999e21581a6cc5bab3226d1f8c69c41dc095b..416ba1eb210cb4cf5ef66e0c37edf60cce35551f 100644 (file)
@@ -1,5 +1,5 @@
 /* ECOFF debugging support.
-   Copyright (C) 1993-2020 Free Software Foundation, Inc.
+   Copyright (C) 1993-2022 Free Software Foundation, Inc.
    Contributed by Cygnus Support.
    This file was put together by Ian Lance Taylor <ian@cygnus.com>.  A
    good deal of it comes directly from mips-tfile.c, by Michael
@@ -1578,7 +1578,8 @@ add_string (varray_t *vp,                 /* string obstack */
 
       strcpy (hash_ptr->string, str);
 
-      str_hash_insert (hash_tbl, str, (char *) hash_ptr);
+      if (str_hash_insert (hash_tbl, str, hash_ptr, 0) != NULL)
+       as_fatal (_("duplicate %s"), str);
     }
 
   if (ret_hash != (shash_t **) NULL)
@@ -2030,7 +2031,7 @@ get_tag (const char *tag, /* tag name */
 
       perm = xstrdup (tag);
       hash_ptr = allocate_shash ();
-      str_hash_insert (tag_hash, perm, (char *) hash_ptr);
+      str_hash_insert (tag_hash, perm, hash_ptr, 0);
       hash_ptr->string = perm;
     }
 
@@ -2219,8 +2220,7 @@ add_file (const char *file_name, int indx ATTRIBUTE_UNUSED, int fake)
     {
       (void) add_ecoff_symbol (file_name, st_Nil, sc_Nil,
                               symbol_new (FAKE_LABEL_NAME, now_seg,
-                                          (valueT) frag_now_fix (),
-                                          frag_now),
+                                          frag_now, frag_now_fix ()),
                               (bfd_vma) 0, 0, ECOFF_MARK_STAB (N_SOL));
       return;
     }
@@ -2312,7 +2312,7 @@ add_file (const char *file_name, int indx ATTRIBUTE_UNUSED, int fake)
    compiler output, only in hand coded assembler.  */
 
 void
-ecoff_new_file (const char *name, int appfile ATTRIBUTE_UNUSED)
+ecoff_new_file (const char *name)
 {
   if (cur_file_ptr != NULL && filename_cmp (cur_file_ptr->name, name) == 0)
     return;
@@ -3010,8 +3010,7 @@ ecoff_directive_end (int ignore ATTRIBUTE_UNUSED)
   else
     (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text,
                             symbol_new (FAKE_LABEL_NAME, now_seg,
-                                        (valueT) frag_now_fix (),
-                                        frag_now),
+                                        frag_now, frag_now_fix ()),
                             (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
 
 #ifdef md_flush_pending_output
@@ -3254,8 +3253,7 @@ ecoff_directive_loc (int ignore ATTRIBUTE_UNUSED)
     {
       (void) add_ecoff_symbol ((char *) NULL, st_Label, sc_Text,
                               symbol_new (FAKE_LABEL_NAME, now_seg,
-                                          (valueT) frag_now_fix (),
-                                          frag_now),
+                                          frag_now, frag_now_fix ()),
                               (bfd_vma) 0, 0, lineno);
       return;
     }
@@ -3553,6 +3551,13 @@ ecoff_stab (segT sec ATTRIBUTE_UNUSED,
   cur_file_ptr = save_file_ptr;
 }
 \f
+static asection ecoff_scom_section;
+static const asymbol ecoff_scom_symbol =
+  GLOBAL_SYM_INIT (SCOMMON, &ecoff_scom_section);
+static asection ecoff_scom_section =
+  BFD_FAKE_SECTION (ecoff_scom_section, &ecoff_scom_symbol,
+                   SCOMMON, 0, SEC_IS_COMMON | SEC_SMALL_DATA);
+
 /* Frob an ECOFF symbol.  Small common symbols go into a special
    .scommon section rather than bfd_com_section.  */
 
@@ -3563,23 +3568,7 @@ ecoff_frob_symbol (symbolS *sym)
       && S_GET_VALUE (sym) > 0
       && S_GET_VALUE (sym) <= bfd_get_gp_size (stdoutput))
     {
-      static asection scom_section;
-      static asymbol scom_symbol;
-
-      /* We must construct a fake section similar to bfd_com_section
-         but with the name .scommon.  */
-      if (scom_section.name == NULL)
-       {
-         scom_section = *bfd_com_section_ptr;
-         scom_section.name = ".scommon";
-         scom_section.output_section = &scom_section;
-         scom_section.symbol = &scom_symbol;
-         scom_section.symbol_ptr_ptr = &scom_section.symbol;
-         scom_symbol = *bfd_com_section_ptr->symbol;
-         scom_symbol.name = ".scommon";
-         scom_symbol.section = &scom_section;
-       }
-      S_SET_SEGMENT (sym, &scom_section);
+      S_SET_SEGMENT (sym, &ecoff_scom_section);
     }
 
   /* Double check weak symbols.  */