sim: add missing values to array initializers
[deliverable/binutils-gdb.git] / bfd / mach-o.c
index cf1d1e02394fbf8e6f6a644a59c2d2a16110df65..d913d3c45ef6b792db6fda4e62abcff0a22f485f 100644 (file)
@@ -1,5 +1,6 @@
 /* Mach-O support for BFD.
-   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+   2009, 2010
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
 #define bfd_mach_o_object_p bfd_mach_o_gen_object_p
 #define bfd_mach_o_core_p bfd_mach_o_gen_core_p
-#define bfd_mach_o_mkobject bfd_false
+#define bfd_mach_o_mkobject bfd_mach_o_gen_mkobject
 
 #define FILE_ALIGN(off, algn) \
   (((off) + ((file_ptr) 1 << (algn)) - 1) & ((file_ptr) -1 << (algn)))
 
-static int bfd_mach_o_scan_read_symtab_symbols (bfd *);
+static int bfd_mach_o_read_symtab_symbols (bfd *);
 
 unsigned int
 bfd_mach_o_version (bfd *abfd)
@@ -90,37 +91,43 @@ struct mach_o_section_name_xlat
 {
   const char *bfd_name;
   const char *mach_o_name;
+  flagword flags;
 };
 
 static const struct mach_o_section_name_xlat dwarf_section_names_xlat[] =
   {
-    { ".debug_frame", "__debug_frame" },
-    { ".debug_info", "__debug_info" },
-    { ".debug_abbrev", "__debug_abbrev" },
-    { ".debug_aranges", "__debug_aranges" },
-    { ".debug_macinfo", "__debug_macinfo" },
-    { ".debug_line", "__debug_line" },
-    { ".debug_loc", "__debug_loc" },
-    { ".debug_pubnames", "__debug_pubnames" },
-    { ".debug_pubtypes", "__debug_pubtypes" },
-    { ".debug_str", "__debug_str" },
-    { ".debug_ranges", "__debug_ranges" },
-    { NULL, NULL}
+    { ".debug_frame",    "__debug_frame",    SEC_DEBUGGING },
+    { ".debug_info",     "__debug_info",     SEC_DEBUGGING },
+    { ".debug_abbrev",   "__debug_abbrev",   SEC_DEBUGGING },
+    { ".debug_aranges",  "__debug_aranges",  SEC_DEBUGGING },
+    { ".debug_macinfo",  "__debug_macinfo",  SEC_DEBUGGING },
+    { ".debug_line",     "__debug_line",     SEC_DEBUGGING },
+    { ".debug_loc",      "__debug_loc",      SEC_DEBUGGING },
+    { ".debug_pubnames", "__debug_pubnames", SEC_DEBUGGING },
+    { ".debug_pubtypes", "__debug_pubtypes", SEC_DEBUGGING },
+    { ".debug_str",      "__debug_str",      SEC_DEBUGGING },
+    { ".debug_ranges",   "__debug_ranges",   SEC_DEBUGGING },
+    { NULL, NULL, 0}
   };
 
 static const struct mach_o_section_name_xlat text_section_names_xlat[] =
   {
-    { ".text", "__text" },
-    { ".cstring", "__cstring" },
-    { ".eh_frame", "__eh_frame" },
-    { NULL, NULL}
+    { ".text",     "__text",      SEC_CODE | SEC_LOAD },
+    { ".const",    "__const",     SEC_READONLY | SEC_DATA | SEC_LOAD },
+    { ".cstring",  "__cstring",   SEC_READONLY | SEC_DATA | SEC_LOAD },
+    { ".eh_frame", "__eh_frame",  SEC_READONLY | SEC_LOAD },
+    { NULL, NULL, 0}
   };
 
 static const struct mach_o_section_name_xlat data_section_names_xlat[] =
   {
-    { ".data", "__data" },
-    { ".bss", "__bss" },
-    { NULL, NULL}
+    { ".data",                "__data",          SEC_DATA | SEC_LOAD },
+    { ".const_data",          "__const",         SEC_DATA | SEC_LOAD },
+    { ".dyld",                "__dyld",          SEC_DATA | SEC_LOAD },
+    { ".lazy_symbol_ptr",     "__la_symbol_ptr", SEC_DATA | SEC_LOAD },
+    { ".non_lazy_symbol_ptr", "__nl_symbol_ptr", SEC_DATA | SEC_LOAD },
+    { ".bss",                 "__bss",           SEC_NO_FLAGS },
+    { NULL, NULL, 0}
   };
 
 struct mach_o_segment_name_xlat
@@ -140,14 +147,18 @@ static const struct mach_o_segment_name_xlat segsec_names_xlat[] =
 
 /* Mach-O to bfd names.  */
 
-static char *
-bfd_mach_o_convert_section_name_to_bfd (bfd *abfd, bfd_mach_o_section *section)
+static void
+bfd_mach_o_convert_section_name_to_bfd (bfd *abfd, bfd_mach_o_section *section,
+                                        char **name, flagword *flags)
 {
   const struct mach_o_segment_name_xlat *seg;
   char *res;
   unsigned int len;
   const char *pfx = "";
 
+  *name = NULL;
+  *flags = SEC_NO_FLAGS;
+
   for (seg = segsec_names_xlat; seg->segname; seg++)
     {
       if (strcmp (seg->segname, section->segname) == 0)
@@ -162,9 +173,11 @@ bfd_mach_o_convert_section_name_to_bfd (bfd *abfd, bfd_mach_o_section *section)
                   res = bfd_alloc (abfd, len + 1);
 
                   if (res == NULL)
-                    return NULL;
+                    return;
                   strcpy (res, sec->bfd_name);
-                  return res;
+                  *name = res;
+                  *flags = sec->flags;
+                  return;
                 }
             }
         }
@@ -185,9 +198,9 @@ bfd_mach_o_convert_section_name_to_bfd (bfd *abfd, bfd_mach_o_section *section)
 
   res = bfd_alloc (abfd, len);
   if (res == NULL)
-    return NULL;
+    return;
   snprintf (res, len, "%s%s.%s", pfx, section->segname, section->sectname);
-  return res;
+  *name = res;
 }
 
 /* Convert a bfd section name to a Mach-O segment + section name.  */
@@ -253,6 +266,43 @@ bfd_mach_o_convert_section_name_to_mach_o (bfd *abfd ATTRIBUTE_UNUSED,
   section->sectname[len] = 0;
 }
 
+/* Return the size of an entry for section SEC.
+   Must be called only for symbol pointer section and symbol stubs
+   sections.  */
+
+static unsigned int
+bfd_mach_o_section_get_entry_size (bfd *abfd, bfd_mach_o_section *sec)
+{
+  switch (sec->flags & BFD_MACH_O_SECTION_TYPE_MASK)
+    {
+    case BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS:
+    case BFD_MACH_O_S_LAZY_SYMBOL_POINTERS:
+      return bfd_mach_o_wide_p (abfd) ? 8 : 4;
+    case BFD_MACH_O_S_SYMBOL_STUBS:
+      return sec->reserved2;
+    default:
+      BFD_FAIL ();
+      return 0;
+    }
+}
+
+/* Return the number of indirect symbols for a section.
+   Must be called only for symbol pointer section and symbol stubs
+   sections.  */
+
+static unsigned int
+bfd_mach_o_section_get_nbr_indirect (bfd *abfd, bfd_mach_o_section *sec)
+{
+  unsigned int elsz;
+
+  elsz = bfd_mach_o_section_get_entry_size (abfd, sec);
+  if (elsz == 0)
+    return 0;
+  else
+    return sec->size / elsz;
+}
+
+
 /* Copy any private info we understand from the input symbol
    to the output symbol.  */
 
@@ -326,7 +376,7 @@ bfd_mach_o_canonicalize_symtab (bfd *abfd, asymbol **alocation)
   if (nsyms < 0)
     return nsyms;
 
-  if (bfd_mach_o_scan_read_symtab_symbols (abfd) != 0)
+  if (bfd_mach_o_read_symtab_symbols (abfd) != 0)
     {
       fprintf (stderr,
                "bfd_mach_o_canonicalize_symtab: unable to load symbols\n");
@@ -343,6 +393,104 @@ bfd_mach_o_canonicalize_symtab (bfd *abfd, asymbol **alocation)
   return nsyms;
 }
 
+long
+bfd_mach_o_get_synthetic_symtab (bfd *abfd,
+                                 long symcount ATTRIBUTE_UNUSED,
+                                 asymbol **syms ATTRIBUTE_UNUSED,
+                                 long dynsymcount ATTRIBUTE_UNUSED,
+                                 asymbol **dynsyms ATTRIBUTE_UNUSED,
+                                 asymbol **ret)
+{
+  bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
+  bfd_mach_o_dysymtab_command *dysymtab = mdata->dysymtab;
+  bfd_mach_o_symtab_command *symtab = mdata->symtab;
+  asymbol *s;
+  unsigned long count, i, j, n;
+  size_t size;
+  char *names;
+  char *nul_name;
+
+  *ret = NULL;
+
+  if (dysymtab == NULL || symtab == NULL || symtab->symbols == NULL)
+    return 0;
+
+  if (dysymtab->nindirectsyms == 0)
+    return 0;
+
+  count = dysymtab->nindirectsyms;
+  size = count * sizeof (asymbol) + 1;
+
+  for (j = 0; j < count; j++)
+    {
+      unsigned int isym = dysymtab->indirect_syms[j];
+              
+      if (isym < symtab->nsyms && symtab->symbols[isym].symbol.name)
+        size += strlen (symtab->symbols[isym].symbol.name) + sizeof ("$stub");
+    }
+
+  s = *ret = (asymbol *) bfd_malloc (size);
+  if (s == NULL)
+    return -1;
+  names = (char *) (s + count);
+  nul_name = names;
+  *names++ = 0;
+  
+  n = 0;
+  for (i = 0; i < mdata->nsects; i++)
+    {
+      bfd_mach_o_section *sec = mdata->sections[i];
+      unsigned int first, last;
+      bfd_vma addr;
+      bfd_vma entry_size;
+      
+      switch (sec->flags & BFD_MACH_O_SECTION_TYPE_MASK)
+        {
+        case BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS:
+        case BFD_MACH_O_S_LAZY_SYMBOL_POINTERS:
+        case BFD_MACH_O_S_SYMBOL_STUBS:
+          first = sec->reserved1;
+          last = first + bfd_mach_o_section_get_nbr_indirect (abfd, sec);
+          addr = sec->addr;
+          entry_size = bfd_mach_o_section_get_entry_size (abfd, sec);
+          for (j = first; j < last; j++)
+            {
+              unsigned int isym = dysymtab->indirect_syms[j];
+
+              s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
+              s->section = sec->bfdsection;
+              s->value = addr - sec->addr;
+              s->udata.p = NULL;
+              
+              if (isym < symtab->nsyms
+                  && symtab->symbols[isym].symbol.name)
+                {
+                  const char *sym = symtab->symbols[isym].symbol.name;
+                  size_t len;
+
+                  s->name = names;
+                  len = strlen (sym);
+                  memcpy (names, sym, len);
+                  names += len;
+                  memcpy (names, "$stub", sizeof ("$stub"));
+                  names += sizeof ("$stub");
+                }
+              else
+                s->name = nul_name;
+
+              addr += entry_size;
+              s++;
+              n++;
+            }
+          break;
+        default:
+          break;
+        }
+    }
+
+  return n;
+}
+
 void
 bfd_mach_o_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED,
                            asymbol *symbol,
@@ -353,7 +501,7 @@ bfd_mach_o_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED,
 
 void
 bfd_mach_o_print_symbol (bfd *abfd,
-                        PTR afile,
+                        void * afile,
                         asymbol *symbol,
                         bfd_print_symbol_type how)
 {
@@ -367,7 +515,7 @@ bfd_mach_o_print_symbol (bfd *abfd,
       fprintf (file, "%s", symbol->name);
       break;
     default:
-      bfd_print_symbol_vandf (abfd, (PTR) file, symbol);
+      bfd_print_symbol_vandf (abfd, (void *) file, symbol);
       if (asym->n_type & BFD_MACH_O_N_STAB)
        name = bfd_get_stab_name (asym->n_type);
       else
@@ -469,14 +617,14 @@ bfd_mach_o_write_header (bfd *abfd, bfd_mach_o_header *header)
     bfd_h_put_32 (abfd, header->reserved, buf + 28);
 
   if (bfd_seek (abfd, 0, SEEK_SET) != 0
-      || bfd_bwrite ((PTR) buf, size, abfd) != size)
+      || bfd_bwrite ((void *) buf, size, abfd) != size)
     return FALSE;
 
   return TRUE;
 }
 
 static int
