summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@bigpond.net.au>2011-06-04 04:07:52 +0000
committerAlan Modra <amodra@bigpond.net.au>2011-06-04 04:07:52 +0000
commit72578de7c541848f67f5a992d22509b7418ac130 (patch)
tree892978a3deab2d656a44438c70954f2c6df0af10
parentedca786eb9e5de10ec80e90af55189e33445065a (diff)
downloadbinutils-redhat-72578de7c541848f67f5a992d22509b7418ac130.tar.gz
* archures.c (bfd_arch_get_compatible): If one arch is unknown,
return the other arch. * elfcode.h (elf_object_p): Allow explicit match to generic ELF target.
-rw-r--r--bfd/ChangeLog7
-rw-r--r--bfd/archures.c37
-rw-r--r--bfd/elfcode.h41
3 files changed, 47 insertions, 38 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 034e9e7917..30b34b6349 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2011-06-04 Alan Modra <amodra@gmail.com>
+
+ * archures.c (bfd_arch_get_compatible): If one arch is unknown,
+ return the other arch.
+ * elfcode.h (elf_object_p): Allow explicit match to generic ELF
+ target.
+
2011-06-03 Bertram Felgenhauer <bertram.felgenhauer@gmail.com>
PR ld/12682
diff --git a/bfd/archures.c b/bfd/archures.c
index cd8500f779..df22b81286 100644
--- a/bfd/archures.c
+++ b/bfd/archures.c
@@ -1,6 +1,6 @@
/* BFD library support routines for architectures.
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+ 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
Free Software Foundation, Inc.
Hacked by John Gilmore and Steve Chamberlain of Cygnus Support.
@@ -748,25 +748,26 @@ bfd_arch_get_compatible (const bfd *abfd,
const bfd *bbfd,
bfd_boolean accept_unknowns)
{
- const bfd * ubfd = NULL;
+ const bfd *ubfd, *kbfd;
/* Look for an unknown architecture. */
- if (((ubfd = abfd) && ubfd->arch_info->arch == bfd_arch_unknown)
- || ((ubfd = bbfd) && ubfd->arch_info->arch == bfd_arch_unknown))
- {
- /* We can allow an unknown architecture if accept_unknowns
- is true, or if the target is the "binary" format, which
- has an unknown architecture. Since the binary format can
- only be set by explicit request from the user, it is safe
- to assume that they know what they are doing. */
- if (accept_unknowns
- || strcmp (bfd_get_target (ubfd), "binary") == 0)
- return ubfd->arch_info;
- return NULL;
- }
-
- /* Otherwise architecture-specific code has to decide. */
- return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
+ if (abfd->arch_info->arch == bfd_arch_unknown)
+ ubfd = abfd, kbfd = bbfd;
+ else if (bbfd->arch_info->arch == bfd_arch_unknown)
+ ubfd = bbfd, kbfd = abfd;
+ else
+ /* Otherwise architecture-specific code has to decide. */
+ return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
+
+ /* We can allow an unknown architecture if accept_unknowns
+ is true, or if the target is the "binary" format, which
+ has an unknown architecture. Since the binary format can
+ only be set by explicit request from the user, it is safe
+ to assume that they know what they are doing. */
+ if (accept_unknowns
+ || strcmp (bfd_get_target (ubfd), "binary") == 0)
+ return kbfd->arch_info;
+ return NULL;
}
/*
diff --git a/bfd/elfcode.h b/bfd/elfcode.h
index d8833dfdcf..fdfeee9b27 100644
--- a/bfd/elfcode.h
+++ b/bfd/elfcode.h
@@ -595,26 +595,27 @@ elf_object_p (bfd *abfd)
/* This is the generic ELF target. Let it match any ELF target
for which we do not have a specific backend. */
- for (target_ptr = bfd_target_vector; *target_ptr != NULL; target_ptr++)
- {
- const struct elf_backend_data *back;
-
- if ((*target_ptr)->flavour != bfd_target_elf_flavour)
- continue;
- back = xvec_get_elf_backend_data (*target_ptr);
- if (back->s->arch_size != ARCH_SIZE)
- continue;
- if (back->elf_machine_code == i_ehdrp->e_machine
- || (back->elf_machine_alt1 != 0
- && back->elf_machine_alt1 == i_ehdrp->e_machine)
- || (back->elf_machine_alt2 != 0
- && back->elf_machine_alt2 == i_ehdrp->e_machine))
- {
- /* target_ptr is an ELF backend which matches this
- object file, so reject the generic ELF target. */
- goto got_wrong_format_error;
- }
- }
+ if (abfd->target_defaulted)
+ for (target_ptr = bfd_target_vector; *target_ptr != NULL; target_ptr++)
+ {
+ const struct elf_backend_data *back;
+
+ if ((*target_ptr)->flavour != bfd_target_elf_flavour)
+ continue;
+ back = xvec_get_elf_backend_data (*target_ptr);
+ if (back->s->arch_size != ARCH_SIZE)
+ continue;
+ if (back->elf_machine_code == i_ehdrp->e_machine
+ || (back->elf_machine_alt1 != 0
+ && back->elf_machine_alt1 == i_ehdrp->e_machine)
+ || (back->elf_machine_alt2 != 0
+ && back->elf_machine_alt2 == i_ehdrp->e_machine))
+ {
+ /* target_ptr is an ELF backend which matches this
+ object file, so reject the generic ELF target. */
+ goto got_wrong_format_error;
+ }
+ }
}
if (i_ehdrp->e_type == ET_EXEC)