mirror of https://github.com/tLDP/LDP
updated
This commit is contained in:
parent
fd09540044
commit
ddc604957f
|
@ -7,7 +7,7 @@
|
|||
<author><firstname>David A.</firstname> <surname>Wheeler</surname>
|
||||
</author>
|
||||
<address><email>dwheeler@dwheeler.com</email></address>
|
||||
<pubdate>version 0.71, 6 September 2000</pubdate>
|
||||
<pubdate>version 0.75, 31 October 2000</pubdate>
|
||||
<abstract>
|
||||
<para>
|
||||
This HOWTO for programmers
|
||||
|
@ -767,6 +767,7 @@ If the library exports a routine named _init, then that
|
|||
code is executed before dlopen() returns.
|
||||
You can use this fact in your own libraries to implement
|
||||
initialization routines.
|
||||
See <xref linkend="init-and-fini"> for more information.
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
|
@ -830,6 +831,8 @@ until dlclose has been called on it as many times as
|
|||
dlopen has succeeded on it.
|
||||
Thus, it's not a problem for the same program
|
||||
to load the same library multiple times.
|
||||
If a library is deallocated, its function _fini is called (if it exists);
|
||||
see <xref linkend="init-and-fini"> for more information.
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
|
@ -942,6 +945,37 @@ documentation locally installed at
|
|||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="init-and-fini">
|
||||
<title>Special functions _init and _fini</title>
|
||||
<para>
|
||||
Two special functions aid in initializing and finalizing a module:
|
||||
_init and _fini.
|
||||
If a function ``_init'' is exported in a library,
|
||||
then it is called whenever dllopen() is called to open the library.
|
||||
In a C program, this just means that you defined some function
|
||||
named _init.
|
||||
There is a corresponding function called _fini, which is called whenever a
|
||||
client calls dlclose() to release a library (and it's released).
|
||||
The C prototypes for these functions are:
|
||||
<programlisting>
|
||||
void _init(void);
|
||||
void _fini(void);
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
When compiling the file into a ``.o'' file in gcc, be sure to add the
|
||||
gcc option ``-nostartfiles''.
|
||||
This keeps the C compiler from
|
||||
linking the system startup libraries against the .so file.
|
||||
Otherwise, you'll get a ``multiple-definition'' error.
|
||||
My thanks to Jim Mischel and Tim Gentry for their suggestion to add
|
||||
this discussion of _init and _fini,
|
||||
as well as help in creating it.
|
||||
</para>
|
||||
|
||||
</sect2>
|
||||
|
||||
<sect2>
|
||||
<title>Shared Libraries Can Be Scripts</title>
|
||||
<para>
|
||||
|
@ -988,6 +1022,18 @@ For more information, see its documentation at
|
|||
<ulink url="http://www.gnu.org/software/libtool/manual.html">http://www.gnu.org/software/libtool/manual.html</ulink>
|
||||
</para>
|
||||
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>Extremely small executables</title>
|
||||
<para>
|
||||
You might find the paper
|
||||
<ulink url="http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html">Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux</ulink>
|
||||
useful.
|
||||
It describes how to make a truly tiny program executable.
|
||||
Frankly, you shouldn't use most of these tricks under normal
|
||||
circumstances, but they're quite instructive in showing how
|
||||
ELF really works.
|
||||
</para>
|
||||
</sect2>
|
||||
</sect1>
|
||||
|
||||
|
|
Loading…
Reference in New Issue