summaryrefslogtreecommitdiff
path: root/bfd/format.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@bigpond.net.au>2011-06-06 01:25:59 +0000
committerAlan Modra <amodra@bigpond.net.au>2011-06-06 01:25:59 +0000
commit972e9da7b2b83ecc949a0f4be4ea2b696ab448f5 (patch)
tree5ea630c9586af13c101794f8bb19834056723f22 /bfd/format.c
parent154834e4c5fbf21304cf2d79c9c02a614fc70e54 (diff)
downloadbinutils-redhat-972e9da7b2b83ecc949a0f4be4ea2b696ab448f5.tar.gz
* targets.c (bfd_target): Make ar_max_namelen an unsigned char.
Add match_priority. * configure.in: Bump bfd version. * elfcode.h (elf_object_p): Delete hacks preventing match of EM_NONE and ELFOSABI_NONE targets when a better match exists. * elfxx-target.h (elf_match_priority): Define and use. * format.c (bfd_check_format_matches): Use target match_priority to choose best of multiple matching targets. In cases with multiple matches rerun _bfd_check_format if we don't choose the last match. * aout-adobe.c, * aout-arm.c, * aout-target.h, * aout-tic30.c, * binary.c, * bout.c, * coff-alpha.c, * coff-i386.c, * coff-i860.c, * coff-i960.c, * coff-ia64.c, * coff-mips.c, * coff-or32.c, * coff-ppc.c, * coff-rs6000.c, * coff-sh.c, * coff-tic30.c, * coff-tic54x.c, * coff-x86_64.c, * coff64-rs6000.c, * coffcode.h, * i386msdos.c, * i386os9k.c, * ieee.c, * ihex.c, * mach-o-target.c, * mipsbsd.c, * mmo.c, * nlm-target.h, * oasys.c, * pdp11.c, * pe-mips.c, * pef.c, * plugin.c, * ppcboot.c, * som.c, * srec.c, * tekhex.c, * trad-core.c, * verilog.c, * versados.c, * vms-alpha.c, * vms-lib.c, * xsym.c: Init match_priority field. * configure: Regenerate. * bfd-in2.h: Regenerate.
Diffstat (limited to 'bfd/format.c')
-rw-r--r--bfd/format.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/bfd/format.c b/bfd/format.c
index 4d89a85e0a..66b9051efe 100644
--- a/bfd/format.c
+++ b/bfd/format.c
@@ -121,8 +121,8 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
extern const bfd_target binary_vec;
const bfd_target * const *target;
const bfd_target **matching_vector = NULL;
- const bfd_target *save_targ, *right_targ, *ar_right_targ;
- int match_count;
+ const bfd_target *save_targ, *right_targ, *ar_right_targ, *match_targ;
+ int match_count, best_count, best_match;
int ar_match_index;
if (matching != NULL)
@@ -156,6 +156,9 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
right_targ = 0;
ar_right_targ = 0;
+ match_targ = 0;
+ best_match = 256;
+ best_count = 0;
/* Presume the answer is yes. */
abfd->format = format;
@@ -194,7 +197,8 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
/* Don't check the default target twice. */
if (*target == &binary_vec
- || (!abfd->target_defaulted && *target == save_targ))
+ || (!abfd->target_defaulted && *target == save_targ)
+ || (*target)->match_priority > best_match)
continue;
abfd->xvec = *target; /* Change BFD's target temporarily. */
@@ -209,6 +213,8 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
bfd_set_error (bfd_error_wrong_format);
temp = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
+ if (temp)
+ match_targ = temp;
if (temp && (abfd->format != bfd_archive || bfd_has_map (abfd)))
{
@@ -219,14 +225,18 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
targets might match. People who want those other targets
have to set the GNUTARGET variable. */
if (temp == bfd_default_vector[0])
- {
- match_count = 1;
- break;
- }
+ goto ok_ret;
if (matching_vector)
matching_vector[match_count] = temp;
match_count++;
+
+ if (temp->match_priority < best_match)
+ {
+ best_match = temp->match_priority;
+ best_count = 0;
+ }
+ best_count++;
}
else if (temp
|| (err = bfd_get_error ()) == bfd_error_wrong_object_format
@@ -245,6 +255,9 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
goto err_ret;
}
+ if (best_count == 1)
+ match_count = 1;
+
if (match_count == 0)
{
/* Try partial matches. */
@@ -287,9 +300,18 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
if (match_count == 1)
{
- ok_ret:
- abfd->xvec = right_targ; /* Change BFD's target permanently. */
+ abfd->xvec = right_targ;
+ /* If we come out of the loop knowing that the last target that
+ matched is the one we want, then ABFD should still be in a usable
+ state (except possibly for XVEC). */
+ if (match_targ != right_targ)
+ {
+ if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
+ goto err_ret;
+ match_targ = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
+ }
+ ok_ret:
/* If the file was opened for update, then `output_has_begun'
some time ago when the file was created. Do not recompute
sections sizes or alignments in _bfd_set_section_contents.