[PATCH/RFA] Ambiguity problem of REL objects on ELF sh*-*-*
Alan Modra
amodra@bigpond.net.au
Sat Nov 2 04:49:00 GMT 2002
On Fri, Nov 01, 2002 at 10:51:29PM +0900, kaz Kojima wrote:
> --- ORIG/src/bfd/format.c Sat Oct 26 11:59:56 2002
> +++ LOCAL/src/bfd/format.c Fri Nov 1 22:33:37 2002
> @@ -235,6 +235,25 @@ bfd_check_format_matches (abfd, format,
> break;
> }
>
> + /* Permit also if it is an associated target. */
> + if (bfd_associated_vector)
> + {
> + const bfd_target **assoc = bfd_associated_vector;
> +
> + while (*assoc)
> + {
> + if (temp == *assoc)
> + break;
> + ++assoc;
> + }
> +
> + if (*assoc)
> + {
> + match_count = 1;
> + break;
> + }
> + }
> +
> if (matching)
> matching_vector[match_count] = temp->name;
>
No, this is the wrong place to match associated targets. Depending
on the order of target vectors, you may hit one of the associated
targets before the default target. Try this:
* format.c (bfd_check_format_matches): Store bfd_target pointers
in matching_vector instead of target names. Select first target
from bfd_associated_vector that matches a list of ambiguous targets.
Index: bfd/format.c
===================================================================
RCS file: /cvs/src/src/bfd/format.c,v
retrieving revision 1.9
diff -u -p -r1.9 format.c
--- bfd/format.c 25 Oct 2002 02:45:53 -0000 1.9
+++ bfd/format.c 2 Nov 2002 10:30:02 -0000
@@ -119,8 +119,9 @@ bfd_check_format_matches (abfd, format,
char ***matching;
{
extern const bfd_target binary_vec;
- const bfd_target * const *target, *save_targ, *right_targ, *ar_right_targ;
- char **matching_vector = NULL;
+ const bfd_target * const *target;
+ const bfd_target **matching_vector = NULL;
+ const bfd_target *save_targ, *right_targ, *ar_right_targ;
int match_count;
int ar_match_index;
@@ -145,8 +146,8 @@ bfd_check_format_matches (abfd, format,
bfd_size_type amt;
*matching = NULL;
- amt = sizeof (char *) * 2 * _bfd_target_vector_entries;
- matching_vector = (char **) bfd_malloc (amt);
+ amt = sizeof (*matching_vector) * 2 * _bfd_target_vector_entries;
+ matching_vector = (const bfd_target **) bfd_malloc (amt);
if (!matching_vector)
return false;
}
@@ -170,7 +171,7 @@ bfd_check_format_matches (abfd, format,
abfd->xvec = right_targ; /* Set the target as returned. */
if (matching)
- free (matching_vector);
+ free ((PTR) matching_vector);
return true; /* File position has moved, BTW. */
}
@@ -193,7 +194,7 @@ bfd_check_format_matches (abfd, format,
abfd->format = bfd_unknown;
if (matching)
- free (matching_vector);
+ free ((PTR) matching_vector);
bfd_set_error (bfd_error_file_not_recognized);
@@ -236,7 +237,7 @@ bfd_check_format_matches (abfd, format,
}
if (matching)
- matching_vector[match_count] = temp->name;
+ matching_vector[match_count] = temp;
match_count++;
@@ -259,7 +260,7 @@ bfd_check_format_matches (abfd, format,
if (ar_right_targ != bfd_default_vector[0])
ar_right_targ = *target;
if (matching)
- matching_vector[ar_match_index] = (*target)->name;
+ matching_vector[ar_match_index] = *target;
ar_match_index++;
}
else if (err != bfd_error_wrong_format)
@@ -268,7 +269,7 @@ bfd_check_format_matches (abfd, format,
abfd->format = bfd_unknown;
if (matching)
- free (matching_vector);
+ free ((PTR) matching_vector);
return false;
}
@@ -289,7 +290,27 @@ bfd_check_format_matches (abfd, format,
{
memcpy (matching_vector,
matching_vector + _bfd_target_vector_entries,
- sizeof (char *) * match_count);
+ sizeof (*matching_vector) * match_count);
+ }
+ }
+ }
+
+ if (match_count > 1 && bfd_associated_vector != NULL)
+ {
+ const bfd_target * const *assoc = bfd_associated_vector;
+
+ while ((right_targ = *assoc++) != NULL)
+ {
+ int i = match_count;
+
+ while (--i >= 0)
+ if (matching_vector[i] == right_targ)
+ break;
+
+ if (i >= 0)
+ {
+ match_count = 1;
+ break;
}
}
}
@@ -299,7 +320,7 @@ bfd_check_format_matches (abfd, format,
abfd->xvec = right_targ; /* Change BFD's target permanently. */
if (matching)
- free (matching_vector);
+ free ((PTR) matching_vector);
return true; /* File position has moved, BTW. */
}
@@ -312,7 +333,7 @@ bfd_check_format_matches (abfd, format,
bfd_set_error (bfd_error_file_not_recognized);
if (matching)
- free (matching_vector);
+ free ((PTR) matching_vector);
}
else
{
@@ -320,8 +341,15 @@ bfd_check_format_matches (abfd, format,
if (matching)
{
- *matching = matching_vector;
+ *matching = (char **) matching_vector;
matching_vector[match_count] = NULL;
+ /* Return target names. This is a little nasty. Maybe we
+ should do another bfd_malloc? */
+ while (--match_count >= 0)
+ {
+ const char *name = matching_vector[match_count]->name;
+ *(const char **) &matching_vector[match_count] = name;
+ }
}
}
--
Alan Modra
IBM OzLabs - Linux Technology Centre
More information about the Binutils
mailing list