[PATCH] gdb: only include mips and riscv targets if building with 64-bit bfd
John Baldwin
jhb@FreeBSD.org
Thu Dec 9 18:50:12 GMT 2021
On 12/9/21 10:08 AM, Andrew Burgess via Gdb-patches wrote:
> While testing another patch I was trying to build different
> configurations of GDB, and, during one test build I ran into a
> problem, I configured with `--enable-targets=all
> --host=i686-w64-mingw32` and saw this error while linking GDB:
>
> .../i686-w64-mingw32/bin/ld: mips-tdep.o: in function `mips_gdbarch_init':
> .../src/gdb/mips-tdep.c:8730: undefined reference to `disassembler_options_mips'
> .../i686-w64-mingw32/bin/ld: riscv-tdep.o: in function `riscv_gdbarch_init':
> .../src/gdb/riscv-tdep.c:3851: undefined reference to `disassembler_options_riscv'
>
> So the `disassembler_options_mips` and `disassembler_options_riscv`
> symbols are missing.
>
> This turns out to be because mips-dis.c and riscv-dis.c, in which
> these symbols are defined, are in the TARGET64_LIBOPCODES_CFILES list
> in opcodes/Makefile.am, these files are only built when we are
> building with a 64-bit bfd.
>
> If we look further, into bfd/Makefile.am, we can see that all the
> files matching elf*-riscv.lo are in the BFD64_BACKENDS list, as are
> the elf*-mips.lo files, and (I know because I tried), the two
> disassemblers do, not surprisingly, depend on features supplied from
> libbfd.
>
> So, though we can build most of GDB just fine for riscv and mips with
> a 32-bit bfd, if I understand correctly, the final GDB
> executable (assuming we could get it to link) would not understand
> these architectures at the bfd level, nor would there be any
> disassembler available. This sounds like a pretty useless GDB to me.
>
> So, in this commit, I move the riscv and mips targets into GDB's list
> of targets that require a 64-bit bfd. After this I can build GDB just
> fine with the configure options given above.
Note that mips-tdep.c and riscv-tdep.c are a bit funky in that they
support both 32-bit and 64-bit flavors of the architectures, unlike
arm or x86 where the 32-bit and 64-bit support use separate tdep files,
so this change requires 64-bit BFD for 32-bit MIPS for example which is
a bit odd. That said, fixing all of that is probably a bit of a work
over in bfd that I'm not volunteering for, so I would be ok with this
compromise. I do wonder what happens if you build a GDB targetting
a 32-bit MIPS or RISC-V without enabling 64-bit bfd though, e.g.
configure --target=mips-unknown-linux
Hmm, seems bfd forces that on for some MIPS targets but not all:
# All MIPS ELF targets need a 64-bit bfd_vma.
case "${targ_defvec} ${targ_selvecs}" in
*mips_elf*)
want64=true
;;
esac
I guess bfd expects you to use 'linuxelf' instead of 'linux' in that
case? (And there's no similar fix for risc-v it seems, probably
because most people are building on 64-bit hosts these days and bfd
defaults to a 64-bit vma on 64-bit hosts.)
--
John Baldwin
More information about the Gdb-patches
mailing list