-bfd_mach_o_scan_write_thread (bfd *abfd, bfd_mach_o_load_command *command)
+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;
@@ -498,7 +646,7 @@ bfd_mach_o_scan_write_thread (bfd *abfd, bfd_mach_o_load_command *command)
       bfd_h_put_32 (abfd, (cmd->flavours[i].size / 4), buf + 4);
 
       if (bfd_seek (abfd, command->offset + offset, SEEK_SET) != 0
-          || bfd_bwrite ((PTR) buf, 8, abfd) != 8)
+          || bfd_bwrite ((void *) buf, 8, abfd) != 8)
        return -1;
 
       offset += cmd->flavours[i].size + 8;
@@ -514,114 +662,203 @@ bfd_mach_o_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
   return (asect->reloc_count + 1) * sizeof (arelent *);
 }
 
-long
-bfd_mach_o_canonicalize_reloc (bfd *abfd, asection *asect,
-                               arelent **rels, asymbol **syms)
+static int
+bfd_mach_o_canonicalize_one_reloc (bfd *abfd, char *buf,
+                                   arelent *res, asymbol **syms)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   bfd_mach_o_backend_data *bed = bfd_mach_o_get_backend_data (abfd);
+  bfd_mach_o_reloc_info reloc;
+  bfd_vma addr;
+  bfd_vma symnum;
+  asymbol **sym;
+
+  addr = bfd_get_32 (abfd, buf + 0);
+  symnum = bfd_get_32 (abfd, buf + 4);
+  
+  if (addr & BFD_MACH_O_SR_SCATTERED)
+    {
+      unsigned int j;
+
+      /* Scattered relocation.
+         Extract section and offset from r_value.  */
+      res->sym_ptr_ptr = NULL;
+      res->addend = 0;
+      for (j = 0; j < mdata->nsects; j++)
+        {
+          bfd_mach_o_section *sect = mdata->sections[j];
+          if (symnum >= sect->addr && symnum < sect->addr + sect->size)
+            {
+              res->sym_ptr_ptr = sect->bfdsection->symbol_ptr_ptr;
+              res->addend = symnum - sect->addr;
+              break;
+            }
+        }
+      res->address = BFD_MACH_O_GET_SR_ADDRESS (addr);
+      reloc.r_type = BFD_MACH_O_GET_SR_TYPE (addr);
+      reloc.r_length = BFD_MACH_O_GET_SR_LENGTH (addr);
+      reloc.r_pcrel = addr & BFD_MACH_O_SR_PCREL;
+      reloc.r_scattered = 1;
+    }
+  else
+    {
+      unsigned int num = BFD_MACH_O_GET_R_SYMBOLNUM (symnum);
+      res->addend = 0;
+      res->address = addr;
+      if (symnum & BFD_MACH_O_R_EXTERN)
+        {
+          sym = syms + num;
+          reloc.r_extern = 1;
+        }
+      else
+        {
+          BFD_ASSERT (num != 0);
+          BFD_ASSERT (num <= mdata->nsects);
+          sym = mdata->sections[num - 1]->bfdsection->symbol_ptr_ptr;
+          /* For a symbol defined in section S, the addend (stored in the
+             binary) contains the address of the section.  To comply with
+             bfd conventio, substract the section address.
+             Use the address from the header, so that the user can modify
+             the vma of the section.  */
+          res->addend = -mdata->sections[num - 1]->addr;
+          reloc.r_extern = 0;
+        }
+      res->sym_ptr_ptr = sym;
+      reloc.r_type = BFD_MACH_O_GET_R_TYPE (symnum);
+      reloc.r_length = BFD_MACH_O_GET_R_LENGTH (symnum);
+      reloc.r_pcrel = (symnum & BFD_MACH_O_R_PCREL) ? 1 : 0;
+      reloc.r_scattered = 0;
+    }
+  
+  if (!(*bed->_bfd_mach_o_swap_reloc_in)(res, &reloc))
+    return -1;
+  return 0;
+}
+
+static int
+bfd_mach_o_canonicalize_relocs (bfd *abfd, unsigned long filepos,
+                                unsigned long count,
+                                arelent *res, asymbol **syms)
+{
   unsigned long i;
-  arelent *res;
   char *native_relocs;
   bfd_size_type native_size;
 
-  if (asect->reloc_count == 0)
-    return 0;
-
-  /* No need to go further if we don't know how to read relocs.  */
-  if (bed->_bfd_mach_o_swap_reloc_in == NULL)
-    return 0;
-
   /* Allocate and read relocs.  */
-  native_size = asect->reloc_count * BFD_MACH_O_RELENT_SIZE;
+  native_size = count * BFD_MACH_O_RELENT_SIZE;
   native_relocs = bfd_malloc (native_size);
   if (native_relocs == NULL)
     return -1;
 
-  if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0
+  if (bfd_seek (abfd, filepos, SEEK_SET) != 0
       || bfd_bread (native_relocs, native_size, abfd) != native_size)
+    goto err;
+
+  for (i = 0; i < count; i++)
     {
-      free (native_relocs);
-      return -1;
+      char *buf = native_relocs + BFD_MACH_O_RELENT_SIZE * i;
+
+      if (bfd_mach_o_canonicalize_one_reloc (abfd, buf, &res[i], syms) < 0)
+        goto err;
     }
+  free (native_relocs);
+  return i;
+ err:
+  free (native_relocs);
+  return -1;
+}
+
+long
+bfd_mach_o_canonicalize_reloc (bfd *abfd, asection *asect,
+                               arelent **rels, asymbol **syms)
+{
+  bfd_mach_o_backend_data *bed = bfd_mach_o_get_backend_data (abfd);
+  unsigned long i;
+  arelent *res;
+
+  if (asect->reloc_count == 0)
+    return 0;
+
+  /* No need to go further if we don't know how to read relocs.  */
+  if (bed->_bfd_mach_o_swap_reloc_in == NULL)
+    return 0;
 
   res = bfd_malloc (asect->reloc_count * sizeof (arelent));
   if (res == NULL)
+    return -1;
+
+  if (bfd_mach_o_canonicalize_relocs (abfd, asect->rel_filepos,
+                                      asect->reloc_count, res, syms) < 0)
     {
-      free (native_relocs);
+      free (res);
       return -1;
     }
 
   for (i = 0; i < asect->reloc_count; i++)
-    {
-      char *buf = native_relocs + BFD_MACH_O_RELENT_SIZE * i;
-      bfd_mach_o_reloc_info reloc;
-      bfd_vma addr;
-      bfd_vma symnum;
-      asymbol **sym;
+    rels[i] = &res[i];
+  rels[i] = NULL;
+  asect->relocation = res;
 
-      addr = bfd_get_32 (abfd, buf + 0);
-      symnum = bfd_get_32 (abfd, buf + 4);
+  return i;
+}
 
-      if (addr & BFD_MACH_O_SR_SCATTERED)
-       {
-          unsigned int j;
+long
+bfd_mach_o_get_dynamic_reloc_upper_bound (bfd *abfd)
+{
+  bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
 
-          /* Scattered relocation.
-             Extract section and offset from r_value.  */
-         res[i].sym_ptr_ptr = NULL;
-         res[i].addend = 0;
-          for (j = 0; j < mdata->nsects; j++)
-            {
-              bfd_mach_o_section *sect = mdata->sections[j];
-              if (symnum >= sect->addr && symnum < sect->addr + sect->size)
-                {
-                  res[i].sym_ptr_ptr = sect->bfdsection->symbol_ptr_ptr;
-                  res[i].addend = symnum - sect->addr;
-                  break;
-                }
-            }
-         res[i].address = BFD_MACH_O_GET_SR_ADDRESS (addr);
-         reloc.r_type = BFD_MACH_O_GET_SR_TYPE (addr);
-         reloc.r_length = BFD_MACH_O_GET_SR_LENGTH (addr);
-         reloc.r_pcrel = addr & BFD_MACH_O_SR_PCREL;
-          reloc.r_scattered = 1;
-       }
-      else
-       {
-         unsigned int num = BFD_MACH_O_GET_R_SYMBOLNUM (symnum);
-         res[i].addend = 0;
-         res[i].address = addr;
-         if (symnum & BFD_MACH_O_R_EXTERN)
-           sym = syms + num;
-         else
-            {
-              BFD_ASSERT (num != 0);
-              BFD_ASSERT (num <= mdata->nsects);
-              sym = mdata->sections[num - 1]->bfdsection->symbol_ptr_ptr;
-            }
-         res[i].sym_ptr_ptr = sym;
-         reloc.r_type = BFD_MACH_O_GET_R_TYPE (symnum);
-         reloc.r_length = BFD_MACH_O_GET_R_LENGTH (symnum);
-         reloc.r_pcrel = (symnum & BFD_MACH_O_R_PCREL) ? 1 : 0;
-          reloc.r_scattered = 0;
-       }
+  if (mdata->dysymtab == NULL)
+    return 1;
+  return (mdata->dysymtab->nextrel + mdata->dysymtab->nlocrel)
+    * sizeof (arelent *);
+}
 
-      if (!(*bed->_bfd_mach_o_swap_reloc_in)(&res[i], &reloc))
-        {
-          free (res);
-          free (native_relocs);
-          return -1;
-        }
-      rels[i] = &res[i];
+long
+bfd_mach_o_canonicalize_dynamic_reloc (bfd *abfd, arelent **rels,
+                                       struct bfd_symbol **syms)
+{
+  bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
+  bfd_mach_o_dysymtab_command *dysymtab = mdata->dysymtab;
+  bfd_mach_o_backend_data *bed = bfd_mach_o_get_backend_data (abfd);
+  unsigned long i;
+  arelent *res;
+
+  if (dysymtab == NULL)
+    return 0;
+  if (dysymtab->nextrel == 0 && dysymtab->nlocrel == 0)
+    return 0;
+
+  /* No need to go further if we don't know how to read relocs.  */
+  if (bed->_bfd_mach_o_swap_reloc_in == NULL)
+    return 0;
+
+  res = bfd_malloc ((dysymtab->nextrel + dysymtab->nlocrel) * sizeof (arelent));
+  if (res == NULL)
+    return -1;
+
+  if (bfd_mach_o_canonicalize_relocs (abfd, dysymtab->extreloff,
+                                      dysymtab->nextrel, res, syms) < 0)
+    {
+      free (res);
+      return -1;
     }
-  asect->relocation = res;
-  free (native_relocs);
+
+  if (bfd_mach_o_canonicalize_relocs (abfd, dysymtab->locreloff,
+                                      dysymtab->nlocrel,
+                                      res + dysymtab->nextrel, syms) < 0)
+    {
+      free (res);
+      return -1;
+    }
+
+  for (i = 0; i < dysymtab->nextrel + dysymtab->nlocrel; i++)
+    rels[i] = &res[i];
+  rels[i] = NULL;
   return i;
 }
 
 static bfd_boolean
-bfd_mach_o_scan_write_relocs (bfd *abfd, bfd_mach_o_section *section)
+bfd_mach_o_write_relocs (bfd *abfd, bfd_mach_o_section *section)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   unsigned int i;
@@ -684,7 +921,7 @@ bfd_mach_o_scan_write_relocs (bfd *abfd, bfd_mach_o_section *section)
           bfd_put_32 (abfd, v, buf + 4);
         }
 
-      if (bfd_bwrite ((PTR) buf, BFD_MACH_O_RELENT_SIZE, abfd)
+      if (bfd_bwrite ((void *) buf, BFD_MACH_O_RELENT_SIZE, abfd)
           != BFD_MACH_O_RELENT_SIZE)
         return FALSE;
     }
@@ -692,7 +929,7 @@ bfd_mach_o_scan_write_relocs (bfd *abfd, bfd_mach_o_section *section)
 }
 
 static int
