]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - bfd/coff-rs6000.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / bfd / coff-rs6000.c
index edff50daaafbb52c76e28307e9768c8fef094b43..a71791e3f9d330678ad391f33199e152ad8f9d31 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD back-end for IBM RS/6000 "XCOFF" files.
-   Copyright (C) 1990-2018 Free Software Foundation, Inc.
+   Copyright (C) 1990-2021 Free Software Foundation, Inc.
    Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
    Archive support from Damon A. Permezel.
    Contributed by IBM Corporation and Cygnus Support.
@@ -38,7 +38,7 @@ extern bfd_boolean _bfd_xcoff_is_local_label_name (bfd *, const char *);
 extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
   (bfd *, bfd_reloc_code_real_type);
 extern bfd_boolean _bfd_xcoff_slurp_armap (bfd *);
-extern const bfd_target *_bfd_xcoff_archive_p (bfd *);
+extern bfd_cleanup _bfd_xcoff_archive_p (bfd *);
 extern void * _bfd_xcoff_read_ar_hdr (bfd *);
 extern bfd *_bfd_xcoff_openr_next_archived_file (bfd *, bfd *);
 extern int _bfd_xcoff_stat_arch_elt (bfd *, struct stat *);
@@ -77,7 +77,7 @@ void xcoff_rtype2howto (arelent *, struct internal_reloc *);
 #define coff_mkobject _bfd_xcoff_mkobject
 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
 #ifdef AIX_CORE
-extern const bfd_target * rs6000coff_core_p (bfd *abfd);
+extern bfd_cleanup rs6000coff_core_p (bfd *abfd);
 extern bfd_boolean rs6000coff_core_file_matches_executable_p
   (bfd *cbfd, bfd *ebfd);
 extern char *rs6000coff_core_file_failing_command (bfd *abfd);
@@ -114,7 +114,6 @@ extern int rs6000coff_core_file_failing_signal (bfd *abfd);
 #define bfd_pe_print_pdata     NULL
 #endif
 
-#include <stdint.h>
 #include "coffcode.h"
 
 /* The main body of code is in coffcode.h.  */
@@ -149,19 +148,15 @@ static bfd_boolean do_pad (bfd *, unsigned int);
 static bfd_boolean do_copy (bfd *, bfd *);
 
 /* Relocation functions */
-static bfd_boolean xcoff_reloc_type_br (XCOFF_RELOC_FUNCTION_ARGS);
-
-static bfd_boolean xcoff_complain_overflow_dont_func
-  (XCOFF_COMPLAIN_FUNCTION_ARGS);
-static bfd_boolean xcoff_complain_overflow_bitfield_func
-  (XCOFF_COMPLAIN_FUNCTION_ARGS);
-static bfd_boolean xcoff_complain_overflow_signed_func
-  (XCOFF_COMPLAIN_FUNCTION_ARGS);
-static bfd_boolean xcoff_complain_overflow_unsigned_func
-  (XCOFF_COMPLAIN_FUNCTION_ARGS);
-
-bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
-  (XCOFF_RELOC_FUNCTION_ARGS) =
+static xcoff_reloc_function xcoff_reloc_type_br;
+
+static xcoff_complain_function xcoff_complain_overflow_dont_func;
+static xcoff_complain_function xcoff_complain_overflow_bitfield_func;
+static xcoff_complain_function xcoff_complain_overflow_signed_func;
+static xcoff_complain_function xcoff_complain_overflow_unsigned_func;
+
+xcoff_reloc_function *const
+xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION] =
 {
   xcoff_reloc_type_pos,         /* R_POS   (0x00) */
   xcoff_reloc_type_neg,         /* R_NEG   (0x01) */
@@ -193,8 +188,8 @@ bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
   xcoff_reloc_type_ba,  /* R_RBRC  (0x1b) */
 };
 
