This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH, RFA] opcodes: Use autoconf to check for `bfd_mips_elf_get_abiflags' in BFD
Fix a regression introduced with commit 5e7fc731f80e ("MIPS/opcodes:
Also set disassembler's ASE flags from ELF structures"), further updated
with commit 4df995c77118 ("MIPS/opcodes: Also set disassembler's ASE
flags from ELF structures"), and use autoconf to check for the presence
of `bfd_mips_elf_get_abiflags' in BFD.
opcodes/
* mips-dis.c (set_default_mips_dis_options): Use
HAVE_BFD_MIPS_ELF_GET_ABIFLAGS rather than BFD64 to guard the
call to `bfd_mips_elf_get_abiflags'.
* configure.ac: Check for `bfd_mips_elf_get_abiflags' in BFD.
* Makefile.am (CONFIG_STATUS_DEPENDENCIES): Add `libbfd.la'.
* aclocal.m4: Regenerate.
* configure: Regenerate.
* config.in: Regenerate.
* Makefile.in: Regenerate.
---
On Thu, 22 Dec 2016, Alan Modra wrote:
> On Mon, Dec 19, 2016 at 11:49:23AM +0000, Maciej W. Rozycki wrote:
> > So I have followed your advice after all and made a minimal change (see
> > commit 4df995c77118 ("MIPS/opcodes: Only call `bfd_mips_elf_get_abiflags'
> > if BFD64")), because in such a configuration we may still have other MIPS
> > BFD targets configured, such as ECOFF, so the disassembler has to remain
> > fully functional for `objdump' at least.
>
> Unfortunately this fails. For --build=x86_64-linux --enable-plugins
> --disable-gdb --disable-sim --disable-readline --disable-libdecnumber
> --enable-obsolete --target=mips-ecoff
>
> ../opcodes/.libs/libopcodes.a(mips-dis.o): In function `set_default_mips_dis_options':
> /home/alan/src/binutils-gdb/opcodes/mips-dis.c:855: undefined reference to `bfd_mips_elf_get_abiflags'
> collect2: error: ld returned 1 exit status
> Makefile:819: recipe for target 'objdump' failed
Hmm, I dropped `mips-ecoff' and `mipsel-ecoff' as test targets for being
obsolete as GAS support was removed a while ago, but this situation proves
it was premature as they at least need to continue building even if we
don't care about regressions anymore. Obviously it would have triggered
and brought my attention even before I pushed my problematic change. I
put them back then.
Let's deal with the breakage the proper way and use autoconf to check for
this symbol, which is what autoconf has been made for. There is a slight
complication with the convoluted way we wire BFD into the link, but that's
nothing that couldn't be dealt with. OTOH I don't think this internal API
is worth abstracting in a target-independent way via a generic BFD entry
point.
No regressions against the usual 164 targets (exact list available upon
request), `mips-ecoff' and `mipsel-ecoff' targets now build successfully,
and the original failing native `i686-pc-linux-gnu' configuration still
builds including binutils/ and gdb/ subdirectories in particular.
OK to apply then?
Maciej
binutils-opcodes-mips-abiflags-autoconf.diff
Index: binutils/opcodes/Makefile.am
===================================================================
--- binutils.orig/opcodes/Makefile.am 2016-12-20 18:41:24.000000000 +0000
+++ binutils/opcodes/Makefile.am 2016-12-23 01:07:40.302417847 +0000
@@ -300,8 +300,9 @@ ALL_MACHINES = $(TARGET_LIBOPCODES_CFILE
OFILES = @BFD_MACHINES@
-# development.sh is used to determine -Werror default.
-CONFIG_STATUS_DEPENDENCIES = $(BFDDIR)/development.sh
+# development.sh is used to determine -Werror default, libbfd.la is needed
+# for function availability checks.
+CONFIG_STATUS_DEPENDENCIES = $(BFDDIR)/development.sh ../bfd/libbfd.la
AM_CPPFLAGS = -I. -I$(srcdir) -I../bfd -I$(INCDIR) -I$(BFDDIR) @HDEFINES@ @INCINTL@
Index: binutils/opcodes/Makefile.in
===================================================================
--- binutils.orig/opcodes/Makefile.in 2016-12-20 18:41:24.000000000 +0000
+++ binutils/opcodes/Makefile.in 2016-12-23 01:07:43.708319394 +0000
@@ -80,7 +80,9 @@ DIST_COMMON = ChangeLog $(srcdir)/Makefi
$(top_srcdir)/po/Make-in $(srcdir)/../depcomp
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/../bfd/acinclude.m4 \
- $(top_srcdir)/../bfd/warning.m4 $(top_srcdir)/../config/acx.m4 \
+ $(top_srcdir)/../bfd/warning.m4 \
+ $(top_srcdir)/../config/acinclude.m4 \
+ $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
$(top_srcdir)/../config/gettext-sister.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
@@ -187,6 +189,8 @@ AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
+BFDHDIR = @BFDHDIR@
+BFDLIB = @BFDLIB@
BFD_MACHINES = @BFD_MACHINES@
BUILD_LIBS = @BUILD_LIBS@
BUILD_LIB_DEPS = @BUILD_LIB_DEPS@
@@ -603,8 +607,9 @@ CFILES = \
ALL_MACHINES = $(TARGET_LIBOPCODES_CFILES:.c=.lo)
OFILES = @BFD_MACHINES@
-# development.sh is used to determine -Werror default.
-CONFIG_STATUS_DEPENDENCIES = $(BFDDIR)/development.sh
+# development.sh is used to determine -Werror default, libbfd.la is needed
+# for function availability checks.
+CONFIG_STATUS_DEPENDENCIES = $(BFDDIR)/development.sh ../bfd/libbfd.la
AM_CPPFLAGS = -I. -I$(srcdir) -I../bfd -I$(INCDIR) -I$(BFDDIR) @HDEFINES@ @INCINTL@
libopcodes_la_SOURCES = dis-buf.c disassemble.c dis-init.c
# It's desirable to list ../bfd/libbfd.la in DEPENDENCIES and LIBADD.
Index: binutils/opcodes/aclocal.m4
===================================================================
--- binutils.orig/opcodes/aclocal.m4 2016-12-22 20:11:50.376586695 +0000
+++ binutils/opcodes/aclocal.m4 2016-12-22 20:14:39.423005866 +0000
@@ -990,6 +990,7 @@ AC_SUBST([am__untar])
m4_include([../bfd/acinclude.m4])
m4_include([../bfd/warning.m4])
+m4_include([../config/acinclude.m4])
m4_include([../config/acx.m4])
m4_include([../config/depstand.m4])
m4_include([../config/gettext-sister.m4])
Index: binutils/opcodes/config.in
===================================================================
--- binutils.orig/opcodes/config.in 2016-12-22 20:11:50.214485476 +0000
+++ binutils/opcodes/config.in 2016-12-22 20:14:39.439141818 +0000
@@ -11,6 +11,9 @@
language is requested. */
#undef ENABLE_NLS
+/* Define to 1 if you have the `bfd_mips_elf_get_abiflags' function. */
+#undef HAVE_BFD_MIPS_ELF_GET_ABIFLAGS
+
/* Define to 1 if you have the declaration of `basename', and to 0 if you
don't. */
#undef HAVE_DECL_BASENAME
Index: binutils/opcodes/configure
===================================================================
--- binutils.orig/opcodes/configure 2016-12-22 20:11:50.300991961 +0000
+++ binutils/opcodes/configure 2016-12-23 01:57:34.234831514 +0000
@@ -604,6 +604,8 @@ LTLIBOBJS
LIBOBJS
BFD_MACHINES
archdefs
+BFDLIB
+BFDHDIR
SHARED_DEPENDENCIES
SHARED_LIBADD
SHARED_LDFLAGS
@@ -11151,7 +11153,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11154 "configure"
+#line 11156 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -11257,7 +11259,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11260 "configure"
+#line 11262 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -12586,6 +12588,100 @@ fi
# target-specific stuff:
+# Check if `bfd_mips_elf_get_abiflags' is present in BFD, needed by
+# `mips-dis.c'. Avoid using AC_CHECK_LIB as it uses a cache variable
+# which could hold the wrong value if we are rerun due to the
+# `../bfd/libbfd.la' dependency for `config.status', so use a handcoded
+# sequence which is equivalent but does not use the cache.
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the bfd header in the build tree" >&5
+$as_echo_n "checking for the bfd header in the build tree... " >&6; }
+dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
+if test "${ac_cv_c_bfdh+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+
+for i in $dirlist; do
+ if test -f "$i/bfd/bfd.h" ; then
+ ac_cv_c_bfdh=`(cd $i/bfd; ${PWDCMD-pwd})`
+ break
+ fi
+done
+
+fi
+
+if test x"${ac_cv_c_bfdh}" != x; then
+ BFDHDIR="-I${ac_cv_c_bfdh}"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${ac_cv_c_bfdh}" >&5
+$as_echo "${ac_cv_c_bfdh}" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5
+$as_echo "none" >&6; }
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the bfd library in the build tree" >&5
+$as_echo_n "checking for the bfd library in the build tree... " >&6; }
+if test "${ac_cv_c_bfdlib+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+
+for i in $dirlist; do
+ if test -f "$i/bfd/Makefile" ; then
+ ac_cv_c_bfdlib=`(cd $i/bfd; ${PWDCMD-pwd})`
+ fi
+done
+
+fi
+
+if test x"${ac_cv_c_bfdlib}" != x; then
+ BFDLIB="-L${ac_cv_c_bfdlib} -L${ac_cv_c_bfdlib}/.libs"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${ac_cv_c_bfdlib}" >&5
+$as_echo "${ac_cv_c_bfdlib}" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5
+$as_echo "none" >&6; }
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for bfd_mips_elf_get_abiflags in -lbfd" >&5
+$as_echo_n "checking for bfd_mips_elf_get_abiflags in -lbfd... " >&6; }
+opcodes_save_LIBS=$LIBS
+LIBS="$BFDLIB -lbfd ../libiberty/libiberty.a `test -e ../bfd/libbfd.la && . ../bfd/libbfd.la; echo $dependency_libs`"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char bfd_mips_elf_get_abiflags ();
+int
+main ()
+{
+return bfd_mips_elf_get_abiflags ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ opcodes_lib_bfd_bfd_mips_elf_get_abiflags=yes
+else
+ opcodes_lib_bfd_bfd_mips_elf_get_abiflags=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$opcodes_save_LIBS
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $opcodes_lib_bfd_bfd_mips_elf_get_abiflags" >&5
+$as_echo "$opcodes_lib_bfd_bfd_mips_elf_get_abiflags" >&6; }
+if test x"$opcodes_lib_bfd_bfd_mips_elf_get_abiflags" = xyes; then
+
+$as_echo "#define HAVE_BFD_MIPS_ELF_GET_ABIFLAGS 1" >>confdefs.h
+
+fi
+
# Canonicalize the secondary target names.
if test -n "$enable_targets" ; then
for targ in `echo $enable_targets | sed 's/,/ /g'`
Index: binutils/opcodes/configure.ac
===================================================================
--- binutils.orig/opcodes/configure.ac 2016-12-22 20:11:50.305044953 +0000
+++ binutils/opcodes/configure.ac 2016-12-23 01:57:26.538274592 +0000
@@ -210,6 +210,25 @@ AC_SUBST(SHARED_DEPENDENCIES)
# target-specific stuff:
+# Check if `bfd_mips_elf_get_abiflags' is present in BFD, needed by
+# `mips-dis.c'. Avoid using AC_CHECK_LIB as it uses a cache variable
+# which could hold the wrong value if we are rerun due to the
+# `../bfd/libbfd.la' dependency for `config.status', so use a handcoded
+# sequence which is equivalent but does not use the cache.
+CYG_AC_PATH_BFD
+AC_MSG_CHECKING([for bfd_mips_elf_get_abiflags in -lbfd])
+opcodes_save_LIBS=$LIBS
+LIBS="$BFDLIB -lbfd ../libiberty/libiberty.a `test -e ../bfd/libbfd.la && . ../bfd/libbfd.la; echo $dependency_libs`"
+AC_LINK_IFELSE([AC_LANG_CALL([], [bfd_mips_elf_get_abiflags])],
+ [opcodes_lib_bfd_bfd_mips_elf_get_abiflags=yes],
+ [opcodes_lib_bfd_bfd_mips_elf_get_abiflags=no])
+LIBS=$opcodes_save_LIBS
+AC_MSG_RESULT([$opcodes_lib_bfd_bfd_mips_elf_get_abiflags])
+if test x"$opcodes_lib_bfd_bfd_mips_elf_get_abiflags" = xyes; then
+ AC_DEFINE([HAVE_BFD_MIPS_ELF_GET_ABIFLAGS], [1],
+ [Define to 1 if you have the `bfd_mips_elf_get_abiflags' function.])
+fi
+
# Canonicalize the secondary target names.
if test -n "$enable_targets" ; then
for targ in `echo $enable_targets | sed 's/,/ /g'`
Index: binutils/opcodes/mips-dis.c
===================================================================
--- binutils.orig/opcodes/mips-dis.c 2016-12-22 20:11:52.872833905 +0000
+++ binutils/opcodes/mips-dis.c 2016-12-22 20:14:39.478580342 +0000
@@ -847,11 +847,12 @@ set_default_mips_dis_options (struct dis
Elf_Internal_Ehdr *header = elf_elfheader (abfd);
Elf_Internal_ABIFlags_v0 *abiflags = NULL;
- /* We won't ever get here if !BFD64, because we won't then have
- a MIPS/ELF BFD, however we need to guard against a link error
- in a `--enable-targets=...' configuration with a 32-bit host,
- where the MIPS target is a secondary. */
-#ifdef BFD64
+ /* We won't ever get here if !HAVE_BFD_MIPS_ELF_GET_ABIFLAGS,
+ because we won't then have a MIPS/ELF BFD, however we need
+ to guard against a link error in a `--enable-targets=...'
+ configuration with a 32-bit host where the MIPS target is
+ a secondary, or with MIPS/ECOFF configurations. */
+#ifdef HAVE_BFD_MIPS_ELF_GET_ABIFLAGS
abiflags = bfd_mips_elf_get_abiflags (abfd);
#endif
/* If an ELF "newabi" binary, use the n32/(n)64 GPR names. */