-bfd_mach_o_scan_write_section_32 (bfd *abfd, bfd_mach_o_section *section)
+bfd_mach_o_write_section_32 (bfd *abfd, bfd_mach_o_section *section)
 {
   unsigned char buf[BFD_MACH_O_SECTION_SIZE];
 
@@ -708,7 +945,7 @@ bfd_mach_o_scan_write_section_32 (bfd *abfd, bfd_mach_o_section *section)
   bfd_h_put_32 (abfd, section->reserved1, buf + 60);
   bfd_h_put_32 (abfd, section->reserved2, buf + 64);
 
-  if (bfd_bwrite ((PTR) buf, BFD_MACH_O_SECTION_SIZE, abfd)
+  if (bfd_bwrite ((void *) buf, BFD_MACH_O_SECTION_SIZE, abfd)
       != BFD_MACH_O_SECTION_SIZE)
     return -1;
 
@@ -716,7 +953,7 @@ bfd_mach_o_scan_write_section_32 (bfd *abfd, bfd_mach_o_section *section)
 }
 
 static int
-bfd_mach_o_scan_write_section_64 (bfd *abfd, bfd_mach_o_section *section)
+bfd_mach_o_write_section_64 (bfd *abfd, bfd_mach_o_section *section)
 {
   unsigned char buf[BFD_MACH_O_SECTION_64_SIZE];
 
@@ -733,7 +970,7 @@ bfd_mach_o_scan_write_section_64 (bfd *abfd, bfd_mach_o_section *section)
   bfd_h_put_32 (abfd, section->reserved2, buf + 72);
   bfd_h_put_32 (abfd, section->reserved3, buf + 76);
 
-  if (bfd_bwrite ((PTR) buf, BFD_MACH_O_SECTION_64_SIZE, abfd)
+  if (bfd_bwrite ((void *) buf, BFD_MACH_O_SECTION_64_SIZE, abfd)
       != BFD_MACH_O_SECTION_64_SIZE)
     return -1;
 
@@ -741,7 +978,7 @@ bfd_mach_o_scan_write_section_64 (bfd *abfd, bfd_mach_o_section *section)
 }
 
 static int
-bfd_mach_o_scan_write_segment_32 (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_write_segment_32 (bfd *abfd, bfd_mach_o_load_command *command)
 {
   unsigned char buf[BFD_MACH_O_LC_SEGMENT_SIZE];
   bfd_mach_o_segment_command *seg = &command->command.segment;
@@ -750,7 +987,7 @@ bfd_mach_o_scan_write_segment_32 (bfd *abfd, bfd_mach_o_load_command *command)
   BFD_ASSERT (command->type == BFD_MACH_O_LC_SEGMENT);
 
   for (i = 0; i < seg->nsects; i++)
-    if (!bfd_mach_o_scan_write_relocs (abfd, &seg->sections[i]))
+    if (!bfd_mach_o_write_relocs (abfd, &seg->sections[i]))
       return -1;
 
   memcpy (buf, seg->segname, 16);
@@ -764,19 +1001,19 @@ bfd_mach_o_scan_write_segment_32 (bfd *abfd, bfd_mach_o_load_command *command)
   bfd_h_put_32 (abfd, seg->flags, buf + 44);
   
   if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
-      || (bfd_bwrite ((PTR) buf, BFD_MACH_O_LC_SEGMENT_SIZE - 8, abfd) 
+      || (bfd_bwrite ((void *) buf, BFD_MACH_O_LC_SEGMENT_SIZE - 8, abfd) 
           != BFD_MACH_O_LC_SEGMENT_SIZE - 8))
     return -1;
 
   for (i = 0; i < seg->nsects; i++)
-    if (bfd_mach_o_scan_write_section_32 (abfd, &seg->sections[i]))
+    if (bfd_mach_o_write_section_32 (abfd, &seg->sections[i]))
       return -1;
 
   return 0;
 }
 
 static int
-bfd_mach_o_scan_write_segment_64 (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_write_segment_64 (bfd *abfd, bfd_mach_o_load_command *command)
 {
   unsigned char buf[BFD_MACH_O_LC_SEGMENT_64_SIZE];
   bfd_mach_o_segment_command *seg = &command->command.segment;
@@ -785,7 +1022,7 @@ bfd_mach_o_scan_write_segment_64 (bfd *abfd, bfd_mach_o_load_command *command)
   BFD_ASSERT (command->type == BFD_MACH_O_LC_SEGMENT_64);
 
   for (i = 0; i < seg->nsects; i++)
-    if (!bfd_mach_o_scan_write_relocs (abfd, &seg->sections[i]))
+    if (!bfd_mach_o_write_relocs (abfd, &seg->sections[i]))
       return -1;
 
   memcpy (buf, seg->segname, 16);
@@ -799,19 +1036,19 @@ bfd_mach_o_scan_write_segment_64 (bfd *abfd, bfd_mach_o_load_command *command)
   bfd_h_put_32 (abfd, seg->flags, buf + 60);
 
   if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
-      || (bfd_bwrite ((PTR) buf, BFD_MACH_O_LC_SEGMENT_64_SIZE - 8, abfd)
+      || (bfd_bwrite ((void *) buf, BFD_MACH_O_LC_SEGMENT_64_SIZE - 8, abfd)
           != BFD_MACH_O_LC_SEGMENT_64_SIZE - 8))
     return -1;
 
   for (i = 0; i < seg->nsects; i++)
-    if (bfd_mach_o_scan_write_section_64 (abfd, &seg->sections[i]))
+    if (bfd_mach_o_write_section_64 (abfd, &seg->sections[i]))
       return -1;
 
   return 0;
 }
 
 static bfd_boolean
-bfd_mach_o_scan_write_symtab (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_write_symtab (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   bfd_mach_o_symtab_command *sym = &command->command.symtab;
@@ -839,21 +1076,20 @@ bfd_mach_o_scan_write_symtab (bfd *abfd, bfd_mach_o_load_command *command)
 
   for (i = 0; i < sym->nsyms; i++)
     {
-      unsigned char buf[16];
-      bfd_size_type index;
+      bfd_size_type str_index;
       bfd_mach_o_asymbol *s = (bfd_mach_o_asymbol *)symbols[i];
 
       /* Compute name index.  */
       /* An index of 0 always means the empty string.  */
       if (s->symbol.name == 0 || s->symbol.name[0] == '\0')
-        index = 0;
+        str_index = 0;
       else
         {
-          index = _bfd_stringtab_add (strtab, s->symbol.name, TRUE, FALSE);
-          if (index == (bfd_size_type) -1)
+          str_index = _bfd_stringtab_add (strtab, s->symbol.name, TRUE, FALSE);
+          if (str_index == (bfd_size_type) -1)
             goto err;
         }
-      bfd_h_put_32 (abfd, index, buf);
+      bfd_h_put_32 (abfd, str_index, buf);
       bfd_h_put_8 (abfd, s->n_type, buf + 4);
       bfd_h_put_8 (abfd, s->n_sect, buf + 5);
       bfd_h_put_16 (abfd, s->n_desc, buf + 6);
@@ -862,7 +1098,7 @@ bfd_mach_o_scan_write_symtab (bfd *abfd, bfd_mach_o_load_command *command)
       else
         bfd_h_put_32 (abfd, s->symbol.section->vma + s->symbol.value, buf + 8);
 
-      if (bfd_bwrite ((PTR) buf, symlen, abfd) != symlen)
+      if (bfd_bwrite ((void *) buf, symlen, abfd) != symlen)
         goto err;
     }
   sym->strsize = _bfd_stringtab_size (strtab);
@@ -880,7 +1116,7 @@ bfd_mach_o_scan_write_symtab (bfd *abfd, bfd_mach_o_load_command *command)
   bfd_h_put_32 (abfd, sym->strsize, buf + 12);
 
   if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
-      || bfd_bwrite ((PTR) buf, 16, abfd) != 16)
+      || bfd_bwrite ((void *) buf, 16, abfd) != 16)
     return FALSE;
 
   return TRUE;
@@ -976,28 +1212,28 @@ bfd_mach_o_write_contents (bfd *abfd)
       bfd_h_put_32 (abfd, cur->len, buf + 4);
 
       if (bfd_seek (abfd, cur->offset, SEEK_SET) != 0
-          || bfd_bwrite ((PTR) buf, 8, abfd) != 8)
+          || bfd_bwrite ((void *) buf, 8, abfd) != 8)
        return FALSE;
 
       switch (cur->type)
        {
        case BFD_MACH_O_LC_SEGMENT:
-         if (bfd_mach_o_scan_write_segment_32 (abfd, cur) != 0)
+         if (bfd_mach_o_write_segment_32 (abfd, cur) != 0)
            return FALSE;
          break;
        case BFD_MACH_O_LC_SEGMENT_64:
-         if (bfd_mach_o_scan_write_segment_64 (abfd, cur) != 0)
+         if (bfd_mach_o_write_segment_64 (abfd, cur) != 0)
            return FALSE;
          break;
        case BFD_MACH_O_LC_SYMTAB:
-         if (!bfd_mach_o_scan_write_symtab (abfd, cur))
+         if (!bfd_mach_o_write_symtab (abfd, cur))
            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_scan_write_thread (abfd, cur) != 0)
+         if (bfd_mach_o_write_thread (abfd, cur) != 0)
            return FALSE;
          break;
        case BFD_MACH_O_LC_LOADFVMLIB:
@@ -1175,14 +1411,14 @@ bfd_mach_o_sizeof_headers (bfd *a ATTRIBUTE_UNUSED,
 asymbol *
 bfd_mach_o_make_empty_symbol (bfd *abfd)
 {
-  asymbol *new;
+  asymbol *new_symbol;
 
-  new = bfd_zalloc (abfd, sizeof (bfd_mach_o_asymbol));
-  if (new == NULL)
-    return new;
-  new->the_bfd = abfd;
-  new->udata.i = 0;
-  return new;
+  new_symbol = bfd_zalloc (abfd, sizeof (bfd_mach_o_asymbol));
+  if (new_symbol == NULL)
+    return new_symbol;
+  new_symbol->the_bfd = abfd;
+  new_symbol->udata.i = 0;
+  return new_symbol;
 }
 
 static bfd_boolean
@@ -1194,7 +1430,7 @@ bfd_mach_o_read_header (bfd *abfd, bfd_mach_o_header *header)
 
   /* Just read the magic number.  */
   if (bfd_seek (abfd, 0, SEEK_SET) != 0
-      || bfd_bread ((PTR) buf, 4, abfd) != 4)
+      || bfd_bread ((void *) buf, 4, abfd) != 4)
     return FALSE;
 
   if (bfd_getb32 (buf) == BFD_MACH_O_MH_MAGIC)
@@ -1236,7 +1472,7 @@ bfd_mach_o_read_header (bfd *abfd, bfd_mach_o_header *header)
     BFD_MACH_O_HEADER_64_SIZE : BFD_MACH_O_HEADER_SIZE;
 
   if (bfd_seek (abfd, 0, SEEK_SET) != 0
-      || bfd_bread ((PTR) buf, size, abfd) != size)
+      || bfd_bread ((void *) buf, size, abfd) != size)
     return FALSE;
 
   header->cputype = (*get32) (buf + 4);
@@ -1260,27 +1496,39 @@ bfd_mach_o_make_bfd_section (bfd *abfd, bfd_mach_o_section *section,
   char *sname;
   flagword flags;
 
-  sname = bfd_mach_o_convert_section_name_to_bfd (abfd, section);
+  bfd_mach_o_convert_section_name_to_bfd (abfd, section, &sname, &flags);
   if (sname == NULL)
     return NULL;
 
-  if (section->flags & BFD_MACH_O_S_ATTR_DEBUG)
-    flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
+  if (flags == SEC_NO_FLAGS)
+    {
+      /* Try to guess flags.  */
+      if (section->flags & BFD_MACH_O_S_ATTR_DEBUG)
+        flags = SEC_DEBUGGING;
+      else
+        {
+          flags = SEC_ALLOC;
+          if ((section->flags & BFD_MACH_O_SECTION_TYPE_MASK)
+              != BFD_MACH_O_S_ZEROFILL)
+            {
+              flags |= SEC_LOAD;
+              if (prot & BFD_MACH_O_PROT_EXECUTE)
+                flags |= SEC_CODE;
+              if (prot & BFD_MACH_O_PROT_WRITE)
+                flags |= SEC_DATA;
+              else if (prot & BFD_MACH_O_PROT_READ)
+                flags |= SEC_READONLY;
+            }
+        }
+    }
   else
     {
-      flags = SEC_ALLOC;
-      if ((section->flags & BFD_MACH_O_SECTION_TYPE_MASK)
-         != BFD_MACH_O_S_ZEROFILL)
-       {
-         flags |= SEC_HAS_CONTENTS | SEC_LOAD;
-         if (prot & BFD_MACH_O_PROT_EXECUTE)
-           flags |= SEC_CODE;
-         if (prot & BFD_MACH_O_PROT_WRITE)
-           flags |= SEC_DATA;
-         else if (prot & BFD_MACH_O_PROT_READ)
-           flags |= SEC_READONLY;
-       }
+      if ((flags & SEC_DEBUGGING) == 0)
+        flags |= SEC_ALLOC;
     }
+
+  if (section->offset != 0)
+    flags |= SEC_HAS_CONTENTS;
   if (section->nreloc != 0)
     flags |= SEC_RELOC;
 
@@ -1301,15 +1549,15 @@ bfd_mach_o_make_bfd_section (bfd *abfd, bfd_mach_o_section *section,
 }
 
 static int
-bfd_mach_o_scan_read_section_32 (bfd *abfd,
-                                bfd_mach_o_section *section,
-                                unsigned int offset,
-                                unsigned long prot)
+bfd_mach_o_read_section_32 (bfd *abfd,
+                            bfd_mach_o_section *section,
+                            unsigned int offset,
+                            unsigned long prot)
 {
   unsigned char buf[BFD_MACH_O_SECTION_SIZE];
 
   if (bfd_seek (abfd, offset, SEEK_SET) != 0
-      || (bfd_bread ((PTR) buf, BFD_MACH_O_SECTION_SIZE, abfd)
+      || (bfd_bread ((void *) buf, BFD_MACH_O_SECTION_SIZE, abfd)
           != BFD_MACH_O_SECTION_SIZE))
     return -1;
 
@@ -1336,15 +1584,15 @@ bfd_mach_o_scan_read_section_32 (bfd *abfd,
 }
 
 static int
-bfd_mach_o_scan_read_section_64 (bfd *abfd,
-                                bfd_mach_o_section *section,
-                                unsigned int offset,
-                                unsigned long prot)
+bfd_mach_o_read_section_64 (bfd *abfd,
+                            bfd_mach_o_section *section,
+                            unsigned int offset,
+                            unsigned long prot)
 {
   unsigned char buf[BFD_MACH_O_SECTION_64_SIZE];
 
   if (bfd_seek (abfd, offset, SEEK_SET) != 0
-      || (bfd_bread ((PTR) buf, BFD_MACH_O_SECTION_64_SIZE, abfd)
+      || (bfd_bread ((void *) buf, BFD_MACH_O_SECTION_64_SIZE, abfd)
           != BFD_MACH_O_SECTION_64_SIZE))
     return -1;
 
@@ -1371,23 +1619,23 @@ bfd_mach_o_scan_read_section_64 (bfd *abfd,
 }
 
 static int
-bfd_mach_o_scan_read_section (bfd *abfd,
-                             bfd_mach_o_section *section,
-                             unsigned int offset,
-                             unsigned long prot,
-                             unsigned int wide)
+bfd_mach_o_read_section (bfd *abfd,
+                         bfd_mach_o_section *section,
+                         unsigned int offset,
+                         unsigned long prot,
+                         unsigned int wide)
 {
   if (wide)
-    return bfd_mach_o_scan_read_section_64 (abfd, section, offset, prot);
+    return bfd_mach_o_read_section_64 (abfd, section, offset, prot);
   else
-    return bfd_mach_o_scan_read_section_32 (abfd, section, offset, prot);
+    return bfd_mach_o_read_section_32 (abfd, section, offset, prot);
 }
 
 static int
-bfd_mach_o_scan_read_symtab_symbol (bfd *abfd,
-                                   bfd_mach_o_symtab_command *sym,
-                                   bfd_mach_o_asymbol *s,
-                                   unsigned long i)
+bfd_mach_o_read_symtab_symbol (bfd *abfd,
+                               bfd_mach_o_symtab_command *sym,
+                               bfd_mach_o_asymbol *s,
+                               unsigned long i)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   unsigned int wide = mach_o_wide_p (&mdata->header);
@@ -1405,9 +1653,9 @@ bfd_mach_o_scan_read_symtab_symbol (bfd *abfd,
   BFD_ASSERT (sym->strtab != NULL);
 
   if (bfd_seek (abfd, symoff, SEEK_SET) != 0
-      || bfd_bread ((PTR) buf, symwidth, abfd) != symwidth)
+      || bfd_bread ((void *) buf, symwidth, abfd) != symwidth)
     {
-      fprintf (stderr, "bfd_mach_o_scan_read_symtab_symbol: unable to read %d bytes at %lu\n",
+      fprintf (stderr, "bfd_mach_o_read_symtab_symbol: unable to read %d bytes at %lu\n",
               symwidth, (unsigned long) symoff);
       return -1;
     }
@@ -1424,7 +1672,7 @@ bfd_mach_o_scan_read_symtab_symbol (bfd *abfd,
 
   if (stroff >= sym->strsize)
     {
-      fprintf (stderr, "bfd_mach_o_scan_read_symtab_symbol: symbol name out of range (%lu >= %lu)\n",
+      fprintf (stderr, "bfd_mach_o_read_symtab_symbol: symbol name out of range (%lu >= %lu)\n",
               (unsigned long) stroff, (unsigned long) sym->strsize);
       return -1;
     }
@@ -1508,7 +1756,7 @@ bfd_mach_o_scan_read_symtab_symbol (bfd *abfd,
              /* Mach-O uses 0 to mean "no section"; not an error.  */
              if (section != 0)
                {
-                 fprintf (stderr, "bfd_mach_o_scan_read_symtab_symbol: "
+                 fprintf (stderr, "bfd_mach_o_read_symtab_symbol: "
                           "symbol \"%s\" specified invalid section %d (max %lu): setting to undefined\n",
                           s->symbol.name, section, mdata->nsects);
                }
@@ -1516,13 +1764,13 @@ bfd_mach_o_scan_read_symtab_symbol (bfd *abfd,
            }
          break;
        case BFD_MACH_O_N_INDR:
-         fprintf (stderr, "bfd_mach_o_scan_read_symtab_symbol: "
+         fprintf (stderr, "bfd_mach_o_read_symtab_symbol: "
                   "symbol \"%s\" is unsupported 'indirect' reference: setting to undefined\n",
                   s->symbol.name);
          s->symbol.section = bfd_und_section_ptr;
          break;
        default:
-         fprintf (stderr, "bfd_mach_o_scan_read_symtab_symbol: "
+         fprintf (stderr, "bfd_mach_o_read_symtab_symbol: "
                   "symbol \"%s\" specified invalid type field 0x%x: setting to undefined\n",
                   s->symbol.name, symtype);
          s->symbol.section = bfd_und_section_ptr;
@@ -1534,7 +1782,7 @@ bfd_mach_o_scan_read_symtab_symbol (bfd *abfd,
 }
 
 static int
-bfd_mach_o_scan_read_symtab_strtab (bfd *abfd)
+bfd_mach_o_read_symtab_strtab (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   bfd_mach_o_symtab_command *sym = mdata->symtab;
@@ -1567,7 +1815,7 @@ bfd_mach_o_scan_read_symtab_strtab (bfd *abfd)
         return -1;
 
       if (bfd_seek (abfd, sym->stroff, SEEK_SET) != 0
-          || bfd_bread ((PTR) sym->strtab, sym->strsize, abfd) != sym->strsize)
+          || bfd_bread ((void *) sym->strtab, sym->strsize, abfd) != sym->strsize)
         {
           bfd_set_error (bfd_error_file_truncated);
           return -1;
@@ -1578,7 +1826,7 @@ bfd_mach_o_scan_read_symtab_strtab (bfd *abfd)
 }
 
 static int
-bfd_mach_o_scan_read_symtab_symbols (bfd *abfd)
+bfd_mach_o_read_symtab_symbols (bfd *abfd)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   bfd_mach_o_symtab_command *sym = mdata->symtab;
@@ -1592,17 +1840,17 @@ bfd_mach_o_scan_read_symtab_symbols (bfd *abfd)
 
   if (sym->symbols == NULL)
     {
-      fprintf (stderr, "bfd_mach_o_scan_read_symtab_symbols: unable to allocate memory for symbols\n");
+      fprintf (stderr, "bfd_mach_o_read_symtab_symbols: unable to allocate memory for symbols\n");
       return -1;
     }
 
-  ret = bfd_mach_o_scan_read_symtab_strtab (abfd);
+  ret = bfd_mach_o_read_symtab_strtab (abfd);
   if (ret != 0)
     return ret;
 
   for (i = 0; i < sym->nsyms; i++)
     {
-      ret = bfd_mach_o_scan_read_symtab_symbol (abfd, sym, &sym->symbols[i], i);
+      ret = bfd_mach_o_read_symtab_symbol (abfd, sym, &sym->symbols[i], i);
       if (ret != 0)
        return ret;
     }
@@ -1611,28 +1859,28 @@ bfd_mach_o_scan_read_symtab_symbols (bfd *abfd)
 }
 
 int
-bfd_mach_o_scan_read_dysymtab_symbol (bfd *abfd,
-                                     bfd_mach_o_dysymtab_command *dysym,
-                                     bfd_mach_o_symtab_command *sym,
-                                     bfd_mach_o_asymbol *s,
-                                     unsigned long i)
+bfd_mach_o_read_dysymtab_symbol (bfd *abfd,
+                                 bfd_mach_o_dysymtab_command *dysym,
+                                 bfd_mach_o_symtab_command *sym,
+                                 bfd_mach_o_asymbol *s,
+                                 unsigned long i)
 {
   unsigned long isymoff = dysym->indirectsymoff + (i * 4);
-  unsigned long symindex;
+  unsigned long sym_index;
   unsigned char buf[4];
 
   BFD_ASSERT (i < dysym->nindirectsyms);
 
   if (bfd_seek (abfd, isymoff, SEEK_SET) != 0
-      || bfd_bread ((PTR) buf, 4, abfd) != 4)
+      || bfd_bread ((void *) buf, 4, abfd) != 4)
     {
-      fprintf (stderr, "bfd_mach_o_scan_read_dysymtab_symbol: unable to read %lu bytes at %lu\n",
+      fprintf (stderr, "bfd_mach_o_read_dysymtab_symbol: unable to read %lu bytes at %lu\n",
               (unsigned long) 4, isymoff);
       return -1;
     }
-  symindex = bfd_h_get_32 (abfd, buf);
+  sym_index = bfd_h_get_32 (abfd, buf);
 
-  return bfd_mach_o_scan_read_symtab_symbol (abfd, sym, s, symindex);
+  return bfd_mach_o_read_symtab_symbol (abfd, sym, s, sym_index);
 }
 
 static const char *
@@ -1652,7 +1900,7 @@ bfd_mach_o_i386_flavour_string (unsigned int flavour)
     case BFD_MACH_O_x86_DEBUG_STATE32:     return "x86_DEBUG_STATE32";
     case BFD_MACH_O_x86_DEBUG_STATE64:     return "x86_DEBUG_STATE64";
     case BFD_MACH_O_x86_DEBUG_STATE:       return "x86_DEBUG_STATE";
-    case BFD_MACH_O_THREAD_STATE_NONE:     return "THREAD_STATE_NONE";
+    case BFD_MACH_O_x86_THREAD_STATE_NONE: return "x86_THREAD_STATE_NONE";
     default: return "UNKNOWN";
     }
 }
@@ -1662,94 +1910,64 @@ bfd_mach_o_ppc_flavour_string (unsigned int flavour)
 {
   switch ((int) flavour)
     {
-    case BFD_MACH_O_PPC_THREAD_STATE: return "PPC_THREAD_STATE";
-    case BFD_MACH_O_PPC_FLOAT_STATE: return "PPC_FLOAT_STATE";
-    case BFD_MACH_O_PPC_EXCEPTION_STATE: return "PPC_EXCEPTION_STATE";
-    case BFD_MACH_O_PPC_VECTOR_STATE: return "PPC_VECTOR_STATE";
+    case BFD_MACH_O_PPC_THREAD_STATE:      return "PPC_THREAD_STATE";
+    case BFD_MACH_O_PPC_FLOAT_STATE:       return "PPC_FLOAT_STATE";
+    case BFD_MACH_O_PPC_EXCEPTION_STATE:   return "PPC_EXCEPTION_STATE";
+    case BFD_MACH_O_PPC_VECTOR_STATE:      return "PPC_VECTOR_STATE";
+    case BFD_MACH_O_PPC_THREAD_STATE64:    return "PPC_THREAD_STATE64";
+    case BFD_MACH_O_PPC_EXCEPTION_STATE64: return "PPC_EXCEPTION_STATE64";
     default: return "UNKNOWN";
     }
 }
 
 static int
-bfd_mach_o_scan_read_dylinker (bfd *abfd,
-                              bfd_mach_o_load_command *command)
+bfd_mach_o_read_dylinker (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_dylinker_command *cmd = &command->command.dylinker;
   unsigned char buf[4];
   unsigned int nameoff;
-  asection *bfdsec;
-  char *sname;
-  const char *prefix;
 
   BFD_ASSERT ((command->type == BFD_MACH_O_LC_ID_DYLINKER)
              || (command->type == BFD_MACH_O_LC_LOAD_DYLINKER));
 
   if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
-      || bfd_bread ((PTR) buf, 4, abfd) != 4)
+      || bfd_bread ((void *) buf, 4, abfd) != 4)
     return -1;
 
   nameoff = bfd_h_get_32 (abfd, buf + 0);
 
   cmd->name_offset = command->offset + nameoff;
   cmd->name_len = command->len - nameoff;
-
-  if (command->type == BFD_MACH_O_LC_LOAD_DYLINKER)
-    prefix = "LC_LOAD_DYLINKER";
-  else if (command->type == BFD_MACH_O_LC_ID_DYLINKER)
-    prefix = "LC_ID_DYLINKER";
-  else
-    abort ();
-
-  sname = bfd_alloc (abfd, strlen (prefix) + 1);
-  if (sname == NULL)
+  cmd->name_str = bfd_alloc (abfd, cmd->name_len);
+  if (cmd->name_str == NULL)
     return -1;
-  strcpy (sname, prefix);
-
-  bfdsec = bfd_make_section_anyway_with_flags (abfd, sname, SEC_HAS_CONTENTS);
-  if (bfdsec == NULL)
+  if (bfd_seek (abfd, cmd->name_offset, SEEK_SET) != 0
+      || bfd_bread (cmd->name_str, cmd->name_len, abfd) != cmd->name_len)
     return -1;
-
-  bfdsec->vma = 0;
-  bfdsec->lma = 0;
-  bfdsec->size = command->len - nameoff;
-  bfdsec->filepos = command->offset + nameoff;
-  bfdsec->alignment_power = 0;
-
-  cmd->section = bfdsec;
-
   return 0;
 }
 
 static int
-bfd_mach_o_scan_read_dylib (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_read_dylib (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_dylib_command *cmd = &command->command.dylib;
   unsigned char buf[16];
   unsigned int nameoff;
-  asection *bfdsec;
-  char *sname;
-  const char *prefix;
 
   switch (command->type)
     {
     case BFD_MACH_O_LC_LOAD_DYLIB:
-      prefix = "LC_LOAD_DYLIB";
-      break;
     case BFD_MACH_O_LC_LOAD_WEAK_DYLIB:
-      prefix = "LC_LOAD_WEAK_DYLIB";
-      break;
     case BFD_MACH_O_LC_ID_DYLIB:
-      prefix = "LC_ID_DYLIB";
-      break;
     case BFD_MACH_O_LC_REEXPORT_DYLIB:
-      prefix = "LC_REEXPORT_DYLIB";
       break;
     default:
-      abort ();
+      BFD_FAIL ();
+      return -1;
     }
 
   if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
-      || bfd_bread ((PTR) buf, 16, abfd) != 16)
+      || bfd_bread ((void *) buf, 16, abfd) != 16)
     return -1;
 
   nameoff = bfd_h_get_32 (abfd, buf + 0);
@@ -1759,30 +1977,18 @@ bfd_mach_o_scan_read_dylib (bfd *abfd, bfd_mach_o_load_command *command)
 
   cmd->name_offset = command->offset + nameoff;
   cmd->name_len = command->len - nameoff;
-
-  sname = bfd_alloc (abfd, strlen (prefix) + 1);
-  if (sname == NULL)
+  cmd->name_str = bfd_alloc (abfd, cmd->name_len);
+  if (cmd->name_str == NULL)
     return -1;
-  strcpy (sname, prefix);
-
-  bfdsec = bfd_make_section_anyway_with_flags (abfd, sname, SEC_HAS_CONTENTS);
-  if (bfdsec == NULL)
+  if (bfd_seek (abfd, cmd->name_offset, SEEK_SET) != 0
+      || bfd_bread (cmd->name_str, cmd->name_len, abfd) != cmd->name_len)
     return -1;
-
-  bfdsec->vma = 0;
-  bfdsec->lma = 0;
-  bfdsec->size = command->len - 8;
-  bfdsec->filepos = command->offset + 8;
-  bfdsec->alignment_power = 0;
-
-  cmd->section = bfdsec;
-
   return 0;
 }
 
 static int
-bfd_mach_o_scan_read_prebound_dylib (bfd *abfd ATTRIBUTE_UNUSED,
-                                    bfd_mach_o_load_command *command ATTRIBUTE_UNUSED)
+bfd_mach_o_read_prebound_dylib (bfd *abfd ATTRIBUTE_UNUSED,
+                                bfd_mach_o_load_command *command ATTRIBUTE_UNUSED)
 {
   /* bfd_mach_o_prebound_dylib_command *cmd = &command->command.prebound_dylib; */
 
@@ -1791,9 +1997,9 @@ bfd_mach_o_scan_read_prebound_dylib (bfd *abfd ATTRIBUTE_UNUSED,
 }
 
 static int
-bfd_mach_o_scan_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
 {
-  bfd_mach_o_data_struct *mdata = NULL;
+  bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   bfd_mach_o_thread_command *cmd = &command->command.thread;
   unsigned char buf[8];
   unsigned int offset;
@@ -1803,9 +2009,7 @@ bfd_mach_o_scan_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
   BFD_ASSERT ((command->type == BFD_MACH_O_LC_THREAD)
              || (command->type == BFD_MACH_O_LC_UNIXTHREAD));
 
-  BFD_ASSERT (bfd_mach_o_valid (abfd));
-  mdata = bfd_mach_o_get_data (abfd);
-
+  /* Count the number of threads.  */
   offset = 8;
   nflavours = 0;
   while (offset != command->len)
@@ -1814,14 +2018,16 @@ bfd_mach_o_scan_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
        return -1;
 
       if (bfd_seek (abfd, command->offset + offset, SEEK_SET) != 0
-          || bfd_bread ((PTR) buf, 8, abfd) != 8)
+          || bfd_bread ((void *) buf, 8, abfd) != 8)
        return -1;
 
       offset += 8 + bfd_h_get_32 (abfd, buf + 4) * 4;
       nflavours++;
     }
 
-  cmd->flavours = bfd_alloc (abfd, nflavours * sizeof (bfd_mach_o_thread_flavour));
+  /* Allocate threads.  */
+  cmd->flavours = bfd_alloc
+    (abfd, nflavours * sizeof (bfd_mach_o_thread_flavour));
   if (cmd->flavours == NULL)
     return -1;
   cmd->nflavours = nflavours;
@@ -1837,7 +2043,7 @@ bfd_mach_o_scan_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
        return -1;
 
       if (bfd_seek (abfd, command->offset + offset, SEEK_SET) != 0
-          || bfd_bread ((PTR) buf, 8, abfd) != 8)
+          || bfd_bread ((void *) buf, 8, abfd) != 8)
        return -1;
 
       cmd->flavours[nflavours].flavour = bfd_h_get_32 (abfd, buf);
@@ -1899,15 +2105,16 @@ bfd_mach_o_scan_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
 }
 
 static int
-bfd_mach_o_scan_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_dysymtab_command *cmd = &command->command.dysymtab;
+  bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   unsigned char buf[72];
 
   BFD_ASSERT (command->type == BFD_MACH_O_LC_DYSYMTAB);
 
   if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
-      || bfd_bread ((PTR) buf, 72, abfd) != 72)
+      || bfd_bread ((void *) buf, 72, abfd) != 72)
     return -1;
 
   cmd->ilocalsym = bfd_h_get_32 (abfd, buf + 0);
@@ -1931,7 +2138,6 @@ bfd_mach_o_scan_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
 
   if (cmd->nmodtab != 0)
     {
-      char buf[56];
       unsigned int i;
       int wide = bfd_mach_o_wide_p (abfd);
       unsigned int module_len = wide ? 56 : 52;
@@ -1949,7 +2155,7 @@ bfd_mach_o_scan_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
           bfd_mach_o_dylib_module *module = &cmd->dylib_module[i];
           unsigned long v;
 
-          if (bfd_bread ((PTR) buf, module_len, abfd) != module_len)
+          if (bfd_bread ((void *) buf, module_len, abfd) != module_len)
             return -1;
 
           module->module_name_idx = bfd_h_get_32 (abfd, buf + 0);
@@ -1982,7 +2188,6 @@ bfd_mach_o_scan_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
   
   if (cmd->ntoc != 0)
     {
-      char buf[8];
       unsigned int i;
 
       cmd->dylib_toc = bfd_alloc
@@ -1997,7 +2202,7 @@ bfd_mach_o_scan_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
         {
           bfd_mach_o_dylib_table_of_content *toc = &cmd->dylib_toc[i];
 
-          if (bfd_bread ((PTR) buf, 8, abfd) != 8)
+          if (bfd_bread ((void *) buf, 8, abfd) != 8)
             return -1;
 
           toc->symbol_index = bfd_h_get_32 (abfd, buf + 0);
@@ -2007,7 +2212,6 @@ bfd_mach_o_scan_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
 
   if (cmd->nindirectsyms != 0)
     {
-      char buf[4];
       unsigned int i;
 
       cmd->indirect_syms = bfd_alloc
@@ -2022,7 +2226,7 @@ bfd_mach_o_scan_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
         {
           unsigned int *is = &cmd->indirect_syms[i];
 
-          if (bfd_bread ((PTR) buf, 4, abfd) != 4)
+          if (bfd_bread ((void *) buf, 4, abfd) != 4)
             return -1;
 
           *is = bfd_h_get_32 (abfd, buf + 0);
@@ -2031,7 +2235,6 @@ bfd_mach_o_scan_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
 
   if (cmd->nextrefsyms != 0)
     {
-      char buf[4];
       unsigned long v;
       unsigned int i;
 
@@ -2047,20 +2250,34 @@ bfd_mach_o_scan_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
         {
           bfd_mach_o_dylib_reference *ref = &cmd->ext_refs[i];
 
-          if (bfd_bread ((PTR) buf, 4, abfd) != 4)
+          if (bfd_bread ((void *) buf, 4, abfd) != 4)
             return -1;
 
+          /* Fields isym and flags are written as bit-fields, thus we need
+             a specific processing for endianness.  */
           v = bfd_h_get_32 (abfd, buf + 0);
-          ref->isym = (v >> 8) & 0xffffff;
-          ref->flags = v & 0xff;
+          if (bfd_big_endian (abfd))
+            {
+              ref->isym = (v >> 8) & 0xffffff;
+              ref->flags = v & 0xff;
+            }
+          else
+            {
+              ref->isym = v & 0xffffff;
+              ref->flags = (v >> 24) & 0xff;
+            }
         }
     }
 
+  if (mdata->dysymtab)
+    return -1;
+  mdata->dysymtab = cmd;
+
   return 0;
 }
 
 static int
-bfd_mach_o_scan_read_symtab (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_read_symtab (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_symtab_command *symtab = &command->command.symtab;
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
@@ -2069,7 +2286,7 @@ bfd_mach_o_scan_read_symtab (bfd *abfd, bfd_mach_o_load_command *command)
   BFD_ASSERT (command->type == BFD_MACH_O_LC_SYMTAB);
 
   if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
-      || bfd_bread ((PTR) buf, 16, abfd) != 16)
+      || bfd_bread ((void *) buf, 16, abfd) != 16)
     return -1;
 
   symtab->symoff = bfd_h_get_32 (abfd, buf);
@@ -2089,47 +2306,27 @@ bfd_mach_o_scan_read_symtab (bfd *abfd, bfd_mach_o_load_command *command)
 }
 
 static int
-bfd_mach_o_scan_read_uuid (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_read_uuid (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_uuid_command *cmd = &command->command.uuid;
-  asection *bfdsec;
-  char *sname;
-  static const char prefix[] = "LC_UUID";
 
   BFD_ASSERT (command->type == BFD_MACH_O_LC_UUID);
 
   if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
-      || bfd_bread ((PTR) cmd->uuid, 16, abfd) != 16)
+      || bfd_bread ((void *) cmd->uuid, 16, abfd) != 16)
     return -1;
 
-  sname = bfd_alloc (abfd, strlen (prefix) + 1);
-  if (sname == NULL)
-    return -1;
-  strcpy (sname, prefix);
-
-  bfdsec = bfd_make_section_anyway_with_flags (abfd, sname, SEC_HAS_CONTENTS);
-  if (bfdsec == NULL)
-    return -1;
-
-  bfdsec->vma = 0;
-  bfdsec->lma = 0;
-  bfdsec->size = command->len - 8;
-  bfdsec->filepos = command->offset + 8;
-  bfdsec->alignment_power = 0;
-
-  cmd->section = bfdsec;
-
   return 0;
 }
 
 static int
-bfd_mach_o_scan_read_linkedit (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_read_linkedit (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_linkedit_command *cmd = &command->command.linkedit;
   char buf[8];
 
   if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
-      || bfd_bread ((PTR) buf, 8, abfd) != 8)
+      || bfd_bread ((void *) buf, 8, abfd) != 8)
     return -1;
 
   cmd->dataoff = bfd_get_32 (abfd, buf + 0);
@@ -2138,14 +2335,14 @@ bfd_mach_o_scan_read_linkedit (bfd *abfd, bfd_mach_o_load_command *command)
 }
 
 static int
-bfd_mach_o_scan_read_str (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_read_str (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_str_command *cmd = &command->command.str;
-  char buf[8];
+  char buf[4];
   unsigned long off;
 
   if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
-      || bfd_bread ((PTR) buf, 4, abfd) != 4)
+      || bfd_bread ((void *) buf, 4, abfd) != 4)
     return -1;
 
   off = bfd_get_32 (abfd, buf + 0);
@@ -2155,15 +2352,38 @@ bfd_mach_o_scan_read_str (bfd *abfd, bfd_mach_o_load_command *command)
   if (cmd->str == NULL)
     return -1;
   if (bfd_seek (abfd, cmd->stroff, SEEK_SET) != 0
-      || bfd_bread ((PTR) cmd->str, cmd->str_len, abfd) != cmd->str_len)
+      || bfd_bread ((void *) cmd->str, cmd->str_len, abfd) != cmd->str_len)
+    return -1;
+  return 0;
+}
+
+static int
+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;
+  char buf[40];
+
+  if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
+      || bfd_bread ((void *) buf, sizeof (buf), abfd) != sizeof (buf))
     return -1;
+
+  cmd->rebase_off = bfd_get_32 (abfd, buf + 0);
+  cmd->rebase_size = bfd_get_32 (abfd, buf + 4);
+  cmd->bind_off = bfd_get_32 (abfd, buf + 8);
+  cmd->bind_size = bfd_get_32 (abfd, buf + 12);
+  cmd->weak_bind_off = bfd_get_32 (abfd, buf + 16);
+  cmd->weak_bind_size = bfd_get_32 (abfd, buf + 20);
+  cmd->lazy_bind_off = bfd_get_32 (abfd, buf + 24);
+  cmd->lazy_bind_size = bfd_get_32 (abfd, buf + 28);
+  cmd->export_off = bfd_get_32 (abfd, buf + 32);
+  cmd->export_size = bfd_get_32 (abfd, buf + 36);
   return 0;
 }
 
 static int
-bfd_mach_o_scan_read_segment (bfd *abfd,
-                             bfd_mach_o_load_command *command,
-                             unsigned int wide)
+bfd_mach_o_read_segment (bfd *abfd,
+                         bfd_mach_o_load_command *command,
+                         unsigned int wide)
 {
   unsigned char buf[64];
   bfd_mach_o_segment_command *seg = &command->command.segment;
@@ -2174,7 +2394,7 @@ bfd_mach_o_scan_read_segment (bfd *abfd,
       BFD_ASSERT (command->type == BFD_MACH_O_LC_SEGMENT_64);
 
       if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
-          || bfd_bread ((PTR) buf, 64, abfd) != 64)
+          || bfd_bread ((void *) buf, 64, abfd) != 64)
        return -1;
 
       memcpy (seg->segname, buf, 16);
@@ -2194,7 +2414,7 @@ bfd_mach_o_scan_read_segment (bfd *abfd,
       BFD_ASSERT (command->type == BFD_MACH_O_LC_SEGMENT);
 
       if (bfd_seek (abfd, command->offset + 8, SEEK_SET) != 0
-          || bfd_bread ((PTR) buf, 48, abfd) != 48)
+          || bfd_bread ((void *) buf, 48, abfd) != 48)
        return -1;
 
       memcpy (seg->segname, buf, 16);
@@ -2227,7 +2447,7 @@ bfd_mach_o_scan_read_segment (bfd *abfd,
             segoff = command->offset + BFD_MACH_O_LC_SEGMENT_SIZE
               + (i * BFD_MACH_O_SECTION_SIZE);
 
-         if (bfd_mach_o_scan_read_section
+         if (bfd_mach_o_read_section
              (abfd, &seg->sections[i], segoff, seg->initprot, wide) != 0)
            return -1;
        }
@@ -2237,25 +2457,25 @@ bfd_mach_o_scan_read_segment (bfd *abfd,
 }
 
 static int
-bfd_mach_o_scan_read_segment_32 (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_read_segment_32 (bfd *abfd, bfd_mach_o_load_command *command)
 {
-  return bfd_mach_o_scan_read_segment (abfd, command, 0);
+  return bfd_mach_o_read_segment (abfd, command, 0);
 }
 
 static int
-bfd_mach_o_scan_read_segment_64 (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_read_segment_64 (bfd *abfd, bfd_mach_o_load_command *command)
 {
-  return bfd_mach_o_scan_read_segment (abfd, command, 1);
+  return bfd_mach_o_read_segment (abfd, command, 1);
 }
 
 static int
-bfd_mach_o_scan_read_command (bfd *abfd, bfd_mach_o_load_command *command)
+bfd_mach_o_read_command (bfd *abfd, bfd_mach_o_load_command *command)
 {
   unsigned char buf[8];
 
   /* Read command type and length.  */
   if (bfd_seek (abfd, command->offset, SEEK_SET) != 0
-      || bfd_bread ((PTR) buf, 8, abfd) != 8)
+      || bfd_bread ((void *) buf, 8, abfd) != 8)
     return -1;
 
   command->type = bfd_h_get_32 (abfd, buf) & ~BFD_MACH_O_LC_REQ_DYLD;
@@ -2266,38 +2486,38 @@ bfd_mach_o_scan_read_command (bfd *abfd, bfd_mach_o_load_command *command)
   switch (command->type)
     {
     case BFD_MACH_O_LC_SEGMENT:
-      if (bfd_mach_o_scan_read_segment_32 (abfd, command) != 0)
+      if (bfd_mach_o_read_segment_32 (abfd, command) != 0)
        return -1;
       break;
     case BFD_MACH_O_LC_SEGMENT_64:
-      if (bfd_mach_o_scan_read_segment_64 (abfd, command) != 0)
+      if (bfd_mach_o_read_segment_64 (abfd, command) != 0)
        return -1;
       break;
     case BFD_MACH_O_LC_SYMTAB:
-      if (bfd_mach_o_scan_read_symtab (abfd, command) != 0)
+      if (bfd_mach_o_read_symtab (abfd, command) != 0)
        return -1;
       break;
     case BFD_MACH_O_LC_SYMSEG:
       break;
     case BFD_MACH_O_LC_THREAD:
     case BFD_MACH_O_LC_UNIXTHREAD:
-      if (bfd_mach_o_scan_read_thread (abfd, command) != 0)
+      if (bfd_mach_o_read_thread (abfd, command) != 0)
        return -1;
       break;
     case BFD_MACH_O_LC_LOAD_DYLINKER:
     case BFD_MACH_O_LC_ID_DYLINKER:
-      if (bfd_mach_o_scan_read_dylinker (abfd, command) != 0)
+      if (bfd_mach_o_read_dylinker (abfd, command) != 0)
        return -1;
       break;
     case BFD_MACH_O_LC_LOAD_DYLIB:
     case BFD_MACH_O_LC_ID_DYLIB:
     case BFD_MACH_O_LC_LOAD_WEAK_DYLIB:
     case BFD_MACH_O_LC_REEXPORT_DYLIB:
-      if (bfd_mach_o_scan_read_dylib (abfd, command) != 0)
+      if (bfd_mach_o_read_dylib (abfd, command) != 0)
        return -1;
       break;
     case BFD_MACH_O_LC_PREBOUND_DYLIB:
-      if (bfd_mach_o_scan_read_prebound_dylib (abfd, command) != 0)
+      if (bfd_mach_o_read_prebound_dylib (abfd, command) != 0)
        return -1;
       break;
     case BFD_MACH_O_LC_LOADFVMLIB:
@@ -2311,23 +2531,28 @@ bfd_mach_o_scan_read_command (bfd *abfd, bfd_mach_o_load_command *command)
     case BFD_MACH_O_LC_SUB_UMBRELLA:
     case BFD_MACH_O_LC_SUB_LIBRARY:
     case BFD_MACH_O_LC_SUB_CLIENT:
-      if (bfd_mach_o_scan_read_str (abfd, command) != 0)
+    case BFD_MACH_O_LC_RPATH:
+      if (bfd_mach_o_read_str (abfd, command) != 0)
         return -1;
       break;
     case BFD_MACH_O_LC_DYSYMTAB:
-      if (bfd_mach_o_scan_read_dysymtab (abfd, command) != 0)
+      if (bfd_mach_o_read_dysymtab (abfd, command) != 0)
        return -1;
       break;
     case BFD_MACH_O_LC_TWOLEVEL_HINTS:
     case BFD_MACH_O_LC_PREBIND_CKSUM:
       break;
     case BFD_MACH_O_LC_UUID:
-      if (bfd_mach_o_scan_read_uuid (abfd, command) != 0)
+      if (bfd_mach_o_read_uuid (abfd, command) != 0)
        return -1;
       break;
     case BFD_MACH_O_LC_CODE_SIGNATURE:
     case BFD_MACH_O_LC_SEGMENT_SPLIT_INFO:
-      if (bfd_mach_o_scan_read_linkedit (abfd, command) != 0)
+      if (bfd_mach_o_read_linkedit (abfd, command) != 0)
+       return -1;
+      break;
+    case BFD_MACH_O_LC_DYLD_INFO:
+      if (bfd_mach_o_read_dyld_info (abfd, command) != 0)
        return -1;
       break;
     default:
@@ -2432,7 +2657,7 @@ bfd_mach_o_scan_start_address (bfd *abfd)
          abfd->start_address = bfd_h_get_32 (abfd, buf);
        }
       else if ((mdata->header.cputype == BFD_MACH_O_CPU_TYPE_POWERPC_64)
-               && (cmd->flavours[i].flavour == BFD_MACH_O_PPC_THREAD_STATE_64))
+               && (cmd->flavours[i].flavour == BFD_MACH_O_PPC_THREAD_STATE64))
         {
           unsigned char buf[8];
 
@@ -2458,6 +2683,23 @@ bfd_mach_o_scan_start_address (bfd *abfd)
   return 0;
 }
 
+bfd_boolean
+bfd_mach_o_set_arch_mach (bfd *abfd,
+                          enum bfd_architecture arch,
+                          unsigned long machine)
+{
+  bfd_mach_o_backend_data *bed = bfd_mach_o_get_backend_data (abfd);
+
+  /* If this isn't the right architecture for this backend, and this
+     isn't the generic backend, fail.  */
+  if (arch != bed->arch
+      && arch != bfd_arch_unknown
+      && bed->arch != bfd_arch_unknown)
+    return FALSE;
+
+  return bfd_default_set_arch_mach (abfd, arch, machine);
+}
+
 int
 bfd_mach_o_scan (bfd *abfd,
                 bfd_mach_o_header *header,
@@ -2520,7 +2762,7 @@ bfd_mach_o_scan (bfd *abfd,
              cur->offset = prev->offset + prev->len;
            }
 
-         if (bfd_mach_o_scan_read_command (abfd, cur) < 0)
+         if (bfd_mach_o_read_command (abfd, cur) < 0)
            return -1;
        }
     }
@@ -2557,6 +2799,24 @@ bfd_mach_o_mkobject_init (bfd *abfd)
   return TRUE;
 }
 
+static bfd_boolean
+bfd_mach_o_gen_mkobject (bfd *abfd)
+{
+  bfd_mach_o_data_struct *mdata;
+
+  if (!bfd_mach_o_mkobject_init (abfd))
+    return FALSE;
+
+  mdata = bfd_mach_o_get_data (abfd);
+  mdata->header.magic = BFD_MACH_O_MH_MAGIC;
+  mdata->header.cputype = 0;
+  mdata->header.cpusubtype = 0;
+  mdata->header.byteorder = abfd->xvec->byteorder;
+  mdata->header.version = 1;
+
+  return TRUE;
+}
+
 const bfd_target *
 bfd_mach_o_header_p (bfd *abfd,
                      bfd_mach_o_filetype filetype,
@@ -2678,7 +2938,7 @@ bfd_mach_o_archive_p (bfd *abfd)
   unsigned long i;
 
   if (bfd_seek (abfd, 0, SEEK_SET) != 0
-      || bfd_bread ((PTR) buf, 8, abfd) != 8)
+      || bfd_bread ((void *) buf, 8, abfd) != 8)
     goto error;
 
   adata = bfd_alloc (abfd, sizeof (mach_o_fat_data_struct));
@@ -2703,7 +2963,7 @@ bfd_mach_o_archive_p (bfd *abfd)
   for (i = 0; i < adata->nfat_arch; i++)
     {
       if (bfd_seek (abfd, 8 + 20 * i, SEEK_SET) != 0
-          || bfd_bread ((PTR) buf, 20, abfd) != 20)
+          || bfd_bread ((void *) buf, 20, abfd) != 20)
        goto error;
       adata->archentries[i].cputype = bfd_getb32 (buf);
       adata->archentries[i].cpusubtype = bfd_getb32 (buf + 4);
@@ -2879,13 +3139,6 @@ bfd_mach_o_lookup_section (bfd *abfd,
        continue;
       seg = &cmd->command.segment;
 
-      if (seg->segment == section)
-       {
-         if (num == 0)
-           ncmd = cmd;
-         num++;
-       }
-
       for (j = 0; j < seg->nsects; j++)
        {
          struct bfd_mach_o_section *sect = &seg->sections[j];
@@ -2893,7 +3146,10 @@ bfd_mach_o_lookup_section (bfd *abfd,
          if (sect->bfdsection == section)
            {
              if (num == 0)
-               nsect = sect;
+                {
+                  nsect = sect;
+                  ncmd = cmd;
+                }
              num++;
            }
        }
@@ -3004,33 +3260,36 @@ bfd_mach_o_get_name (const bfd_mach_o_xlat_name *table, unsigned long val)
 
 static bfd_mach_o_xlat_name bfd_mach_o_cpu_name[] =
 {
-  { "vax", BFD_MACH_O_CPU_TYPE_VAX},
-  { "mc680x0", BFD_MACH_O_CPU_TYPE_MC680x0},
-  { "i386", BFD_MACH_O_CPU_TYPE_I386},
-  { "mips", BFD_MACH_O_CPU_TYPE_MIPS},
-  { "mc98000", BFD_MACH_O_CPU_TYPE_MC98000},
-  { "hppa", BFD_MACH_O_CPU_TYPE_HPPA},
-  { "arm", BFD_MACH_O_CPU_TYPE_ARM},
-  { "mc88000", BFD_MACH_O_CPU_TYPE_MC88000},
-  { "sparc", BFD_MACH_O_CPU_TYPE_SPARC},
-  { "i860", BFD_MACH_O_CPU_TYPE_I860},
-  { "alpha", BFD_MACH_O_CPU_TYPE_ALPHA},
-  { "powerpc", BFD_MACH_O_CPU_TYPE_POWERPC},
-  { "powerpc_64", BFD_MACH_O_CPU_TYPE_POWERPC_64},
-  { "x86_64", BFD_MACH_O_CPU_TYPE_X86_64},
+  { "vax", BFD_MACH_O_CPU_TYPE_VAX },
+  { "mc680x0", BFD_MACH_O_CPU_TYPE_MC680x0 },
+  { "i386", BFD_MACH_O_CPU_TYPE_I386 },
+  { "mips", BFD_MACH_O_CPU_TYPE_MIPS },
+  { "mc98000", BFD_MACH_O_CPU_TYPE_MC98000 },
+  { "hppa", BFD_MACH_O_CPU_TYPE_HPPA },
+  { "arm", BFD_MACH_O_CPU_TYPE_ARM },
+  { "mc88000", BFD_MACH_O_CPU_TYPE_MC88000 },
+  { "sparc", BFD_MACH_O_CPU_TYPE_SPARC },
+  { "i860", BFD_MACH_O_CPU_TYPE_I860 },
+  { "alpha", BFD_MACH_O_CPU_TYPE_ALPHA },
+  { "powerpc", BFD_MACH_O_CPU_TYPE_POWERPC },
+  { "powerpc_64", BFD_MACH_O_CPU_TYPE_POWERPC_64 },
+  { "x86_64", BFD_MACH_O_CPU_TYPE_X86_64 },
   { NULL, 0}
 };
 
 static bfd_mach_o_xlat_name bfd_mach_o_filetype_name[] = 
 {
-  { "object", BFD_MACH_O_MH_OBJECT},
-  { "execute", BFD_MACH_O_MH_EXECUTE},
-  { "fvmlib", BFD_MACH_O_MH_FVMLIB},
-  { "core", BFD_MACH_O_MH_CORE},
-  { "preload", BFD_MACH_O_MH_PRELOAD},
-  { "dylib", BFD_MACH_O_MH_DYLIB},
-  { "dylinker", BFD_MACH_O_MH_DYLINKER},
-  { "bundle", BFD_MACH_O_MH_BUNDLE},
+  { "object", BFD_MACH_O_MH_OBJECT },
+  { "execute", BFD_MACH_O_MH_EXECUTE },
+  { "fvmlib", BFD_MACH_O_MH_FVMLIB },
+  { "core", BFD_MACH_O_MH_CORE },
+  { "preload", BFD_MACH_O_MH_PRELOAD },
+  { "dylib", BFD_MACH_O_MH_DYLIB },
+  { "dylinker", BFD_MACH_O_MH_DYLINKER },
+  { "bundle", BFD_MACH_O_MH_BUNDLE },
+  { "dylib_stub", BFD_MACH_O_MH_DYLIB_STUB },
+  { "dym", BFD_MACH_O_MH_DSYM },
+  { "kext_bundle", BFD_MACH_O_MH_KEXT_BUNDLE },
   { NULL, 0}
 };
 
@@ -3133,6 +3392,7 @@ static bfd_mach_o_xlat_name bfd_mach_o_load_command_name[] =
   { "reexport_dylib", BFD_MACH_O_LC_REEXPORT_DYLIB},
   { "lazy_load_dylib", BFD_MACH_O_LC_LAZY_LOAD_DYLIB},
   { "encryption_info", BFD_MACH_O_LC_ENCRYPTION_INFO},
+  { "dyld_info", BFD_MACH_O_LC_DYLD_INFO},
   { NULL, 0}
 };
 
@@ -3142,7 +3402,7 @@ bfd_mach_o_print_private_header (bfd *abfd, FILE *file)
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   bfd_mach_o_header *h = &mdata->header;
 
-  fprintf (file, _("Mach-O header:\n"));
+  fputs (_("Mach-O header:\n"), file);
   fprintf (file, _(" magic     : %08lx\n"), h->magic);
   fprintf (file, _(" cputype   : %08lx (%s)\n"), h->cputype,
            bfd_mach_o_get_name (bfd_mach_o_cpu_name, h->cputype));
@@ -3150,11 +3410,11 @@ bfd_mach_o_print_private_header (bfd *abfd, FILE *file)
   fprintf (file, _(" filetype  : %08lx (%s)\n"),
            h->filetype,
            bfd_mach_o_get_name (bfd_mach_o_filetype_name, h->filetype));
-  fprintf (file, _(" ncmds     : %08lx\n"), h->ncmds);
+  fprintf (file, _(" ncmds     : %08lx (%lu)\n"), h->ncmds, h->ncmds);
   fprintf (file, _(" sizeofcmds: %08lx\n"), h->sizeofcmds);
   fprintf (file, _(" flags     : %08lx ("), h->flags);
   bfd_mach_o_print_flags (bfd_mach_o_header_flags_name, h->flags, file);
-  fprintf (file, _(")\n"));
+  fputs (_(")\n"), file);
   fprintf (file, _(" reserved  : %08x\n"), h->reserved);
 }
 
@@ -3165,8 +3425,8 @@ bfd_mach_o_print_section_map (bfd *abfd, FILE *file)
   unsigned int i, j;
   unsigned int sec_nbr = 0;
 
-  fprintf (file, _("Segments and Sections:\n"));
-  fprintf (file, _(" #: Segment name     Section name     Address\n"));
+  fputs (_("Segments and Sections:\n"), file);
+  fputs (_(" #: Segment name     Section name     Address\n"), file);
 
   for (i = 0; i < mdata->header.ncmds; i++)
     {
@@ -3200,39 +3460,12 @@ bfd_mach_o_print_section_map (bfd *abfd, FILE *file)
     }
 }
 
