Some questions on binutils (mostly ld)

Joel Coltoff
Tue May 16 07:29:00 GMT 2000


This is somewhat long but sometimes thinks work out that way.
Thanks for your patience.

I've got some questions on an esoteric use of the binutils.
We have a library written in C that we've using for a while
and we need to overload some of the functions. I'll spare
you the long version of why. Essentially we need to add some
support for use of remote links. I'm using a mips64orion-elf
target but I don't think that matters.  Currently we'll do
something like this.

	    DEV *dev;
	    dev = pciopen("pci0a");

and compile with
	gcc -o file file.c -lpci.

The new code looks like this

           main.c                            pciopen.c

	main()                          |  pciopen()
	{                               |  {
	    DEV *dev;                   |    // version for remote links
		.                       |         .
	    remoteInit()                |         .
		.                       |         .
	    dev = pciopen("pci0a");     |
		.                       |         .
	}                               |  }

In this code remoteInit() looks a lot like main() from the first example,
it calls pciopen() to open a local device. The important thing here is
that the pciopen() that it calls is from libpci.a while the pciopen() in
main needs to be the one from the new library. This one uses a network
to send packets to a remote device. I do have something that works but
I'm not sure if it will work reliably.

What I did was create intermediate object files.

	ld -r -o tmp.o remote.o libpci.a
	objcopy -Lpciopen tmp.o new_remote.o
	ld -r -o tmp2.o main.o pciopen.o
	objcopy -Lpciopen tmp2.o new_main.o

and then linked them all together.

	ld -o file new_main.o (my other .o files) new_remote.o -lpci

Should this work for me everytime? By that I mean does it matter
what order files appear on the command line? How come when I tried
this without making the file new_main.o it didn't work? In this
case the version of pciopen() called by remoteInit() was my local
version even though there was a local symbol of the same name
in it's own object file and my version of pciopen() appeared after
that object file on the command line.

Is this the only/best solution to this problem?

 - Joel

Want more information?  See the CrossGCC FAQ,
Want to unsubscribe? Send a note to

More information about the crossgcc mailing list