2012-01-04 Tristan Gingold <gingold@adacore.com>
authorTristan Gingold <gingold@adacore.com>
Wed, 4 Jan 2012 13:22:21 +0000 (13:22 +0000)
committerTristan Gingold <gingold@adacore.com>
Wed, 4 Jan 2012 13:22:21 +0000 (13:22 +0000)
* mach-o.c (bfd_mach_o_fat_member_init): New function.
(bfd_mach_o_openr_next_archived_file): Reindent.
Adjust to call bfd_mach_o_fat_member_init.
(bfd_mach_o_fat_extract): Adjust to call bfd_mach_o_fat_member_init.

bfd/ChangeLog
bfd/mach-o.c

index 2328a478240a6f3bdbac9e123f3588abe2f9e6ed..f49a8dc0596d38790e00878b2dfe0cf830e50fce 100644 (file)
@@ -1,3 +1,10 @@
+2012-01-04  Tristan Gingold  <gingold@adacore.com>
+
+       * mach-o.c (bfd_mach_o_fat_member_init): New function.
+       (bfd_mach_o_openr_next_archived_file): Reindent.
+       Adjust to call bfd_mach_o_fat_member_init.
+       (bfd_mach_o_fat_extract): Adjust to call bfd_mach_o_fat_member_init.
+
 2012-01-04  Tristan Gingold  <gingold@adacore.com>
 
        * mach-o-x86-64.c (bfd_mach_o_x86_64_swap_reloc_out): Handle
index d2fd7e1867e49dfd4a35facbed38219a7a71f2cd..4618fe8b28d010ed189115432a75860d178d2415 100644 (file)
@@ -4107,6 +4107,42 @@ bfd_mach_o_archive_p (bfd *abfd)
   return NULL;
 }
 
+/* Set the filename for a fat binary member ABFD, whose bfd architecture is
+   ARCH_TYPE/ARCH_SUBTYPE and corresponding entry in header is ENTRY.
+   Set arelt_data and origin fields too.  */
+
+static void
+bfd_mach_o_fat_member_init (bfd *abfd,
+                            enum bfd_architecture arch_type,
+                            unsigned long arch_subtype,
+                            mach_o_fat_archentry *entry)
+{
+  struct areltdata *areltdata;
+  /* Create the member filename. Use ARCH_NAME.  */
+  const bfd_arch_info_type *ap = bfd_lookup_arch (arch_type, arch_subtype);
+
+  if (ap)
+    {
+      /* Use the architecture name if known.  */
+      abfd->filename = ap->printable_name;
+    }
+  else
+    {
+      /* Forge a uniq id.  */
+      const size_t namelen = 2 + 8 + 1 + 2 + 8 + 1;
+      char *name = bfd_alloc (abfd, namelen);
+      snprintf (name, namelen, "0x%lx-0x%lx",
+                entry->cputype, entry->cpusubtype);
+      abfd->filename = name;
+    }
+
+  areltdata = bfd_zalloc (abfd, sizeof (struct areltdata));
+  areltdata->parsed_size = entry->size;
+  abfd->arelt_data = areltdata;
+  abfd->iostream = NULL;
+  abfd->origin = entry->offset;
+}
+
 bfd *
 bfd_mach_o_openr_next_archived_file (bfd *archive, bfd *prev)
 {
@@ -4122,9 +4158,13 @@ bfd_mach_o_openr_next_archived_file (bfd *archive, bfd *prev)
 
   /* Find index of previous entry.  */
   if (prev == NULL)
-    i = 0;     /* Start at first one.  */
+    {
+      /* Start at first one.  */
+      i = 0;
+    }
   else
     {
+      /* Find index of PREV.  */
       for (i = 0; i < adata->nfat_arch; i++)
        {
          if (adata->archentries[i].offset == prev->origin)
@@ -4137,8 +4177,10 @@ bfd_mach_o_openr_next_archived_file (bfd *archive, bfd *prev)
          bfd_set_error (bfd_error_bad_value);
          return NULL;
        }
-    i++;       /* Get next entry.  */
-  }
+
+      /* Get next entry.  */
+      i++;
+    }
 
   if (i >= adata->nfat_arch)
     {
@@ -4151,14 +4193,11 @@ bfd_mach_o_openr_next_archived_file (bfd *archive, bfd *prev)
   if (nbfd == NULL)
     return NULL;
 
-  nbfd->origin = entry->offset;
-
   bfd_mach_o_convert_architecture (entry->cputype, entry->cpusubtype,
                                   &arch_type, &arch_subtype);
 
-  /* Create the member filename. Use ARCH_NAME.  */
-  nbfd->filename = bfd_printable_arch_mach (arch_type, arch_subtype);
-  nbfd->iostream = NULL;
+  bfd_mach_o_fat_member_init (nbfd, arch_type, arch_subtype, entry);
+
   bfd_set_arch_mach (nbfd, arch_type, arch_subtype);
 
   return nbfd;
@@ -4169,6 +4208,7 @@ bfd_mach_o_openr_next_archived_file (bfd *archive, bfd *prev)
    and ARCH, returns it.
    In other case, returns NULL.
    This function allows transparent uses of fat images.  */
+
 bfd *
 bfd_mach_o_fat_extract (bfd *abfd,
                        bfd_format format,
@@ -4208,10 +4248,7 @@ bfd_mach_o_fat_extract (bfd *abfd,
       if (res == NULL)
        return NULL;
 
-      res->origin = e->offset;
-
-      res->filename = bfd_printable_arch_mach (cpu_type, cpu_subtype);
-      res->iostream = NULL;
+      bfd_mach_o_fat_member_init (res, cpu_type, cpu_subtype, e);
 
       if (bfd_check_format (res, format))
        {