Wednesday, June 4, 2008

How to run a shared library on Open Solaris

Its is surprising that how is this possible to run a shared library.
Yes, its possible to run any shared library. I have done this R&D on Open Solaris.
It is also possible to run any shared library on Linux by using GNU Toolchain.
Please read my blog: How to run a shared library on Linux:

There are some special shared object examples that can be run as an exectable:
On open solaris you can try to invoke run time linker ( direclty
$ /usr/lib/
usage: [-e option,...] dynamic-object [object args,...]

To run any executable/application
$ /usr/lib/ ./appl

On linux you can run
$ /lib/
This will give you the version of libc library.

Shared object should have following entries to run:
1. +x permission that is by default is given by the static linker(program linker) when creating a shared object.
2. Entry point at which the program/shared library is starts to run.
3. Interpreter(Run time linker) that is used to run any shared library after loaded by kernel part exec().

By using static linker(program linker) option '-e entry_point', an entry point can be specified.
By using static linker(program linker) option '-I interpreter_path', an .interp section can be created that contains
the absolute path of the interpreter(run time linker).

You can see the interpreter path using following command
$ elfdump -i

Interpreter Section: .interp

Demo on Open-Solaris machine
$ cat func.c
void bar();
exit (0);

$ gcc -o -shared -fPIC func.c
$ ./ Bad entry point

$ gcc -o -shared -fPIC func.c -Wl,-e,func
$ ./
Segmentation Fault (core dumped)

$ gcc -o -shared -fPIC foo.c -Wl,-e,func -Wl,-I,/usr/lib/
$ ./

Thats cool man, Now try yourself.
Happy hacking.

No comments: