lto test fails with -fno-inline in CFLAGS
[binutils-gdb.git] / bfd / mach-o.c
index 25ae21dbe00cea982939d8567cad859c4b23a2aa..4d414fd95dbe962ec3cfde7f6fb321642604e0e1 100644 (file)
@@ -1,5 +1,5 @@
 /* Mach-O support for BFD.
-   Copyright (C) 1999-2020 Free Software Foundation, Inc.
+   Copyright (C) 1999-2023 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -36,9 +36,9 @@
 #define bfd_mach_o_mkobject bfd_mach_o_gen_mkobject
 
 #define FILE_ALIGN(off, algn) \
-  (((off) + ((file_ptr) 1 << (algn)) - 1) & ((file_ptr) -1U << (algn)))
+  (((off) + ((ufile_ptr) 1 << (algn)) - 1) & ((ufile_ptr) -1 << (algn)))
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_dyld_content (bfd *abfd, bfd_mach_o_dyld_info_command *cmd);
 
 unsigned int
@@ -52,36 +52,36 @@ bfd_mach_o_version (bfd *abfd)
   return mdata->header.version;
 }
 
-bfd_boolean
+bool
 bfd_mach_o_valid (bfd *abfd)
 {
   if (abfd == NULL || abfd->xvec == NULL)
-    return FALSE;
+    return false;
 
   if (abfd->xvec->flavour != bfd_target_mach_o_flavour)
-    return FALSE;
+    return false;
 
   if (bfd_mach_o_get_data (abfd) == NULL)
-    return FALSE;
-  return TRUE;
+    return false;
+  return true;
 }
 
-static INLINE bfd_boolean
+static inline bool
 mach_o_wide_p (bfd_mach_o_header *header)
 {
   switch (header->version)
     {
     case 1:
-      return FALSE;
+      return false;
     case 2:
-      return TRUE;
+      return true;
     default:
       BFD_FAIL ();
-      return FALSE;
+      return false;
     }
 }
 
-static INLINE bfd_boolean
+static inline bool
 bfd_mach_o_wide_p (bfd *abfd)
 {
   return mach_o_wide_p (&bfd_mach_o_get_data (abfd)->header);
@@ -379,7 +379,7 @@ bfd_mach_o_convert_section_name_to_bfd (bfd *abfd, const char *segname,
 {
   const mach_o_section_name_xlat *xlat;
   char *res;
-  unsigned int len;
+  size_t len;
   const char *pfx = "";
 
   *name = NULL;
@@ -394,7 +394,7 @@ bfd_mach_o_convert_section_name_to_bfd (bfd *abfd, const char *segname,
       res = bfd_alloc (abfd, len + 1);
       if (res == NULL)
        return;
-      memcpy (res, xlat->bfd_name, len+1);
+      memcpy (res, xlat->bfd_name, len + 1);
       *name = res;
       *flags = xlat->bfd_flags;
       return;
@@ -440,9 +440,9 @@ bfd_mach_o_convert_section_name_to_mach_o (bfd *abfd ATTRIBUTE_UNUSED,
   const char *name = bfd_section_name (sect);
   const char *segname;
   const char *dot;
-  unsigned int len;
-  unsigned int seglen;
-  unsigned int seclen;
+  size_t len;
+  size_t seglen;
+  size_t seclen;
 
   memset (section->segname, 0, BFD_MACH_O_SEGNAME_SIZE + 1);
   memset (section->sectname, 0, BFD_MACH_O_SECTNAME_SIZE + 1);
@@ -526,6 +526,15 @@ bfd_mach_o_section_get_nbr_indirect (bfd *abfd, bfd_mach_o_section *sec)
 {
   unsigned int elsz;
 
+  /* FIXME: This array is set by the assembler but does not seem to be
+     set anywhere for objcopy.  Since bfd_mach_o_build_dysymtab will
+     not fill in output bfd_mach_o_dysymtab_command indirect_syms when
+     this array is NULL we may as well return zero for the size.
+     This is enough to stop objcopy allocating huge amounts of memory
+     for indirect symbols in fuzzed object files.  */
+  if (sec->indirect_syms == NULL)
+    return 0;
+
   elsz = bfd_mach_o_section_get_entry_size (abfd, sec);
   if (elsz == 0)
     return 0;
@@ -551,7 +560,7 @@ bfd_mach_o_append_command (bfd *abfd, bfd_mach_o_load_command *cmd)
 /* Copy any private info we understand from the input symbol
    to the output symbol.  */
 
-bfd_boolean
+bool
 bfd_mach_o_bfd_copy_private_symbol_data (bfd *ibfd ATTRIBUTE_UNUSED,
                                         asymbol *isymbol,
                                         bfd *obfd ATTRIBUTE_UNUSED,
@@ -566,13 +575,13 @@ bfd_mach_o_bfd_copy_private_symbol_data (bfd *ibfd ATTRIBUTE_UNUSED,
   os->n_desc = is->n_desc;
   os->symbol.udata.i = is->symbol.udata.i;
 
-  return TRUE;
+  return true;
 }
 
 /* Copy any private info we understand from the input section
    to the output section.  */
 
-bfd_boolean
+bool
 bfd_mach_o_bfd_copy_private_section_data (bfd *ibfd, asection *isection,
                                          bfd *obfd, asection *osection)
 {
@@ -581,7 +590,7 @@ bfd_mach_o_bfd_copy_private_section_data (bfd *ibfd, asection *isection,
 
   if (ibfd->xvec->flavour != bfd_target_mach_o_flavour
       || obfd->xvec->flavour != bfd_target_mach_o_flavour)
-    return TRUE;
+    return true;
 
   BFD_ASSERT (is != NULL && os != NULL);
 
@@ -590,7 +599,7 @@ bfd_mach_o_bfd_copy_private_section_data (bfd *ibfd, asection *isection,
   os->reserved2 = is->reserved2;
   os->reserved3 = is->reserved3;
 
-  return TRUE;
+  return true;
 }
 
 static const char *
@@ -688,7 +697,7 @@ cpusubtype (unsigned long cpu_type, unsigned long cpu_subtype, char *buffer)
   return buffer;
 }
 
-bfd_boolean
+bool
 bfd_mach_o_bfd_print_private_bfd_data (bfd *abfd, void *ptr)
 {
   FILE * file = (FILE *) ptr;
@@ -707,13 +716,13 @@ bfd_mach_o_bfd_print_private_bfd_data (bfd *abfd, void *ptr)
   fprintf (file, _("   flags:      %#lx\n"), (long) mdata->header.flags);
   fprintf (file, _("   version:    %x\n"), mdata->header.version);
 
-  return TRUE;
+  return true;
 }
 
 /* Copy any private info we understand from the input bfd
    to the output bfd.  */
 
-bfd_boolean
+bool
 bfd_mach_o_bfd_copy_private_header_data (bfd *ibfd, bfd *obfd)
 {
   bfd_mach_o_data_struct *imdata;
@@ -722,7 +731,7 @@ bfd_mach_o_bfd_copy_private_header_data (bfd *ibfd, bfd *obfd)
 
   if (bfd_get_flavour (ibfd) != bfd_target_mach_o_flavour
       || bfd_get_flavour (obfd) != bfd_target_mach_o_flavour)
-    return TRUE;
+    return true;
 
   BFD_ASSERT (bfd_mach_o_valid (ibfd));
   BFD_ASSERT (bfd_mach_o_valid (obfd));
@@ -761,7 +770,7 @@ bfd_mach_o_bfd_copy_private_header_data (bfd *ibfd, bfd *obfd)
          /* Command is copied.  */
          ocmd = bfd_alloc (obfd, sizeof (bfd_mach_o_load_command));
          if (ocmd == NULL)
-           return FALSE;
+           return false;
 
          /* Copy common fields.  */
          ocmd->type = icmd->type;
@@ -849,23 +858,23 @@ bfd_mach_o_bfd_copy_private_header_data (bfd *ibfd, bfd *obfd)
       bfd_mach_o_append_command (obfd, ocmd);
     }
 
-  return TRUE;
+  return true;
 }
 
 /* This allows us to set up to 32 bits of flags (unless we invent some
    fiendish scheme to subdivide).  For now, we'll just set the file flags
    without error checking - just overwrite.  */
 
-bfd_boolean
+bool
 bfd_mach_o_bfd_set_private_flags (bfd *abfd, flagword flags)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
 
   if (!mdata)
-    return FALSE;
+    return false;
 
   mdata->header.flags = flags;
-  return TRUE;
+  return true;
 }
 
 /* Count the total number of symbols.  */
@@ -910,7 +919,7 @@ bfd_mach_o_canonicalize_symtab (bfd *abfd, asymbol **alocation)
     {
       _bfd_error_handler
        (_("bfd_mach_o_canonicalize_symtab: unable to load symbols"));
-      return 0;
+      return -1;
     }
 
   BFD_ASSERT (sym->symbols != NULL);
