switch to a 60 bit hash
[httpd-crcsyncproxy.git] / docs / manual / dso.html.en
blob4309a47c5dd998e3edd9ba528d342a57b1987bda
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 This file is generated from xml source: DO NOT EDIT
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7 -->
8 <title>Dynamic Shared Object (DSO) Support - Apache HTTP Server</title>
9 <link href="./style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="./style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="./style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
12 <link href="./images/favicon.ico" rel="shortcut icon" /></head>
13 <body id="manual-page"><div id="page-header">
14 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/directives.html">Directives</a> | <a href="./faq/">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p>
15 <p class="apache">Apache HTTP Server Version 2.3</p>
16 <img alt="" src="./images/feather.gif" /></div>
17 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="./images/left.gif" /></a></div>
18 <div id="path">
19 <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="./">Version 2.3</a></div><div id="page-content"><div id="preamble"><h1>Dynamic Shared Object (DSO) Support</h1>
20 <div class="toplang">
21 <p><span>Available Languages: </span><a href="./en/dso.html" title="English">&nbsp;en&nbsp;</a> |
22 <a href="./fr/dso.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
23 <a href="./ja/dso.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
24 <a href="./ko/dso.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
25 <a href="./tr/dso.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
26 </div>
28 <p>The Apache HTTP Server is a modular program where the
29 administrator can choose the functionality to include in the
30 server by selecting a set of modules. The modules can be
31 statically compiled into the <code class="program"><a href="./programs/httpd.html">httpd</a></code> binary when the
32 server is built. Alternatively, modules can be compiled as
33 Dynamic Shared Objects (DSOs) that exist separately from the
34 main <code class="program"><a href="./programs/httpd.html">httpd</a></code> binary file. DSO modules may be
35 compiled at the time the server is built, or they may be
36 compiled and added at a later time using the Apache Extension
37 Tool (<code class="program"><a href="./programs/apxs.html">apxs</a></code>).</p>
39 <p>This document describes how to use DSO modules as well as
40 the theory behind their use.</p>
41 </div>
42 <div id="quickview"><ul id="toc"><li><img alt="" src="./images/down.gif" /> <a href="#implementation">Implementation</a></li>
43 <li><img alt="" src="./images/down.gif" /> <a href="#usage">Usage Summary</a></li>
44 <li><img alt="" src="./images/down.gif" /> <a href="#background">Background</a></li>
45 <li><img alt="" src="./images/down.gif" /> <a href="#advantages">Advantages and Disadvantages</a></li>
46 </ul></div>
47 <div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
48 <div class="section">
49 <h2><a name="implementation" id="implementation">Implementation</a></h2>
51 <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="./mod/mod_so.html">mod_so</a></code></li></ul></td><td><ul><li><code class="directive"><a href="./mod/mod_so.html#loadmodule">LoadModule</a></code></li></ul></td></tr></table>
53 <p>The DSO support for loading individual Apache modules is based
54 on a module named <code class="module"><a href="./mod/mod_so.html">mod_so</a></code> which must be statically
55 compiled into the Apache core. It is the only module besides
56 <code class="module"><a href="./mod/core.html">core</a></code> which cannot be put into a DSO
57 itself. Practically all other distributed Apache modules can then
58 be placed into a DSO by individually enabling the DSO build for
59 them via <code class="program"><a href="./programs/configure.html">configure</a></code>'s
60 <code>--enable-<em>module</em>=shared</code> option as discussed
61 in the <a href="install.html">install documentation</a>. After a
62 module is compiled into a DSO named <code>mod_foo.so</code> you
63 can use <code class="module"><a href="./mod/mod_so.html">mod_so</a></code>'s <code class="directive"><a href="./mod/mod_so.html#loadmodule">LoadModule</a></code> command in your
64 <code>httpd.conf</code> file to load this module at server startup
65 or restart.</p>
67 <p>To simplify this creation of DSO files for Apache modules
68 (especially for third-party modules) a new support program
69 named <code class="program"><a href="./programs/apxs.html">apxs</a></code> (<dfn>APache
70 eXtenSion</dfn>) is available. It can be used to build DSO based
71 modules <em>outside of</em> the Apache source tree. The idea is
72 simple: When installing Apache the <code class="program"><a href="./programs/configure.html">configure</a></code>'s
73 <code>make install</code> procedure installs the Apache C
74 header files and puts the platform-dependent compiler and
75 linker flags for building DSO files into the <code class="program"><a href="./programs/apxs.html">apxs</a></code>
76 program. This way the user can use <code class="program"><a href="./programs/apxs.html">apxs</a></code> to compile
77 his Apache module sources without the Apache distribution
78 source tree and without having to fiddle with the
79 platform-dependent compiler and linker flags for DSO
80 support.</p>
81 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
82 <div class="section">
83 <h2><a name="usage" id="usage">Usage Summary</a></h2>
85 <p>To give you an overview of the DSO features of Apache 2.x,
86 here is a short and concise summary:</p>
88 <ol>
89 <li>
90 Build and install a <em>distributed</em> Apache module, say
91 <code>mod_foo.c</code>, into its own DSO
92 <code>mod_foo.so</code>:
94 <div class="example"><p><code>
95 $ ./configure --prefix=/path/to/install --enable-foo=shared<br />
96 $ make install
97 </code></p></div>
98 </li>
100 <li>
101 Build and install a <em>third-party</em> Apache module, say
102 <code>mod_foo.c</code>, into its own DSO
103 <code>mod_foo.so</code>:
105 <div class="example"><p><code>
106 $ ./configure --add-module=<var>module_type</var>:/path/to/3rdparty/mod_foo.c \<br />
107 <span class="indent">
108 --enable-foo=shared<br />
109 </span>
110 $ make install
111 </code></p></div>
112 </li>
114 <li>
115 Configure Apache for <em>later installation</em> of shared
116 modules:
118 <div class="example"><p><code>
119 $ ./configure --enable-so<br />
120 $ make install
121 </code></p></div>
122 </li>
124 <li>
125 Build and install a <em>third-party</em> Apache module, say
126 <code>mod_foo.c</code>, into its own DSO
127 <code>mod_foo.so</code> <em>outside of</em> the Apache
128 source tree using <code class="program"><a href="./programs/apxs.html">apxs</a></code>:
130 <div class="example"><p><code>
131 $ cd /path/to/3rdparty<br />
132 $ apxs -c mod_foo.c<br />
133 $ apxs -i -a -n foo mod_foo.la
134 </code></p></div>
135 </li>
136 </ol>
138 <p>In all cases, once the shared module is compiled, you must
139 use a <code class="directive"><a href="./mod/mod_so.html#loadmodule">LoadModule</a></code>
140 directive in <code>httpd.conf</code> to tell Apache to activate
141 the module.</p>
142 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
143 <div class="section">
144 <h2><a name="background" id="background">Background</a></h2>
146 <p>On modern Unix derivatives there exists a nifty mechanism
147 usually called dynamic linking/loading of <em>Dynamic Shared
148 Objects</em> (DSO) which provides a way to build a piece of
149 program code in a special format for loading it at run-time
150 into the address space of an executable program.</p>
152 <p>This loading can usually be done in two ways: Automatically
153 by a system program called <code>ld.so</code> when an
154 executable program is started or manually from within the
155 executing program via a programmatic system interface to the
156 Unix loader through the system calls
157 <code>dlopen()/dlsym()</code>.</p>
159 <p>In the first way the DSO's are usually called <em>shared
160 libraries</em> or <em>DSO libraries</em> and named
161 <code>libfoo.so</code> or <code>libfoo.so.1.2</code>. They
162 reside in a system directory (usually <code>/usr/lib</code>)
163 and the link to the executable program is established at
164 build-time by specifying <code>-lfoo</code> to the linker
165 command. This hard-codes library references into the executable
166 program file so that at start-time the Unix loader is able to
167 locate <code>libfoo.so</code> in <code>/usr/lib</code>, in
168 paths hard-coded via linker-options like <code>-R</code> or in
169 paths configured via the environment variable
170 <code>LD_LIBRARY_PATH</code>. It then resolves any (yet
171 unresolved) symbols in the executable program which are
172 available in the DSO.</p>
174 <p>Symbols in the executable program are usually not referenced
175 by the DSO (because it's a reusable library of general code)
176 and hence no further resolving has to be done. The executable
177 program has no need to do anything on its own to use the
178 symbols from the DSO because the complete resolving is done by
179 the Unix loader. (In fact, the code to invoke
180 <code>ld.so</code> is part of the run-time startup code which
181 is linked into every executable program which has been bound
182 non-static). The advantage of dynamic loading of common library
183 code is obvious: the library code needs to be stored only once,
184 in a system library like <code>libc.so</code>, saving disk
185 space for every program.</p>
187 <p>In the second way the DSO's are usually called <em>shared
188 objects</em> or <em>DSO files</em> and can be named with an
189 arbitrary extension (although the canonical name is
190 <code>foo.so</code>). These files usually stay inside a
191 program-specific directory and there is no automatically
192 established link to the executable program where they are used.
193 Instead the executable program manually loads the DSO at
194 run-time into its address space via <code>dlopen()</code>. At
195 this time no resolving of symbols from the DSO for the
196 executable program is done. But instead the Unix loader
197 automatically resolves any (yet unresolved) symbols in the DSO
198 from the set of symbols exported by the executable program and
199 its already loaded DSO libraries (especially all symbols from
200 the ubiquitous <code>libc.so</code>). This way the DSO gets
201 knowledge of the executable program's symbol set as if it had
202 been statically linked with it in the first place.</p>
204 <p>Finally, to take advantage of the DSO's API the executable
205 program has to resolve particular symbols from the DSO via
206 <code>dlsym()</code> for later use inside dispatch tables
207 <em>etc.</em> In other words: The executable program has to
208 manually resolve every symbol it needs to be able to use it.
209 The advantage of such a mechanism is that optional program
210 parts need not be loaded (and thus do not spend memory) until
211 they are needed by the program in question. When required,
212 these program parts can be loaded dynamically to extend the
213 base program's functionality.</p>
215 <p>Although this DSO mechanism sounds straightforward there is
216 at least one difficult step here: The resolving of symbols from
217 the executable program for the DSO when using a DSO to extend a
218 program (the second way). Why? Because "reverse resolving" DSO
219 symbols from the executable program's symbol set is against the
220 library design (where the library has no knowledge about the
221 programs it is used by) and is neither available under all
222 platforms nor standardized. In practice the executable
223 program's global symbols are often not re-exported and thus not
224 available for use in a DSO. Finding a way to force the linker
225 to export all global symbols is the main problem one has to
226 solve when using DSO for extending a program at run-time.</p>
228 <p>The shared library approach is the typical one, because it
229 is what the DSO mechanism was designed for, hence it is used
230 for nearly all types of libraries the operating system
231 provides. On the other hand using shared objects for extending
232 a program is not used by a lot of programs.</p>
234 <p>As of 1998 there are only a few software packages available
235 which use the DSO mechanism to actually extend their
236 functionality at run-time: Perl 5 (via its XS mechanism and the
237 DynaLoader module), Netscape Server, <em>etc.</em> Starting
238 with version 1.3, Apache joined the crew, because Apache
239 already uses a module concept to extend its functionality and
240 internally uses a dispatch-list-based approach to link external
241 modules into the Apache core functionality. So, Apache is
242 really predestined for using DSO to load its modules at
243 run-time.</p>
244 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
245 <div class="section">
246 <h2><a name="advantages" id="advantages">Advantages and Disadvantages</a></h2>
248 <p>The above DSO based features have the following
249 advantages:</p>
251 <ul>
252 <li>The server package is more flexible at run-time because
253 the actual server process can be assembled at run-time via
254 <code class="directive"><a href="./mod/mod_so.html#loadmodule">LoadModule</a></code>
255 <code>httpd.conf</code> configuration commands instead of
256 <code class="program"><a href="./programs/configure.html">configure</a></code> options at build-time. For instance
257 this way one is able to run different server instances
258 (standard &amp; SSL version, minimalistic &amp; powered up
259 version [mod_perl, PHP3], <em>etc.</em>) with only one Apache
260 installation.</li>
262 <li>The server package can be easily extended with
263 third-party modules even after installation. This is at least
264 a great benefit for vendor package maintainers who can create
265 a Apache core package and additional packages containing
266 extensions like PHP3, mod_perl, mod_fastcgi,
267 <em>etc.</em></li>
269 <li>Easier Apache module prototyping because with the
270 DSO/<code class="program"><a href="./programs/apxs.html">apxs</a></code> pair you can both work outside the
271 Apache source tree and only need an <code>apxs -i</code>
272 command followed by an <code>apachectl restart</code> to
273 bring a new version of your currently developed module into
274 the running Apache server.</li>
275 </ul>
277 <p>DSO has the following disadvantages:</p>
279 <ul>
280 <li>The DSO mechanism cannot be used on every platform
281 because not all operating systems support dynamic loading of
282 code into the address space of a program.</li>
284 <li>The server is approximately 20% slower at startup time
285 because of the symbol resolving overhead the Unix loader now
286 has to do.</li>
288 <li>The server is approximately 5% slower at execution time
289 under some platforms because position independent code (PIC)
290 sometimes needs complicated assembler tricks for relative
291 addressing which are not necessarily as fast as absolute
292 addressing.</li>
294 <li>Because DSO modules cannot be linked against other
295 DSO-based libraries (<code>ld -lfoo</code>) on all platforms
296 (for instance a.out-based platforms usually don't provide
297 this functionality while ELF-based platforms do) you cannot
298 use the DSO mechanism for all types of modules. Or in other
299 words, modules compiled as DSO files are restricted to only
300 use symbols from the Apache core, from the C library
301 (<code>libc</code>) and all other dynamic or static libraries
302 used by the Apache core, or from static library archives
303 (<code>libfoo.a</code>) containing position independent code.
304 The only chances to use other code is to either make sure the
305 Apache core itself already contains a reference to it or
306 loading the code yourself via <code>dlopen()</code>.</li>
307 </ul>
309 </div></div>
310 <div class="bottomlang">
311 <p><span>Available Languages: </span><a href="./en/dso.html" title="English">&nbsp;en&nbsp;</a> |
312 <a href="./fr/dso.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
313 <a href="./ja/dso.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
314 <a href="./ko/dso.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
315 <a href="./tr/dso.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
316 </div><div id="footer">
317 <p class="apache">Copyright 2009 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
318 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/directives.html">Directives</a> | <a href="./faq/">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p></div>
319 </body></html>