Re: How does one cross-compile gdbserver?

Dan Kegel
2002-01-30T02:22:34Z

Daniel Jacobowitz wrote:
>
> On Tue, Jan 29, 2002 at 05:28:05PM -0800, Dan Kegel wrote:
> > I'm going crazy trying to build gdb 5.1.1's gdbserver
> > in a cross-development environment.
> >
> > Has anyone here build one recently?
> > If so, can you please post your recipe?
>
> Same way as anything else! You need to have a compiler capable of
> building target userland binaries, and a development environment set up
> for same. You may need to run configure in the gdbserver directory
> manually, with CC set appropriately. Note that you want a gdb
> configured --host=<your target>, not --target=<>!
>
> I don't give it good odds of compiling. I've tried several times to
> clean that up and gotten stymied in various people's objections to my
> methods (sorry Andrew). I'll be taking another stab at it this week I
> think.

Glad someone's working on it. (I'm hoping my company can funnel some
money to mvista soon. Every time I turn around, Montavista is doing things
that help us.)

All I'm trying to do is build
gdbserver to run on the embedded system. It appears that gdbserver
won't build unless you also build gdb *for the exact same environment*,
as it shares gdb's config.h, so I build a sacrificial gdb for the
embedded system even though I never plan to run gdb itself there.
(Just configuring it should be enough, but I think it turned
out I ran into trouble if I didn't actually build it.)
Here's what I'm doing at the moment, and where I get stuck. (This is
using Montavista Journeyman Linux 2.0 for the PowerPC 405, which does
not have floating point registers.)

1. Unpack gdb-5.1.1.
2. Apply three kludges to get around build problems:
Edit gdb/Makefile.in to keep gdb-all from building sim.
Edit gdb/low-linux.c to define NUM_FREGS 0 if it's not defined.
Edit gdb/low-linux.c to redefine BYTES_REGISTER to 32000 instead
of the nonconstant it has by default.
3. Build as follows:

mkdir nativeppc405
cd nativeppc405
CC=/opt/hardhat/devkit/ppc/405/bin/ppc_405-gcc CFLAGS="-mcpu=403" /bin/sh ../gdb-5.1.1/configure powerpc-foo-linux-gnu
CC=/opt/hardhat/devkit/ppc/405/bin/ppc_405-gcc CFLAGS="-mcpu=403" make all-gdb
cd ..
cd nativeppc405/gdb/gdbserver
CC=/opt/hardhat/devkit/ppc/405/bin/ppc_405-gcc CFLAGS="-mcpu=403" /bin/sh ../../../gdb-5.1.1/gdb/gdbserver/configure powerpc-foo-linux-gnu
CC=/opt/hardhat/devkit/ppc/405/bin/ppc_405-gcc CFLAGS="-mcpu=403" make

This works right up until it tries to link gdbserver, at which point it fails
with undefined symbols and bad relocations:

/opt/hardhat/devkit/ppc/405/bin/ppc_405-gcc -o gdbserver utils.o low-linux.o server.o remote-utils.o \

low-linux.o: In function `register_addr':
/home/dank/ixia/Software/Source/linux/3rdParty/gdb/nativeppc405/gdb/gdbserver/../../../gdb-5.1.1/gdb/gdbserver/low-linux.c:555: undefined reference to
`current_gdbarch'
/home/dank/ixia/Software/Source/linux/3rdParty/gdb/nativeppc405/gdb/gdbserver/../../../gdb-5.1.1/gdb/gdbserver/low-linux.c:555: undefined reference to
`current_gdbarch'
/home/dank/ixia/Software/Source/linux/3rdParty/gdb/nativeppc405/gdb/gdbserver/../../../gdb-5.1.1/gdb/gdbserver/low-linux.c:555: undefined reference to
`gdbarch_num_regs'
/home/dank/ixia/Software/Source/linux/3rdParty/gdb/nativeppc405/gdb/gdbserver/../../../gdb-5.1.1/gdb/gdbserver/low-linux.c:555: relocation truncated to fit:
R_PPC_REL24 gdbarch_num_regs
/home/dank/ixia/Software/Source/linux/3rdParty/gdb/nativeppc405/gdb/gdbserver/../../../gdb-5.1.1/gdb/gdbserver/low-linux.c:558: undefined reference to
`ppc_register_u_addr'
/home/dank/ixia/Software/Source/linux/3rdParty/gdb/nativeppc405/gdb/gdbserver/../../../gdb-5.1.1/gdb/gdbserver/low-linux.c:558: relocation truncated to fit:
R_PPC_REL24 ppc_register_u_addr
...

Any suggestions?

Thanks,
Dan