Running SO files
Segher Boessenkool
segher@kernel.crashing.org
Sun Jun 1 11:05:00 GMT 2008
> I have noticed that some shared object (.so) files can be executed. For
> example, I can type:
>
> $ /lib/libc.so.6
>
> which prints a message with the version of GNU C library and other
> information. How does this work? How is it possible to execute a shared
> object file?
It's a little hack in the Linux kernel. The SO needs an entry point,
and a ".interp" section.
> Does it have a main/start function?
It does. It's calling convention is just like normal main() on some
platforms, but pretty strange on others.
> How can I create such a
> file (one that can be executed)?
At http://git.infradead.org/users/segher/profall.git?a=tree you can look
at a tiny example of this. It's pretty horrible code, don't go blind
:-)
> I have also noticed that this is not true
> for every SO file. I would appreciate any information on how this
> works.
You can't "run" a SO if it's not marked +x. The Linux kernel will
happily
try to run any SO that is executable, but will segfault it just as
happily
unless you get all the little bits right.
Happy hacking,
Segher
More information about the Binutils
mailing list