-bfd_boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW])
-  (XCOFF_COMPLAIN_FUNCTION_ARGS) =
+xcoff_complain_function *const
+xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW] =
 {
   xcoff_complain_overflow_dont_func,
   xcoff_complain_overflow_bitfield_func,
@@ -324,7 +319,7 @@ bfd_boolean
 _bfd_xcoff_mkobject (bfd *abfd)
 {
   coff_data_type *coff;
-  bfd_size_type amt = sizeof (struct xcoff_tdata);
+  size_t amt = sizeof (struct xcoff_tdata);
 
   abfd->tdata.xcoff_obj_data = (struct xcoff_tdata *) bfd_zalloc (abfd, amt);
   if (abfd->tdata.xcoff_obj_data == NULL)
@@ -653,7 +648,7 @@ _bfd_xcoff_swap_aux_out (bfd *abfd, void * inp, int type, int in_class,
                ext->x_sym.x_misc.x_lnsz.x_size);
     }
 
-end:
+ end:
   return bfd_coff_auxesz (abfd);
 }
 \f
@@ -1170,20 +1165,6 @@ _bfd_xcoff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
    to take care that we are not generating the new form of archives
    on AIX 4.2 or earlier systems.  */
 
-/* XCOFF archives use this as a magic string.  Note that both strings
-   have the same length.  */
-
-/* Set the magic for archive.  */
-
-bfd_boolean
-bfd_xcoff_ar_archive_set_magic (bfd *abfd ATTRIBUTE_UNUSED,
-                               char *magic ATTRIBUTE_UNUSED)
-{
-  /* Not supported yet.  */
-  return FALSE;
- /* bfd_xcoff_archive_set_magic (abfd, magic); */
-}
-
 /* PR 21786:  The PE/COFF standard does not require NUL termination for any of
    the ASCII fields in the archive headers.  So in order to be able to extract
    numerical values we provide our own versions of strtol and strtoll which
@@ -1215,19 +1196,19 @@ _bfd_strntoll (const char * nptr, int base, unsigned int maxlen)
 }
 
 /* Macro to read an ASCII value stored in an archive header field.  */
-#define GET_VALUE_IN_FIELD(VAR, FIELD)           \
-  do                                             \
-    {                                            \
-      (VAR) = sizeof (VAR) > sizeof (long)       \
-       ? _bfd_strntoll (FIELD, 10, sizeof FIELD) \
-       : _bfd_strntol (FIELD, 10, sizeof FIELD); \
-    }                                            \
+#define GET_VALUE_IN_FIELD(VAR, FIELD, BASE)                   \
+  do                                                           \
+    {                                                          \
+      (VAR) = (sizeof (VAR) > sizeof (long)                    \
+              ? _bfd_strntoll (FIELD, BASE, sizeof FIELD)      \
+              : _bfd_strntol (FIELD, BASE, sizeof FIELD));     \
+    }                                                          \
   while (0)
 
-#define EQ_VALUE_IN_FIELD(VAR, FIELD)                  \
-  (sizeof (VAR) > sizeof (long)                                \
-   ? (VAR) ==_bfd_strntoll (FIELD, 10, sizeof FIELD)   \
-   : (VAR) == _bfd_strntol (FIELD, 10, sizeof FIELD))
+#define EQ_VALUE_IN_FIELD(VAR, FIELD, BASE)                    \
+  (sizeof (VAR) > sizeof (long)                                        \
+   ? (VAR) == _bfd_strntoll (FIELD, BASE, sizeof FIELD)                \
+   : (VAR) == _bfd_strntol (FIELD, BASE, sizeof FIELD))
 
 /* Read in the armap of an XCOFF archive.  */
 
@@ -1244,7 +1225,7 @@ _bfd_xcoff_slurp_armap (bfd *abfd)
 
   if (xcoff_ardata (abfd) == NULL)
     {
-      bfd_has_map (abfd) = FALSE;
+      abfd->has_armap = FALSE;
       return TRUE;
     }
 
@@ -1253,10 +1234,10 @@ _bfd_xcoff_slurp_armap (bfd *abfd)
       /* This is for the old format.  */
       struct xcoff_ar_hdr hdr;
 
-      GET_VALUE_IN_FIELD (off, xcoff_ardata (abfd)->symoff);
+      GET_VALUE_IN_FIELD (off, xcoff_ardata (abfd)->symoff, 10);
       if (off == 0)
        {
-         bfd_has_map (abfd) = FALSE;
+         abfd->has_armap = FALSE;
          return TRUE;
        }
 
@@ -1269,24 +1250,31 @@ _bfd_xcoff_slurp_armap (bfd *abfd)
        return FALSE;
 
       /* Skip the name (normally empty).  */
