binutils-gdb/config
Maciej W. Rozycki d9639e091c Fix 64-bit BFD detection causing build failures
We have a discrepancy with 64-bit BFD handling across our component
subdirectories leading to link failures such as:

ld: ../opcodes/.libs/libopcodes.a(disassemble.o): in function `disassembler': disassemble.c:(.text+0x65): undefined reference to `print_insn_alpha'
ld: disassemble.c:(.text+0x105): undefined reference to `print_insn_ia64'
ld: disassemble.c:(.text+0x11d): undefined reference to `print_insn_loongarch'
ld: disassemble.c:(.text+0x1a1): undefined reference to `print_insn_big_mips'
[...]

with some configurations having a 32-bit host and 64-bit BFD, such as:
`--host=i386-linux-gnu --target=riscv64-linux-gnu --enable-targets=all'.
This is ultimately due to how 64-bit BFD is enabled for bfd/ itself and
other subdirectorses and has been a regression from commit 1d5269c994
("unify 64-bit bfd checks").

For bfd/ the BFD_64_BIT autoconf macro from config/bfd64.m4 is used
combined with this logic in bfd/configure.ac:

case ${host64}-${target64}-${want64} in
  *true*)
    wordsize=64
    bfd64_libs='$(BFD64_LIBS)'
    all_backends='$(BFD64_BACKENDS) $(BFD32_BACKENDS)'
    [...]
    ;;
  false-false-false)
    wordsize=32
    all_backends='$(BFD32_BACKENDS)'
    ;;
esac

where the value of ${wordsize} switches between 32-bit and 64-bit BFD
via these pieces:

#define BFD_ARCH_SIZE @wordsize@

and:

#if BFD_ARCH_SIZE >= 64
#define BFD64
#endif

in bfd/bfd-in.h, which ultimately becomes a part of "bfd.h".

Then ${host64} is determined in bfd/configure.ac from the host's word
size, via the host's pointer size:

if test "x${ac_cv_sizeof_void_p}" = "x8"; then
  host64=true
fi

And ${target64} is determined in bfd/configure.ac from the target's word
size:

    if test ${target_size} = 64; then
	target64=true
    fi

Where multiple targets have been requested with `--enable-targets=all'
the presence of any 64-bit target will set "true" here.

Finally ${want64} is set according to `--enable-64-bit-bfd' user option
with an arrangement involving BFD_64_BIT:

BFD_64_BIT
if test $enable_64_bit_bfd = yes ; then
  want64=true
else
  want64=false
fi

which also, redundantly, checks and sets its result upon the host's word
size.  Lastly ${want64} is also selectively set by target fragments in
bfd/config.bfd, which mostly if not completely overlaps with ${target64}
setting as described above.

Conversely other subdirectories only rely on BFD_64_BIT, so they fail to
notice that BFD is 64-bit and do not enable their 64-bit handling where
the host requested is 32-bit and 64-bit BFD has been enabled other than
with `--enable-64-bit-bfd'.  One consequence is opcodes/disassemble.c
enables calls to its numerous own 64-bit backends by checking the BFD64
macro from "bfd.h", however does not actually enable said backends in
its Makefile.  Hence the link errors quoted above.

Address the problem then by moving the `--enable-64-bit-bfd' option back
to bfd/configure.ac and remove the call to BFD_64_BIT from there and
then rewrite the macro in terms of checking for the presence of BFD64
macro in "bfd.h", which is the canonical way of determining whether BFD
is 64-bit or not.

Rather than running `grep' directly on ../bfd/bfd-in3.h as the opcodes/
fragment used to before the problematic commit:

    if grep '#define BFD_ARCH_SIZE 64' ../bfd/bfd-in3.h > /dev/null; then

run the preprocessor on "bfd.h", which allows to invoke the macro from
configure.ac files placed in subdirectories located at deeper levels, by
relying on the preprocessor's search path.

This requires however that the invokers rely on `all-bfd' rather than
`configure-bfd' for their `configure' invocation stage, because "bfd.h"
is made by `make all' rather than `configure' in bfd/.