-/* Return the number of indirect symbols for a section.
-   Must be called only for symbol pointer section and symbol stubs
-   sections.  */
-
-static unsigned int
-bfd_mach_o_section_get_nbr_indirect (bfd *abfd, bfd_mach_o_section *sec)
-{
-  unsigned int elsz;
-
-  switch (sec->flags & BFD_MACH_O_SECTION_TYPE_MASK)
-    {
-    case BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS:
-    case BFD_MACH_O_S_LAZY_SYMBOL_POINTERS:
-      elsz = bfd_mach_o_wide_p (abfd) ? 8 : 4;
-      return sec->size / elsz;
-    case BFD_MACH_O_S_SYMBOL_STUBS:
-      elsz = sec->reserved2;
-      if (elsz)
-        return sec->size / elsz;
-      else
-        return 0;
-    default:
-      BFD_FAIL ();
-      return 0;
-    }
-}
-
 static void
 bfd_mach_o_print_section (bfd *abfd ATTRIBUTE_UNUSED,
                           bfd_mach_o_section *sec, FILE *file)
 {
-  fprintf (file, " Section: sectname: %-16s segname: %-16s\n",
-           sec->sectname, sec->segname);
+  fprintf (file, " Section: %-16s %-16s (bfdname: %s)\n",
+           sec->sectname, sec->segname, sec->bfdsection->name);
   fprintf (file, "  addr: ");
   fprintf_vma (file, sec->addr);
   fprintf (file, " size: ");
@@ -3284,7 +3517,7 @@ bfd_mach_o_print_segment (bfd *abfd ATTRIBUTE_UNUSED,
   bfd_mach_o_segment_command *seg = &cmd->command.segment;
   unsigned int i;
 
-  fprintf (file, " name: %s\n", seg->segname);
+  fprintf (file, " name: %s\n", *seg->segname ? seg->segname : "*none*");
   fprintf (file, "    vmaddr: ");
   fprintf_vma (file, seg->vmaddr);
   fprintf (file, "   vmsize: ");
@@ -3311,12 +3544,18 @@ bfd_mach_o_print_dysymtab (bfd *abfd ATTRIBUTE_UNUSED,
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   unsigned int i;
 
-  fprintf (file, "              local symbols: idx: %10lu  num: %lu\n",
+  fprintf (file, "              local symbols: idx: %10lu  num: %-8lu",
            dysymtab->ilocalsym, dysymtab->nlocalsym);
-  fprintf (file, "           external symbols: idx: %10lu  num: %lu\n",
+  fprintf (file, " (nxtidx: %lu)\n",
+           dysymtab->ilocalsym + dysymtab->nlocalsym);
+  fprintf (file, "           external symbols: idx: %10lu  num: %-8lu",
            dysymtab->iextdefsym, dysymtab->nextdefsym);
-  fprintf (file, "          undefined symbols: idx: %10lu  num: %lu\n",
+  fprintf (file, " (nxtidx: %lu)\n",
+           dysymtab->iextdefsym + dysymtab->nextdefsym);
+  fprintf (file, "          undefined symbols: idx: %10lu  num: %-8lu",
            dysymtab->iundefsym, dysymtab->nundefsym);
+  fprintf (file, " (nxtidx: %lu)\n",
+           dysymtab->iundefsym + dysymtab->nundefsym);
   fprintf (file, "           table of content: off: 0x%08lx  num: %-8lu",
            dysymtab->tocoff, dysymtab->ntoc);
   fprintf (file, " (endoff: 0x%08lx)\n",
@@ -3352,12 +3591,12 @@ bfd_mach_o_print_dysymtab (bfd *abfd ATTRIBUTE_UNUSED,
       || dysymtab->nextrefsyms > 0)
     {
       /* Try to read the symbols to display the toc or indirect symbols.  */
-      bfd_mach_o_scan_read_symtab_symbols (abfd);
+      bfd_mach_o_read_symtab_symbols (abfd);
     }
   else if (dysymtab->nmodtab > 0)
     {
       /* Try to read the strtab to display modules name.  */
-      bfd_mach_o_scan_read_symtab_strtab (abfd);
+      bfd_mach_o_read_symtab_strtab (abfd);
     }
   
   for (i = 0; i < dysymtab->nmodtab; i++)
@@ -3431,6 +3670,8 @@ bfd_mach_o_print_dysymtab (bfd *abfd ATTRIBUTE_UNUSED,
           bfd_mach_o_section *sec = mdata->sections[i];
           unsigned int j, first, last;
           bfd_mach_o_symtab_command *symtab = mdata->symtab;
+          bfd_vma addr;
+          bfd_vma entry_size;
       
           switch (sec->flags & BFD_MACH_O_SECTION_TYPE_MASK)
             {
@@ -3439,13 +3680,17 @@ bfd_mach_o_print_dysymtab (bfd *abfd ATTRIBUTE_UNUSED,
             case BFD_MACH_O_S_SYMBOL_STUBS:
               first = sec->reserved1;
               last = first + bfd_mach_o_section_get_nbr_indirect (abfd, sec);
+              addr = sec->addr;
+              entry_size = bfd_mach_o_section_get_entry_size (abfd, sec);
               fprintf (file, "  for section %s.%s:\n",
                        sec->segname, sec->sectname);
               for (j = first; j < last; j++)
                 {
                   unsigned int isym = dysymtab->indirect_syms[j];
                   
-                  fprintf (file, "  %5u: 0x%08x (%u)", j, isym, isym);
+                  fprintf (file, "   ");
+                  fprintf_vma (file, addr);
+                  fprintf (file, " %5u: 0x%08x", j, isym);
                   if (isym & BFD_MACH_O_INDIRECT_SYMBOL_LOCAL)
                     fprintf (file, " LOCAL");
                   if (isym & BFD_MACH_O_INDIRECT_SYMBOL_ABS)
@@ -3455,6 +3700,7 @@ bfd_mach_o_print_dysymtab (bfd *abfd ATTRIBUTE_UNUSED,
                       && symtab->symbols[isym].symbol.name)
                     fprintf (file, " %s", symtab->symbols[isym].symbol.name);
                   fprintf (file, "\n");
+                  addr += entry_size;
                 }
               break;
             default:
@@ -3482,8 +3728,26 @@ bfd_mach_o_print_dysymtab (bfd *abfd ATTRIBUTE_UNUSED,
 
 }
 
+static void
+bfd_mach_o_print_dyld_info (bfd *abfd ATTRIBUTE_UNUSED,
+                            bfd_mach_o_load_command *cmd, FILE *file)
+{
+  bfd_mach_o_dyld_info_command *info = &cmd->command.dyld_info;
+
+  fprintf (file, "       rebase: off: 0x%08x  size: %-8u\n",
+           info->rebase_off, info->rebase_size);
+  fprintf (file, "         bind: off: 0x%08x  size: %-8u\n",
+           info->bind_off, info->bind_size);
+  fprintf (file, "    weak bind: off: 0x%08x  size: %-8u\n",
+           info->weak_bind_off, info->weak_bind_size);
+  fprintf (file, "    lazy bind: off: 0x%08x  size: %-8u\n",
+           info->lazy_bind_off, info->lazy_bind_size);
+  fprintf (file, "       export: off: 0x%08x  size: %-8u\n",
+           info->export_off, info->export_size);
+}
+
 bfd_boolean
-bfd_mach_o_bfd_print_private_bfd_data (bfd *abfd, PTR ptr)
+bfd_mach_o_bfd_print_private_bfd_data (bfd *abfd, void * ptr)
 {
   bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
   FILE *file = (FILE *) ptr;
@@ -3507,10 +3771,10 @@ bfd_mach_o_bfd_print_private_bfd_data (bfd *abfd, PTR ptr)
        case BFD_MACH_O_LC_UUID:
          {
            bfd_mach_o_uuid_command *uuid = &cmd->command.uuid;
-           unsigned int i;
+           unsigned int j;
 
-           for (i = 0; i < sizeof (uuid->uuid); i++)
-             fprintf (file, " %02x", uuid->uuid[i]);
+           for (j = 0; j < sizeof (uuid->uuid); j ++)
+             fprintf (file, " %02x", uuid->uuid[j]);
            fputc ('\n', file);
          }
          break;
@@ -3520,43 +3784,19 @@ bfd_mach_o_bfd_print_private_bfd_data (bfd *abfd, PTR ptr)
        case BFD_MACH_O_LC_ID_DYLIB:
          {
            bfd_mach_o_dylib_command *dylib = &cmd->command.dylib;
-           bfd_byte *data = NULL;
-
-           if (! bfd_malloc_and_get_section (abfd, dylib->section, &data))
-             {
-               if (data != NULL)
-                 free (data);
-               break;
-             }
-           fprintf (file,
-                    " %s\n",
-                    data + dylib->name_offset - cmd->offset - 8);
+           fprintf (file, " %s\n", dylib->name_str);
            fprintf (file, "            time stamp: 0x%08lx\n",
                     dylib->timestamp);
            fprintf (file, "       current version: 0x%08lx\n",
                     dylib->current_version);
            fprintf (file, "  comptibility version: 0x%08lx\n",
                     dylib->compatibility_version);
-           free (data);
            break;
          }
        case BFD_MACH_O_LC_LOAD_DYLINKER:
-         {
-           bfd_mach_o_dylinker_command *linker = &cmd->command.dylinker;
-           bfd_byte *data = NULL;
-
-           if (! bfd_malloc_and_get_section (abfd, linker->section, &data))
-             {
-               if (data != NULL)
-                 free (data);
-               break;
-             }
-           fprintf (file,
-                    " %s\n",
-                    data + linker->name_offset - cmd->offset - 8);
-           free (data);
-           break;
-         }
+       case BFD_MACH_O_LC_ID_DYLINKER:
+          fprintf (file, " %s\n", cmd->command.dylinker.name_str);
+          break;
        case BFD_MACH_O_LC_SYMTAB:
          {
            bfd_mach_o_symtab_command *symtab = &cmd->command.symtab;
@@ -3592,11 +3832,47 @@ bfd_mach_o_bfd_print_private_bfd_data (bfd *abfd, PTR ptr)
         case BFD_MACH_O_LC_SUB_UMBRELLA:
         case BFD_MACH_O_LC_SUB_LIBRARY:
         case BFD_MACH_O_LC_SUB_CLIENT:
+        case BFD_MACH_O_LC_RPATH:
          {
            bfd_mach_o_str_command *str = &cmd->command.str;
            fprintf (file, " %s\n", str->str);
             break;
           }
+        case BFD_MACH_O_LC_THREAD:
+        case BFD_MACH_O_LC_UNIXTHREAD:
+          {
+            bfd_mach_o_thread_command *thread = &cmd->command.thread;
+            unsigned int j;
+            bfd_mach_o_backend_data *bed = bfd_mach_o_get_backend_data (abfd);
+
+            fprintf (file, " nflavours: %lu\n", thread->nflavours);
+            for (j = 0; j < thread->nflavours; j++)
+              {
+                bfd_mach_o_thread_flavour *flavour = &thread->flavours[j];
+
+                fprintf (file, "  %2u: flavour: 0x%08lx  offset: 0x%08lx"
+                         "  size: 0x%08lx\n",
+                         j, flavour->flavour, flavour->offset,
+                         flavour->size);
+                if (bed->_bfd_mach_o_print_thread)
+                  {
+                    char *buf = bfd_malloc (flavour->size);
+
+                    if (buf
+                        && bfd_seek (abfd, flavour->offset, SEEK_SET) == 0
+                        && (bfd_bread (buf, flavour->size, abfd) 
+                            == flavour->size))
+                      (*bed->_bfd_mach_o_print_thread)(abfd, flavour,
+                                                       file, buf);
+                    free (buf);
+                  }
+              }
+            break;
+          }
+       case BFD_MACH_O_LC_DYLD_INFO:
+          fprintf (file, "\n");
+          bfd_mach_o_print_dyld_info (abfd, cmd, file);
+          break;
        default:
          fprintf (file, "\n");
          break;
@@ -3726,20 +4002,24 @@ bfd_mach_o_core_file_failing_signal (bfd *abfd ATTRIBUTE_UNUSED)
 
 #define bfd_mach_o_swap_reloc_in NULL
 #define bfd_mach_o_swap_reloc_out NULL
+#define bfd_mach_o_print_thread NULL
 
 #define TARGET_NAME            mach_o_be_vec
 #define TARGET_STRING          "mach-o-be"
+#define TARGET_ARCHITECTURE    bfd_arch_unknown
 #define TARGET_BIG_ENDIAN      1
 #define TARGET_ARCHIVE                 0
 #include "mach-o-target.c"
 
 #undef TARGET_NAME
 #undef TARGET_STRING
+#undef TARGET_ARCHITECTURE
 #undef TARGET_BIG_ENDIAN
 #undef TARGET_ARCHIVE
 
 #define TARGET_NAME            mach_o_le_vec
 #define TARGET_STRING          "mach-o-le"
+#define TARGET_ARCHITECTURE    bfd_arch_unknown
 #define TARGET_BIG_ENDIAN      0
 #define TARGET_ARCHIVE                 0
 
@@ -3747,11 +4027,28 @@ bfd_mach_o_core_file_failing_signal (bfd *abfd ATTRIBUTE_UNUSED)
 
 #undef TARGET_NAME
 #undef TARGET_STRING
+#undef TARGET_ARCHITECTURE
 #undef TARGET_BIG_ENDIAN
 #undef TARGET_ARCHIVE
 
+/* Not yet handled: creating an archive.  */
+#define bfd_mach_o_mkarchive                      _bfd_noarchive_mkarchive
+
+/* Not used.  */
+#define bfd_mach_o_read_ar_hdr                    _bfd_noarchive_read_ar_hdr
+#define bfd_mach_o_write_ar_hdr                   _bfd_noarchive_write_ar_hdr
+#define bfd_mach_o_slurp_armap                    _bfd_noarchive_slurp_armap
+#define bfd_mach_o_slurp_extended_name_table      _bfd_noarchive_slurp_extended_name_table
+#define bfd_mach_o_construct_extended_name_table  _bfd_noarchive_construct_extended_name_table
+#define bfd_mach_o_truncate_arname                _bfd_noarchive_truncate_arname
+#define bfd_mach_o_write_armap                    _bfd_noarchive_write_armap
+#define bfd_mach_o_get_elt_at_index               _bfd_noarchive_get_elt_at_index
+#define bfd_mach_o_generic_stat_arch_elt          _bfd_noarchive_generic_stat_arch_elt
+#define bfd_mach_o_update_armap_timestamp         _bfd_noarchive_update_armap_timestamp
+
 #define TARGET_NAME            mach_o_fat_vec
 #define TARGET_STRING          "mach-o-fat"
+#define TARGET_ARCHITECTURE    bfd_arch_unknown
 #define TARGET_BIG_ENDIAN      1
 #define TARGET_ARCHIVE                 1
 
@@ -3759,5 +4056,6 @@ bfd_mach_o_core_file_failing_signal (bfd *abfd ATTRIBUTE_UNUSED)
 
 #undef TARGET_NAME
 #undef TARGET_STRING
+#undef TARGET_ARCHITECTURE
 #undef TARGET_BIG_ENDIAN
 #undef TARGET_ARCHIVE
This page took 0.053032 seconds and 4 git commands to generate.