-      GET_VALUE_IN_FIELD (namlen, hdr.namlen);
+      GET_VALUE_IN_FIELD (namlen, hdr.namlen, 10);
       off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
       if (bfd_seek (abfd, off, SEEK_CUR) != 0)
        return FALSE;
 
-      GET_VALUE_IN_FIELD (sz, hdr.size);
+      GET_VALUE_IN_FIELD (sz, hdr.size, 10);
+      if (sz + 1 < 5)
+       {
+         bfd_set_error (bfd_error_bad_value);
+         return FALSE;
+       }
 
       /* Read in the entire symbol table.  */
-      contents = (bfd_byte *) bfd_alloc (abfd, sz);
+      contents = (bfd_byte *) _bfd_alloc_and_read (abfd, sz + 1, sz);
       if (contents == NULL)
        return FALSE;
-      if (bfd_bread (contents, sz, abfd) != sz)
-       return FALSE;
+
+      /* Ensure strings are NULL terminated so we don't wander off the
+        end of the buffer.  */
+      contents[sz] = 0;
 
       /* The symbol table starts with a four byte count.  */
       c = H_GET_32 (abfd, contents);
 
-      if (c * 4 >= sz)
+      if (c >= sz / 4)
        {
          bfd_set_error (bfd_error_bad_value);
          return FALSE;
@@ -1308,10 +1296,10 @@ _bfd_xcoff_slurp_armap (bfd *abfd)
       /* This is for the new format.  */
       struct xcoff_ar_hdr_big hdr;
 
-      GET_VALUE_IN_FIELD (off, xcoff_ardata_big (abfd)->symoff);
+      GET_VALUE_IN_FIELD (off, xcoff_ardata_big (abfd)->symoff, 10);
       if (off == 0)
        {
-         bfd_has_map (abfd) = FALSE;
+         abfd->has_armap = FALSE;
          return TRUE;
        }
 
@@ -1324,24 +1312,31 @@ _bfd_xcoff_slurp_armap (bfd *abfd)
        return FALSE;
 
       /* Skip the name (normally empty).  */
-      GET_VALUE_IN_FIELD (namlen, hdr.namlen);
+      GET_VALUE_IN_FIELD (namlen, hdr.namlen, 10);
       off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
       if (bfd_seek (abfd, off, SEEK_CUR) != 0)
        return FALSE;
 
-      GET_VALUE_IN_FIELD (sz, hdr.size);
+      GET_VALUE_IN_FIELD (sz, hdr.size, 10);
+      if (sz + 1 < 9)
+       {
+         bfd_set_error (bfd_error_bad_value);
+         return FALSE;
+       }
 
       /* Read in the entire symbol table.  */
-      contents = (bfd_byte *) bfd_alloc (abfd, sz);
+      contents = (bfd_byte *) _bfd_alloc_and_read (abfd, sz + 1, sz);
       if (contents == NULL)
        return FALSE;
-      if (bfd_bread (contents, sz, abfd) != sz)
-       return FALSE;
+
+      /* Ensure strings are NULL terminated so we don't wander off the
+        end of the buffer.  */
+      contents[sz] = 0;
 
       /* The symbol table starts with an eight byte count.  */
       c = H_GET_64 (abfd, contents);
 
-      if (c * 8 >= sz)
+      if (c >= sz / 8)
        {
          bfd_set_error (bfd_error_bad_value);
          return FALSE;
@@ -1374,19 +1369,19 @@ _bfd_xcoff_slurp_armap (bfd *abfd)
     }
 
   bfd_ardata (abfd)->symdef_count = c;
-  bfd_has_map (abfd) = TRUE;
+  abfd->has_armap = TRUE;
 
   return TRUE;
 }
 
 /* See if this is an XCOFF archive.  */
 
-const bfd_target *
+bfd_cleanup
 _bfd_xcoff_archive_p (bfd *abfd)
 {
   struct artdata *tdata_hold;
   char magic[SXCOFFARMAG];
-  bfd_size_type amt = SXCOFFARMAG;
+  size_t amt = SXCOFFARMAG;
 
   if (bfd_bread (magic, amt, abfd) != amt)
     {
@@ -1435,7 +1430,7 @@ _bfd_xcoff_archive_p (bfd *abfd)
        }
 
       GET_VALUE_IN_FIELD (bfd_ardata (abfd)->first_file_filepos,
-                         hdr.firstmemoff);
+                         hdr.firstmemoff, 10);
 
       amt = SIZEOF_AR_FILE_HDR;
       bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
