From ba5f62a26ba5432ccbc901b55ce82c559c29ae30 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Tue, 5 Nov 2002 01:18:56 +0000 Subject: [PATCH] * config.bfd (sh-*-linux*): Use bfd_elf*_sh64*lin_vec as sh64 vectors in target_selvecs. (shle-*-netbsdelf*): Use bfd_elf*_sh64*nbsd_vec as sh64 vectors in target_selvecs. (sh-*-netbsdelf*): Likewise. * configure.in (assocvecs): New variable. Handle assocvecs like selvecs. * configure: Regenerate. * 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. * targets.c (_bfd_associated_vector): New array. (bfd_associated_vector): New variable. (_bfd_target_vector): Add bfd_elf*_sh64*lin_vec. * libbfd-in.h (bfd_associated_vector): Declare. * libbfd.h: Regenerate. --- bfd/ChangeLog | 20 ++++++++++++++++++++ bfd/config.bfd | 6 +++--- bfd/configure | 45 +++++++++++++++++++++++++++++++-------------- bfd/configure.in | 17 +++++++++++++++++ bfd/format.c | 54 +++++++++++++++++++++++++++++++++++++++++------------- bfd/libbfd-in.h | 3 +++ bfd/libbfd.h | 3 +++ bfd/targets.c | 15 +++++++++++++++ 8 files changed, 133 insertions(+), 30 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index c2101974e..4d08a74c5 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,23 @@ +2002-11-05 Kaz Kojima + Alan Modra + + * config.bfd (sh-*-linux*): Use bfd_elf*_sh64*lin_vec as sh64 + vectors in target_selvecs. + (shle-*-netbsdelf*): Use bfd_elf*_sh64*nbsd_vec as sh64 vectors + in target_selvecs. + (sh-*-netbsdelf*): Likewise. + * configure.in (assocvecs): New variable. Handle assocvecs like + selvecs. + * configure: Regenerate. + * 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. + * targets.c (_bfd_associated_vector): New array. + (bfd_associated_vector): New variable. + (_bfd_target_vector): Add bfd_elf*_sh64*lin_vec. + * libbfd-in.h (bfd_associated_vector): Declare. + * libbfd.h: Regenerate. + 2002-11-05 Elias Athanasopoulos * vms-gsd.c (_bfd_vms_write_gsd): Check that symbol->udata.p is diff --git a/bfd/config.bfd b/bfd/config.bfd index c37dc7585..596d6de30 100644 --- a/bfd/config.bfd +++ b/bfd/config.bfd @@ -949,7 +949,7 @@ case "${targ}" in targ_defvec=bfd_elf32_shblin_vec targ_selvecs=bfd_elf32_shlin_vec #ifdef BFD64 - targ_selvecs="${targ_selvecs} bfd_elf32_sh64_vec bfd_elf32_sh64l_vec bfd_elf64_sh64_vec bfd_elf64_sh64l_vec" + targ_selvecs="${targ_selvecs} bfd_elf32_sh64lin_vec bfd_elf32_sh64blin_vec bfd_elf64_sh64lin_vec bfd_elf64_sh64blin_vec" #endif ;; sh*eb-*-linux*) @@ -985,7 +985,7 @@ case "${targ}" in targ_defvec=bfd_elf32_shlnbsd_vec targ_selvecs="bfd_elf32_shnbsd_vec shcoff_vec shlcoff_vec" #ifdef BFD64 - targ_selvecs="${targ_selvecs} bfd_elf32_sh64_vec bfd_elf32_sh64l_vec bfd_elf64_sh64_vec bfd_elf64_sh64l_vec" + targ_selvecs="${targ_selvecs} bfd_elf32_sh64lnbsd_vec bfd_elf32_sh64nbsd_vec bfd_elf64_sh64lnbsd_vec bfd_elf64_sh64nbsd_vec" #endif ;; sh*le-*-netbsdelf*) @@ -996,7 +996,7 @@ case "${targ}" in targ_defvec=bfd_elf32_shnbsd_vec targ_selvecs="bfd_elf32_shlnbsd_vec shcoff_vec shlcoff_vec" #ifdef BFD64 - targ_selvecs="${targ_selvecs} bfd_elf32_sh64_vec bfd_elf32_sh64l_vec bfd_elf64_sh64_vec bfd_elf64_sh64l_vec" + targ_selvecs="${targ_selvecs} bfd_elf32_sh64lnbsd_vec bfd_elf32_sh64nbsd_vec bfd_elf64_sh64lnbsd_vec bfd_elf64_sh64nbsd_vec" #endif ;; sh*-*-netbsdelf*) diff --git a/bfd/configure b/bfd/configure index 794cb6205..294554eb0 100755 --- a/bfd/configure +++ b/bfd/configure @@ -5975,12 +5975,14 @@ fi all_targets=false defvec= selvecs= +assocvecs= selarchs= TDEFINES= for targ in $target $canon_targets do if test "x$targ" = "xall"; then all_targets=true + assocvecs="$assocvecs $targ_defvec $targ_selvecs" else . $srcdir/config.bfd if test "x$targ" = "x$target"; then @@ -6011,6 +6013,17 @@ done selvecs="$f" +# uniq the associated vectors in all the configured targets. +f="" +for i in $assocvecs ; do + case " $f " in + *" $i "*) ;; + *) f="$f $i" ;; + esac +done +assocvecs="$f" + + # uniq the architectures in all the configured targets. f="" for i in $selarchs ; do @@ -6320,9 +6333,12 @@ if test x${all_targets} = xtrue ; then selvecs= havevecs= selarchs= + test -n "$assocvecs" && + assocvecs=`echo $assocvecs | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'` else # all_targets is true # Only set these if they will be nonempty, for the clever echo. havevecs= + assocvecs= test -n "$selvecs" && havevecs=`echo $selvecs | sed -e 's/^/-DHAVE_/' -e 's/ \(.\)/ -DHAVE_\1/g'` test -n "$selvecs" && @@ -6343,10 +6359,10 @@ case ${host64}-${target64}-${want64} in if test -n "$GCC" ; then bad_64bit_gcc=no; echo $ac_n "checking for gcc version with buggy 64-bit support""... $ac_c" 1>&6 -echo "configure:6347: checking for gcc version with buggy 64-bit support" >&5 +echo "configure:6363: checking for gcc version with buggy 64-bit support" >&5 # Add more tests for gcc versions with non-working 64-bit support here. cat > conftest.$ac_ext <&6 -echo "configure:6395: checking for $ac_hdr" >&5 +echo "configure:6412: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:6405: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:6422: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -6430,12 +6447,12 @@ done for ac_func in getpagesize do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:6434: checking for $ac_func" >&5 +echo "configure:6451: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:6479: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -6483,7 +6500,7 @@ fi done echo $ac_n "checking for working mmap""... $ac_c" 1>&6 -echo "configure:6487: checking for working mmap" >&5 +echo "configure:6504: checking for working mmap" >&5 if eval "test \"`echo '$''{'ac_cv_func_mmap_fixed_mapped'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -6491,7 +6508,7 @@ else ac_cv_func_mmap_fixed_mapped=no else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:6665: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_func_mmap_fixed_mapped=yes else @@ -6669,12 +6686,12 @@ fi for ac_func in madvise mprotect do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:6673: checking for $ac_func" >&5 +echo "configure:6690: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:6718: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else diff --git a/bfd/configure.in b/bfd/configure.in index b59089d5e..7b41ad23e 100644 --- a/bfd/configure.in +++ b/bfd/configure.in @@ -471,12 +471,14 @@ fi all_targets=false defvec= selvecs= +assocvecs= selarchs= TDEFINES= for targ in $target $canon_targets do if test "x$targ" = "xall"; then all_targets=true + assocvecs="$assocvecs $targ_defvec $targ_selvecs" else . $srcdir/config.bfd if test "x$targ" = "x$target"; then @@ -507,6 +509,17 @@ done selvecs="$f" +# uniq the associated vectors in all the configured targets. +f="" +for i in $assocvecs ; do + case " $f " in + *" $i "*) ;; + *) f="$f $i" ;; + esac +done +assocvecs="$f" + + # uniq the architectures in all the configured targets. f="" for i in $selarchs ; do @@ -816,9 +829,12 @@ if test x${all_targets} = xtrue ; then selvecs= havevecs= selarchs= + test -n "$assocvecs" && + assocvecs=`echo $assocvecs | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'` else # all_targets is true # Only set these if they will be nonempty, for the clever echo. havevecs= + assocvecs= test -n "$selvecs" && havevecs=`echo $selvecs | sed -e 's/^/-DHAVE_/' -e 's/ \(.\)/ -DHAVE_\1/g'` test -n "$selvecs" && @@ -866,6 +882,7 @@ AC_SUBST(bfd_default_target_size) tdefaults="" test -n "${defvec}" && tdefaults="${tdefaults} -DDEFAULT_VECTOR=${defvec}" test -n "${selvecs}" && tdefaults="${tdefaults} -DSELECT_VECS='${selvecs}'" +test -n "${assocvecs}" && tdefaults="${tdefaults} -DASSOCIATED_VECS='${assocvecs}'" test -n "${selarchs}" && tdefaults="${tdefaults} -DSELECT_ARCHITECTURES='${selarchs}'" test -n "${havevecs}" && tdefaults="${tdefaults} ${havevecs}" AC_SUBST(tdefaults) diff --git a/bfd/format.c b/bfd/format.c index ef6b46edf..33291d0f9 100644 --- a/bfd/format.c +++ b/bfd/format.c @@ -119,8 +119,9 @@ bfd_check_format_matches (abfd, format, matching) 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, matching) 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, matching) 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, matching) 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, matching) } 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, matching) 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, matching) 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, matching) { 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, matching) 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, matching) 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, matching) 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; + } } } diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h index 776dcd62f..00d5bd3a6 100644 --- a/bfd/libbfd-in.h +++ b/bfd/libbfd-in.h @@ -567,6 +567,9 @@ extern bfd *bfd_last_cache; extern const bfd_target * const *bfd_target_vector; extern const bfd_target *bfd_default_vector[]; +/* List of associated target vectors. */ +extern const bfd_target * const *bfd_associated_vector; + /* Functions shared by the ECOFF and MIPS ELF backends, which have no other common header files. */ diff --git a/bfd/libbfd.h b/bfd/libbfd.h index ef001f335..6d40e91cb 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -572,6 +572,9 @@ extern bfd *bfd_last_cache; extern const bfd_target * const *bfd_target_vector; extern const bfd_target *bfd_default_vector[]; +/* List of associated target vectors. */ +extern const bfd_target * const *bfd_associated_vector; + /* Functions shared by the ECOFF and MIPS ELF backends, which have no other common header files. */ diff --git a/bfd/targets.c b/bfd/targets.c index e665898bc..a6a0d17e8 100644 --- a/bfd/targets.c +++ b/bfd/targets.c @@ -859,6 +859,8 @@ static const bfd_target * const _bfd_target_vector[] = { &bfd_elf32_sh64l_vec, &bfd_elf32_sh64lnbsd_vec, &bfd_elf32_sh64nbsd_vec, + &bfd_elf32_sh64lin_vec, + &bfd_elf32_sh64blin_vec, #endif &bfd_elf32_sparc_vec, &bfd_elf32_tradbigmips_vec, @@ -889,6 +891,8 @@ static const bfd_target * const _bfd_target_vector[] = { &bfd_elf64_sh64l_vec, &bfd_elf64_sh64lnbsd_vec, &bfd_elf64_sh64nbsd_vec, + &bfd_elf64_sh64lin_vec, + &bfd_elf64_sh64blin_vec, #if 0 &bfd_elf64_sparc_vec, #endif @@ -1106,6 +1110,17 @@ const bfd_target *bfd_default_vector[] = { NULL }; +/* bfd_associated_vector[] contains the associated target vectors used + to reduce the ambiguity in bfd_check_format_matches. */ + +static const bfd_target *_bfd_associated_vector[] = { +#ifdef ASSOCIATED_VECS + ASSOCIATED_VECS, +#endif + NULL +}; +const bfd_target * const *bfd_associated_vector = _bfd_associated_vector; + /* When there is an ambiguous match, bfd_check_format_matches puts the names of the matching targets in an array. This variable is the maximum number of entries that the array could possibly need. */ -- 2.11.4.GIT