This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Executable shared object
- From: Segher Boessenkool <segher at koffie dot nl>
- To: Paolo Massimino <paolo dot massimino at loquendo dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 18 Jul 2003 04:05:42 +0200
- Subject: Re: Executable shared object
- References: <3F02F877.7040508@loquendo.com>
Paolo Massimino wrote:
Hi All!
I have a problem. I need to build a sherd object that, like libc do, can
print some information when you execute it like a normal executable.
Anyone can help me ?
Thank you
Paolo
Assuming you are on an ELF GNU/Linux system...
Link normally, but add -Wl,-e,the_name_of_your_entry_point
for example this Makefile fragment:
--- 8< ---
dop.so: dop.c
gcc -Wall -W -fPIC -shared -o dop.so dop.c -lc -Wl,-e,my_main
--- 8< ---
and add code like this:
--- 8< ---
const char my_interp[] __attribute__((section(".interp"))) = "/lib/ld.so.1";
void my_main(int argc, char **argv)
{
int i;
printf("Called as:");
for (i = 0; i < argc; i++)
printf(" %s", argv[i]);
printf("\n");
exit(0);
}
--- 8< ---
Have fun,
Segher