@@ -1482,7 +1477,7 @@ _bfd_xcoff_archive_p (bfd *abfd)
       return NULL;
     }
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 }
 
 /* Read the archive header in an XCOFF archive.  */
@@ -1492,32 +1487,23 @@ _bfd_xcoff_read_ar_hdr (bfd *abfd)
 {
   bfd_size_type namlen;
   struct areltdata *ret;
-  bfd_size_type amt = sizeof (struct areltdata);
-
-  ret = (struct areltdata *) bfd_zmalloc (amt);
-  if (ret == NULL)
-    return NULL;
+  bfd_size_type amt;
 
   if (! xcoff_big_format_p (abfd))
     {
       struct xcoff_ar_hdr hdr;
       struct xcoff_ar_hdr *hdrp;
 
-      if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
-         != SIZEOF_AR_HDR)
-       {
-         free (ret);
-         return NULL;
-       }
+      if (bfd_bread (&hdr, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR)
+       return NULL;
 
-      GET_VALUE_IN_FIELD (namlen, hdr.namlen);
-      amt = SIZEOF_AR_HDR + namlen + 1;
-      hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
-      if (hdrp == NULL)
-       {
-         free (ret);
-         return NULL;
-       }
+      GET_VALUE_IN_FIELD (namlen, hdr.namlen, 10);
+      amt = sizeof (struct areltdata) + SIZEOF_AR_HDR + namlen + 1;
+      ret = (struct areltdata *) bfd_malloc (amt);
+      if (ret == NULL)
+       return ret;
+
+      hdrp = (struct xcoff_ar_hdr *) (ret + 1);
       memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
       if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen)
        {
@@ -1527,7 +1513,7 @@ _bfd_xcoff_read_ar_hdr (bfd *abfd)
       ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
 
       ret->arch_header = (char *) hdrp;
-      GET_VALUE_IN_FIELD (ret->parsed_size, hdr.size);
+      GET_VALUE_IN_FIELD (ret->parsed_size, hdr.size, 10);
       ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
     }
   else
@@ -1535,21 +1521,16 @@ _bfd_xcoff_read_ar_hdr (bfd *abfd)
       struct xcoff_ar_hdr_big hdr;
       struct xcoff_ar_hdr_big *hdrp;
 
-      if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
-         != SIZEOF_AR_HDR_BIG)
-       {
-         free (ret);
-         return NULL;
-       }
+      if (bfd_bread (&hdr, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG)
+       return NULL;
 
-      GET_VALUE_IN_FIELD (namlen, hdr.namlen);
-      amt = SIZEOF_AR_HDR_BIG + namlen + 1;
-      hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
-      if (hdrp == NULL)
-       {
-         free (ret);
-         return NULL;
-       }
+      GET_VALUE_IN_FIELD (namlen, hdr.namlen, 10);
+      amt = sizeof (struct areltdata) + SIZEOF_AR_HDR_BIG + namlen + 1;
+      ret = (struct areltdata *) bfd_malloc (amt);
+      if (ret == NULL)
+       return ret;
+
+      hdrp = (struct xcoff_ar_hdr_big *) (ret + 1);
       memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
       if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen)
        {
@@ -1559,7 +1540,7 @@ _bfd_xcoff_read_ar_hdr (bfd *abfd)
       ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
 
       ret->arch_header = (char *) hdrp;
-      GET_VALUE_IN_FIELD (ret->parsed_size, hdr.size);
+      GET_VALUE_IN_FIELD (ret->parsed_size, hdr.size, 10);
       ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
     }
 
@@ -1588,11 +1569,11 @@ _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file)
       if (last_file == NULL)
        filestart = bfd_ardata (archive)->first_file_filepos;
       else
