This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
using objcopy --redefine-sym
- From: Wagner Toledo Correa <wtcorrea at CS dot Princeton dot EDU>
- To: binutils at sources dot redhat dot com
- Date: Mon, 25 Aug 2003 10:15:44 -0400
- Subject: using objcopy --redefine-sym
Hello all,
I need to call an executable's main function from another executable.
Say the original executable is hello, and I need to call it from foo.
Here is what I've been trying to do without success:
First, I create a hacked copy of hello with its main function renamed to
hello_main:
objcopy --redefine-sym main=hello_main hello hacked_hello.o
Then, foo.c looks like this:
#include <stdio.h>
extern int hello_main(int argc, char *argv[]);
int main(int argc, char *argv[])
{
fprintf(stderr, "foo\n");
return hello_main(argc, argv);
}
Finally, I try to link foo.o and hacked_hello, but it fails:
ld -o foo foo.o hacked_hello.o -lc
foo.o(.dynamic+0x0): In function `main':
/tmp/foo/foo.c:6: multiple definition of `_DYNAMIC'
hacked_hello.o(.dynamic+0x0): first defined here
foo.o(.got.plt+0x0): In function `main':
/tmp/foo/foo.c:6: multiple definition of `_GLOBAL_OFFSET_TABLE_'
hacked_hello.o(.got+0x0): first defined here
Does anybody know how to solve this problem?
Thanks,
Wagner