testsuite, fortran: fix info-types for intel compilers
[binutils-gdb.git] / gas / write.c
index 7dc78b7fe19f42c172d386dd62583c6078b5dd28..20f5ce24d5fb17e25b487ee887e567432ed0bf4f 100644 (file)
@@ -1,5 +1,5 @@
 /* write.c - emit .o file
-   Copyright (C) 1986-2021 Free Software Foundation, Inc.
+   Copyright (C) 1986-2022 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
 #endif
 
 #ifndef TC_VALIDATE_FIX_SUB
-#ifdef UNDEFINED_DIFFERENCE_OK
-/* The PA needs this for PIC code generation.  */
-#define TC_VALIDATE_FIX_SUB(FIX, SEG)                  \
-  (md_register_arithmetic || (SEG) != reg_section)
-#else
-#define TC_VALIDATE_FIX_SUB(FIX, SEG)                  \
-  ((md_register_arithmetic || (SEG) != reg_section)    \
-   && ((FIX)->fx_r_type == BFD_RELOC_GPREL32           \
-       || (FIX)->fx_r_type == BFD_RELOC_GPREL16))
-#endif
+#define TC_VALIDATE_FIX_SUB(FIX, SEG) 0
 #endif
 
 #ifndef TC_LINKRELAX_FIXUP
@@ -908,6 +899,15 @@ adjust_reloc_syms (bfd *abfd ATTRIBUTE_UNUSED,
   dump_section_relocs (abfd, sec, stderr);
 }
 
+void
+as_bad_subtract (fixS *fixp)
+{
+  as_bad_where (fixp->fx_file, fixp->fx_line,
+               _("can't resolve %s - %s"),
+               fixp->fx_addsy ? S_GET_NAME (fixp->fx_addsy) : "0",
+               S_GET_NAME (fixp->fx_subsy));
+}
+
 /* fixup_segment()
 
    Go through all the fixS's in a segment and see which ones can be
@@ -1030,12 +1030,7 @@ fixup_segment (fixS *fixP, segT this_segment)
                as_bad_where (fixP->fx_file, fixP->fx_line,
                              _("register value used as expression"));
              else
-               as_bad_where (fixP->fx_file, fixP->fx_line,
-                             _("can't resolve `%s' {%s section} - `%s' {%s section}"),
-                             fixP->fx_addsy ? S_GET_NAME (fixP->fx_addsy) : "0",
-                             segment_name (add_symbol_segment),
-                             S_GET_NAME (fixP->fx_subsy),
-                             segment_name (sub_symbol_segment));
+               as_bad_subtract (fixP);
            }
          else if (sub_symbol_segment != undefined_section
                   && ! bfd_is_com_section (sub_symbol_segment)
@@ -1294,6 +1289,13 @@ write_relocs (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
        as_bad_where (fixp->fx_file, fixp->fx_line,
                      _("internal error: fixup not contained within frag"));
 
+#ifdef obj_fixup_removed_symbol
+      if (fixp->fx_addsy && symbol_removed_p (fixp->fx_addsy))
+       obj_fixup_removed_symbol (&fixp->fx_addsy);
+      if (fixp->fx_subsy && symbol_removed_p (fixp->fx_subsy))
+       obj_fixup_removed_symbol (&fixp->fx_subsy);
+#endif
+
 #ifndef RELOC_EXPANSION_POSSIBLE
       *reloc = tc_gen_reloc (sec, fixp);
 #else
@@ -1313,7 +1315,34 @@ write_relocs (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
                }
              r = r->next;
            }
-         relocs[n++] = *reloc;
+#ifdef GAS_SORT_RELOCS
+         if (n != 0 && (*reloc)->address < relocs[n - 1]->address)
+           {
+             size_t lo = 0;
+             size_t hi = n - 1;
+             bfd_vma look = (*reloc)->address;
+             while (lo < hi)
+               {
+                 size_t mid = (lo + hi) / 2;
+                 if (relocs[mid]->address > look)
+                   hi = mid;
+                 else
+                   {
+                     lo = mid + 1;
+                     if (relocs[mid]->address == look)
+                       break;
+                   }
+               }
+             while (lo < hi && relocs[lo]->address == look)
+               lo++;
+             memmove (relocs + lo + 1, relocs + lo,
+                      (n - lo) * sizeof (*relocs));
+             n++;
+             relocs[lo] = *reloc;
+           }
+         else
+#endif
+           relocs[n++] = *reloc;
          install_reloc (sec, *reloc, fixp->fx_frag,
                         fixp->fx_file, fixp->fx_line);
 #ifndef RELOC_EXPANSION_POSSIBLE
@@ -1760,9 +1789,10 @@ set_symtab (void)
      two.  Generate unused section symbols only if needed.  */
   nsyms = 0;
   for (symp = symbol_rootP; symp; symp = symbol_next (symp))
-    if (bfd_keep_unused_section_symbols (stdoutput)
-       || !symbol_section_p (symp)
-       || symbol_used_in_reloc_p (symp))
+    if (!symbol_removed_p (symp)
+       && (bfd_keep_unused_section_symbols (stdoutput)
+           || !symbol_section_p (symp)
+           || symbol_used_in_reloc_p (symp)))
       nsyms++;
 
   if (nsyms)
@@ -1773,9 +1803,10 @@ set_symtab (void)
       asympp = (asymbol **) bfd_alloc (stdoutput, amt);
       symp = symbol_rootP;
       for (i = 0; i < nsyms; symp = symbol_next (symp))
-       if (bfd_keep_unused_section_symbols (stdoutput)
-           || !symbol_section_p (symp)
-           || symbol_used_in_reloc_p (symp))
+       if (!symbol_removed_p (symp)
+           && (bfd_keep_unused_section_symbols (stdoutput)
+               || !symbol_section_p (symp)
+               || symbol_used_in_reloc_p (symp)))
          {
            asympp[i] = symbol_get_bfdsym (symp);
            if (asympp[i]->flags != BSF_SECTION_SYM
@@ -3181,7 +3212,7 @@ print_fixup (fixS *fixp)
 {
   indent_level = 1;
   fprintf (stderr, "fix ");
-  fprintf_vma (stderr, (bfd_vma)((bfd_hostptr_t) fixp));
+  fprintf_vma (stderr, (bfd_vma) (uintptr_t) fixp);
   fprintf (stderr, " %s:%d",fixp->fx_file, fixp->fx_line);
   if (fixp->fx_pcrel)
     fprintf (stderr, " pcrel");
@@ -3192,7 +3223,7 @@ print_fixup (fixS *fixp)
   if (fixp->fx_done)
     fprintf (stderr, " done");
   fprintf (stderr, "\n    size=%d frag=", fixp->fx_size);
-  fprintf_vma (stderr, (bfd_vma) ((bfd_hostptr_t) fixp->fx_frag));
+  fprintf_vma (stderr, (bfd_vma) (uintptr_t) fixp->fx_frag);
   fprintf (stderr, " where=%ld offset=%lx addnumber=%lx",
           (long) fixp->fx_where,
           (unsigned long) fixp->fx_offset,