@@ -938,11 +947,9 @@ bfd_mach_o_get_synthetic_symtab (bfd *abfd,
   bfd_mach_o_symtab_command *symtab = mdata->symtab;
   asymbol *s;
   char * s_start;
-  char * s_end;
   unsigned long count, i, j, n;
   size_t size;
   char *names;
-  char *nul_name;
   const char stub [] = "$stub";
 
   *ret = NULL;
@@ -955,27 +962,27 @@ bfd_mach_o_get_synthetic_symtab (bfd *abfd,
   /* We need to allocate a bfd symbol for every indirect symbol and to
      allocate the memory for its name.  */
   count = dysymtab->nindirectsyms;
-  size = count * sizeof (asymbol) + 1;
-
+  size = 0;
   for (j = 0; j < count; j++)
     {
-      const char * strng;
       unsigned int isym = dysymtab->indirect_syms[j];
+      const char *str;
 
       /* Some indirect symbols are anonymous.  */
-      if (isym < symtab->nsyms && (strng = symtab->symbols[isym].symbol.name))
-       /* PR 17512: file: f5b8eeba.  */
-       size += strnlen (strng, symtab->strsize - (strng - symtab->strtab)) + sizeof (stub);
+      if (isym < symtab->nsyms
+         && (str = symtab->symbols[isym].symbol.name) != NULL)
+       {
+         /* PR 17512: file: f5b8eeba.  */
+         size += strnlen (str, symtab->strsize - (str - symtab->strtab));
+         size += sizeof (stub);
+       }
     }
 
-  s_start = bfd_malloc (size);
+  s_start = bfd_malloc (size + count * sizeof (asymbol));
   s = *ret = (asymbol *) s_start;
   if (s == NULL)
     return -1;
   names = (char *) (s + count);
-  nul_name = names;
-  *names++ = 0;
-  s_end = s_start + size;
 
   n = 0;
   for (i = 0; i < mdata->nsects; i++)
@@ -983,7 +990,7 @@ bfd_mach_o_get_synthetic_symtab (bfd *abfd,
       bfd_mach_o_section *sec = mdata->sections[i];
       unsigned int first, last;
       bfd_vma addr;
-      bfd_vma entry_size;
+      unsigned int entry_size;
 
       switch (sec->flags & BFD_MACH_O_SECTION_TYPE_MASK)
        {
@@ -997,47 +1004,39 @@ bfd_mach_o_get_synthetic_symtab (bfd *abfd,
          entry_size = bfd_mach_o_section_get_entry_size (abfd, sec);
 
          /* PR 17512: file: 08e15eec.  */
-         if (first >= count || last >= count || first > last)
+         if (first >= count || last > count || first > last)
            goto fail;
 
          for (j = first; j < last; j++)
            {
              unsigned int isym = dysymtab->indirect_syms[j];
-
-             /* PR 17512: file: 04d64d9b.  */
-             if (((char *) s) + sizeof (* s) > s_end)
-               goto fail;
-
-             s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
-             s->section = sec->bfdsection;
-             s->value = addr - sec->addr;
-             s->udata.p = NULL;
+             const char *str;
+             size_t len;
 
              if (isym < symtab->nsyms
-                 && symtab->symbols[isym].symbol.name)
+                 && (str = symtab->symbols[isym].symbol.name) != NULL)
                {
-                 const char *sym = symtab->symbols[isym].symbol.name;
-                 size_t len;
-
-                 s->name = names;
-                 len = strlen (sym);
-                 /* PR 17512: file: 47dfd4d2.  */
-                 if (names + len >= s_end)
+                 /* PR 17512: file: 04d64d9b.  */
+                 if (n >= count)
                    goto fail;
-                 memcpy (names, sym, len);
-                 names += len;
-                 /* PR 17512: file: 18f340a4.  */
-                 if (names + sizeof (stub) >= s_end)
+                 len = strnlen (str, symtab->strsize - (str - symtab->strtab));
+                 /* PR 17512: file: 47dfd4d2, 18f340a4.  */
+                 if (size < len + sizeof (stub))
                    goto fail;
-                 memcpy (names, stub, sizeof (stub));
-                 names += sizeof (stub);
+                 memcpy (names, str, len);
+                 memcpy (names + len, stub, sizeof (stub));
+                 s->name = names;
+                 names += len + sizeof (stub);
+                 size -= len + sizeof (stub);
+                 s->the_bfd = symtab->symbols[isym].symbol.the_bfd;
+                 s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
+                 s->section = sec->bfdsection;
+                 s->value = addr - sec->addr;
+                 s->udata.p = NULL;
+                 s++;
+                 n++;
                }
-             else
-               s->name = nul_name;
-
              addr += entry_size;
-             s++;
-             n++;
            }
          break;
        default:
@@ -1202,7 +1201,7 @@ bfd_mach_o_convert_architecture (bfd_mach_o_cpu_type mtype,
    number of bytes written or -1 in case of error.  */
 
 static int
-bfd_mach_o_pad4 (bfd *abfd, unsigned int len)
+bfd_mach_o_pad4 (bfd *abfd, size_t len)
 {
   if (len % 4 != 0)
     {
@@ -1221,14 +1220,14 @@ bfd_mach_o_pad4 (bfd *abfd, unsigned int len)
 /* Likewise, but for a command.  */
 
 static int
-bfd_mach_o_pad_command (bfd *abfd, unsigned int len)
+bfd_mach_o_pad_command (bfd *abfd, size_t len)
 {
-  unsigned int align = bfd_mach_o_wide_p (abfd) ? 8 : 4;
+  size_t align = bfd_mach_o_wide_p (abfd) ? 8 : 4;
 
   if (len % align != 0)
     {
       char pad[8] = {0};
-      unsigned int padlen = align - (len % align);
+      size_t padlen = align - (len % align);
 
       if (bfd_bwrite (pad, padlen, abfd) != padlen)
        return -1;
@@ -1239,11 +1238,11 @@ bfd_mach_o_pad_command (bfd *abfd, unsigned int len)
     return 0;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_header (bfd *abfd, bfd_mach_o_header *header)
 {
   struct mach_o_header_external raw;
-  unsigned int size;
+  size_t size;
 
   size = mach_o_wide_p (header) ?
     BFD_MACH_O_HEADER_64_SIZE : BFD_MACH_O_HEADER_SIZE;
@@ -1261,18 +1260,18 @@ bfd_mach_o_write_header (bfd *abfd, bfd_mach_o_header *header)
 
   if (bfd_seek (abfd, 0, SEEK_SET) != 0
       || bfd_bwrite (&raw, size, abfd) != size)
-    return FALSE;
+    return false;
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_thread (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_thread_command *cmd = &command->command.thread;
   unsigned int i;
   struct mach_o_thread_command_external raw;
-  unsigned int offset;
+  size_t offset;
 
   BFD_ASSERT ((command->type == BFD_MACH_O_LC_THREAD)
              || (command->type == BFD_MACH_O_LC_UNIXTHREAD));
@@ -1281,51 +1280,51 @@ bfd_mach_o_write_thread (bfd *abfd, bfd_mach_o_load_command *command)
   for (i = 0; i < cmd->nflavours; i++)
     {
       BFD_ASSERT ((cmd->flavours[i].size % 4) == 0);
-      BFD_ASSERT (cmd->flavours[i].offset ==
-                 (command->offset + offset + BFD_MACH_O_LC_SIZE));
+      BFD_ASSERT (cmd->flavours[i].offset
+                 == command->offset + offset + BFD_MACH_O_LC_SIZE);
 
       bfd_h_put_32 (abfd, cmd->flavours[i].flavour, raw.flavour);
       bfd_h_put_32 (abfd, (cmd->flavours[i].size / 4), raw.count);
 
       if (bfd_seek (abfd, command->offset + offset, SEEK_SET) != 0
          || bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
-       return FALSE;
+       return false;
 
       offset += cmd->flavours[i].size + sizeof (raw);
     }
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_dylinker (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_dylinker_command *cmd = &command->command.dylinker;
   struct mach_o_str_command_external raw;
-  unsigned int namelen;
+  size_t namelen;
 
   bfd_h_put_32 (abfd, cmd->name_offset, raw.str);
 
   if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
       || bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   namelen = strlen (cmd->name_str) + 1;
   if (bfd_bwrite (cmd->name_str, namelen, abfd) != namelen)
-    return FALSE;
+    return false;
 
   if (bfd_mach_o_pad_command (abfd, namelen) < 0)
-    return FALSE;
+    return false;
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_dylib (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_dylib_command *cmd = &command->command.dylib;
   struct mach_o_dylib_command_external raw;
-  unsigned int namelen;
+  size_t namelen;
 
   bfd_h_put_32 (abfd, cmd->name_offset, raw.name);
   bfd_h_put_32 (abfd, cmd->timestamp, raw.timestamp);
@@ -1334,19 +1333,19 @@ bfd_mach_o_write_dylib (bfd *abfd, bfd_mach_o_load_command *command)
 
   if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
       || bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   namelen = strlen (cmd->name_str) + 1;
   if (bfd_bwrite (cmd->name_str, namelen, abfd) != namelen)
-    return FALSE;
+    return false;
 
   if (bfd_mach_o_pad_command (abfd, namelen) < 0)
-    return FALSE;
+    return false;
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_main (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_main_command *cmd = &command->command.main;
@@ -1357,12 +1356,12 @@ bfd_mach_o_write_main (bfd *abfd, bfd_mach_o_load_command *command)
 
   if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
       || bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_dyld_info (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_dyld_info_command *cmd = &command->command.dyld_info;
@@ -1381,53 +1380,63 @@ bfd_mach_o_write_dyld_info (bfd *abfd, bfd_mach_o_load_command *command)
 
   if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
       || bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   if (cmd->rebase_size != 0)
     if (bfd_seek (abfd, cmd->rebase_off, SEEK_SET) != 0
        || (bfd_bwrite (cmd->rebase_content, cmd->rebase_size, abfd) !=
            cmd->rebase_size))
-      return FALSE;
+      return false;
 
   if (cmd->bind_size != 0)
     if (bfd_seek (abfd, cmd->bind_off, SEEK_SET) != 0
        || (bfd_bwrite (cmd->bind_content, cmd->bind_size, abfd) !=
            cmd->bind_size))
-      return FALSE;
+      return false;
 
   if (cmd->weak_bind_size != 0)
     if (bfd_seek (abfd, cmd->weak_bind_off, SEEK_SET) != 0
        || (bfd_bwrite (cmd->weak_bind_content, cmd->weak_bind_size, abfd) !=
            cmd->weak_bind_size))
-      return FALSE;
+      return false;
 
   if (cmd->lazy_bind_size != 0)
     if (bfd_seek (abfd, cmd->lazy_bind_off, SEEK_SET) != 0
        || (bfd_bwrite (cmd->lazy_bind_content, cmd->lazy_bind_size, abfd) !=
            cmd->lazy_bind_size))
-      return FALSE;
+      return false;
 
   if (cmd->export_size != 0)
     if (bfd_seek (abfd, cmd->export_off, SEEK_SET) != 0
        || (bfd_bwrite (cmd->export_content, cmd->export_size, abfd) !=
            cmd->export_size))
-      return FALSE;
+      return false;
 
-  return TRUE;
+  return true;
 }
 
 long
-bfd_mach_o_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
-                                 asection *asect)
+bfd_mach_o_get_reloc_upper_bound (bfd *abfd, asection *asect)
 {
-#if SIZEOF_LONG == SIZEOF_INT
-   if (asect->reloc_count >= LONG_MAX / sizeof (arelent *))
+  size_t count, raw;
+
+  count = asect->reloc_count;
+  if (count >= LONG_MAX / sizeof (arelent *)
+      || _bfd_mul_overflow (count, BFD_MACH_O_RELENT_SIZE, &raw))
     {
       bfd_set_error (bfd_error_file_too_big);
       return -1;
     }
-#endif
- return (asect->reloc_count + 1) * sizeof (arelent *);
+  if (!bfd_write_p (abfd))
+    {
+      ufile_ptr filesize = bfd_get_file_size (abfd);
+      if (filesize != 0 && raw > filesize)
+       {
+         bfd_set_error (bfd_error_file_truncated);
+         return -1;
+       }
+    }
+  return (count + 1) * sizeof (arelent *);
 }
 
 /* In addition to the need to byte-swap the symbol number, the bit positions
@@ -1461,7 +1470,7 @@ bfd_mach_o_swap_in_non_scattered_reloc (bfd *abfd, bfd_mach_o_reloc_info *rel,
 
 /* Set syms_ptr_ptr and addend of RES.  */
 
-bfd_boolean
+bool
 bfd_mach_o_canonicalize_non_scattered_reloc (bfd *abfd,
                                             bfd_mach_o_reloc_info *reloc,
                                             arelent *res, asymbol **syms)
@@ -1503,7 +1512,7 @@ bfd_mach_o_canonicalize_non_scattered_reloc (bfd *abfd,
        {
          _bfd_error_handler (_("\
 malformed mach-o reloc: section index is greater than the number of sections"));
-         return FALSE;
+         return false;
        }
 
       /* A section number.  */
@@ -1524,7 +1533,7 @@ malformed mach-o reloc: section index is greater than the number of sections"));
      the PPC swap_reloc_in routine.  */
   res->sym_ptr_ptr = sym;
 
-  return TRUE;
+  return true;
 }
 
 /* Do most of the work for canonicalize_relocs on RAW: create internal
@@ -1535,7 +1544,7 @@ malformed mach-o reloc: section index is greater than the number of sections"));
    (like arm64) don't follow the generic rules (symnum is a value for the
    non-scattered relocation ADDEND).  */
 
-bfd_boolean
+bool
 bfd_mach_o_pre_canonicalize_one_reloc (bfd *abfd,
                                       struct mach_o_reloc_info_external *raw,
                                       bfd_mach_o_reloc_info *reloc,
@@ -1545,7 +1554,7 @@ bfd_mach_o_pre_canonicalize_one_reloc (bfd *abfd,
   bfd_vma addr;
 
   addr = bfd_get_32 (abfd, raw->r_address);
-  res->sym_ptr_ptr = NULL;
+  res->sym_ptr_ptr = bfd_und_section_ptr->symbol_ptr_ptr;
   res->addend = 0;
 
   if (addr & BFD_MACH_O_SR_SCATTERED)
@@ -1563,7 +1572,7 @@ bfd_mach_o_pre_canonicalize_one_reloc (bfd *abfd,
         end of the data for the section (e.g. in a calculation of section
         data length).  At present, the symbol will end up associated with
         the following section or, if it falls within alignment padding, as
-        null - which will assert later.  */
+        the undefined section symbol.  */
       for (j = 0; j < mdata->nsects; j++)
        {
          bfd_mach_o_section *sect = mdata->sections[j];
@@ -1595,14 +1604,14 @@ bfd_mach_o_pre_canonicalize_one_reloc (bfd *abfd,
 
       if (!bfd_mach_o_canonicalize_non_scattered_reloc (abfd, reloc,
                                                        res, syms))
-       return FALSE;
+       return false;
     }
 
   /* We have set up a reloc with all the information present, so the swapper
      can modify address, value and addend fields, if necessary, to convey
      information in the generic BFD reloc that is mach-o specific.  */
 
-  return TRUE;
+  return true;
 }
 
 static int
@@ -1663,7 +1672,10 @@ bfd_mach_o_canonicalize_reloc (bfd *abfd, asection *asect,
       size_t amt;
 
       if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
-       return -1;
+       {
+         bfd_set_error (bfd_error_file_too_big);
+         return -1;
+       }
       res = bfd_malloc (amt);
       if (res == NULL)
        return -1;
@@ -1689,11 +1701,36 @@ long
 bfd_mach_o_get_dynamic_reloc_upper_bound (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
+  bfd_mach_o_dysymtab_command *dysymtab = mdata->dysymtab;
 
-  if (mdata->dysymtab == NULL)
+  if (dysymtab == NULL)
     return 1;
-  return (mdata->dysymtab->nextrel + mdata->dysymtab->nlocrel + 1)
-    * sizeof (arelent *);
+
+  ufile_ptr filesize = bfd_get_file_size (abfd);
+  size_t amt;
+
+  if (filesize != 0)
+    {
+      if (dysymtab->extreloff > filesize
+         || dysymtab->nextrel > ((filesize - dysymtab->extreloff)
+                                 / BFD_MACH_O_RELENT_SIZE)
+         || dysymtab->locreloff > filesize
+         || dysymtab->nlocrel > ((filesize - dysymtab->locreloff)
+                                 / BFD_MACH_O_RELENT_SIZE))
+       {
+         bfd_set_error (bfd_error_file_truncated);
+         return -1;
+       }
+    }
+  if (dysymtab->nextrel + dysymtab->nlocrel < dysymtab->nextrel
+      || _bfd_mul_overflow (dysymtab->nextrel + dysymtab->nlocrel,
+                           sizeof (arelent), &amt))
+    {
+      bfd_set_error (bfd_error_file_too_big);
+      return -1;
+    }
+
+  return (dysymtab->nextrel + dysymtab->nlocrel + 1) * sizeof (arelent *);
 }
 
 long
@@ -1717,29 +1754,7 @@ bfd_mach_o_canonicalize_dynamic_reloc (bfd *abfd, arelent **rels,
 
   if (mdata->dyn_reloc_cache == NULL)
     {
-      ufile_ptr filesize = bfd_get_file_size (abfd);
-      size_t amt;
-
-      if (filesize != 0)
-       {
-         if (dysymtab->extreloff > filesize
-             || dysymtab->nextrel > ((filesize - dysymtab->extreloff)
-                                     / BFD_MACH_O_RELENT_SIZE)
-             || dysymtab->locreloff > filesize
-             || dysymtab->nlocrel > ((filesize - dysymtab->locreloff)
-                                     / BFD_MACH_O_RELENT_SIZE))
-           {
-             bfd_set_error (bfd_error_file_truncated);
-             return -1;
-           }
-       }
-      if (_bfd_mul_overflow (dysymtab->nextrel + dysymtab->nlocrel,
-                            sizeof (arelent), &amt))
-       {
-         bfd_set_error (bfd_error_file_too_big);
-         return -1;
-       }
-
+      size_t amt = (dysymtab->nextrel + dysymtab->nlocrel) * sizeof (arelent);
       res = bfd_malloc (amt);
       if (res == NULL)
        return -1;
@@ -1804,7 +1819,7 @@ bfd_mach_o_swap_out_non_scattered_reloc (bfd *abfd, unsigned char *fields,
   fields[3] = info;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_relocs (bfd *abfd, bfd_mach_o_section *section)
 {
   unsigned int i;
@@ -1814,13 +1829,13 @@ bfd_mach_o_write_relocs (bfd *abfd, bfd_mach_o_section *section)
 
   sec = section->bfdsection;
   if (sec->reloc_count == 0)
-    return TRUE;
+    return true;
 
   if (bed->_bfd_mach_o_swap_reloc_out == NULL)
-    return TRUE;
+    return true;
 
   if (bfd_seek (abfd, section->reloff, SEEK_SET) != 0)
-    return FALSE;
+    return false;
 
   /* Convert and write.  */
   entries = section->bfdsection->orelocation;
@@ -1832,7 +1847,7 @@ bfd_mach_o_write_relocs (bfd *abfd, bfd_mach_o_section *section)
 
       /* Convert relocation to an intermediate representation.  */
       if (!(*bed->_bfd_mach_o_swap_reloc_out) (rel, pinfo))
-       return FALSE;
+       return false;
 
       /* Lower the relocation info.  */
       if (pinfo->r_scattered)
@@ -1857,12 +1872,12 @@ bfd_mach_o_write_relocs (bfd *abfd, bfd_mach_o_section *section)
 
       if (bfd_bwrite (&raw, BFD_MACH_O_RELENT_SIZE, abfd)
          != BFD_MACH_O_RELENT_SIZE)
-       return FALSE;
+       return false;
     }
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_section_32 (bfd *abfd, bfd_mach_o_section *section)
 {
   struct mach_o_section_32_external raw;
@@ -1881,12 +1896,12 @@ bfd_mach_o_write_section_32 (bfd *abfd, bfd_mach_o_section *section)
 
   if (bfd_bwrite (&raw, BFD_MACH_O_SECTION_SIZE, abfd)
       != BFD_MACH_O_SECTION_SIZE)
-    return FALSE;
+    return false;
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_section_64 (bfd *abfd, bfd_mach_o_section *section)
 {
   struct mach_o_section_64_external raw;
@@ -1906,12 +1921,12 @@ bfd_mach_o_write_section_64 (bfd *abfd, bfd_mach_o_section *section)
 
   if (bfd_bwrite (&raw, BFD_MACH_O_SECTION_64_SIZE, abfd)
       != BFD_MACH_O_SECTION_64_SIZE)
-    return FALSE;
+    return false;
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_segment_32 (bfd *abfd, bfd_mach_o_load_command *command)
 {
   struct mach_o_segment_command_32_external raw;
@@ -1922,7 +1937,7 @@ bfd_mach_o_write_segment_32 (bfd *abfd, bfd_mach_o_load_command *command)
 
   for (sec = seg->sect_head; sec != NULL; sec = sec->next)
     if (!bfd_mach_o_write_relocs (abfd, sec))
-      return FALSE;
+      return false;
 
   memcpy (raw.segname, seg->segname, 16);
   bfd_h_put_32 (abfd, seg->vmaddr, raw.vmaddr);
@@ -1936,16 +1951,16 @@ bfd_mach_o_write_segment_32 (bfd *abfd, bfd_mach_o_load_command *command)
 
   if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
       || bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   for (sec = seg->sect_head; sec != NULL; sec = sec->next)
     if (!bfd_mach_o_write_section_32 (abfd, sec))
-      return FALSE;
+      return false;
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_segment_64 (bfd *abfd, bfd_mach_o_load_command *command)
 {
   struct mach_o_segment_command_64_external raw;
@@ -1956,7 +1971,7 @@ bfd_mach_o_write_segment_64 (bfd *abfd, bfd_mach_o_load_command *command)
 
   for (sec = seg->sect_head; sec != NULL; sec = sec->next)
     if (!bfd_mach_o_write_relocs (abfd, sec))
-      return FALSE;
+      return false;
 
   memcpy (raw.segname, seg->segname, 16);
   bfd_h_put_64 (abfd, seg->vmaddr, raw.vmaddr);
@@ -1970,16 +1985,16 @@ bfd_mach_o_write_segment_64 (bfd *abfd, bfd_mach_o_load_command *command)
 
   if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
       || bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   for (sec = seg->sect_head; sec != NULL; sec = sec->next)
     if (!bfd_mach_o_write_section_64 (abfd, sec))
-      return FALSE;
+      return false;
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_symtab_content (bfd *abfd, bfd_mach_o_symtab_command *sym)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
@@ -1991,17 +2006,17 @@ bfd_mach_o_write_symtab_content (bfd *abfd, bfd_mach_o_symtab_command *sym)
 
   /* Write the symbols first.  */
   if (bfd_seek (abfd, sym->symoff, SEEK_SET) != 0)
-    return FALSE;
+    return false;
 
   strtab = _bfd_stringtab_init ();
   if (strtab == NULL)
-    return FALSE;
+    return false;
 
   if (sym->nsyms > 0)
     /* Although we don't strictly need to do this, for compatibility with
        Darwin system tools, actually output an empty string for the index
        0 entry.  */
-    _bfd_stringtab_add (strtab, "", TRUE, FALSE);
+    _bfd_stringtab_add (strtab, "", true, false);
 
   for (i = 0; i < sym->nsyms; i++)
     {
@@ -2013,7 +2028,7 @@ bfd_mach_o_write_symtab_content (bfd *abfd, bfd_mach_o_symtab_command *sym)
        str_index = 0;
       else
        {
-         str_index = _bfd_stringtab_add (strtab, s->symbol.name, TRUE, FALSE);
+         str_index = _bfd_stringtab_add (strtab, s->symbol.name, true, false);
 
          if (str_index == (bfd_size_type) -1)
            goto err;
@@ -2058,22 +2073,24 @@ bfd_mach_o_write_symtab_content (bfd *abfd, bfd_mach_o_symtab_command *sym)
   if (!_bfd_stringtab_emit (abfd, strtab))
     goto err;
 
+  _bfd_stringtab_free (strtab);
+
   /* Pad string table.  */
   padlen = bfd_mach_o_pad4 (abfd, sym->strsize);
   if (padlen < 0)
-    return FALSE;
+    return false;
   mdata->filelen += padlen;
   sym->strsize += padlen;
 
-  return TRUE;
+  return true;
 
  err:
   _bfd_stringtab_free (strtab);
   sym->strsize = 0;
-  return FALSE;
+  return false;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_symtab (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_symtab_command *sym = &command->command.symtab;
@@ -2089,9 +2106,9 @@ bfd_mach_o_write_symtab (bfd *abfd, bfd_mach_o_load_command *command)
 
   if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
       || bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
-  return TRUE;
+  return true;
 }
 
 /* Count the number of indirect symbols in the image.
@@ -2123,7 +2140,7 @@ bfd_mach_o_count_indirect_symbols (bfd *abfd, bfd_mach_o_data_struct *mdata)
 
 /* Create the dysymtab.  */
 
-static bfd_boolean
+static bool
 bfd_mach_o_build_dysymtab (bfd *abfd, bfd_mach_o_dysymtab_command *cmd)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
@@ -2137,7 +2154,7 @@ bfd_mach_o_build_dysymtab (bfd *abfd, bfd_mach_o_dysymtab_command *cmd)
     {
       _bfd_error_handler (_("sorry: modtab, toc and extrefsyms are not yet"
                            " implemented for dysymtab commands."));
-      return FALSE;
+      return false;
     }
 
   cmd->ilocalsym = 0;
@@ -2187,12 +2204,12 @@ bfd_mach_o_build_dysymtab (bfd *abfd, bfd_mach_o_dysymtab_command *cmd)
       mdata->filelen = FILE_ALIGN (mdata->filelen, 2);
       cmd->indirectsymoff = mdata->filelen;
       if (_bfd_mul_overflow (cmd->nindirectsyms, 4, &amt))
-       return FALSE;
+       return false;
       mdata->filelen += amt;
 
       cmd->indirect_syms = bfd_zalloc (abfd, amt);
       if (cmd->indirect_syms == NULL)
-       return FALSE;
+       return false;
 
       n = 0;
       for (i = 0; i < mdata->nsects; ++i)
@@ -2232,13 +2249,13 @@ bfd_mach_o_build_dysymtab (bfd *abfd, bfd_mach_o_dysymtab_command *cmd)
        }
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Write a dysymtab command.
    TODO: Possibly coalesce writes of smaller objects.  */
 
-static bfd_boolean
+static bool
 bfd_mach_o_write_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_dysymtab_command *cmd = &command->command.dysymtab;
@@ -2250,7 +2267,7 @@ bfd_mach_o_write_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
       unsigned int i;
 
       if (bfd_seek (abfd, cmd->modtaboff, SEEK_SET) != 0)
-       return FALSE;
+       return false;
 
       for (i = 0; i < cmd->nmodtab; i++)
        {
@@ -2285,7 +2302,7 @@ bfd_mach_o_write_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
                            &w.objc_module_info_size);
 
              if (bfd_bwrite ((void *) &w, sizeof (w), abfd) != sizeof (w))
-               return FALSE;
+               return false;
            }
          else
            {
@@ -2308,7 +2325,7 @@ bfd_mach_o_write_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
                            &n.objc_module_info_size);
 
              if (bfd_bwrite ((void *) &n, sizeof (n), abfd) != sizeof (n))
-               return FALSE;
+               return false;
            }
        }
     }
@@ -2318,7 +2335,7 @@ bfd_mach_o_write_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
       unsigned int i;
 
       if (bfd_seek (abfd, cmd->tocoff, SEEK_SET) != 0)
-       return FALSE;
+       return false;
 
       for (i = 0; i < cmd->ntoc; i++)
        {
@@ -2329,7 +2346,7 @@ bfd_mach_o_write_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
          bfd_h_put_32 (abfd, toc->module_index, &raw.module_index);
 
          if (bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
-           return FALSE;
+           return false;
        }
     }
 
@@ -2338,7 +2355,7 @@ bfd_mach_o_write_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
       unsigned int i;
 
       if (bfd_seek (abfd, cmd->indirectsymoff, SEEK_SET) != 0)
-       return FALSE;
+       return false;
 
       for (i = 0; i < cmd->nindirectsyms; ++i)
        {
@@ -2346,7 +2363,7 @@ bfd_mach_o_write_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
 
          bfd_h_put_32 (abfd, cmd->indirect_syms[i], &raw);
          if (bfd_bwrite (raw, sizeof (raw), abfd) != sizeof (raw))
-           return FALSE;
+           return false;
        }
     }
 
@@ -2355,7 +2372,7 @@ bfd_mach_o_write_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
       unsigned int i;
 
       if (bfd_seek (abfd, cmd->extrefsymoff, SEEK_SET) != 0)
-       return FALSE;
+       return false;
 
       for (i = 0; i < cmd->nextrefsyms; i++)
        {
@@ -2379,13 +2396,13 @@ bfd_mach_o_write_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
 
          bfd_h_put_32 (abfd, v, raw);
          if (bfd_bwrite (raw, sizeof (raw), abfd) != sizeof (raw))
-           return FALSE;
+           return false;
        }
     }
 
   /* The command.  */
   if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0)
-    return FALSE;
+    return false;
   else
     {
       struct mach_o_dysymtab_command_external raw;
@@ -2410,10 +2427,10 @@ bfd_mach_o_write_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
       bfd_h_put_32 (abfd, cmd->nlocrel, &raw.nlocrel);
 
       if (bfd_bwrite (&raw, sizeof (raw), abfd) != sizeof (raw))
-       return FALSE;
+       return false;
     }
 
-  return TRUE;
+  return true;
 }
 
 static unsigned
@@ -2488,14 +2505,14 @@ bfd_mach_o_cf_symbols (const void *a, const void *b)
                (by name)
 */
 
-static bfd_boolean
+static bool
 bfd_mach_o_mangle_symbols (bfd *abfd)
 {
   unsigned long i;
   asymbol **symbols = bfd_get_outsymbols (abfd);
 
   if (symbols == NULL || bfd_get_symcount (abfd) == 0)
-    return TRUE;
+    return true;
 
   for (i = 0; i < bfd_get_symcount (abfd); i++)
     {
@@ -2558,13 +2575,13 @@ bfd_mach_o_mangle_symbols (bfd *abfd)
       s->symbol.udata.i = i;  /* renumber.  */
     }
 
-  return TRUE;
+  return true;
 }
 
 /* We build a flat table of sections, which can be re-ordered if necessary.
    Fill in the section number and other mach-o-specific data.  */
 
-static bfd_boolean
+static bool
 bfd_mach_o_mangle_sections (bfd *abfd, bfd_mach_o_data_struct *mdata)
 {
   asection *sec;
@@ -2578,21 +2595,21 @@ bfd_mach_o_mangle_sections (bfd *abfd, bfd_mach_o_data_struct *mdata)
      doing.  */
   if (mdata->nsects == nsect
       && (mdata->nsects == 0 || mdata->sections != NULL))
-    return TRUE;
+    return true;
 
   /* We need to check that this can be done...  */
   if (nsect > 255)
     {
       _bfd_error_handler (_("mach-o: there are too many sections (%u)"
                            " maximum is 255,\n"), nsect);
-      return FALSE;
+      return false;
     }
 
   mdata->nsects = nsect;
   amt = mdata->nsects * sizeof (bfd_mach_o_section *);
   mdata->sections = bfd_alloc (abfd, amt);
   if (mdata->sections == NULL)
-    return FALSE;
+    return false;
 
   /* Create Mach-O sections.
      Section type, attribute and align should have been set when the
@@ -2616,10 +2633,10 @@ bfd_mach_o_mangle_sections (bfd *abfd, bfd_mach_o_data_struct *mdata)
       sec->target_index = ++target_index;
     }
 
-  return TRUE;
+  return true;
 }
 
-bfd_boolean
+bool
 bfd_mach_o_write_contents (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
@@ -2630,12 +2647,12 @@ bfd_mach_o_write_contents (bfd *abfd)
 
   /* Make the commands, if not already present.  */
   if (!abfd->output_has_begun && !bfd_mach_o_build_commands (abfd))
-    return FALSE;
-  abfd->output_has_begun = TRUE;
+    return false;
+  abfd->output_has_begun = true;
 
   /* Write the header.  */
   if (!bfd_mach_o_write_header (abfd, &mdata->header))
-    return FALSE;
+    return false;
 
   /* First pass: allocate the linkedit segment.  */
   for (cmd = mdata->first_command; cmd != NULL; cmd = cmd->next)
@@ -2656,31 +2673,16 @@ bfd_mach_o_write_contents (bfd *abfd)
        {
          bfd_mach_o_dyld_info_command *di = &cmd->command.dyld_info;
 
-         if (di->rebase_size != 0)
-           {
-             di->rebase_off = mdata->filelen;
-             mdata->filelen += di->rebase_size;
-           }
-         if (di->bind_size != 0)
-           {
-             di->bind_off = mdata->filelen;
-             mdata->filelen += di->bind_size;
-           }
-         if (di->weak_bind_size != 0)
-           {
-             di->weak_bind_off = mdata->filelen;
-             mdata->filelen += di->weak_bind_size;
-           }
-         if (di->lazy_bind_size != 0)
-           {
-             di->lazy_bind_off = mdata->filelen;
-             mdata->filelen += di->lazy_bind_size;
-           }
-         if (di->export_size != 0)
-           {
-             di->export_off = mdata->filelen;
-             mdata->filelen += di->export_size;
-           }
+         di->rebase_off = di->rebase_size != 0 ? mdata->filelen : 0;
+         mdata->filelen += di->rebase_size;
+         di->bind_off = di->bind_size != 0 ? mdata->filelen : 0;
+         mdata->filelen += di->bind_size;
+         di->weak_bind_off = di->weak_bind_size != 0 ? mdata->filelen : 0;
+         mdata->filelen += di->weak_bind_size;
+         di->lazy_bind_off = di->lazy_bind_size != 0 ? mdata->filelen : 0;
+         mdata->filelen += di->lazy_bind_size;
+         di->export_off = di->export_size != 0 ? mdata->filelen : 0;
+         mdata->filelen += di->export_size;
        }
        break;
       case BFD_MACH_O_LC_LOAD_DYLIB:
@@ -2718,12 +2720,12 @@ bfd_mach_o_write_contents (bfd *abfd)
   /* Build the dysymtab.  */
   if (dysymtab != NULL)
     if (!bfd_mach_o_build_dysymtab (abfd, dysymtab))
-      return FALSE;
+      return false;
 
   /* Write symtab and strtab.  */
   if (symtab != NULL)
     if (!bfd_mach_o_write_symtab_content (abfd, symtab))
-      return FALSE;
+      return false;
 
   /* Adjust linkedit size.  */
   if (linkedit != NULL)
@@ -2752,56 +2754,56 @@ bfd_mach_o_write_contents (bfd *abfd)
 
       if (bfd_seek (abfd, cmd->offset, SEEK_SET) != 0
          || bfd_bwrite (&raw, BFD_MACH_O_LC_SIZE, abfd) != 8)
-       return FALSE;
+       return false;
 
       switch (cmd->type)
        {
        case BFD_MACH_O_LC_SEGMENT:
          if (!bfd_mach_o_write_segment_32 (abfd, cmd))
-           return FALSE;
+           return false;
          break;
        case BFD_MACH_O_LC_SEGMENT_64:
          if (!bfd_mach_o_write_segment_64 (abfd, cmd))
-           return FALSE;
+           return false;
          break;
        case BFD_MACH_O_LC_SYMTAB:
          if (!bfd_mach_o_write_symtab (abfd, cmd))
-           return FALSE;
+           return false;
          break;
        case BFD_MACH_O_LC_DYSYMTAB:
          if (!bfd_mach_o_write_dysymtab (abfd, cmd))
-           return FALSE;
+           return false;
          break;
        case BFD_MACH_O_LC_THREAD:
        case BFD_MACH_O_LC_UNIXTHREAD:
          if (!bfd_mach_o_write_thread (abfd, cmd))
-           return FALSE;
+           return false;
          break;
        case BFD_MACH_O_LC_LOAD_DYLIB:
          if (!bfd_mach_o_write_dylib (abfd, cmd))
-           return FALSE;
+           return false;
          break;
        case BFD_MACH_O_LC_LOAD_DYLINKER:
          if (!bfd_mach_o_write_dylinker (abfd, cmd))
-           return FALSE;
+           return false;
          break;
        case BFD_MACH_O_LC_MAIN:
          if (!bfd_mach_o_write_main (abfd, cmd))
-           return FALSE;
+           return false;
          break;
        case BFD_MACH_O_LC_DYLD_INFO:
          if (!bfd_mach_o_write_dyld_info (abfd, cmd))
-           return FALSE;
+           return false;
          break;
        default:
          _bfd_error_handler
            (_("unable to write unknown load command %#x"),
             cmd->type);
-         return FALSE;
+         return false;
        }
     }
 
-  return TRUE;
+  return true;
 }
 
 static void
@@ -2838,7 +2840,7 @@ bfd_mach_o_set_section_flags_from_bfd (bfd *abfd ATTRIBUTE_UNUSED,
     s->flags = BFD_MACH_O_S_REGULAR;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_build_obj_seg_command (bfd *abfd, bfd_mach_o_segment_command *seg)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
@@ -2943,10 +2945,10 @@ bfd_mach_o_build_obj_seg_command (bfd *abfd, bfd_mach_o_segment_command *seg)
       mdata->filelen += sec->reloc_count * BFD_MACH_O_RELENT_SIZE;
     }
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_build_exec_seg_command (bfd *abfd, bfd_mach_o_segment_command *seg)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
@@ -2982,7 +2984,7 @@ bfd_mach_o_build_exec_seg_command (bfd *abfd, bfd_mach_o_segment_command *seg)
            (_("section address (%#" PRIx64 ") "
               "below start of segment (%#" PRIx64 ")"),
               (uint64_t) s->addr, (uint64_t) vma);
-         return FALSE;
+         return false;
        }
 
       vma = s->addr + s->size;
@@ -3038,7 +3040,7 @@ bfd_mach_o_build_exec_seg_command (bfd *abfd, bfd_mach_o_segment_command *seg)
 
       /* Relocs shouldn't appear in non-object files.  */
       if (s->bfdsection->reloc_count != 0)
-       return FALSE;
+       return false;
     }
 
   /* Set maxprot.  */
@@ -3053,13 +3055,13 @@ bfd_mach_o_build_exec_seg_command (bfd *abfd, bfd_mach_o_segment_command *seg)
   seg->filesize = (seg->filesize + pagemask) & ~pagemask;
   mdata->filelen = (mdata->filelen + pagemask) & ~pagemask;
 
-  return TRUE;
+  return true;
 }
 
 /* Layout the commands: set commands size and offset, set ncmds and sizeofcmds
    fields in header.  */
 
-static bfd_boolean
+static bool
 bfd_mach_o_layout_commands (bfd_mach_o_data_struct *mdata)
 {
   unsigned wide = mach_o_wide_p (&mdata->header);
@@ -3067,7 +3069,7 @@ bfd_mach_o_layout_commands (bfd_mach_o_data_struct *mdata)
   ufile_ptr offset;
   bfd_mach_o_load_command *cmd;
   unsigned int align;
-  bfd_boolean ret = TRUE;
+  bool ret = true;
 
   hdrlen = wide ? BFD_MACH_O_HEADER_64_SIZE : BFD_MACH_O_HEADER_SIZE;
   align = wide ? 8 - 1 : 4 - 1;
@@ -3123,7 +3125,7 @@ bfd_mach_o_layout_commands (bfd_mach_o_data_struct *mdata)
          _bfd_error_handler
            (_("unable to layout unknown load command %#x"),
             cmd->type);
-         ret = FALSE;
+         ret = false;
          break;
        }
 
@@ -3149,7 +3151,7 @@ bfd_mach_o_init_segment (bfd_mach_o_data_struct *mdata,
 
   /* Init segment command.  */
   cmd->type = wide ? BFD_MACH_O_LC_SEGMENT_64 : BFD_MACH_O_LC_SEGMENT;
-  cmd->type_required = FALSE;
+  cmd->type_required = false;
 
   strcpy (seg->segname, segname);
   seg->nsects = nbr_sect;
@@ -3170,7 +3172,7 @@ bfd_mach_o_init_segment (bfd_mach_o_data_struct *mdata,
    TODO: Other file formats, rebuilding symtab/dysymtab commands for strip
    and copy functionality.  */
 
-bfd_boolean
+bool
 bfd_mach_o_build_commands (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
@@ -3185,7 +3187,7 @@ bfd_mach_o_build_commands (bfd *abfd)
 
   /* Return now if already built.  */
   if (mdata->header.ncmds != 0)
-    return TRUE;
+    return true;
 
   /* Fill in the file type, if not already set.  */
   if (mdata->header.filetype == 0)
@@ -3203,12 +3205,12 @@ bfd_mach_o_build_commands (bfd *abfd)
      since that depends on properly numbered sections.  */
   if (mdata->nsects == 0 || mdata->sections == NULL)
     if (! bfd_mach_o_mangle_sections (abfd, mdata))
-      return FALSE;
+      return false;
 
   /* Order the symbol table, fill-in/check mach-o specific fields and
      partition out any indirect symbols.  */
   if (!bfd_mach_o_mangle_symbols (abfd))
-    return FALSE;
+    return false;
 
   /* Segment commands.  */
   if (mdata->header.filetype == BFD_MACH_O_MH_OBJECT)
@@ -3274,7 +3276,7 @@ bfd_mach_o_build_commands (bfd *abfd)
   /* Create commands for segments (and symtabs), prepend them.  */
   commands = bfd_zalloc (abfd, nbr_commands * sizeof (bfd_mach_o_load_command));
   if (commands == NULL)
-    return FALSE;
+    return false;
   for (i = 0; i < nbr_commands - 1; i++)
     commands[i].next = &commands[i + 1];
   commands[nbr_commands - 1].next = mdata->first_command;
@@ -3325,7 +3327,7 @@ bfd_mach_o_build_commands (bfd *abfd)
       bfd_mach_o_load_command *cmd = &commands[symtab_idx];
 
       cmd->type = BFD_MACH_O_LC_SYMTAB;
-      cmd->type_required = FALSE;
+      cmd->type_required = false;
     }
 
   /* If required, setup symtab command, see comment above about the quality
@@ -3335,7 +3337,7 @@ bfd_mach_o_build_commands (bfd *abfd)
       bfd_mach_o_load_command *cmd = &commands[dysymtab_idx];
 
       cmd->type = BFD_MACH_O_LC_DYSYMTAB;
-      cmd->type_required = FALSE;
+      cmd->type_required = false;
     }
 
   /* Create the main command.  */
@@ -3344,7 +3346,7 @@ bfd_mach_o_build_commands (bfd *abfd)
       bfd_mach_o_load_command *cmd = &commands[main_idx];
 
       cmd->type = BFD_MACH_O_LC_MAIN;
-      cmd->type_required = TRUE;
+      cmd->type_required = true;
 
       cmd->command.main.entryoff = 0;
       cmd->command.main.stacksize = 0;
@@ -3352,7 +3354,7 @@ bfd_mach_o_build_commands (bfd *abfd)
 
   /* Layout commands.  */
   if (! bfd_mach_o_layout_commands (mdata))
-    return FALSE;
+    return false;
 
   /* So, now we have sized the commands and the filelen set to that.
      Now we can build the segment command and set the section file offsets.  */
@@ -3361,7 +3363,7 @@ bfd_mach_o_build_commands (bfd *abfd)
       for (i = 0; i < nbr_segcmd; i++)
        if (!bfd_mach_o_build_obj_seg_command
            (abfd, &commands[i].command.segment))
-         return FALSE;
+         return false;
     }
   else
     {
@@ -3373,7 +3375,7 @@ bfd_mach_o_build_commands (bfd *abfd)
          bfd_mach_o_segment_command *seg = &commands[i].command.segment;
 
          if (!bfd_mach_o_build_exec_seg_command (abfd, seg))
-           return FALSE;
+           return false;
 
          if (seg->vmaddr + seg->vmsize > maxvma)
            maxvma = seg->vmaddr + seg->vmsize;
@@ -3393,12 +3395,12 @@ bfd_mach_o_build_commands (bfd *abfd)
          bfd_get_start_address (abfd) - commands[1].command.segment.vmaddr;
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Set the contents of a section.  */
 
-bfd_boolean
+bool
 bfd_mach_o_set_section_contents (bfd *abfd,
                                 asection *section,
                                 const void * location,
@@ -3410,17 +3412,17 @@ bfd_mach_o_set_section_contents (bfd *abfd,
   /* Trying to write the first section contents will trigger the creation of
      the load commands if they are not already present.  */
   if (!abfd->output_has_begun && !bfd_mach_o_build_commands (abfd))
-    return FALSE;
+    return false;
 
   if (count == 0)
-    return TRUE;
+    return true;
 
   pos = section->filepos + offset;
   if (bfd_seek (abfd, pos, SEEK_SET) != 0
       || bfd_bwrite (location, count, abfd) != count)
-    return FALSE;
+    return false;
 
-  return TRUE;
+  return true;
 }
 
 int
@@ -3446,7 +3448,7 @@ bfd_mach_o_make_empty_symbol (bfd *abfd)
   return new_symbol;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_header (bfd *abfd, file_ptr hdr_off, bfd_mach_o_header *header)
 {
   struct mach_o_header_external raw;
@@ -3456,7 +3458,7 @@ bfd_mach_o_read_header (bfd *abfd, file_ptr hdr_off, bfd_mach_o_header *header)
   /* Just read the magic number.  */
   if (bfd_seek (abfd, hdr_off, SEEK_SET) != 0
       || bfd_bread (raw.magic, sizeof (raw.magic), abfd) != 4)
-    return FALSE;
+    return false;
 
   if (bfd_getb32 (raw.magic) == BFD_MACH_O_MH_MAGIC)
     {
@@ -3489,7 +3491,7 @@ bfd_mach_o_read_header (bfd *abfd, file_ptr hdr_off, bfd_mach_o_header *header)
   else
     {
       header->byteorder = BFD_ENDIAN_UNKNOWN;
-      return FALSE;
+      return false;
     }
 
   /* Once the size of the header is known, read the full header.  */
@@ -3498,7 +3500,7 @@ bfd_mach_o_read_header (bfd *abfd, file_ptr hdr_off, bfd_mach_o_header *header)
 
   if (bfd_seek (abfd, hdr_off, SEEK_SET) != 0
       || bfd_bread (&raw, size, abfd) != size)
-    return FALSE;
+    return false;
 
   header->cputype = (*get32) (raw.cputype);
   header->cpusubtype = (*get32) (raw.cpusubtype);
@@ -3512,10 +3514,10 @@ bfd_mach_o_read_header (bfd *abfd, file_ptr hdr_off, bfd_mach_o_header *header)
   else
     header->reserved = 0;
 
-  return TRUE;
+  return true;
 }
 
-bfd_boolean
+bool
 bfd_mach_o_new_section_hook (bfd *abfd, asection *sec)
 {
   bfd_mach_o_section *s;
@@ -3529,7 +3531,7 @@ bfd_mach_o_new_section_hook (bfd *abfd, asection *sec)
 
       s = (bfd_mach_o_section *) bfd_zalloc (abfd, sizeof (*s));
       if (s == NULL)
-       return FALSE;
+       return false;
       sec->used_by_bfd = s;
       s->bfdsection = sec;
 
@@ -3653,12 +3655,12 @@ bfd_mach_o_read_section_32 (bfd *abfd, unsigned long prot)
   section->offset = bfd_h_get_32 (abfd, raw.offset);
   section->align = bfd_h_get_32 (abfd, raw.align);
   /* PR 17512: file: 0017eb76.  */
-  if (section->align > 64)
+  if (section->align >= 31)
     {
       _bfd_error_handler
-       (_("bfd_mach_o_read_section_32: overlarge alignment value: %#lx, "
-          "using 32 instead"), section->align);
-      section->align = 32;
+       (_("bfd_mach_o_read_section_32: overlarge alignment value: %#lx"),
+        section->align);
+      section->align = 30;
     }
   section->reloff = bfd_h_get_32 (abfd, raw.reloff);
   section->nreloc = bfd_h_get_32 (abfd, raw.nreloc);
@@ -3696,12 +3698,12 @@ bfd_mach_o_read_section_64 (bfd *abfd, unsigned long prot)
   section->size = bfd_h_get_64 (abfd, raw.size);
   section->offset = bfd_h_get_32 (abfd, raw.offset);
   section->align = bfd_h_get_32 (abfd, raw.align);
-  if (section->align > 64)
+  if (section->align >= 63)
     {
       _bfd_error_handler
-       (_("bfd_mach_o_read_section_64: overlarge alignment value: %#lx, "
-          "using 32 instead"), section->align);
-      section->align = 32;
+       (_("bfd_mach_o_read_section_64: overlarge alignment value: %#lx"),
+        section->align);
+      section->align = 62;
     }
   section->reloff = bfd_h_get_32 (abfd, raw.reloff);
   section->nreloc = bfd_h_get_32 (abfd, raw.nreloc);
@@ -3724,7 +3726,7 @@ bfd_mach_o_read_section (bfd *abfd, unsigned long prot, unsigned int wide)
     return bfd_mach_o_read_section_32 (abfd, prot);
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_symtab_symbol (bfd *abfd,
                               bfd_mach_o_symtab_command *sym,
                               bfd_mach_o_asymbol *s,
@@ -3752,7 +3754,7 @@ bfd_mach_o_read_symtab_symbol (bfd *abfd,
        /* xgettext:c-format */
        (_("bfd_mach_o_read_symtab_symbol: unable to read %d bytes at %u"),
         symwidth, symoff);
-      return FALSE;
+      return false;
     }
 
   stroff = bfd_h_get_32 (abfd, raw.n_strx);
@@ -3772,7 +3774,7 @@ bfd_mach_o_read_symtab_symbol (bfd *abfd,
        (_("bfd_mach_o_read_symtab_symbol: name out of range (%lu >= %u)"),
         stroff,
         sym->strsize);
-      return FALSE;
+      return false;
     }
 
   s->symbol.the_bfd = abfd;
@@ -3879,10 +3881,10 @@ bfd_mach_o_read_symtab_symbol (bfd *abfd,
        }
     }
 
-  return TRUE;
+  return true;
 }
 
-bfd_boolean
+bool
 bfd_mach_o_read_symtab_strtab (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
@@ -3890,11 +3892,11 @@ bfd_mach_o_read_symtab_strtab (bfd *abfd)
 
   /* Fail if there is no symtab.  */
   if (sym == NULL)
-    return FALSE;
+    return false;
 
   /* Success if already loaded.  */
   if (sym->strtab)
-    return TRUE;
+    return true;
 
   if (abfd->flags & BFD_IN_MEMORY)
     {
@@ -3905,7 +3907,7 @@ bfd_mach_o_read_symtab_strtab (bfd *abfd)
       if ((sym->stroff + sym->strsize) > b->size)
        {
          bfd_set_error (bfd_error_file_truncated);
-         return FALSE;
+         return false;
        }
       sym->strtab = (char *) b->buffer + sym->stroff;
     }
@@ -3913,22 +3915,22 @@ bfd_mach_o_read_symtab_strtab (bfd *abfd)
     {
       /* See PR 21840 for a reproducer.  */
       if ((sym->strsize + 1) == 0)
-       return FALSE;
+       return false;
       if (bfd_seek (abfd, sym->stroff, SEEK_SET) != 0)
-       return FALSE;
+       return false;
       sym->strtab = (char *) _bfd_alloc_and_read (abfd, sym->strsize + 1,
                                                  sym->strsize);
       if (sym->strtab == NULL)
-       return FALSE;
+       return false;
 
       /* Zero terminate the string table.  */
       sym->strtab[sym->strsize] = 0;
     }
 
-  return TRUE;
+  return true;
 }
 
-bfd_boolean
+bool
 bfd_mach_o_read_symtab_symbols (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
@@ -3939,7 +3941,7 @@ bfd_mach_o_read_symtab_symbols (bfd *abfd)
 
   if (sym == NULL || sym->nsyms == 0 || sym->symbols)
     /* Return now if there are no symbols or if already loaded.  */
-    return TRUE;
+    return true;
 
   filesize = bfd_get_file_size (abfd);
   if (filesize != 0)
@@ -3953,7 +3955,7 @@ bfd_mach_o_read_symtab_symbols (bfd *abfd)
        {
          bfd_set_error (bfd_error_file_truncated);
          sym->nsyms = 0;
-         return FALSE;
+         return false;
        }
     }
   if (_bfd_mul_overflow (sym->nsyms, sizeof (bfd_mach_o_asymbol), &amt)
@@ -3961,7 +3963,7 @@ bfd_mach_o_read_symtab_symbols (bfd *abfd)
     {
       bfd_set_error (bfd_error_no_memory);
       sym->nsyms = 0;
-      return FALSE;
+      return false;
     }
 
   if (!bfd_mach_o_read_symtab_strtab (abfd))
@@ -3971,13 +3973,13 @@ bfd_mach_o_read_symtab_symbols (bfd *abfd)
     if (!bfd_mach_o_read_symtab_symbol (abfd, sym, &sym->symbols[i], i))
       goto fail;
 
-  return TRUE;
+  return true;
 
  fail:
   bfd_release (abfd, sym->symbols);
   sym->symbols = NULL;
   sym->nsyms = 0;
-  return FALSE;
+  return false;
 }
 
 static const char *
@@ -4018,49 +4020,54 @@ bfd_mach_o_ppc_flavour_string (unsigned int flavour)
 }
 
 static unsigned char *
-bfd_mach_o_alloc_and_read (bfd *abfd, file_ptr filepos, size_t size)
+bfd_mach_o_alloc_and_read (bfd *abfd, file_ptr filepos,
+                          size_t size, size_t extra)
 {
   if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
     return NULL;
-  return _bfd_alloc_and_read (abfd, size, size);
+  unsigned char *ret = _bfd_alloc_and_read (abfd, size + extra, size);
+  if (ret && extra != 0)
+    memset (ret + size, 0, extra);
+  return ret;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_dylinker (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_dylinker_command *cmd = &command->command.dylinker;
   struct mach_o_str_command_external raw;
   unsigned int nameoff;
-  unsigned int namelen;
+  size_t namelen;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   nameoff = bfd_h_get_32 (abfd, raw.str);
   if (nameoff > command->len)
-    return FALSE;
+    return false;
 
   cmd->name_offset = nameoff;
   namelen = command->len - nameoff;
   nameoff += command->offset;
-  cmd->name_str = (char *) bfd_mach_o_alloc_and_read (abfd, nameoff, namelen);
+  cmd->name_str = (char *) bfd_mach_o_alloc_and_read (abfd, nameoff,
+                                                     namelen, 1);
   return cmd->name_str != NULL;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_dylib (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   bfd_mach_o_dylib_command *cmd = &command->command.dylib;
   struct mach_o_dylib_command_external raw;
   unsigned int nameoff;
-  unsigned int namelen;
+  size_t namelen;
   file_ptr pos;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   switch (command->type)
     {
     case BFD_MACH_O_LC_LOAD_DYLIB:
@@ -4072,15 +4079,15 @@ bfd_mach_o_read_dylib (bfd *abfd, bfd_mach_o_load_command *command)
       break;
     default:
       BFD_FAIL ();
-      return FALSE;
+      return false;
     }
 
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   nameoff = bfd_h_get_32 (abfd, raw.name);
   if (nameoff > command->len)
-    return FALSE;
+    return false;
   cmd->timestamp = bfd_h_get_32 (abfd, raw.timestamp);
   cmd->current_version = bfd_h_get_32 (abfd, raw.current_version);
   cmd->compatibility_version = bfd_h_get_32 (abfd, raw.compatibility_version);
@@ -4088,11 +4095,11 @@ bfd_mach_o_read_dylib (bfd *abfd, bfd_mach_o_load_command *command)
   cmd->name_offset = command->offset + nameoff;
   namelen = command->len - nameoff;
   pos = mdata->hdr_offset + cmd->name_offset;
-  cmd->name_str = (char *) bfd_mach_o_alloc_and_read (abfd, pos, namelen);
+  cmd->name_str = (char *) bfd_mach_o_alloc_and_read (abfd, pos, namelen, 1);
   return cmd->name_str != NULL;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_prebound_dylib (bfd *abfd,
                                bfd_mach_o_load_command *command)
 {
@@ -4104,19 +4111,19 @@ bfd_mach_o_read_prebound_dylib (bfd *abfd,
   unsigned char *str;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   nameoff = bfd_h_get_32 (abfd, raw.name);
   modoff = bfd_h_get_32 (abfd, raw.linked_modules);
   if (nameoff > command->len || modoff > command->len)
-    return FALSE;
+    return false;
 
   str_len = command->len - sizeof (raw);
   str = _bfd_alloc_and_read (abfd, str_len, str_len);
   if (str == NULL)
-    return FALSE;
+    return false;
 
   cmd->name_offset = command->offset + nameoff;
   cmd->nmodules = bfd_h_get_32 (abfd, raw.nmodules);
@@ -4124,10 +4131,10 @@ bfd_mach_o_read_prebound_dylib (bfd *abfd,
 
   cmd->name_str = (char *)str + nameoff - (sizeof (raw) + BFD_MACH_O_LC_SIZE);
   cmd->linked_modules = str + modoff - (sizeof (raw) + BFD_MACH_O_LC_SIZE);
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_prebind_cksum (bfd *abfd,
                               bfd_mach_o_load_command *command)
 {
@@ -4135,15 +4142,15 @@ bfd_mach_o_read_prebind_cksum (bfd *abfd,
   struct mach_o_prebind_cksum_command_external raw;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   cmd->cksum = bfd_get_32 (abfd, raw.cksum);
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_twolevel_hints (bfd *abfd,
                                bfd_mach_o_load_command *command)
 {
@@ -4151,42 +4158,42 @@ bfd_mach_o_read_twolevel_hints (bfd *abfd,
   struct mach_o_twolevel_hints_command_external raw;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   cmd->offset = bfd_get_32 (abfd, raw.offset);
   cmd->nhints = bfd_get_32 (abfd, raw.nhints);
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_fvmlib (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_fvmlib_command *fvm = &command->command.fvmlib;
   struct mach_o_fvmlib_command_external raw;
   unsigned int nameoff;
-  unsigned int namelen;
+  size_t namelen;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   nameoff = bfd_h_get_32 (abfd, raw.name);
   if (nameoff > command->len)
-    return FALSE;
+    return false;
   fvm->minor_version = bfd_h_get_32 (abfd, raw.minor_version);
   fvm->header_addr = bfd_h_get_32 (abfd, raw.header_addr);
 
   fvm->name_offset = command->offset + nameoff;
   namelen = command->len - nameoff;
   fvm->name_str = (char *) bfd_mach_o_alloc_and_read (abfd, fvm->name_offset,
-                                                     namelen);
+                                                     namelen, 1);
   return fvm->name_str != NULL;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
@@ -4209,27 +4216,27 @@ bfd_mach_o_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
 
       if (bfd_seek (abfd, command->offset + offset, SEEK_SET) != 0
          || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-       return FALSE;
+       return false;
 
       count = bfd_h_get_32 (abfd, raw.count);
       if (count > (unsigned) -1 / 4
          || command->len - (offset + sizeof (raw)) < count * 4)
-       return FALSE;
+       return false;
       offset += sizeof (raw) + count * 4;
       nflavours++;
     }
   if (nflavours == 0 || offset != command->len)
-    return FALSE;
+    return false;
 
   /* Allocate threads.  */
   if (_bfd_mul_overflow (nflavours, sizeof (bfd_mach_o_thread_flavour), &amt))
     {
       bfd_set_error (bfd_error_file_too_big);
-      return FALSE;
+      return false;
     }
   cmd->flavours = bfd_alloc (abfd, amt);
   if (cmd->flavours == NULL)
-    return FALSE;
+    return false;
   cmd->nflavours = nflavours;
 
   offset = 8;
@@ -4238,7 +4245,7 @@ bfd_mach_o_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
     {
       if (bfd_seek (abfd, command->offset + offset, SEEK_SET) != 0
          || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-       return FALSE;
+       return false;
 
       cmd->flavours[nflavours].flavour = bfd_h_get_32 (abfd, raw.flavour);
       cmd->flavours[nflavours].offset = command->offset + offset + sizeof (raw);
@@ -4250,7 +4257,7 @@ bfd_mach_o_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
   for (i = 0; i < nflavours; i++)
     {
       asection *bfdsec;
-      unsigned int snamelen;
+      size_t snamelen;
       char *sname;
       const char *flavourstr;
       const char *prefix = "LC_THREAD";
@@ -4276,7 +4283,7 @@ bfd_mach_o_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
       snamelen = strlen (prefix) + 1 + 20 + 1 + strlen (flavourstr) + 1;
       sname = bfd_alloc (abfd, snamelen);
       if (sname == NULL)
-       return FALSE;
+       return false;
 
       for (;;)
        {
@@ -4297,10 +4304,10 @@ bfd_mach_o_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
       cmd->section = bfdsec;
     }
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command,
                          ufile_ptr filesize)
 {
@@ -4313,9 +4320,9 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command,
     struct mach_o_dysymtab_command_external raw;
 
     if (command->len < sizeof (raw) + 8)
-      return FALSE;
+      return false;
     if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-      return FALSE;
+      return false;
 
     cmd->ilocalsym = bfd_h_get_32 (abfd, raw.ilocalsym);
     cmd->nlocalsym = bfd_h_get_32 (abfd, raw.nlocalsym);
@@ -4348,20 +4355,20 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command,
          || cmd->nmodtab > (filesize - cmd->modtaboff) / module_len)
        {
          bfd_set_error (bfd_error_file_truncated);
-         return FALSE;
+         return false;
        }
       if (_bfd_mul_overflow (cmd->nmodtab,
                             sizeof (bfd_mach_o_dylib_module), &amt))
        {
          bfd_set_error (bfd_error_file_too_big);
-         return FALSE;
+         return false;
        }
       cmd->dylib_module = bfd_alloc (abfd, amt);
       if (cmd->dylib_module == NULL)
-       return FALSE;
+       return false;
 
       if (bfd_seek (abfd, cmd->modtaboff, SEEK_SET) != 0)
-       return FALSE;
+       return false;
 
       for (i = 0; i < cmd->nmodtab; i++)
        {
@@ -4370,7 +4377,7 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command,
          unsigned char buf[56];
 
          if (bfd_bread ((void *) buf, module_len, abfd) != module_len)
-           return FALSE;
+           return false;
 
          module->module_name_idx = bfd_h_get_32 (abfd, buf + 0);
          module->iextdefsym = bfd_h_get_32 (abfd, buf + 4);
@@ -4410,27 +4417,27 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command,
          || cmd->ntoc > (filesize - cmd->tocoff) / sizeof (raw))
        {
          bfd_set_error (bfd_error_file_truncated);
-         return FALSE;
+         return false;
        }
       if (_bfd_mul_overflow (cmd->ntoc,
                             sizeof (bfd_mach_o_dylib_table_of_content), &amt))
        {
          bfd_set_error (bfd_error_file_too_big);
-         return FALSE;
+         return false;
        }
       cmd->dylib_toc = bfd_alloc (abfd, amt);
       if (cmd->dylib_toc == NULL)
-       return FALSE;
+       return false;
 
       if (bfd_seek (abfd, cmd->tocoff, SEEK_SET) != 0)
-       return FALSE;
+       return false;
 
       for (i = 0; i < cmd->ntoc; i++)
        {
          bfd_mach_o_dylib_table_of_content *toc = &cmd->dylib_toc[i];
 
          if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-           return FALSE;
+           return false;
 
          toc->symbol_index = bfd_h_get_32 (abfd, raw.symbol_index);
          toc->module_index = bfd_h_get_32 (abfd, raw.module_index);
@@ -4446,19 +4453,19 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command,
          || cmd->nindirectsyms > (filesize - cmd->indirectsymoff) / 4)
        {
          bfd_set_error (bfd_error_file_truncated);
-         return FALSE;
+         return false;
        }
       if (_bfd_mul_overflow (cmd->nindirectsyms, sizeof (unsigned int), &amt))
        {
          bfd_set_error (bfd_error_file_too_big);
-         return FALSE;
+         return false;
        }
       cmd->indirect_syms = bfd_alloc (abfd, amt);
       if (cmd->indirect_syms == NULL)
-       return FALSE;
+       return false;
 
       if (bfd_seek (abfd, cmd->indirectsymoff, SEEK_SET) != 0)
-       return FALSE;
+       return false;
 
       for (i = 0; i < cmd->nindirectsyms; i++)
        {
@@ -4466,7 +4473,7 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command,
          unsigned int *is = &cmd->indirect_syms[i];
 
          if (bfd_bread (raw, sizeof (raw), abfd) != sizeof (raw))
-           return FALSE;
+           return false;
 
          *is = bfd_h_get_32 (abfd, raw);
        }
@@ -4482,20 +4489,20 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command,
          || cmd->nextrefsyms > (filesize - cmd->extrefsymoff) / 4)
        {
          bfd_set_error (bfd_error_file_truncated);
-         return FALSE;
+         return false;
        }
       if (_bfd_mul_overflow (cmd->nextrefsyms,
                             sizeof (bfd_mach_o_dylib_reference), &amt))
        {
          bfd_set_error (bfd_error_file_too_big);
-         return FALSE;
+         return false;
        }
       cmd->ext_refs = bfd_alloc (abfd, amt);
       if (cmd->ext_refs == NULL)
-       return FALSE;
+       return false;
 
       if (bfd_seek (abfd, cmd->extrefsymoff, SEEK_SET) != 0)
-       return FALSE;
+       return false;
 
       for (i = 0; i < cmd->nextrefsyms; i++)
        {
@@ -4503,7 +4510,7 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command,
          bfd_mach_o_dylib_reference *ref = &cmd->ext_refs[i];
 
          if (bfd_bread (raw, sizeof (raw), abfd) != sizeof (raw))
-           return FALSE;
+           return false;
 
          /* Fields isym and flags are written as bit-fields, thus we need
             a specific processing for endianness.  */
@@ -4522,13 +4529,13 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command,
     }
 
   if (mdata->dysymtab)
-    return FALSE;
+    return false;
   mdata->dysymtab = cmd;
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_symtab (bfd *abfd, bfd_mach_o_load_command *command,
                        ufile_ptr filesize)
 {
@@ -4539,9 +4546,9 @@ bfd_mach_o_read_symtab (bfd *abfd, bfd_mach_o_load_command *command,
   BFD_ASSERT (command->type == BFD_MACH_O_LC_SYMTAB);
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   symtab->symoff = bfd_h_get_32 (abfd, raw.symoff);
   symtab->nsyms = bfd_h_get_32 (abfd, raw.nsyms);
@@ -4556,19 +4563,19 @@ bfd_mach_o_read_symtab (bfd *abfd, bfd_mach_o_load_command *command,
       || symtab->strsize > filesize - symtab->stroff)
     {
       bfd_set_error (bfd_error_file_truncated);
-      return FALSE;
+      return false;
     }
 
   if (symtab->nsyms != 0)
     abfd->flags |= HAS_SYMS;
 
   if (mdata->symtab)
-    return FALSE;
+    return false;
   mdata->symtab = symtab;
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_uuid (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_uuid_command *cmd = &command->command.uuid;
@@ -4576,30 +4583,30 @@ bfd_mach_o_read_uuid (bfd *abfd, bfd_mach_o_load_command *command)
   BFD_ASSERT (command->type == BFD_MACH_O_LC_UUID);
 
   if (command->len < 16 + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (cmd->uuid, 16, abfd) != 16)
-    return FALSE;
+    return false;
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_linkedit (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_linkedit_command *cmd = &command->command.linkedit;
   struct mach_o_linkedit_data_command_external raw;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   cmd->dataoff = bfd_get_32 (abfd, raw.dataoff);
   cmd->datasize = bfd_get_32 (abfd, raw.datasize);
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_str (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_str_command *cmd = &command->command.str;
@@ -4607,82 +4614,87 @@ bfd_mach_o_read_str (bfd *abfd, bfd_mach_o_load_command *command)
   unsigned long off;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   off = bfd_get_32 (abfd, raw.str);
   if (off > command->len)
-    return FALSE;
+    return false;
 
   cmd->stroff = command->offset + off;
   cmd->str_len = command->len - off;
   cmd->str = (char *) bfd_mach_o_alloc_and_read (abfd, cmd->stroff,
-                                                cmd->str_len);
+                                                cmd->str_len, 1);
   return cmd->str != NULL;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_dyld_content (bfd *abfd, bfd_mach_o_dyld_info_command *cmd)
 {
   /* Read rebase content.  */
   if (cmd->rebase_content == NULL && cmd->rebase_size != 0)
     {
       cmd->rebase_content
-       = bfd_mach_o_alloc_and_read (abfd, cmd->rebase_off, cmd->rebase_size);
+       = bfd_mach_o_alloc_and_read (abfd, cmd->rebase_off,
+                                    cmd->rebase_size, 0);
       if (cmd->rebase_content == NULL)
-       return FALSE;
+       return false;
     }
 
   /* Read bind content.  */
   if (cmd->bind_content == NULL && cmd->bind_size != 0)
     {
       cmd->bind_content
-       = bfd_mach_o_alloc_and_read (abfd, cmd->bind_off, cmd->bind_size);
+       = bfd_mach_o_alloc_and_read (abfd, cmd->bind_off,
+                                    cmd->bind_size, 0);
       if (cmd->bind_content == NULL)
-       return FALSE;
+       return false;
     }
 
   /* Read weak bind content.  */
   if (cmd->weak_bind_content == NULL && cmd->weak_bind_size != 0)
     {
-      cmd->weak_bind_content = bfd_mach_o_alloc_and_read
-       (abfd, cmd->weak_bind_off, cmd->weak_bind_size);
+      cmd->weak_bind_content
+       = bfd_mach_o_alloc_and_read (abfd, cmd->weak_bind_off,
+                                    cmd->weak_bind_size, 0);
       if (cmd->weak_bind_content == NULL)
-       return FALSE;
+       return false;
     }
 
   /* Read lazy bind content.  */
   if (cmd->lazy_bind_content == NULL && cmd->lazy_bind_size != 0)
     {
-      cmd->lazy_bind_content = bfd_mach_o_alloc_and_read
-       (abfd, cmd->lazy_bind_off, cmd->lazy_bind_size);
+      cmd->lazy_bind_content
+       = bfd_mach_o_alloc_and_read (abfd, cmd->lazy_bind_off,
+                                    cmd->lazy_bind_size, 0);
       if (cmd->lazy_bind_content == NULL)
-       return FALSE;
+       return false;
     }
 
   /* Read export content.  */
   if (cmd->export_content == NULL && cmd->export_size != 0)
     {
-      cmd->export_content = bfd_mach_o_alloc_and_read
-       (abfd, cmd->export_off, cmd->export_size);
+      cmd->export_content
+       = bfd_mach_o_alloc_and_read (abfd, cmd->export_off,
+                                    cmd->export_size, 0);
       if (cmd->export_content == NULL)
-       return FALSE;
+       return false;
     }
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_dyld_info (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_dyld_info_command *cmd = &command->command.dyld_info;
   struct mach_o_dyld_info_command_external raw;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   cmd->rebase_off = bfd_get_32 (abfd, raw.rebase_off);
   cmd->rebase_size = bfd_get_32 (abfd, raw.rebase_size);
@@ -4699,86 +4711,86 @@ bfd_mach_o_read_dyld_info (bfd *abfd, bfd_mach_o_load_command *command)
   cmd->export_off = bfd_get_32 (abfd, raw.export_off);
   cmd->export_size = bfd_get_32 (abfd, raw.export_size);
   cmd->export_content = NULL;
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_version_min (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_version_min_command *cmd = &command->command.version_min;
   struct mach_o_version_min_command_external raw;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   cmd->version = bfd_get_32 (abfd, raw.version);
   cmd->sdk = bfd_get_32 (abfd, raw.sdk);
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_encryption_info (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_encryption_info_command *cmd = &command->command.encryption_info;
   struct mach_o_encryption_info_command_external raw;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   cmd->cryptoff = bfd_get_32 (abfd, raw.cryptoff);
   cmd->cryptsize = bfd_get_32 (abfd, raw.cryptsize);
   cmd->cryptid = bfd_get_32 (abfd, raw.cryptid);
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_encryption_info_64 (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_encryption_info_command *cmd = &command->command.encryption_info;
   struct mach_o_encryption_info_64_command_external raw;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   cmd->cryptoff = bfd_get_32 (abfd, raw.cryptoff);
   cmd->cryptsize = bfd_get_32 (abfd, raw.cryptsize);
   cmd->cryptid = bfd_get_32 (abfd, raw.cryptid);
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_main (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_main_command *cmd = &command->command.main;
   struct mach_o_entry_point_command_external raw;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   cmd->entryoff = bfd_get_64 (abfd, raw.entryoff);
   cmd->stacksize = bfd_get_64 (abfd, raw.stacksize);
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_source_version (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_source_version_command *cmd = &command->command.source_version;
   struct mach_o_source_version_command_external raw;
-  bfd_uint64_t ver;
+  uint64_t ver;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   ver = bfd_get_64 (abfd, raw.version);
   /* Note: we use a serie of shift to avoid shift > 32 (for which gcc
@@ -4793,45 +4805,45 @@ bfd_mach_o_read_source_version (bfd *abfd, bfd_mach_o_load_command *command)
   cmd->b = ver & 0x3ff;
   ver >>= 10;
   cmd->a = ver & 0xffffff;
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_note (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_note_command *cmd = &command->command.note;
   struct mach_o_note_command_external raw;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   memcpy (cmd->data_owner, raw.data_owner, 16);
   cmd->offset = bfd_get_64 (abfd, raw.offset);
   cmd->size = bfd_get_64 (abfd, raw.size);
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_build_version (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_build_version_command *cmd = &command->command.build_version;
   struct mach_o_build_version_command_external raw;
 
   if (command->len < sizeof (raw) + 8)
-    return FALSE;
+    return false;
   if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-    return FALSE;
+    return false;
 
   cmd->platform = bfd_get_32 (abfd, raw.platform);
   cmd->minos = bfd_get_32 (abfd, raw.minos);
   cmd->sdk = bfd_get_32 (abfd, raw.sdk);
   cmd->ntools = bfd_get_32 (abfd, raw.ntools);
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_segment (bfd *abfd,
                         bfd_mach_o_load_command *command,
                         unsigned int wide)
@@ -4846,9 +4858,9 @@ bfd_mach_o_read_segment (bfd *abfd,
       BFD_ASSERT (command->type == BFD_MACH_O_LC_SEGMENT_64);
 
       if (command->len < sizeof (raw) + 8)
-       return FALSE;
+       return false;
       if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-       return FALSE;
+       return false;
 
       memcpy (seg->segname, raw.segname, 16);
       seg->segname[16] = '\0';
@@ -4869,9 +4881,9 @@ bfd_mach_o_read_segment (bfd *abfd,
       BFD_ASSERT (command->type == BFD_MACH_O_LC_SEGMENT);
 
       if (command->len < sizeof (raw) + 8)
-       return FALSE;
+       return false;
       if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
-       return FALSE;
+       return false;
 
       memcpy (seg->segname, raw.segname, 16);
       seg->segname[16] = '\0';
@@ -4894,28 +4906,28 @@ bfd_mach_o_read_segment (bfd *abfd,
 
       sec = bfd_mach_o_read_section (abfd, seg->initprot, wide);
       if (sec == NULL)
-       return FALSE;
+       return false;
 
       bfd_mach_o_append_section_to_segment
        (seg, bfd_mach_o_get_mach_o_section (sec));
     }
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_segment_32 (bfd *abfd, bfd_mach_o_load_command *command)
 {
   return bfd_mach_o_read_segment (abfd, command, 0);
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_segment_64 (bfd *abfd, bfd_mach_o_load_command *command)
 {
   return bfd_mach_o_read_segment (abfd, command, 1);
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_read_command (bfd *abfd, bfd_mach_o_load_command *command,
                         ufile_ptr filesize)
 {
@@ -4926,41 +4938,41 @@ bfd_mach_o_read_command (bfd *abfd, bfd_mach_o_load_command *command,
   /* Read command type and length.  */
   if (bfd_seek (abfd, mdata->hdr_offset + command->offset, SEEK_SET) != 0
       || bfd_bread (&raw, BFD_MACH_O_LC_SIZE, abfd) != BFD_MACH_O_LC_SIZE)
-    return FALSE;
+    return false;
 
   cmd = bfd_h_get_32 (abfd, raw.cmd);
   command->type = cmd & ~BFD_MACH_O_LC_REQ_DYLD;
-  command->type_required = cmd & BFD_MACH_O_LC_REQ_DYLD ? TRUE : FALSE;
+  command->type_required = (cmd & BFD_MACH_O_LC_REQ_DYLD) != 0;
   command->len = bfd_h_get_32 (abfd, raw.cmdsize);
   if (command->len < 8 || command->len % 4 != 0)
-    return FALSE;
+    return false;
 
   switch (command->type)
     {
     case BFD_MACH_O_LC_SEGMENT:
       if (!bfd_mach_o_read_segment_32 (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_SEGMENT_64:
       if (!bfd_mach_o_read_segment_64 (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_SYMTAB:
       if (!bfd_mach_o_read_symtab (abfd, command, filesize))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_SYMSEG:
       break;
     case BFD_MACH_O_LC_THREAD:
     case BFD_MACH_O_LC_UNIXTHREAD:
       if (!bfd_mach_o_read_thread (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_LOAD_DYLINKER:
     case BFD_MACH_O_LC_ID_DYLINKER:
     case BFD_MACH_O_LC_DYLD_ENVIRONMENT:
       if (!bfd_mach_o_read_dylinker (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_LOAD_DYLIB:
     case BFD_MACH_O_LC_LAZY_LOAD_DYLIB:
@@ -4969,16 +4981,16 @@ bfd_mach_o_read_command (bfd *abfd, bfd_mach_o_load_command *command,
     case BFD_MACH_O_LC_REEXPORT_DYLIB:
     case BFD_MACH_O_LC_LOAD_UPWARD_DYLIB:
       if (!bfd_mach_o_read_dylib (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_PREBOUND_DYLIB:
       if (!bfd_mach_o_read_prebound_dylib (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_LOADFVMLIB:
     case BFD_MACH_O_LC_IDFVMLIB:
       if (!bfd_mach_o_read_fvmlib (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_IDENT:
     case BFD_MACH_O_LC_FVMFILE:
@@ -4992,23 +5004,23 @@ bfd_mach_o_read_command (bfd *abfd, bfd_mach_o_load_command *command,
     case BFD_MACH_O_LC_SUB_CLIENT:
     case BFD_MACH_O_LC_RPATH:
       if (!bfd_mach_o_read_str (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_DYSYMTAB:
       if (!bfd_mach_o_read_dysymtab (abfd, command, filesize))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_PREBIND_CKSUM:
       if (!bfd_mach_o_read_prebind_cksum (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_TWOLEVEL_HINTS:
       if (!bfd_mach_o_read_twolevel_hints (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_UUID:
       if (!bfd_mach_o_read_uuid (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_CODE_SIGNATURE:
     case BFD_MACH_O_LC_SEGMENT_SPLIT_INFO:
@@ -5019,56 +5031,56 @@ bfd_mach_o_read_command (bfd *abfd, bfd_mach_o_load_command *command,
     case BFD_MACH_O_LC_DYLD_EXPORTS_TRIE:
     case BFD_MACH_O_LC_DYLD_CHAINED_FIXUPS:
       if (!bfd_mach_o_read_linkedit (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_ENCRYPTION_INFO:
       if (!bfd_mach_o_read_encryption_info (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_ENCRYPTION_INFO_64:
       if (!bfd_mach_o_read_encryption_info_64 (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_DYLD_INFO:
       if (!bfd_mach_o_read_dyld_info (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_VERSION_MIN_MACOSX:
     case BFD_MACH_O_LC_VERSION_MIN_IPHONEOS:
     case BFD_MACH_O_LC_VERSION_MIN_WATCHOS:
     case BFD_MACH_O_LC_VERSION_MIN_TVOS:
       if (!bfd_mach_o_read_version_min (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_MAIN:
       if (!bfd_mach_o_read_main (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_SOURCE_VERSION:
       if (!bfd_mach_o_read_source_version (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_LINKER_OPTIONS:
       break;
     case BFD_MACH_O_LC_NOTE:
       if (!bfd_mach_o_read_note (abfd, command))
-       return FALSE;
+       return false;
       break;
     case BFD_MACH_O_LC_BUILD_VERSION:
       if (!bfd_mach_o_read_build_version (abfd, command))
-       return FALSE;
+       return false;
       break;
     default:
       command->len = 0;
       _bfd_error_handler (_("%pB: unknown load command %#x"),
                          abfd, command->type);
-      return FALSE;
+      return false;
     }
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_flatten_sections (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
@@ -5094,11 +5106,11 @@ bfd_mach_o_flatten_sections (bfd *abfd)
   if (_bfd_mul_overflow (mdata->nsects, sizeof (bfd_mach_o_section *), &amt))
     {
       bfd_set_error (bfd_error_file_too_big);
-      return FALSE;
+      return false;
     }
   mdata->sections = bfd_alloc (abfd, amt);
   if (mdata->sections == NULL && mdata->nsects != 0)
-    return FALSE;
+    return false;
 
   /* Fill the array.  */
   csect = 0;
@@ -5117,10 +5129,10 @@ bfd_mach_o_flatten_sections (bfd *abfd)
            mdata->sections[csect++] = sec;
        }
     }
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_scan_start_address (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
@@ -5144,13 +5156,13 @@ bfd_mach_o_scan_start_address (bfd *abfd)
          {
            abfd->start_address = main_cmd->entryoff
              + (text_sect->addr - text_sect->offset);
-           return TRUE;
+           return true;
          }
       }
 
   /* An object file has no start address, so do not fail if not found.  */
   if (thr == NULL)
-    return TRUE;
+    return true;
 
   /* FIXME: create a subtarget hook ?  */
   for (i = 0; i < thr->nflavours; i++)
@@ -5162,7 +5174,7 @@ bfd_mach_o_scan_start_address (bfd *abfd)
 
          if (bfd_seek (abfd, thr->flavours[i].offset + 40, SEEK_SET) != 0
              || bfd_bread (buf, 4, abfd) != 4)
-           return FALSE;
+           return false;
 
          abfd->start_address = bfd_h_get_32 (abfd, buf);
        }
@@ -5173,7 +5185,7 @@ bfd_mach_o_scan_start_address (bfd *abfd)
 
          if (bfd_seek (abfd, thr->flavours[i].offset + 0, SEEK_SET) != 0
              || bfd_bread (buf, 4, abfd) != 4)
-           return FALSE;
+           return false;
 
          abfd->start_address = bfd_h_get_32 (abfd, buf);
        }
@@ -5184,7 +5196,7 @@ bfd_mach_o_scan_start_address (bfd *abfd)
 
          if (bfd_seek (abfd, thr->flavours[i].offset + 0, SEEK_SET) != 0
              || bfd_bread (buf, 8, abfd) != 8)
-           return FALSE;
+           return false;
 
          abfd->start_address = bfd_h_get_64 (abfd, buf);
        }
@@ -5195,16 +5207,16 @@ bfd_mach_o_scan_start_address (bfd *abfd)
 
          if (bfd_seek (abfd, thr->flavours[i].offset + (16 * 8), SEEK_SET) != 0
              || bfd_bread (buf, 8, abfd) != 8)
-           return FALSE;
+           return false;
 
          abfd->start_address = bfd_h_get_64 (abfd, buf);
        }
     }
 
-  return TRUE;
+  return true;
 }
 
-bfd_boolean
+bool
 bfd_mach_o_set_arch_mach (bfd *abfd,
                          enum bfd_architecture arch,
                          unsigned long machine)
@@ -5216,12 +5228,12 @@ bfd_mach_o_set_arch_mach (bfd *abfd,
   if (arch != bed->arch
       && arch != bfd_arch_unknown
       && bed->arch != bfd_arch_unknown)
-    return FALSE;
+    return false;
 
   return bfd_default_set_arch_mach (abfd, arch, machine);
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_scan (bfd *abfd,
                 bfd_mach_o_header *header,
                 bfd_mach_o_data_struct *mdata)
@@ -5261,7 +5273,7 @@ bfd_mach_o_scan (bfd *abfd,
        /* xgettext:c-format */
        (_("bfd_mach_o_scan: unknown architecture 0x%lx/0x%lx"),
         header->cputype, header->cpusubtype);
-      return FALSE;
+      return false;
     }
 
   bfd_set_arch_mach (abfd, cpu_type, cpu_subtype);
@@ -5281,17 +5293,17 @@ bfd_mach_o_scan (bfd *abfd,
       if (header->ncmds > (filesize - hdrsize) / BFD_MACH_O_LC_SIZE)
        {
          bfd_set_error (bfd_error_file_truncated);
-         return FALSE;
+         return false;
        }
       if (_bfd_mul_overflow (header->ncmds,
                             sizeof (bfd_mach_o_load_command), &amt))
        {
          bfd_set_error (bfd_error_file_too_big);
-         return FALSE;
+         return false;
        }
       cmd = bfd_alloc (abfd, amt);
       if (cmd == NULL)
-       return FALSE;
+       return false;
 
       for (i = 0; i < header->ncmds; i++)
        {
@@ -5308,27 +5320,27 @@ bfd_mach_o_scan (bfd *abfd,
            }
 
          if (!bfd_mach_o_read_command (abfd, cur, filesize))
-           return FALSE;
+           return false;
        }
     }
 
   /* Sections should be flatten before scanning start address.  */
   if (!bfd_mach_o_flatten_sections (abfd))
-    return FALSE;
+    return false;
   if (!bfd_mach_o_scan_start_address (abfd))
-    return FALSE;
+    return false;
 
-  return TRUE;
+  return true;
 }
 
-bfd_boolean
+bool
 bfd_mach_o_mkobject_init (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata = NULL;
 
   mdata = bfd_zalloc (abfd, sizeof (bfd_mach_o_data_struct));
   if (mdata == NULL)
-    return FALSE;
+    return false;
   abfd->tdata.mach_o_data = mdata;
 
   mdata->header.magic = 0;
@@ -5345,16 +5357,16 @@ bfd_mach_o_mkobject_init (bfd *abfd)
   mdata->sections = NULL;
   mdata->dyn_reloc_cache = NULL;
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_gen_mkobject (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata;
 
   if (!bfd_mach_o_mkobject_init (abfd))
-    return FALSE;
+    return false;
 
   mdata = bfd_mach_o_get_data (abfd);
   mdata->header.magic = BFD_MACH_O_MH_MAGIC;
@@ -5363,7 +5375,7 @@ bfd_mach_o_gen_mkobject (bfd *abfd)
   mdata->header.byteorder = abfd->xvec->byteorder;
   mdata->header.version = 1;
 
-  return TRUE;
+  return true;
 }
 
 bfd_cleanup
@@ -5502,6 +5514,22 @@ typedef struct mach_o_fat_data_struct
   mach_o_fat_archentry *archentries;
 } mach_o_fat_data_struct;
 
+/* Check for overlapping archive elements.  Note that we can't allow
+   multiple elements at the same offset even if one is empty, because
+   bfd_mach_o_fat_openr_next_archived_file assume distinct offsets.  */
+static bool
+overlap_previous (const mach_o_fat_archentry *elt, unsigned long i)
+{
+  unsigned long j = i;
+  while (j-- != 0)
+    if (elt[i].offset == elt[j].offset
+       || (elt[i].offset > elt[j].offset
+           ? elt[i].offset - elt[j].offset < elt[j].size
+           : elt[j].offset - elt[i].offset < elt[i].size))
+      return true;
+  return false;
+}
+
 bfd_cleanup
 bfd_mach_o_fat_archive_p (bfd *abfd)
 {
@@ -5509,6 +5537,7 @@ bfd_mach_o_fat_archive_p (bfd *abfd)
   struct mach_o_fat_header_external hdr;
   unsigned long i;
   size_t amt;
+  ufile_ptr filesize;
 
   if (bfd_seek (abfd, 0, SEEK_SET) != 0
       || bfd_bread (&hdr, sizeof (hdr), abfd) != sizeof (hdr))
@@ -5538,6 +5567,7 @@ bfd_mach_o_fat_archive_p (bfd *abfd)
   if (adata->archentries == NULL)
     goto error;
 
+  filesize = bfd_get_file_size (abfd);
   for (i = 0; i < adata->nfat_arch; i++)
     {
       struct mach_o_fat_arch_external arch;
@@ -5548,6 +5578,18 @@ bfd_mach_o_fat_archive_p (bfd *abfd)
       adata->archentries[i].offset = bfd_getb32 (arch.offset);
       adata->archentries[i].size = bfd_getb32 (arch.size);
       adata->archentries[i].align = bfd_getb32 (arch.align);
+      if ((filesize != 0
+          && (adata->archentries[i].offset > filesize
+              || (adata->archentries[i].size
+                  > filesize - adata->archentries[i].offset)))
+         || (adata->archentries[i].offset
+             < sizeof (hdr) + adata->nfat_arch * sizeof (arch))
+         || overlap_previous (adata->archentries, i))
+       {
+         bfd_release (abfd, adata);
+         bfd_set_error (bfd_error_malformed_archive);
+         return NULL;
+       }
     }
 
   abfd->tdata.mach_o_fat_data = adata;
@@ -5565,7 +5607,7 @@ bfd_mach_o_fat_archive_p (bfd *abfd)
    ARCH_TYPE/ARCH_SUBTYPE and corresponding entry in header is ENTRY.
    Set arelt_data and origin fields too.  */
 
-static bfd_boolean
+static bool
 bfd_mach_o_fat_member_init (bfd *abfd,
                            enum bfd_architecture arch_type,
                            unsigned long arch_subtype,
@@ -5590,16 +5632,16 @@ bfd_mach_o_fat_member_init (bfd *abfd,
       filename = bfd_set_filename (abfd, buf);
     }
   if (!filename)
-    return FALSE;
+    return false;
 
   areltdata = bfd_zmalloc (sizeof (struct areltdata));
   if (areltdata == NULL)
-    return FALSE;
+    return false;
   areltdata->parsed_size = entry->size;
   abfd->arelt_data = areltdata;
   abfd->iostream = NULL;
   abfd->origin = entry->offset;
-  return TRUE;
+  return true;
 }
 
 bfd *
@@ -5744,11 +5786,11 @@ bfd_mach_o_fat_extract (bfd *abfd,
   return NULL;
 }
 
-static bfd_boolean
+static bool
 bfd_mach_o_fat_close_and_cleanup (bfd *abfd)
 {
   _bfd_unlink_from_archive_parent (abfd);
-  return TRUE;
+  return true;
 }
 
 int
@@ -5931,7 +5973,8 @@ bfd_mach_o_core_fetch_environment (bfd *abfd,
                {
                  unsigned long val;
 
-                 val = *((unsigned long *) (buf + size - offset));
+                 val = bfd_get_32(abfd, buf + size - offset);
+
                  if (! found_nonnull)
                    {
                      if (val != 0)
@@ -5994,13 +6037,13 @@ bfd_mach_o_lookup_uuid_command (bfd *abfd)
   bfd_mach_o_load_command *uuid_cmd = NULL;
   int ncmd = bfd_mach_o_lookup_command (abfd, BFD_MACH_O_LC_UUID, &uuid_cmd);
   if (ncmd != 1 || uuid_cmd == NULL)
-    return FALSE;
+    return false;
   return &uuid_cmd->command.uuid;
 }
 
 /* Return true if ABFD is a dSYM file and its UUID matches UUID_CMD. */
 
-static bfd_boolean
+static bool
 bfd_mach_o_dsym_for_uuid_p (bfd *abfd, const bfd_mach_o_uuid_command *uuid_cmd)
 {
   bfd_mach_o_uuid_command *dsym_uuid_cmd;
@@ -6009,22 +6052,22 @@ bfd_mach_o_dsym_for_uuid_p (bfd *abfd, const bfd_mach_o_uuid_command *uuid_cmd)
   BFD_ASSERT (uuid_cmd);
 
   if (!bfd_check_format (abfd, bfd_object))
-    return FALSE;
+    return false;
 
   if (bfd_get_flavour (abfd) != bfd_target_mach_o_flavour
       || bfd_mach_o_get_data (abfd) == NULL
       || bfd_mach_o_get_data (abfd)->header.filetype != BFD_MACH_O_MH_DSYM)
-    return FALSE;
+    return false;
 
   dsym_uuid_cmd = bfd_mach_o_lookup_uuid_command (abfd);
   if (dsym_uuid_cmd == NULL)
-    return FALSE;
+    return false;
 
   if (memcmp (uuid_cmd->uuid, dsym_uuid_cmd->uuid,
              sizeof (uuid_cmd->uuid)) != 0)
-    return FALSE;
+    return false;
 
-  return TRUE;
+  return true;
 }
 
 /* Find a BFD in DSYM_FILENAME which matches ARCH and UUID_CMD.
@@ -6105,7 +6148,7 @@ bfd_mach_o_follow_dsym (bfd *abfd)
   return dsym_bfd;
 }
 
-bfd_boolean
+bool
 bfd_mach_o_find_nearest_line (bfd *abfd,
                              asymbol **symbols,
                              asection *section,
@@ -6117,7 +6160,7 @@ bfd_mach_o_find_nearest_line (bfd *abfd,
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   if (mdata == NULL)
-    return FALSE;
+    return false;
   switch (mdata->header.filetype)
     {
     case BFD_MACH_O_MH_OBJECT:
@@ -6138,12 +6181,12 @@ bfd_mach_o_find_nearest_line (bfd *abfd,
          if (! _bfd_dwarf2_slurp_debug_info (abfd, mdata->dsym_bfd,
                                              dwarf_debug_sections, symbols,
                                              &mdata->dwarf2_find_line_info,
-                                             FALSE))
-           return FALSE;
+                                             false))
+           return false;
        }
       break;
     default:
-      return FALSE;
+      return false;
     }
   return _bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
                                        filename_ptr, functionname_ptr,
@@ -6152,14 +6195,12 @@ bfd_mach_o_find_nearest_line (bfd *abfd,
                                        &mdata->dwarf2_find_line_info);
 }
 
-bfd_boolean
+bool
 bfd_mach_o_close_and_cleanup (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   if (bfd_get_format (abfd) == bfd_object && mdata != NULL)
     {
-      _bfd_dwarf2_cleanup_debug_info (abfd, &mdata->dwarf2_find_line_info);
-      bfd_mach_o_free_cached_info (abfd);
       if (mdata->dsym_bfd != NULL)
        {
          bfd *fat_bfd = mdata->dsym_bfd->my_archive;
@@ -6189,20 +6230,29 @@ bfd_mach_o_close_and_cleanup (bfd *abfd)
   return _bfd_generic_close_and_cleanup (abfd);
 }
 
-bfd_boolean
-bfd_mach_o_free_cached_info (bfd *abfd)
+bool
+bfd_mach_o_bfd_free_cached_info (bfd *abfd)
 {
-  bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
-  asection *asect;
-  free (mdata->dyn_reloc_cache);
-  mdata->dyn_reloc_cache = NULL;
-  for (asect = abfd->sections; asect != NULL; asect = asect->next)
+  bfd_mach_o_data_struct *mdata;
+
+  if ((bfd_get_format (abfd) == bfd_object
+       || bfd_get_format (abfd) == bfd_core)
+      && (mdata = bfd_mach_o_get_data (abfd)) != NULL)
     {
-      free (asect->relocation);
-      asect->relocation = NULL;
+      _bfd_dwarf2_cleanup_debug_info (abfd, &mdata->dwarf2_find_line_info);
+      free (mdata->dyn_reloc_cache);
+      mdata->dyn_reloc_cache = NULL;
+
+      for (asection *asect = abfd->sections; asect; asect = asect->next)
+       {
+         free (asect->relocation);
+         asect->relocation = NULL;
+       }
     }
 
-  return TRUE;
+  /* Do not call _bfd_generic_bfd_free_cached_info here.
+     bfd_mach_o_close_and_cleanup uses tdata.  */
+  return true;
 }
 
 #define bfd_mach_o_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup