Line 119... |
Line 119... |
bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
|
bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
|
{
|
{
|
extern const bfd_target binary_vec;
|
extern const bfd_target binary_vec;
|
const bfd_target * const *target;
|
const bfd_target * const *target;
|
const bfd_target **matching_vector = NULL;
|
const bfd_target **matching_vector = NULL;
|
const bfd_target *save_targ, *right_targ, *ar_right_targ;
|
const bfd_target *save_targ, *right_targ, *ar_right_targ, *match_targ;
|
int match_count;
|
int match_count, best_count, best_match;
|
int ar_match_index;
|
int ar_match_index;
|
|
|
if (matching != NULL)
|
if (matching != NULL)
|
*matching = NULL;
|
*matching = NULL;
|
|
|
Line 154... |
Line 154... |
return FALSE;
|
return FALSE;
|
}
|
}
|
|
|
right_targ = 0;
|
right_targ = 0;
|
ar_right_targ = 0;
|
ar_right_targ = 0;
|
|
match_targ = 0;
|
|
best_match = 256;
|
|
best_count = 0;
|
|
|
/* Presume the answer is yes. */
|
/* Presume the answer is yes. */
|
abfd->format = format;
|
abfd->format = format;
|
|
|
/* If the target type was explicitly specified, just check that target. */
|
/* If the target type was explicitly specified, just check that target. */
|
Line 192... |
Line 195... |
const bfd_target *temp;
|
const bfd_target *temp;
|
bfd_error_type err;
|
bfd_error_type err;
|
|
|
/* Don't check the default target twice. */
|
/* Don't check the default target twice. */
|
if (*target == &binary_vec
|
if (*target == &binary_vec
|
|| (!abfd->target_defaulted && *target == save_targ))
|
|| (!abfd->target_defaulted && *target == save_targ)
|
|
|| (*target)->match_priority > best_match)
|
continue;
|
continue;
|
|
|
abfd->xvec = *target; /* Change BFD's target temporarily. */
|
abfd->xvec = *target; /* Change BFD's target temporarily. */
|
|
|
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
|
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
|
Line 207... |
Line 211... |
attention to bfd_error, so I suspect that some
|
attention to bfd_error, so I suspect that some
|
_bfd_check_format might have this problem. */
|
_bfd_check_format might have this problem. */
|
bfd_set_error (bfd_error_wrong_format);
|
bfd_set_error (bfd_error_wrong_format);
|
|
|
temp = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
|
temp = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
|
|
if (temp)
|
|
match_targ = temp;
|
|
|
if (temp && (abfd->format != bfd_archive || bfd_has_map (abfd)))
|
if (temp && (abfd->format != bfd_archive || bfd_has_map (abfd)))
|
{
|
{
|
/* This format checks out as ok! */
|
/* This format checks out as ok! */
|
right_targ = temp;
|
right_targ = temp;
|
|
|
/* If this is the default target, accept it, even if other
|
/* If this is the default target, accept it, even if other
|
targets might match. People who want those other targets
|
targets might match. People who want those other targets
|
have to set the GNUTARGET variable. */
|
have to set the GNUTARGET variable. */
|
if (temp == bfd_default_vector[0])
|
if (temp == bfd_default_vector[0])
|
{
|
goto ok_ret;
|
match_count = 1;
|
|
break;
|
|
}
|
|
|
|
if (matching_vector)
|
if (matching_vector)
|
matching_vector[match_count] = temp;
|
matching_vector[match_count] = temp;
|
match_count++;
|
match_count++;
|
|
|
|
if (temp->match_priority < best_match)
|
|
{
|
|
best_match = temp->match_priority;
|
|
best_count = 0;
|
|
}
|
|
best_count++;
|
}
|
}
|
else if (temp
|
else if (temp
|
|| (err = bfd_get_error ()) == bfd_error_wrong_object_format
|
|| (err = bfd_get_error ()) == bfd_error_wrong_object_format
|
|| err == bfd_error_file_ambiguously_recognized)
|
|| err == bfd_error_file_ambiguously_recognized)
|
{
|
{
|
Line 243... |
Line 253... |
}
|
}
|
else if (err != bfd_error_wrong_format)
|
else if (err != bfd_error_wrong_format)
|
goto err_ret;
|
goto err_ret;
|
}
|
}
|
|
|
|
if (best_count == 1)
|
|
match_count = 1;
|
|
|
if (match_count == 0)
|
if (match_count == 0)
|
{
|
{
|
/* Try partial matches. */
|
/* Try partial matches. */
|
right_targ = ar_right_targ;
|
right_targ = ar_right_targ;
|
|
|
Line 285... |
Line 298... |
}
|
}
|
}
|
}
|
|
|
if (match_count == 1)
|
if (match_count == 1)
|
{
|
{
|
ok_ret:
|
abfd->xvec = right_targ;
|
abfd->xvec = right_targ; /* Change BFD's target permanently. */
|
/* 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'
|
/* If the file was opened for update, then `output_has_begun'
|
some time ago when the file was created. Do not recompute
|
some time ago when the file was created. Do not recompute
|
sections sizes or alignments in _bfd_set_section_contents.
|
sections sizes or alignments in _bfd_set_section_contents.
|
We can not set this flag until after checking the format,
|
We can not set this flag until after checking the format,
|
because it will interfere with creation of BFD sections. */
|
because it will interfere with creation of BFD sections. */
|