This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[Darwin]: Use id for name of unknown arch fat binary members
- From: Tristan Gingold <gingold at adacore dot com>
- To: binutils Development <binutils at sourceware dot org>
- Date: Wed, 4 Jan 2012 14:22:20 +0100
- Subject: [Darwin]: Use id for name of unknown arch fat binary members
Hi,
previously bfd_printable_arch_mach was used to give a name to fat binary members. This doesn't work well with unknown architecture as the name returned is "UNKNOWN!". With this patch, the numeric mach-o architecture id will be used instead for unknown architecture.
Also, the code for naming members is now factorized.
Committed to trunk.
Tristan.
bfd/
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.
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.c,v
retrieving revision 1.89
diff -c -r1.89 mach-o.c
*** mach-o.c 4 Jan 2012 10:37:35 -0000 1.89
--- mach-o.c 4 Jan 2012 13:15:01 -0000
***************
*** 4107,4112 ****
--- 4107,4148 ----
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,4130 ****
/* Find index of previous entry. */
if (prev == NULL)
! i = 0; /* Start at first one. */
else
{
for (i = 0; i < adata->nfat_arch; i++)
{
if (adata->archentries[i].offset == prev->origin)
--- 4158,4170 ----
/* Find index of previous entry. */
if (prev == NULL)
! {
! /* 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,4144 ****
bfd_set_error (bfd_error_bad_value);
return NULL;
}
! i++; /* Get next entry. */
! }
if (i >= adata->nfat_arch)
{
--- 4177,4186 ----
bfd_set_error (bfd_error_bad_value);
return NULL;
}
!
! /* Get next entry. */
! i++;
! }
if (i >= adata->nfat_arch)
{
***************
*** 4151,4164 ****
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_set_arch_mach (nbfd, arch_type, arch_subtype);
return nbfd;
--- 4193,4203 ----
if (nbfd == NULL)
return NULL;
bfd_mach_o_convert_architecture (entry->cputype, entry->cpusubtype,
&arch_type, &arch_subtype);
! bfd_mach_o_fat_member_init (nbfd, arch_type, arch_subtype, entry);
!
bfd_set_arch_mach (nbfd, arch_type, arch_subtype);
return nbfd;
***************
*** 4169,4174 ****
--- 4208,4214 ----
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,4217 ****
if (res == NULL)
return NULL;
! res->origin = e->offset;
!
! res->filename = bfd_printable_arch_mach (cpu_type, cpu_subtype);
! res->iostream = NULL;
if (bfd_check_format (res, format))
{
--- 4248,4254 ----
if (res == NULL)
return NULL;
! bfd_mach_o_fat_member_init (res, cpu_type, cpu_subtype, e);
if (bfd_check_format (res, format))
{