Do not cache the result of this check however, as reconfiguring a tree
such as to flip `--enable-64-bit-bfd' on or to change a secondary target
may affect BFD64 and we have no access to information about secondary
targets in BFD_64_BIT.

Also remove the ENABLE_BFD_64_BIT automake conditional, as it's not used
anywhere.

Last but not least remove the hack from gdb/configure.ac to fail builds
for `mips*-*-*' hosts where `--enable-targets=all' has been requested,
but `--enable-64-bit-bfd' has not as it's no longer needed.  Such builds
complete successfully now, having enabled 64-bit BFD implicitly.

Tested-By: Guinevere Larsen <guinevere@redhat.com>
Tested-By: Luis Machado <luis.machado@arm.com>
Approved-By: Alan Modra <amodra@gmail.com>
Approved-By: Luis Machado <luis.machado@arm.com>
2025-04-28 18:53:30 +01:00
..
acinclude.m4 config: delete unused sim macros 2021-05-18 17:46:55 -04:00
acx.m4 Sync toplevel configure fixup 2024-11-22 20:57:06 +00:00
asmcfi.m4 Resync config/ from GCC. 2012-05-29 15:58:15 +00:00
ax_check_define.m4 Update top level configure files by synchronizing them with gcc. 2018-01-10 15:29:21 +00:00
ax_count_cpus.m4 Merge changes from GCC for the config/ directory 2020-02-19 17:51:24 +00:00
ax_cxx_compile_stdcxx.m4 Merge configure.ac from gcc project 2022-10-10 11:14:21 +10:30
ax_pthread.m4 config: Sync with GCC 2018-06-18 09:33:48 -04:00
bfd64.m4 Fix 64-bit BFD detection causing build failures 2025-04-28 18:53:30 +01:00
bitfields.m4 Sync config files with GCC 2015-07-14 09:18:16 -07:00
bootstrap-asan.mk sync binutils config/ with gcc 2016-12-08 21:35:11 +10:30
bootstrap-cet.mk config: Sync with GCC 2018-06-18 09:33:48 -04:00
bootstrap-debug-big.mk
bootstrap-debug-ckovw.mk
bootstrap-debug-lean.mk Update top level configure files by synchronizing them with gcc. 2018-01-10 15:29:21 +00:00
bootstrap-debug-lib.mk
bootstrap-debug.mk
bootstrap-lto-lean.mk Fix PR bootstrap/102389: --with-build-config=bootstrap-lto is broken 2023-08-12 10:24:26 +09:30
bootstrap-lto-noplugin.mk config: Sync with GCC 2018-06-18 09:33:48 -04:00
bootstrap-lto.mk Fix PR bootstrap/102389: --with-build-config=bootstrap-lto is broken 2023-08-12 10:24:26 +09:30
bootstrap-O1.mk
bootstrap-O3.mk
bootstrap-Og.mk Merge changes from GCC for the config/ directory 2020-02-19 17:51:24 +00:00
bootstrap-time.mk
bootstrap-ubsan.mk config: Sync with GCC 2018-06-18 09:33:48 -04:00
cet.m4 GCC_CET_HOST_FLAGS: Check if host supports multi-byte NOPs 2021-03-18 08:02:46 -07:00
ChangeLog libiberty: Disable hwcaps for sha1.o 2023-11-30 10:14:30 +01:00
codeset.m4
debuginfod.m4 autoupdate: replace obsolete macros AC_HELP_STRING 2024-06-10 08:25:55 +09:30
dejagnu.m4 libsframe: add the SFrame library 2022-11-15 15:24:29 -08:00
depstand.m4
dfp.m4 Merge config/ changes from GCC, to enable DFP on AArch64 2022-05-24 10:47:29 +01:00
elf.m4 Sync elf.m4 with GCC tree 2015-03-16 08:49:06 -07:00
enable.m4 autoupdate: replace obsolete macros AC_HELP_STRING 2024-06-10 08:25:55 +09:30
extensions.m4
futex.m4 Merge changes from GCC for the config/ directory 2020-02-19 17:51:24 +00:00
gc++filt.m4 * gc++filt.m4: New file. 2010-07-02 11:58:19 +00:00
gcc-plugin.m4 config: Fix host -rdynamic detection for build != host != target 2023-09-01 15:20:47 +00:00
gettext-sister.m4 Revert "Remove LIBINTL_DEP" 2024-06-20 21:15:27 +09:30
gettext.m4 Finalized intl-update patches 2023-11-15 12:53:04 +00:00
glibc21.m4
gthr.m4 gcc: Add 'mcf' thread model support from mcfgthread 2023-08-12 10:24:26 +09:30
gxx-include-dir.m4
hwcaps.m4 libiberty: Disable hwcaps for sha1.o 2023-11-30 10:14:30 +01:00
iconv.m4 Finalized intl-update patches 2023-11-15 12:53:04 +00:00
intdiv0.m4
intlmacosx.m4 Finalized intl-update patches 2023-11-15 12:53:04 +00:00
inttypes-pri.m4
inttypes.m4
inttypes_h.m4
isl.m4 Update top level configure files by synchronizing them with gcc. 2018-01-10 15:29:21 +00:00
jobserver.m4 Implement a workaround for GNU mak jobserver 2021-01-12 05:45:44 -08:00
largefile.m4 Unify Solaris procfs and largefile handling 2020-07-30 15:41:50 +02:00
lcmessage.m4
ld-symbolic.m4
lead-dot.m4
lib-ld.m4 egrep in binutils 2022-09-28 13:37:31 +09:30
lib-link.m4 Merge changes from GCC for the config/ directory 2020-02-19 17:51:24 +00:00
lib-prefix.m4 autoupdate: replace obsolete macros AC_HELP_STRING 2024-06-10 08:25:55 +09:30
libstdc++-raw-cxx.m4 Remove "-I" from LIBSTDCXX_RAW_CXX_LDFLAGS 2013-01-07 18:25:13 +00:00
lthostflags.m4 autoupdate: replace obsolete macros AC_CANONICAL_SYSTEM 2024-06-10 08:25:55 +09:30
math.m4 Sync config and libiberty with GCC 2020-04-29 14:25:36 -07:00
mh-alpha-linux Sync toplevel configure.ac with GCC 2015-07-14 07:49:50 -07:00
mh-cygwin 2011-03-24 Paolo Bonzini <bonzini@gnu.org> 2011-03-24 17:31:20 +00:00
mh-darwin configure: Allow host fragments to react to --enable-host-shared. 2023-08-12 10:24:26 +09:30
mh-djgpp
mh-mingw mh-mingw: drop unused BOOT_CXXFLAGS variable 2023-08-12 10:24:26 +09:30
mh-pa
mh-ppc-aix Resync config/ from GCC. 2012-05-29 15:58:15 +00:00
mmap.m4 mmap: Avoid the sanitizer configure check failure 2024-04-10 03:57:02 -07:00
mt-alphaieee Resync config/ from GCC. 2012-05-29 15:58:15 +00:00
mt-android Update top level configure files by synchronizing them with gcc. 2018-01-10 15:29:21 +00:00
mt-d30v
mt-gnu Don't reset CXXFLAGS_FOR_TARGET 2015-03-16 08:41:42 -07:00
mt-mips-elfoabi
mt-mips-gnu
mt-mips16-compat
mt-ospace Append -g -Os rather than overwriting 2015-03-16 08:44:41 -07:00
mt-sde 2012-09-19 Steve Ellcey <sellcey@mips.com> 2012-09-19 21:22:33 +00:00
mt-spu
multi.m4 Merge config/ changes from GCC. 2018-10-31 17:16:41 +00:00
nls.m4
no-executables.m4 mmap: Avoid the sanitizer configure check failure 2024-04-10 03:57:02 -07:00
override.m4 PR27116, Spelling errors found by Debian style checker 2021-01-01 14:36:35 +10:30
picflag.m4 Merge config/picflag.m4 from gcc 2023-01-04 13:23:54 +10:30
pkg.m4 PKG_CHECK_MODULES: Properly check if $pkg_cv_[]$1[]_LIBS works 2020-07-28 06:59:30 -07:00
plugins.m4 config: Sync with GCC 2018-04-05 15:22:13 -07:00
po.m4 Sync config with GCC 2015-07-27 07:43:26 -07:00
proginstall.m4
progtest.m4
sjlj.m4 Sync config files with GCC 2015-07-14 09:18:16 -07:00
stdint.m4 Sync config with GCC 2015-07-27 07:43:26 -07:00
stdint_h.m4
target-posix Sync config files with GCC 2015-07-14 09:18:16 -07:00
tcl.m4 Sync config with GCC 2015-07-27 07:43:26 -07:00
tls.m4 Merge changes from GCC for the config/ directory 2020-02-19 17:51:24 +00:00
toolexeclibdir.m4 Merge changes from GCC for the config/ directory 2020-02-19 17:51:24 +00:00
ulonglong.m4
unwind_ipinfo.m4
warnings.m4 Sync config/warnings.m4 with GCC 2015-07-14 08:39:12 -07:00
weakref.m4 Resync config/ from GCC. 2012-05-29 15:58:15 +00:00
zlib.m4 Set zlibdir/zlibinc with top_builddir/top_srcdir 2015-04-02 05:43:07 -07:00
zstd.m4 configure: require libzstd >= 1.4.0 2022-11-07 14:32:10 +01:00