-       GET_VALUE_IN_FIELD (filestart, arch_xhdr (last_file)->nextoff);
+       GET_VALUE_IN_FIELD (filestart, arch_xhdr (last_file)->nextoff, 10);
 
       if (filestart == 0
-         || EQ_VALUE_IN_FIELD (filestart, xcoff_ardata (archive)->memoff)
-         || EQ_VALUE_IN_FIELD (filestart, xcoff_ardata (archive)->symoff))
+         || EQ_VALUE_IN_FIELD (filestart, xcoff_ardata (archive)->memoff, 10)
+         || EQ_VALUE_IN_FIELD (filestart, xcoff_ardata (archive)->symoff, 10))
        {
          bfd_set_error (bfd_error_no_more_archived_files);
          return NULL;
@@ -1603,11 +1584,11 @@ _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file)
       if (last_file == NULL)
        filestart = bfd_ardata (archive)->first_file_filepos;
       else
-       GET_VALUE_IN_FIELD (filestart, arch_xhdr_big (last_file)->nextoff);
+       GET_VALUE_IN_FIELD (filestart, arch_xhdr_big (last_file)->nextoff, 10);
 
       if (filestart == 0
-         || EQ_VALUE_IN_FIELD (filestart, xcoff_ardata_big (archive)->memoff)
-         || EQ_VALUE_IN_FIELD (filestart, xcoff_ardata_big (archive)->symoff))
+         || EQ_VALUE_IN_FIELD (filestart, xcoff_ardata_big (archive)->memoff, 10)
+         || EQ_VALUE_IN_FIELD (filestart, xcoff_ardata_big (archive)->symoff, 10))
        {
          bfd_set_error (bfd_error_no_more_archived_files);
          return NULL;
@@ -1632,20 +1613,20 @@ _bfd_xcoff_stat_arch_elt (bfd *abfd, struct stat *s)
     {
       struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
 
-      GET_VALUE_IN_FIELD (s->st_mtime, hdrp->date);
-      GET_VALUE_IN_FIELD (s->st_uid, hdrp->uid);
-      GET_VALUE_IN_FIELD (s->st_gid, hdrp->gid);
-      GET_VALUE_IN_FIELD (s->st_mode, hdrp->mode);
+      GET_VALUE_IN_FIELD (s->st_mtime, hdrp->date, 10);
+      GET_VALUE_IN_FIELD (s->st_uid, hdrp->uid, 10);
+      GET_VALUE_IN_FIELD (s->st_gid, hdrp->gid, 10);
+      GET_VALUE_IN_FIELD (s->st_mode, hdrp->mode, 8);
       s->st_size = arch_eltdata (abfd)->parsed_size;
     }
   else
     {
       struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
 
-      GET_VALUE_IN_FIELD (s->st_mtime, hdrp->date);
-      GET_VALUE_IN_FIELD (s->st_uid, hdrp->uid);
-      GET_VALUE_IN_FIELD (s->st_gid, hdrp->gid);
-      GET_VALUE_IN_FIELD (s->st_mode, hdrp->mode);
+      GET_VALUE_IN_FIELD (s->st_mtime, hdrp->date, 10);
+      GET_VALUE_IN_FIELD (s->st_uid, hdrp->uid, 10);
+      GET_VALUE_IN_FIELD (s->st_gid, hdrp->gid, 10);
+      GET_VALUE_IN_FIELD (s->st_mode, hdrp->mode, 8);
       s->st_size = arch_eltdata (abfd)->parsed_size;
     }
 
@@ -2111,12 +2092,31 @@ xcoff_write_archive_contents_old (bfd *abfd)
          struct xcoff_ar_hdr *ahdrp;
          struct stat s;
 
-         if (stat (bfd_get_filename (sub), &s) != 0)
+         if ((sub->flags & BFD_IN_MEMORY) != 0)
+           {
+             /* Assume we just "made" the member, and fake it.  */
+             struct bfd_in_memory *bim
+               = (struct bfd_in_memory *) sub->iostream;
+             time (&s.st_mtime);
+             s.st_uid = getuid ();
+             s.st_gid = getgid ();
+             s.st_mode = 0644;
+             s.st_size = bim->size;
+           }
+         else if (stat (bfd_get_filename (sub), &s) != 0)
            {
-             bfd_set_error (bfd_error_system_call);
+             bfd_set_input_error (sub, bfd_error_system_call);
              return FALSE;
            }
 
+         if ((abfd->flags & BFD_DETERMINISTIC_OUTPUT) != 0)
+           {
+             s.st_mtime = 0;
+             s.st_uid = 0;
+             s.st_gid = 0;
+             s.st_mode = 0644;
+           }
+
          ahdrp = bfd_zalloc (sub, sizeof (*ahdrp));
          if (ahdrp == NULL)
            return FALSE;
@@ -2328,15 +2328,31 @@ xcoff_write_archive_contents_big (bfd *abfd)
          struct xcoff_ar_hdr_big *ahdrp;
          struct stat s;
 
-         /* XXX This should actually be a call to stat64 (at least on
-            32-bit machines).
-            XXX This call will fail if the original object is not found.  */
-         if (stat (bfd_get_filename (current_bfd), &s) != 0)
+         if ((current_bfd->flags & BFD_IN_MEMORY) != 0)
            {
-             bfd_set_error (bfd_error_system_call);
+             /* Assume we just "made" the member, and fake it.  */
+             struct bfd_in_memory *bim
+               = (struct bfd_in_memory *) current_bfd->iostream;
+             time (&s.st_mtime);
+             s.st_uid = getuid ();
+             s.st_gid = getgid ();
+             s.st_mode = 0644;
+             s.st_size = bim->size;
+           }
+         else if (stat (bfd_get_filename (current_bfd), &s) != 0)
+           {
+             bfd_set_input_error (current_bfd, bfd_error_system_call);
              return FALSE;
            }
 
+         if ((abfd->flags & BFD_DETERMINISTIC_OUTPUT) != 0)
+           {
+             s.st_mtime = 0;
+             s.st_uid = 0;
+             s.st_gid = 0;
+             s.st_mode = 0644;
+           }
+
          ahdrp = bfd_zalloc (current_bfd, sizeof (*ahdrp));
          if (ahdrp == NULL)
            return FALSE;
@@ -2581,11 +2597,13 @@ _bfd_xcoff_sizeof_headers (bfd *abfd,
       /* Sum.  */
       for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
        for (s = sub->sections; s != NULL; s = s->next)
-         {
-           struct nbr_reloc_lineno *e = &n_rl[s->output_section->index];
-           e->reloc_count += s->reloc_count;
-           e->lineno_count += s->lineno_count;
-         }
+         if (s->output_section->owner == abfd
+             && !bfd_section_removed_from_list (abfd, s->output_section))
+           {
+             struct nbr_reloc_lineno *e = &n_rl[s->output_section->index];
+             e->reloc_count += s->reloc_count;
+             e->lineno_count += s->lineno_count;
+           }
 
       /* Add the size of a section for each section with an overflow.  */
       for (s = abfd->sections; s != NULL; s = s->next)
@@ -3404,7 +3422,8 @@ xcoff_ppc_relocate_section (bfd *output_bfd,
                  (info, h->root.root.string,
                   input_bfd, input_section,
                   rel->r_vaddr - input_section->vma,
-                  info->unresolved_syms_in_objects == RM_GENERATE_ERROR);
+                  info->unresolved_syms_in_objects == RM_DIAGNOSE &&
+                      !info->warn_unresolved_syms);
 
              if (h->root.type == bfd_link_hash_defined
                  || h->root.type == bfd_link_hash_defweak)
@@ -3958,7 +3977,7 @@ HOWTO (0,                 /* type */
    The first word of global linkage code must be modified by filling in
    the correct TOC offset.  */
 
-static unsigned long xcoff_glink_code[9] =
+static const unsigned long xcoff_glink_code[9] =
   {
     0x81820000,        /* lwz r12,0(r2) */
     0x90410014,        /* stw r2,20(r1) */
@@ -4058,6 +4077,7 @@ const struct xcoff_dwsect_name xcoff_dwsect_names[] = {
 #define _bfd_xcoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define _bfd_xcoff_bfd_merge_sections bfd_generic_merge_sections
 #define _bfd_xcoff_bfd_is_group_section bfd_generic_is_group_section
+#define _bfd_xcoff_bfd_group_name bfd_generic_group_name
 #define _bfd_xcoff_bfd_discard_group bfd_generic_discard_group
 #define _bfd_xcoff_section_already_linked _bfd_generic_section_already_linked
 #define _bfd_xcoff_bfd_define_common_symbol _bfd_xcoff_define_common_symbol