gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / bfd / xcofflink.c
index 06ac544e0c90762fb866a05db9828f05c1f3848f..4497be25291b7c278c76f520f7df9f3fe40cf11b 100644 (file)
@@ -1,5 +1,5 @@
 /* POWER/PowerPC XCOFF linker support.
-   Copyright (C) 1995-2015 Free Software Foundation, Inc.
+   Copyright (C) 1995-2020 Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@cygnus.com>, Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -28,6 +28,7 @@
 #include "libcoff.h"
 #include "libxcoff.h"
 #include "libiberty.h"
+#include "xcofflink.h"
 
 /* This file holds the XCOFF linker code.  */
 
@@ -213,7 +214,7 @@ xcoff_get_section_contents (bfd *abfd, asection *sec)
 {
   if (coff_section_data (abfd, sec) == NULL)
     {
-      bfd_size_type amt = sizeof (struct coff_section_tdata);
+      size_t amt = sizeof (struct coff_section_tdata);
 
       sec->used_by_bfd = bfd_zalloc (abfd, amt);
       if (sec->used_by_bfd == NULL)
@@ -226,8 +227,7 @@ xcoff_get_section_contents (bfd *abfd, asection *sec)
 
       if (! bfd_malloc_and_get_section (abfd, sec, &contents))
        {
-         if (contents != NULL)
-           free (contents);
+         free (contents);
          return FALSE;
        }
       coff_section_data (abfd, sec)->contents = contents;
@@ -592,7 +592,7 @@ struct bfd_link_hash_table *
 _bfd_xcoff_bfd_link_hash_table_create (bfd *abfd)
 {
   struct xcoff_link_hash_table *ret;
-  bfd_size_type amt = sizeof (* ret);
+  size_t amt = sizeof (* ret);
 
   ret = bfd_zmalloc (amt);
   if (ret == NULL)
@@ -763,7 +763,7 @@ xcoff_set_import_path (struct bfd_link_info *info,
       if (*pp == NULL)
        {
          struct xcoff_import_file *n;
-         bfd_size_type amt = sizeof (* n);
+         size_t amt = sizeof (*n);
 
          n = bfd_alloc (info->output_bfd, amt);
          if (n == NULL)
@@ -828,9 +828,9 @@ xcoff_link_add_dynamic_symbols (bfd *abfd, struct bfd_link_info *info)
      output file.  */
    if (info->output_bfd->xvec != abfd->xvec)
     {
-      (*_bfd_error_handler)
-       (_("%s: XCOFF shared object when not producing XCOFF output"),
-        bfd_get_filename (abfd));
+      _bfd_error_handler
+       (_("%pB: XCOFF shared object when not producing XCOFF output"),
+        abfd);
       bfd_set_error (bfd_error_invalid_operation);
       return FALSE;
     }
@@ -849,9 +849,9 @@ xcoff_link_add_dynamic_symbols (bfd *abfd, struct bfd_link_info *info)
   lsec = bfd_get_section_by_name (abfd, ".loader");
   if (lsec == NULL)
     {
-      (*_bfd_error_handler)
-       (_("%s: dynamic object with no .loader section"),
-        bfd_get_filename (abfd));
+      _bfd_error_handler
+       (_("%pB: dynamic object with no .loader section"),
+        abfd);
       bfd_set_error (bfd_error_no_symbols);
       return FALSE;
     }
@@ -997,9 +997,9 @@ xcoff_link_add_dynamic_symbols (bfd *abfd, struct bfd_link_info *info)
     return FALSE;
   n->next = NULL;
 
-  if (abfd->my_archive == NULL)
+  if (abfd->my_archive == NULL || bfd_is_thin_archive (abfd->my_archive))
     {
-      if (!bfd_xcoff_split_import_path (abfd, abfd->filename,
+      if (!bfd_xcoff_split_import_path (abfd, bfd_get_filename (abfd),
                                        &n->path, &n->file))
        return FALSE;
       n->member = "";
@@ -1012,7 +1012,8 @@ xcoff_link_add_dynamic_symbols (bfd *abfd, struct bfd_link_info *info)
       if (!archive_info->impfile)
        {
          if (!bfd_xcoff_split_import_path (archive_info->archive,
-                                           archive_info->archive->filename,
+                                           bfd_get_filename (archive_info
+                                                             ->archive),
                                            &archive_info->imppath,
                                            &archive_info->impfile))
            return FALSE;
@@ -1050,7 +1051,7 @@ xcoff_link_create_extra_sections (bfd * abfd, struct bfd_link_info *info)
         won't work if we're producing an XCOFF output file with no
         XCOFF input files.  FIXME.  */
 
-      if (!info->relocatable
+      if (!bfd_link_relocatable (info)
          && xcoff_hash_table (info)->loader_section == NULL)
        {
          asection *lsec;
@@ -1316,14 +1317,17 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
        {
          bfd_byte *linenos;
 
-         amt = linesz * o->lineno_count;
-         linenos = bfd_malloc (amt);
+         if (bfd_seek (abfd, o->line_filepos, SEEK_SET) != 0)
+           goto error_return;
+         if (_bfd_mul_overflow (linesz, o->lineno_count, &amt))
+           {
+             bfd_set_error (bfd_error_file_too_big);
+             goto error_return;
+           }
+         linenos = _bfd_malloc_and_read (abfd, amt, amt);
          if (linenos == NULL)
            goto error_return;
          reloc_info[o->target_index].linenos = linenos;
-         if (bfd_seek (abfd, o->line_filepos, SEEK_SET) != 0
-             || bfd_bread (linenos, amt, abfd) != amt)
-           goto error_return;
        }
     }
 
@@ -1366,7 +1370,7 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
          if (csect != NULL)
            *csect_cache = csect;
          else if (first_csect == NULL
-                   || sym.n_sclass == C_FILE || sym.n_sclass == C_DWARF)
+                  || sym.n_sclass == C_FILE || sym.n_sclass == C_DWARF)
            *csect_cache = coff_section_from_bfd_index (abfd, sym.n_scnum);
          else
            *csect_cache = NULL;
@@ -1408,8 +1412,9 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
              enclosing = xcoff_section_data (abfd, csect)->enclosing;
              if (enclosing == NULL)
                {
-                 (*_bfd_error_handler)
-                   (_("%B: `%s' has line numbers but no enclosing section"),
+                 _bfd_error_handler
+                   /* xgettext:c-format */
+                   (_("%pB: `%s' has line numbers but no enclosing section"),
                     abfd, name);
                  bfd_set_error (bfd_error_bad_value);
                  goto error_return;
@@ -1460,8 +1465,9 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
       /* Pick up the csect auxiliary information.  */
       if (sym.n_numaux == 0)
        {
-         (*_bfd_error_handler)
-           (_("%B: class %d symbol `%s' has no aux entries"),
+         _bfd_error_handler
+           /* xgettext:c-format */
+           (_("%pB: class %d symbol `%s' has no aux entries"),
             abfd, sym.n_sclass, name);
          bfd_set_error (bfd_error_bad_value);
          goto error_return;
@@ -1482,8 +1488,9 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
       switch (smtyp)
        {
        default:
-         (*_bfd_error_handler)
-           (_("%B: symbol `%s' has unrecognized csect type %d"),
+         _bfd_error_handler
+           /* xgettext:c-format */
+           (_("%pB: symbol `%s' has unrecognized csect type %d"),
             abfd, name, smtyp);
          bfd_set_error (bfd_error_bad_value);
          goto error_return;
@@ -1494,10 +1501,12 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
              || sym.n_scnum != N_UNDEF
              || aux.x_csect.x_scnlen.l != 0)
            {
-             (*_bfd_error_handler)
-               (_("%B: bad XTY_ER symbol `%s': class %d scnum %d scnlen %d"),
+             _bfd_error_handler
+               /* xgettext:c-format */
+               (_("%pB: bad XTY_ER symbol `%s': class %d scnum %d "
+                  "scnlen %" PRId64),
                 abfd, name, sym.n_sclass, sym.n_scnum,
-                aux.x_csect.x_scnlen.l);
+                (int64_t) aux.x_csect.x_scnlen.l);
              bfd_set_error (bfd_error_bad_value);
              goto error_return;
            }
@@ -1523,9 +1532,10 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
              if (sym.n_sclass != C_HIDEXT
                  || aux.x_csect.x_scnlen.l != 0)
                {
-                 (*_bfd_error_handler)
-                   (_("%B: XMC_TC0 symbol `%s' is class %d scnlen %d"),
-                    abfd, name, sym.n_sclass, aux.x_csect.x_scnlen.l);
+                 _bfd_error_handler
+                   /* xgettext:c-format */
+                   (_("%pB: XMC_TC0 symbol `%s' is class %d scnlen %" PRId64),
+                    abfd, name, sym.n_sclass, (int64_t) aux.x_csect.x_scnlen.l);
                  bfd_set_error (bfd_error_bad_value);
                  goto error_return;
                }
@@ -1669,8 +1679,9 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
                    || ((bfd_vma) sym.n_value + aux.x_csect.x_scnlen.l
                        > enclosing->vma + enclosing->size)))
              {
-               (*_bfd_error_handler)
-                 (_("%B: csect `%s' not in enclosing section"),
+               _bfd_error_handler
+                 /* xgettext:c-format */
+                 (_("%pB: csect `%s' not in enclosing section"),
                   abfd, name);
                bfd_set_error (bfd_error_bad_value);
                goto error_return;
@@ -1776,13 +1787,14 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
              }
            if (bad)
              {
-               (*_bfd_error_handler)
-                 (_("%B: misplaced XTY_LD `%s'"),
+               _bfd_error_handler
+                 /* xgettext:c-format */
+                 (_("%pB: misplaced XTY_LD `%s'"),
                   abfd, name);
                bfd_set_error (bfd_error_bad_value);
                goto error_return;
              }
-           csect = section;
+           csect = section;
            value = sym.n_value - csect->vma;
          }
          break;
@@ -1874,7 +1886,7 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
 
       if (EXTERN_SYM_P (sym.n_sclass))
        {
-         bfd_boolean copy;
+         bfd_boolean copy, ok;
          flagword flags;
 
          BFD_ASSERT (section != NULL);
@@ -1919,7 +1931,7 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
             We also have to handle the case of statically linking a
             shared object, which will cause symbol redefinitions,
             although this is an easier case to detect.  */
-         else if (info->output_bfd->xvec == abfd->xvec)
+         else if (info->output_bfd->xvec == abfd->xvec)
            {
              if (! bfd_is_und_section (section))
                *sym_hash = xcoff_link_hash_lookup (xcoff_hash_table (info),
@@ -1992,9 +2004,10 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
                     sure the XCOFF linker is wholly prepared to
                     handle them, and that would only be a warning,
                     not an error.  */
-                 if (! ((*info->callbacks->multiple_definition)
-                        (info, &(*sym_hash)->root, NULL, NULL, (bfd_vma) 0)))
-                   goto error_return;
+                 (*info->callbacks->multiple_definition) (info,
+                                                          &(*sym_hash)->root,
+                                                          NULL, NULL,
+                                                          (bfd_vma) 0);
                  /* Try not to give this error too many times.  */
                  (*sym_hash)->flags &= ~XCOFF_MULTIPLY_DEFINED;
                }
@@ -2013,12 +2026,12 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
          BFD_ASSERT (last_real->next == first_csect);
          last_real->next = NULL;
          flags = (sym.n_sclass == C_EXT ? BSF_GLOBAL : BSF_WEAK);
-         if (! (_bfd_generic_link_add_one_symbol
-                (info, abfd, name, flags, section, value,
-                 NULL, copy, TRUE,
-                 (struct bfd_link_hash_entry **) sym_hash)))
-           goto error_return;
+         ok = (_bfd_generic_link_add_one_symbol
+               (info, abfd, name, flags, section, value, NULL, copy, TRUE,
+                (struct bfd_link_hash_entry **) sym_hash));
          last_real->next = first_csect;
+         if (!ok)
+           goto error_return;
 
          if (smtyp == XTY_CM)
            {
@@ -2031,7 +2044,7 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
                  = csect->alignment_power;
            }
 
-         if (info->output_bfd->xvec == abfd->xvec)
+         if (info->output_bfd->xvec == abfd->xvec)
            {
              int flag;
 
@@ -2071,14 +2084,14 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
   for (o = abfd->sections; o != first_csect; o = o->next)
     {
       /* Debugging sections have no csects.  */
-      if (bfd_get_section_flags (abfd, o) & SEC_DEBUGGING)
-        continue;
+      if (bfd_section_flags (o) & SEC_DEBUGGING)
+       continue;
 
       /* Reset the section size and the line number count, since the
         data is now attached to the csects.  Don't reset the size of
         the .debug section, since we need to read it below in
         bfd_xcoff_size_dynamic_sections.  */
-      if (strcmp (bfd_get_section_name (abfd, o), ".debug") != 0)
+      if (strcmp (bfd_section_name (o), ".debug") != 0)
        o->size = 0;
       o->lineno_count = 0;
 
@@ -2095,9 +2108,10 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
            {
              if (*rel_csect == NULL)
                {
-                 (*_bfd_error_handler)
-                   (_("%B: reloc %s:%d not in csect"),
-                    abfd, o->name, i);
+                 _bfd_error_handler
+                   /* xgettext:c-format */
+                   (_("%pB: reloc %s:%" PRId64 " not in csect"),
+                    abfd, o->name, (int64_t) i);
                  bfd_set_error (bfd_error_bad_value);
                  goto error_return;
                }
@@ -2105,7 +2119,7 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
              /* We identify all function symbols that are the target
                 of a relocation, so that we can create glue code for
                 functions imported from dynamic objects.  */
-             if (info->output_bfd->xvec == abfd->xvec
+             if (info->output_bfd->xvec == abfd->xvec
                  && *rel_csect != bfd_und_section_ptr
                  && obj_xcoff_sym_hashes (abfd)[rel->r_symndx] != NULL)
                {
@@ -2164,7 +2178,6 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
          /* If we are not keeping memory, free the reloc information.  */
          if (! info->keep_memory
              && coff_section_data (abfd, o) != NULL
-             && coff_section_data (abfd, o)->relocs != NULL
              && ! coff_section_data (abfd, o)->keep_relocs)
            {
              free (coff_section_data (abfd, o)->relocs);
@@ -2174,11 +2187,8 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
 
       /* Free up the line numbers.  FIXME: We could cache these
         somewhere for the final link, to avoid reading them again.  */
-      if (reloc_info[o->target_index].linenos != NULL)
-       {
-         free (reloc_info[o->target_index].linenos);
-         reloc_info[o->target_index].linenos = NULL;
-       }
+      free (reloc_info[o->target_index].linenos);
+      reloc_info[o->target_index].linenos = NULL;
     }
 
   free (reloc_info);
@@ -2192,10 +2202,8 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
     {
       for (o = abfd->sections; o != NULL; o = o->next)
        {
-         if (reloc_info[o->target_index].csects != NULL)
-           free (reloc_info[o->target_index].csects);
-         if (reloc_info[o->target_index].linenos != NULL)
-           free (reloc_info[o->target_index].linenos);
+         free (reloc_info[o->target_index].csects);
+         free (reloc_info[o->target_index].linenos);
        }
       free (reloc_info);
     }
@@ -2291,7 +2299,7 @@ xcoff_link_check_dynamic_ar_symbols (bfd *abfd,
        {
          if (!(*info->callbacks
                ->add_archive_element) (info, abfd, name, subsbfd))
-           return FALSE;
+           continue;
          *pneeded = TRUE;
          return TRUE;
        }
@@ -2357,13 +2365,13 @@ xcoff_link_check_ar_symbols (bfd *abfd,
             undefined references in shared objects.  */
          if (h != NULL
              && h->type == bfd_link_hash_undefined
-             && (info->output_bfd->xvec != abfd->xvec
+             && (info->output_bfd->xvec != abfd->xvec
                  || (((struct xcoff_link_hash_entry *) h)->flags
                      & XCOFF_DEF_DYNAMIC) == 0))
            {
              if (!(*info->callbacks
                    ->add_archive_element) (info, abfd, name, subsbfd))
-               return FALSE;
+               continue;
              *pneeded = TRUE;
              return TRUE;
            }
@@ -2509,7 +2517,7 @@ xcoff_find_function (struct bfd_link_info *info,
     {
       char *fnname;
       struct xcoff_link_hash_entry *hfn;
-      bfd_size_type amt;
+      size_t amt;
 
       amt = strlen (h->root.root.string) + 2;
       fnname = bfd_malloc (amt);
@@ -2677,10 +2685,7 @@ xcoff_need_ldrel_p (struct bfd_link_info *info, struct internal_reloc *rel,
     case R_RLA:
       /* Absolute relocations against absolute symbols can be
         resolved statically.  */
-      if (h != NULL
-         && (h->root.type == bfd_link_hash_defined
-             || h->root.type == bfd_link_hash_defweak)
-         && bfd_is_abs_section (h->root.u.def.section))
+      if (h != NULL && bfd_is_abs_symbol (&h->root))
        return FALSE;
 
       return TRUE;
@@ -2700,7 +2705,7 @@ xcoff_mark_symbol (struct bfd_link_info *info, struct xcoff_link_hash_entry *h)
 
   /* If we're marking an undefined symbol, try find some way of
      defining it.  */
-  if (!info->relocatable
+  if (!bfd_link_relocatable (info)
       && (h->flags & XCOFF_IMPORT) == 0
       && (h->flags & XCOFF_DEF_REGULAR) == 0
       && (h->root.type == bfd_link_hash_undefined
@@ -2973,7 +2978,6 @@ xcoff_mark (struct bfd_link_info *info, asection *sec)
 
          if (! info->keep_memory
              && coff_section_data (sec->owner, sec) != NULL
-             && coff_section_data (sec->owner, sec)->relocs != NULL
              && ! coff_section_data (sec->owner, sec)->keep_relocs)
            {
              free (coff_section_data (sec->owner, sec)->relocs);
@@ -3012,7 +3016,7 @@ xcoff_sweep (struct bfd_link_info *info)
                  || o == xcoff_hash_table (info)->loader_section
                  || o == xcoff_hash_table (info)->linkage_section
                  || o == xcoff_hash_table (info)->descriptor_section
-                  || (bfd_get_section_flags (sub, o) & SEC_DEBUGGING)
+                 || (bfd_section_flags (o) & SEC_DEBUGGING)
                  || strcmp (o->name, ".debug") == 0)
                o->flags |= SEC_MARK;
              else
@@ -3036,7 +3040,7 @@ bfd_xcoff_link_record_set (bfd *output_bfd,
 {
   struct xcoff_link_hash_entry *h = (struct xcoff_link_hash_entry *) harg;
   struct xcoff_link_size_list *n;
-  bfd_size_type amt;
+  size_t amt;
 
   if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
     return TRUE;
@@ -3115,13 +3119,10 @@ bfd_xcoff_import_symbol (bfd *output_bfd,
   if (val != (bfd_vma) -1)
     {
       if (h->root.type == bfd_link_hash_defined
-         && (! bfd_is_abs_section (h->root.u.def.section)
+         && (!bfd_is_abs_symbol (&h->root)
              || h->root.u.def.value != val))
-       {
-         if (! ((*info->callbacks->multiple_definition)
-                (info, &h->root, output_bfd, bfd_abs_section_ptr, val)))
-           return FALSE;
-       }
+       (*info->callbacks->multiple_definition) (info, &h->root, output_bfd,
+                                                bfd_abs_section_ptr, val);
 
       h->root.type = bfd_link_hash_defined;
       h->root.u.def.section = bfd_abs_section_ptr;
@@ -3189,7 +3190,7 @@ bfd_xcoff_link_count_reloc (bfd *output_bfd,
                                     FALSE));
   if (h == NULL)
     {
-      (*_bfd_error_handler) (_("%s: no such symbol"), name);
+      _bfd_error_handler (_("%s: no such symbol"), name);
       bfd_set_error (bfd_error_no_symbols);
       return FALSE;
     }
@@ -3287,13 +3288,13 @@ static bfd_boolean
 xcoff_build_ldsym (struct xcoff_loader_info *ldinfo,
                   struct xcoff_link_hash_entry *h)
 {
-  bfd_size_type amt;
+  size_t amt;
 
   /* Warn if this symbol is exported but not defined.  */
   if ((h->flags & XCOFF_EXPORT) != 0
       && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
     {
-      (*_bfd_error_handler)
+      _bfd_error_handler
        (_("warning: attempt to export undefined symbol `%s'"),
         h->root.root.string);
       return TRUE;
@@ -3635,7 +3636,7 @@ bfd_xcoff_size_dynamic_sections (bfd *output_bfd,
   bfd *sub;
   struct bfd_strtab_hash *debug_strtab;
   bfd_byte *debug_contents = NULL;
-  bfd_size_type amt;
+  size_t amt;
 
   if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
     {
@@ -3672,7 +3673,7 @@ bfd_xcoff_size_dynamic_sections (bfd *output_bfd,
                                     "__rtinit", FALSE, FALSE, TRUE);
       if (hsym == NULL)
        {
-         (*_bfd_error_handler)
+         _bfd_error_handler
            (_("error: undefined symbol __rtinit"));
          return FALSE;
        }
@@ -3714,7 +3715,7 @@ bfd_xcoff_size_dynamic_sections (bfd *output_bfd,
     }
 
   /* Garbage collect unused sections.  */
-  if (info->relocatable || !gc)
+  if (bfd_link_relocatable (info) || !gc)
     {
       gc = FALSE;
       xcoff_hash_table (info)->gc = FALSE;
@@ -3962,10 +3963,8 @@ bfd_xcoff_size_dynamic_sections (bfd *output_bfd,
   return TRUE;
 
  error_return:
-  if (ldinfo.strings != NULL)
-    free (ldinfo.strings);
-  if (debug_contents != NULL)
-    free (debug_contents);
+  free (ldinfo.strings);
+  free (debug_contents);
   return FALSE;
 }
 
@@ -4051,8 +4050,9 @@ xcoff_create_ldrel (bfd *output_bfd, struct xcoff_final_link_info *flinfo,
        ldrel.l_symndx = 2;
       else
        {
-         (*_bfd_error_handler)
-           (_("%B: loader reloc in unrecognized section `%s'"),
+         _bfd_error_handler
+           /* xgettext:c-format */
+           (_("%pB: loader reloc in unrecognized section `%s'"),
             reference_bfd, secname);
          bfd_set_error (bfd_error_nonrepresentable_section);
          return FALSE;
@@ -4062,8 +4062,9 @@ xcoff_create_ldrel (bfd *output_bfd, struct xcoff_final_link_info *flinfo,
     {
       if (h->ldindx < 0)
        {
-         (*_bfd_error_handler)
-           (_("%B: `%s' in loader reloc but not loader sym"),
+         _bfd_error_handler
+           /* xgettext:c-format */
+           (_("%pB: `%s' in loader reloc but not loader sym"),
             reference_bfd, h->root.root.string);
          bfd_set_error (bfd_error_bad_value);
          return FALSE;
@@ -4078,8 +4079,9 @@ xcoff_create_ldrel (bfd *output_bfd, struct xcoff_final_link_info *flinfo,
   if (xcoff_hash_table (flinfo->info)->textro
       && strcmp (output_section->name, ".text") == 0)
     {
-      (*_bfd_error_handler)
-       (_("%B: loader reloc in read-only section %A"),
+      _bfd_error_handler
+       /* xgettext:c-format */
+       (_("%pB: loader reloc in read-only section %pA"),
         reference_bfd, output_section);
       bfd_set_error (bfd_error_invalid_operation);
       return FALSE;
@@ -4145,7 +4147,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
   if (! flinfo->info->keep_memory)
     copy = TRUE;
   hash = TRUE;
-  if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
+  if (flinfo->info->traditional_format)
     hash = FALSE;
 
   if (! _bfd_coff_get_external_symbols (input_bfd))
@@ -4727,8 +4729,8 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
       flinfo->last_file.n_value = output_index;
       bfd_coff_swap_sym_out (output_bfd, (void *) &flinfo->last_file,
                             (void *) (flinfo->outsyms
-                                   + ((flinfo->last_file_index - syment_base)
-                                      * osymesz)));
+                                   + ((flinfo->last_file_index - syment_base)
+                                      * osymesz)));
     }
 
   /* Write the modified symbols to the output file.  */
@@ -4774,7 +4776,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
        {
          bfd_size_type sz = o->rawsize ? o->rawsize : o->size;
          if (!bfd_get_section_contents (input_bfd, o, flinfo->contents, 0, sz))
-           return FALSE;
+           goto err_out;
          contents = flinfo->contents;
        }
 
@@ -4796,7 +4798,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
                              (flinfo->section_info[target_index].relocs
                               + o->output_section->reloc_count)));
          if (internal_relocs == NULL)
-           return FALSE;
+           goto err_out;
 
          /* Call processor specific code to relocate the section
             contents.  */
@@ -4806,7 +4808,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
                                           internal_relocs,
                                           flinfo->internal_syms,
                                           xcoff_data (input_bfd)->csects))
-           return FALSE;
+           goto err_out;
 
          offset = o->output_section->vma + o->output_offset - o->vma;
          irel = internal_relocs;
@@ -4853,12 +4855,12 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
                        {
                          struct xcoff_toc_rel_hash *n;
                          struct xcoff_link_section_info *si;
-                         bfd_size_type amt;
+                         size_t amt;
 
                          amt = sizeof (* n);
                          n = bfd_alloc (flinfo->output_bfd, amt);
                          if (n == NULL)
-                           return FALSE;
+                           goto err_out;
                          si = flinfo->section_info + target_index;
                          n->next = si->toc_rel_hashes;
                          n->h = h;
@@ -4934,25 +4936,24 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
                             this case, but I don't think it's worth it.  */
                          is = flinfo->internal_syms + r_symndx;
 
-                          if (is->n_sclass != C_DWARF)
-                            {
-                              name = (_bfd_coff_internal_syment_name
-                                      (input_bfd, is, buf));
+                         if (is->n_sclass != C_DWARF)
+                           {
+                             name = (_bfd_coff_internal_syment_name
+                                     (input_bfd, is, buf));
 
-                              if (name == NULL)
-                                return FALSE;
+                             if (name == NULL)
+                               goto err_out;
 
-                              if (!(*flinfo->info->callbacks->unattached_reloc)
-                                  (flinfo->info, name, input_bfd, o,
-                                   irel->r_vaddr))
-                                return FALSE;
-                            }
+                             (*flinfo->info->callbacks->unattached_reloc)
+                               (flinfo->info, name,
+                                input_bfd, o, irel->r_vaddr);
+                           }
                        }
                    }
                }
 
              if ((o->flags & SEC_DEBUGGING) == 0
-                  && xcoff_need_ldrel_p (flinfo->info, irel, h))
+                 && xcoff_need_ldrel_p (flinfo->info, irel, h))
                {
                  asection *sec;
 
@@ -4965,7 +4966,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
                  if (!xcoff_create_ldrel (output_bfd, flinfo,
                                           o->output_section, input_bfd,
                                           irel, sec, h))
-                   return FALSE;
+                   goto err_out;
                }
            }
 
@@ -4976,7 +4977,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
       if (! bfd_set_section_contents (output_bfd, o->output_section,
                                      contents, (file_ptr) o->output_offset,
                                      o->size))
-       return FALSE;
+       goto err_out;
     }
 
   obj_coff_keep_syms (input_bfd) = keep_syms;
@@ -4988,6 +4989,10 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
     }
 
   return TRUE;
+
+ err_out:
+  obj_coff_keep_syms (input_bfd) = keep_syms;
+  return FALSE;
 }
 
 #undef N_TMASK
@@ -5103,10 +5108,10 @@ xcoff_find_tc0 (bfd *output_bfd, struct xcoff_final_link_info *flinfo)
       /* Make sure that the start of the TOC is also within range.  */
       if (best_address > toc_start + 0x8000)
        {
-         (*_bfd_error_handler)
-           (_("TOC overflow: 0x%lx > 0x10000; try -mminimal-toc "
+         _bfd_error_handler
+           (_("TOC overflow: %#" PRIx64 " > 0x10000; try -mminimal-toc "
               "when compiling"),
-            (unsigned long) (toc_end - toc_start));
+            (uint64_t) (toc_end - toc_start));
          bfd_set_error (bfd_error_file_too_big);
          return FALSE;
        }
@@ -5118,7 +5123,8 @@ xcoff_find_tc0 (bfd *output_bfd, struct xcoff_final_link_info *flinfo)
   xcoff_data (output_bfd)->sntoc = section_index;
 
   /* Fill out the TC0 symbol.  */
-  if (!bfd_xcoff_put_symbol_name (output_bfd, flinfo->strtab, &irsym, "TOC"))
+  if (!bfd_xcoff_put_symbol_name (output_bfd, flinfo->info, flinfo->strtab,
+                                 &irsym, "TOC"))
     return FALSE;
   irsym.n_value = best_address;
   irsym.n_scnum = section_index;
@@ -5301,7 +5307,7 @@ xcoff_write_global_symbol (struct bfd_hash_entry *bh, void * inf)
        tocoff += h->descriptor->u.toc_offset;
 
       /* The first instruction in the glink code needs to be
-        cooked to to hold the correct offset in the toc.  The
+        cooked to hold the correct offset in the toc.  The
         rest are just output raw.  */
       bfd_put_32 (output_bfd,
                  bfd_xcoff_glink_code(output_bfd, 0) | (tocoff & 0xffff), p);
@@ -5383,7 +5389,8 @@ xcoff_write_global_symbol (struct bfd_hash_entry *bh, void * inf)
         the reloc.  */
       if (flinfo->info->strip != strip_all)
        {
-         result = bfd_xcoff_put_symbol_name (output_bfd, flinfo->strtab,
+         result = bfd_xcoff_put_symbol_name (output_bfd, flinfo->info,
+                                             flinfo->strtab,
                                              &irsym, h->root.root.string);
          if (!result)
            return FALSE;
@@ -5557,8 +5564,8 @@ xcoff_write_global_symbol (struct bfd_hash_entry *bh, void * inf)
 
   h->indx = obj_raw_syment_count (output_bfd);
 
-  result = bfd_xcoff_put_symbol_name (output_bfd, flinfo->strtab, &isym,
-                                     h->root.root.string);
+  result = bfd_xcoff_put_symbol_name (output_bfd, flinfo->info, flinfo->strtab,
+                                     &isym, h->root.root.string);
   if (!result)
     return FALSE;
 
@@ -5578,10 +5585,10 @@ xcoff_write_global_symbol (struct bfd_hash_entry *bh, void * inf)
            || h->root.type == bfd_link_hash_defweak)
           && h->smclas == XMC_XO)
     {
-      BFD_ASSERT (bfd_is_abs_section (h->root.u.def.section));
+      BFD_ASSERT (bfd_is_abs_symbol (&h->root));
       isym.n_value = h->root.u.def.value;
       isym.n_scnum = N_UNDEF;
-      if (h->root.type == bfd_link_hash_undefweak
+      if (h->root.type == bfd_link_hash_defweak
          && C_WEAKEXT == C_AIX_WEAKEXT)
        isym.n_sclass = C_WEAKEXT;
       else
@@ -5647,7 +5654,7 @@ xcoff_write_global_symbol (struct bfd_hash_entry *bh, void * inf)
       /* We just output an SD symbol.  Now output an LD symbol.  */
       h->indx += 2;
 
-      if (h->root.type == bfd_link_hash_undefweak
+      if (h->root.type == bfd_link_hash_defweak
          && C_WEAKEXT == C_AIX_WEAKEXT)
        isym.n_sclass = C_WEAKEXT;
       else
@@ -5710,9 +5717,8 @@ xcoff_reloc_link_order (bfd *output_bfd,
                                     FALSE, FALSE, TRUE));
   if (h == NULL)
     {
-      if (! ((*flinfo->info->callbacks->unattached_reloc)
-            (flinfo->info, link_order->u.reloc.p->u.name, NULL, NULL, (bfd_vma) 0)))
-       return FALSE;
+      (*flinfo->info->callbacks->unattached_reloc)
+       (flinfo->info, link_order->u.reloc.p->u.name, NULL, NULL, (bfd_vma) 0);
       return TRUE;
     }
 
@@ -5738,7 +5744,7 @@ xcoff_reloc_link_order (bfd *output_bfd,
 
       size = bfd_get_reloc_size (howto);
       buf = bfd_zmalloc (size);
-      if (buf == NULL)
+      if (buf == NULL && size != 0)
        return FALSE;
 
       rstat = _bfd_relocate_contents (howto, output_bfd, addend, buf);
@@ -5750,13 +5756,9 @@ xcoff_reloc_link_order (bfd *output_bfd,
        case bfd_reloc_outofrange:
          abort ();
        case bfd_reloc_overflow:
-         if (! ((*flinfo->info->callbacks->reloc_overflow)
-                (flinfo->info, NULL, link_order->u.reloc.p->u.name,
-                 howto->name, addend, NULL, NULL, (bfd_vma) 0)))
-           {
-             free (buf);
-             return FALSE;
-           }
+         (*flinfo->info->callbacks->reloc_overflow)
+           (flinfo->info, NULL, link_order->u.reloc.p->u.name,
+            howto->name, addend, NULL, NULL, (bfd_vma) 0);
          break;
        }
       ok = bfd_set_section_contents (output_bfd, output_section, (void *) buf,
@@ -5830,7 +5832,7 @@ _bfd_xcoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
   file_ptr pos;
   bfd_size_type amt;
 
-  if (info->shared)
+  if (bfd_link_pic (info))
     abfd->flags |= DYNAMIC;
 
   symesz = bfd_coff_symesz (abfd);
@@ -6195,31 +6197,16 @@ _bfd_xcoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
     }
 
   /* Free up the buffers used by xcoff_link_input_bfd.  */
-  if (flinfo.internal_syms != NULL)
-    {
-      free (flinfo.internal_syms);
-      flinfo.internal_syms = NULL;
-    }
-  if (flinfo.sym_indices != NULL)
-    {
-      free (flinfo.sym_indices);
-      flinfo.sym_indices = NULL;
-    }
-  if (flinfo.linenos != NULL)
-    {
-      free (flinfo.linenos);
-      flinfo.linenos = NULL;
-    }
-  if (flinfo.contents != NULL)
-    {
-      free (flinfo.contents);
-      flinfo.contents = NULL;
-    }
-  if (flinfo.external_relocs != NULL)
-    {
-      free (flinfo.external_relocs);
-      flinfo.external_relocs = NULL;
-    }
+  free (flinfo.internal_syms);
+  flinfo.internal_syms = NULL;
+  free (flinfo.sym_indices);
+  flinfo.sym_indices = NULL;
+  free (flinfo.linenos);
+  flinfo.linenos = NULL;
+  free (flinfo.contents);
+  flinfo.contents = NULL;
+  free (flinfo.external_relocs);
+  flinfo.external_relocs = NULL;
 
   /* The value of the last C_FILE symbol is supposed to be -1.  Write
      it out again.  */
@@ -6238,11 +6225,8 @@ _bfd_xcoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
      input files.  */
   bfd_hash_traverse (&info->hash->table, xcoff_write_global_symbol, &flinfo);
 
-  if (flinfo.outsyms != NULL)
-    {
-      free (flinfo.outsyms);
-      flinfo.outsyms = NULL;
-    }
+  free (flinfo.outsyms);
+  flinfo.outsyms = NULL;
 
   /* Now that we have written out all the global symbols, we know the
      symbol indices to use for relocs against them, and we can finally
@@ -6280,10 +6264,9 @@ _bfd_xcoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
            {
              if ((*rel_hash)->indx < 0)
                {
-                 if (! ((*info->callbacks->unattached_reloc)
-                        (info, (*rel_hash)->root.root.string,
-                         NULL, o, irel->r_vaddr)))
-                   goto error_return;
+                 (*info->callbacks->unattached_reloc)
+                   (info, (*rel_hash)->root.root.string,
+                    NULL, o, irel->r_vaddr);
                  (*rel_hash)->indx = 0;
                }
              irel->r_symndx = (*rel_hash)->indx;
@@ -6296,10 +6279,9 @@ _bfd_xcoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
        {
          if (toc_rel_hash->h->u.toc_indx < 0)
            {
-             if (! ((*info->callbacks->unattached_reloc)
-                    (info, toc_rel_hash->h->root.root.string,
-                     NULL, o, toc_rel_hash->rel->r_vaddr)))
-               goto error_return;
+             (*info->callbacks->unattached_reloc)
+               (info, toc_rel_hash->h->root.root.string,
+                NULL, o, toc_rel_hash->rel->r_vaddr);
              toc_rel_hash->h->u.toc_indx = 0;
            }
          toc_rel_hash->rel->r_symndx = toc_rel_hash->h->u.toc_indx;
@@ -6326,11 +6308,8 @@ _bfd_xcoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
        goto error_return;
     }
 
-  if (external_relocs != NULL)
-    {
-      free (external_relocs);
-      external_relocs = NULL;
-    }
+  free (external_relocs);
+  external_relocs = NULL;
 
   /* Free up the section information.  */
   if (flinfo.section_info != NULL)
@@ -6339,10 +6318,8 @@ _bfd_xcoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
 
       for (i = 0; i < abfd->section_count; i++)
        {
-         if (flinfo.section_info[i].relocs != NULL)
-           free (flinfo.section_info[i].relocs);
-         if (flinfo.section_info[i].rel_hashes != NULL)
-           free (flinfo.section_info[i].rel_hashes);
+         free (flinfo.section_info[i].relocs);
+         free (flinfo.section_info[i].rel_hashes);
        }
       free (flinfo.section_info);
       flinfo.section_info = NULL;
@@ -6411,9 +6388,9 @@ _bfd_xcoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
        goto error_return;
     }
 
-  /* Setting bfd_get_symcount to 0 will cause write_object_contents to
+  /* Setting symcount to 0 will cause write_object_contents to
      not try to write out the symbols.  */
-  bfd_get_symcount (abfd) = 0;
+  abfd->symcount = 0;
 
   return TRUE;
 
@@ -6427,27 +6404,18 @@ _bfd_xcoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
 
       for (i = 0; i < abfd->section_count; i++)
        {
-         if (flinfo.section_info[i].relocs != NULL)
-           free (flinfo.section_info[i].relocs);
-         if (flinfo.section_info[i].rel_hashes != NULL)
-           free (flinfo.section_info[i].rel_hashes);
+         free (flinfo.section_info[i].relocs);
+         free (flinfo.section_info[i].rel_hashes);
        }
       free (flinfo.section_info);
     }
 
-  if (flinfo.internal_syms != NULL)
-    free (flinfo.internal_syms);
-  if (flinfo.sym_indices != NULL)
-    free (flinfo.sym_indices);
-  if (flinfo.outsyms != NULL)
-    free (flinfo.outsyms);
-  if (flinfo.linenos != NULL)
-    free (flinfo.linenos);
-  if (flinfo.contents != NULL)
-    free (flinfo.contents);
-  if (flinfo.external_relocs != NULL)
-    free (flinfo.external_relocs);
-  if (external_relocs != NULL)
-    free (external_relocs);
+  free (flinfo.internal_syms);
+  free (flinfo.sym_indices);
+  free (flinfo.outsyms);
+  free (flinfo.linenos);
+  free (flinfo.contents);
+  free (flinfo.external_relocs);
+  free (external_relocs);
   return FALSE;
 }
This page took 0.047336 seconds and 4 git commands to generate.