]> granicus.if.org Git - apache/blob - docs/manual/dso.html.en
Clean up a stray <p>, copy n paste error
[apache] / docs / manual / dso.html.en
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 <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
5 <!--
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7               This file is generated from xml source: DO NOT EDIT
8         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9       -->
10 <title>Dynamic Shared Object (DSO) Support - Apache HTTP Server Version 2.5</title>
11 <link href="./style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
12 <link href="./style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
13 <link href="./style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="./style/css/prettify.css" />
14 <script src="./style/scripts/prettify.min.js" type="text/javascript">
15 </script>
16
17 <link href="./images/favicon.ico" rel="shortcut icon" /></head>
18 <body id="manual-page"><div id="page-header">
19 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p>
20 <p class="apache">Apache HTTP Server Version 2.5</p>
21 <img alt="" src="./images/feather.png" /></div>
22 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="./images/left.gif" /></a></div>
23 <div id="path">
24 <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.5</a></div><div id="page-content"><div id="preamble"><h1>Dynamic Shared Object (DSO) Support</h1>
25 <div class="toplang">
26 <p><span>Available Languages: </span><a href="./en/dso.html" title="English">&nbsp;en&nbsp;</a> |
27 <a href="./fr/dso.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
28 <a href="./ja/dso.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
29 <a href="./ko/dso.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
30 <a href="./tr/dso.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
31 </div>
32
33     <p>The Apache HTTP Server is a modular program where the
34     administrator can choose the functionality to include in the
35     server by selecting a set of modules.
36     Modules will be compiled as Dynamic Shared Objects (DSOs)
37     that exist separately from the main <code class="program"><a href="./programs/httpd.html">httpd</a></code>
38     binary file. DSO modules may be compiled at the time the server
39     is built, or they may be compiled and added at a later time
40     using the Apache Extension Tool (<code class="program"><a href="./programs/apxs.html">apxs</a></code>).</p>
41     <p>Alternatively, the modules can be statically compiled into
42     the <code class="program"><a href="./programs/httpd.html">httpd</a></code> binary when the server is built.</p>
43
44     <p>This document describes how to use DSO modules as well as
45     the theory behind their use.</p>
46   </div>
47 <div id="quickview"><ul id="toc"><li><img alt="" src="./images/down.gif" /> <a href="#implementation">Implementation</a></li>
48 <li><img alt="" src="./images/down.gif" /> <a href="#usage">Usage Summary</a></li>
49 <li><img alt="" src="./images/down.gif" /> <a href="#background">Background</a></li>
50 <li><img alt="" src="./images/down.gif" /> <a href="#advantages">Advantages and Disadvantages</a></li>
51 </ul><h3>See also</h3><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
52 <div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
53 <div class="section">
54 <h2><a name="implementation" id="implementation">Implementation</a></h2>
55
56 <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>
57
58     <p>The DSO support for loading individual Apache httpd modules is based
59     on a module named <code class="module"><a href="./mod/mod_so.html">mod_so</a></code> which must be statically
60     compiled into the Apache httpd core. It is the only module besides
61     <code class="module"><a href="./mod/core.html">core</a></code> which cannot be put into a DSO
62     itself. Practically all other distributed Apache httpd modules will then
63     be placed into a DSO. After a module is compiled into a DSO named
64     <code>mod_foo.so</code> you 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> directive in your
65     <code>httpd.conf</code> file to load this module at server startup
66     or restart.</p>
67     <p>The DSO builds for individual modules can be disabled via
68     <code class="program"><a href="./programs/configure.html">configure</a></code>'s <code>--enable-mods-static</code>
69     option as discussed in the <a href="install.html">install
70     documentation</a>.</p>
71
72     <p>To simplify this creation of DSO files for Apache httpd modules
73     (especially for third-party modules) a support program
74     named <code class="program"><a href="./programs/apxs.html">apxs</a></code> (<dfn>APache
75     eXtenSion</dfn>) is available. It can be used to build DSO based
76     modules <em>outside of</em> the Apache httpd source tree. The idea is
77     simple: When installing Apache HTTP Server the <code class="program"><a href="./programs/configure.html">configure</a></code>'s
78     <code>make install</code> procedure installs the Apache httpd C
79     header files and puts the platform-dependent compiler and
80     linker flags for building DSO files into the <code class="program"><a href="./programs/apxs.html">apxs</a></code>
81     program. This way the user can use <code class="program"><a href="./programs/apxs.html">apxs</a></code> to compile
82     his Apache httpd module sources without the Apache httpd distribution
83     source tree and without having to fiddle with the
84     platform-dependent compiler and linker flags for DSO
85     support.</p>
86 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
87 <div class="section">
88 <h2><a name="usage" id="usage">Usage Summary</a></h2>
89
90     <p>To give you an overview of the DSO features of Apache HTTP Server 2.x,
91     here is a short and concise summary:</p>
92
93     <ol>
94       <li>
95         <p>Build and install a <em>distributed</em> Apache httpd module, say
96         <code>mod_foo.c</code>, into its own DSO
97         <code>mod_foo.so</code>:</p>
98
99 <div class="example"><p><code>
100 $ ./configure --prefix=/path/to/install --enable-foo<br />
101 $ make install
102 </code></p></div>
103       </li>
104
105       <li>
106       <p>Configure Apache HTTP Server with all modules enabled. Only a basic
107       set will be loaded during server startup. You can change the set of loaded
108       modules by activating or deactivating the <code class="directive"><a href="./mod/mod_so.html#loadmodule">LoadModule</a></code> directives in
109       <code>httpd.conf</code>.</p>
110
111 <div class="example"><p><code>
112 $ ./configure --enable-mods-shared=all<br />
113 $ make install
114 </code></p></div>
115       </li>
116
117       <li>
118       <p>Some modules are only useful for developers and will not be build.
119       when using the module set <em>all</em>. To build all available modules
120       including developer modules use <em>reallyall</em>. In addition the
121       <code class="directive"><a href="./mod/mod_so.html#loadmodule">LoadModule</a></code> directives for all
122       built modules can be activated via the configure option
123       <code>--enable-load-all-modules</code>.</p>
124
125 <div class="example"><p><code>
126 $ ./configure --enable-mods-shared=reallyall --enable-load-all-modules<br />
127 $ make install
128 </code></p></div>
129       </li>
130
131       <li>
132         Build and install a <em>third-party</em> Apache httpd module, say
133         <code>mod_foo.c</code>, into its own DSO
134         <code>mod_foo.so</code> <em>outside of</em> the Apache httpd
135         source tree using <code class="program"><a href="./programs/apxs.html">apxs</a></code>:
136
137 <div class="example"><p><code>
138 $ cd /path/to/3rdparty<br />
139 $ apxs -cia mod_foo.c
140 </code></p></div>
141       </li>
142     </ol>
143
144     <p>In all cases, once the shared module is compiled, you must
145     use a <code class="directive"><a href="./mod/mod_so.html#loadmodule">LoadModule</a></code>
146     directive in <code>httpd.conf</code> to tell Apache httpd to activate
147     the module.</p>
148
149     <p>See the <a href="programs/apxs.html">apxs documentation</a> for more details.</p>
150 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
151 <div class="section">
152 <h2><a name="background" id="background">Background</a></h2>
153
154     <p>On modern Unix derivatives there exists a mechanism
155     called dynamic linking/loading of <em>Dynamic Shared
156     Objects</em> (DSO) which provides a way to build a piece of
157     program code in a special format for loading it at run-time
158     into the address space of an executable program.</p>
159
160     <p>This loading can usually be done in two ways: automatically
161     by a system program called <code>ld.so</code> when an
162     executable program is started or manually from within the
163     executing program via a programmatic system interface to the
164     Unix loader through the system calls
165     <code>dlopen()/dlsym()</code>.</p>
166
167     <p>In the first way the DSO's are usually called <em>shared
168     libraries</em> or <em>DSO libraries</em> and named
169     <code>libfoo.so</code> or <code>libfoo.so.1.2</code>. They
170     reside in a system directory (usually <code>/usr/lib</code>)
171     and the link to the executable program is established at
172     build-time by specifying <code>-lfoo</code> to the linker
173     command. This hard-codes library references into the executable
174     program file so that at start-time the Unix loader is able to
175     locate <code>libfoo.so</code> in <code>/usr/lib</code>, in
176     paths hard-coded via linker-options like <code>-R</code> or in
177     paths configured via the environment variable
178     <code>LD_LIBRARY_PATH</code>. It then resolves any (yet
179     unresolved) symbols in the executable program which are
180     available in the DSO.</p>
181
182     <p>Symbols in the executable program are usually not referenced
183     by the DSO (because it's a reusable library of general code)
184     and hence no further resolving has to be done. The executable
185     program has no need to do anything on its own to use the
186     symbols from the DSO because the complete resolving is done by
187     the Unix loader. (In fact, the code to invoke
188     <code>ld.so</code> is part of the run-time startup code which
189     is linked into every executable program which has been bound
190     non-static). The advantage of dynamic loading of common library
191     code is obvious: the library code needs to be stored only once,
192     in a system library like <code>libc.so</code>, saving disk
193     space for every program.</p>
194
195     <p>In the second way the DSO's are usually called <em>shared
196     objects</em> or <em>DSO files</em> and can be named with an
197     arbitrary extension (although the canonical name is
198     <code>foo.so</code>). These files usually stay inside a
199     program-specific directory and there is no automatically
200     established link to the executable program where they are used.
201     Instead the executable program manually loads the DSO at
202     run-time into its address space via <code>dlopen()</code>. At
203     this time no resolving of symbols from the DSO for the
204     executable program is done. But instead the Unix loader
205     automatically resolves any (yet unresolved) symbols in the DSO
206     from the set of symbols exported by the executable program and
207     its already loaded DSO libraries (especially all symbols from
208     the ubiquitous <code>libc.so</code>). This way the DSO gets
209     knowledge of the executable program's symbol set as if it had
210     been statically linked with it in the first place.</p>
211
212     <p>Finally, to take advantage of the DSO's API the executable
213     program has to resolve particular symbols from the DSO via
214     <code>dlsym()</code> for later use inside dispatch tables
215     <em>etc.</em> In other words: The executable program has to
216     manually resolve every symbol it needs to be able to use it.
217     The advantage of such a mechanism is that optional program
218     parts need not be loaded (and thus do not spend memory) until
219     they are needed by the program in question. When required,
220     these program parts can be loaded dynamically to extend the
221     base program's functionality.</p>
222
223     <p>Although this DSO mechanism sounds straightforward there is
224     at least one difficult step here: The resolving of symbols from
225     the executable program for the DSO when using a DSO to extend a
226     program (the second way). Why? Because "reverse resolving" DSO
227     symbols from the executable program's symbol set is against the
228     library design (where the library has no knowledge about the
229     programs it is used by) and is neither available under all
230     platforms nor standardized. In practice the executable
231     program's global symbols are often not re-exported and thus not
232     available for use in a DSO. Finding a way to force the linker
233     to export all global symbols is the main problem one has to
234     solve when using DSO for extending a program at run-time.</p>
235
236     <p>The shared library approach is the typical one, because it
237     is what the DSO mechanism was designed for, hence it is used
238     for nearly all types of libraries the operating system
239     provides.</p>
240
241 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
242 <div class="section">
243 <h2><a name="advantages" id="advantages">Advantages and Disadvantages</a></h2>
244
245     <p>The above DSO based features have the following
246     advantages:</p>
247
248     <ul>
249       <li>The server package is more flexible at run-time because
250       the server process can be assembled at run-time via
251       <code class="directive"><a href="./mod/mod_so.html#loadmodule">LoadModule</a></code>
252       <code>httpd.conf</code> configuration directives instead of
253       <code class="program"><a href="./programs/configure.html">configure</a></code> options at build-time. For instance,
254       this way one is able to run different server instances
255       (standard &amp; SSL version, minimalistic &amp; dynamic
256       version [mod_perl, mod_php], <em>etc.</em>) with only one Apache httpd
257       installation.</li>
258
259       <li>The server package can be easily extended with
260       third-party modules even after installation. This is
261       a great benefit for vendor package maintainers, who can create
262       an Apache httpd core package and additional packages containing
263       extensions like PHP, mod_perl, mod_security, <em>etc.</em></li>
264
265       <li>Easier Apache httpd module prototyping, because with the
266       DSO/<code class="program"><a href="./programs/apxs.html">apxs</a></code> pair you can both work outside the
267       Apache httpd source tree and only need an <code>apxs -i</code>
268       command followed by an <code>apachectl restart</code> to
269       bring a new version of your currently developed module into
270       the running Apache HTTP Server.</li>
271     </ul>
272
273     <p>DSO has the following disadvantages:</p>
274
275     <ul>
276       <li>The server is approximately 20% slower at startup time
277       because of the symbol resolving overhead the Unix loader now
278       has to do.</li>
279
280       <li>The server is approximately 5% slower at execution time
281       under some platforms, because position independent code (PIC)
282       sometimes needs complicated assembler tricks for relative
283       addressing, which are not necessarily as fast as absolute
284       addressing.</li>
285
286       <li>Because DSO modules cannot be linked against other
287       DSO-based libraries (<code>ld -lfoo</code>) on all platforms
288       (for instance a.out-based platforms usually don't provide
289       this functionality while ELF-based platforms do) you cannot
290       use the DSO mechanism for all types of modules. Or in other
291       words, modules compiled as DSO files are restricted to only
292       use symbols from the Apache httpd core, from the C library
293       (<code>libc</code>) and all other dynamic or static libraries
294       used by the Apache httpd core, or from static library archives
295       (<code>libfoo.a</code>) containing position independent code.
296       The only chances to use other code is to either make sure the
297       httpd core itself already contains a reference to it or
298       loading the code yourself via <code>dlopen()</code>.</li>
299     </ul>
300
301 </div></div>
302 <div class="bottomlang">
303 <p><span>Available Languages: </span><a href="./en/dso.html" title="English">&nbsp;en&nbsp;</a> |
304 <a href="./fr/dso.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
305 <a href="./ja/dso.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
306 <a href="./ko/dso.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
307 <a href="./tr/dso.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
308 </div><div class="top"><a href="#page-header"><img src="./images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
309 <script type="text/javascript"><!--//--><![CDATA[//><!--
310 var comments_shortname = 'httpd';
311 var comments_identifier = 'http://httpd.apache.org/docs/trunk/dso.html';
312 (function(w, d) {
313     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
314         d.write('<div id="comments_thread"><\/div>');
315         var s = d.createElement('script');
316         s.type = 'text/javascript';
317         s.async = true;
318         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
319         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
320     }
321     else {
322         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
323     }
324 })(window, document);
325 //--><!]]></script></div><div id="footer">
326 <p class="apache">Copyright 2016 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>
327 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
328 if (typeof(prettyPrint) !== 'undefined') {
329     prettyPrint();
330 }
331 //--><!]]></script>
332 </body></html>