fix a reference to a manpage
[debian-policy.git] / policy / ch-sharedlibs.rst
blobd2fcc25d8a490e5ea2c189be10e6d9a45b6492f6
1 Shared libraries
2 ================
4 Packages containing shared libraries must be constructed with a little
5 care to make sure that the shared library is always available. This is
6 especially important for packages whose shared libraries are vitally
7 important, such as the C library (currently ``libc6``).
9 This section deals only with public shared libraries: shared libraries
10 that are placed in directories searched by the dynamic linker by default
11 or which are intended to be linked against normally and possibly used by
12 other, independent packages. Shared libraries that are internal to a
13 particular package or that are only loaded as dynamic modules are not
14 covered by this section and are not subject to its requirements.
16 A shared library is identified by the ``SONAME`` attribute stored in its
17 dynamic section. When a binary is linked against a shared library, the
18 ``SONAME`` of the shared library is recorded in the binary's ``NEEDED``
19 section so that the dynamic linker knows that library must be loaded at
20 runtime. The shared library file's full name (which usually contains
21 additional version information not needed in the ``SONAME``) is
22 therefore normally not referenced directly. Instead, the shared library
23 is loaded by its ``SONAME``, which exists on the file system as a
24 symlink pointing to the full name of the shared library. This symlink
25 must be provided by the package.
26 :ref:`s-sharedlibs-runtime` describes how to do this.  [#]_
28 When linking a binary or another shared library against a shared
29 library, the ``SONAME`` for that shared library is not yet known.
30 Instead, the shared library is found by looking for a file matching the
31 library name with ``.so`` appended. This file exists on the file system
32 as a symlink pointing to the shared library.
34 Shared libraries are normally split into several binary packages. The
35 ``SONAME`` symlink is installed by the runtime shared library package,
36 and the bare ``.so`` symlink is installed in the development package
37 since it's only used when linking binaries or shared libraries. However,
38 there are some exceptions for unusual shared libraries or for shared
39 libraries that are also loaded as dynamic modules by other programs.
41 This section is primarily concerned with how the separation of shared
42 libraries into multiple packages should be done and how dependencies on
43 and between shared library binary packages are managed in Debian.
44 :ref:`s-libraries` should be read in conjunction with
45 this section and contains additional rules for the files contained in
46 the shared library packages.
48 .. _s-sharedlibs-runtime:
50 Run-time shared libraries
51 -------------------------
53 The run-time shared library must be placed in a package whose name
54 changes whenever the ``SONAME`` of the shared library changes. This
55 allows several versions of the shared library to be installed at the
56 same time, allowing installation of the new version of the shared
57 library without immediately breaking binaries that depend on the old
58 version. Normally, the run-time shared library and its ``SONAME``
59 symlink should be placed in a package named librarynamesoversion, where
60 soversion is the version number in the ``SONAME`` of the shared library.
61 Alternatively, if it would be confusing to directly append soversion to
62 libraryname (if, for example, libraryname itself ends in a number), you
63 should use libraryname-soversion instead.
65 To determine the soversion, look at the ``SONAME`` of the library,
66 stored in the ELF ``SONAME`` attribute. It is usually of the form
67 ``name.so.major-version`` (for example, ``libz.so.1``). The version part
68 is the part which comes after ``.so.``, so in that example it is ``1``.
69 The soname may instead be of the form ``name-major-version.so``, such as
70 ``libdb-5.1.so``, in which case the name would be ``libdb`` and the
71 version would be ``5.1``.
73 If you have several shared libraries built from the same source tree,
74 you may lump them all together into a single shared library package
75 provided that all of their ``SONAME``\ s will always change together. Be
76 aware that this is not normally the case, and if the ``SONAME``\ s do
77 not change together, upgrading such a merged shared library package will
78 be unnecessarily difficult because of file conflicts with the old
79 version of the package. When in doubt, always split shared library
80 packages so that each binary package installs a single shared library.
82 Every time the shared library ABI changes in a way that may break
83 binaries linked against older versions of the shared library, the
84 ``SONAME`` of the library and the corresponding name for the binary
85 package containing the runtime shared library should change. Normally,
86 this means the ``SONAME`` should change any time an interface is removed
87 from the shared library or the signature of an interface (the number of
88 parameters or the types of parameters that it takes, for example) is
89 changed. This practice is vital to allowing clean upgrades from older
90 versions of the package and clean transitions between the old ABI and
91 new ABI without having to upgrade every affected package simultaneously.
93 The ``SONAME`` and binary package name need not, and indeed normally
94 should not, change if new interfaces are added but none are removed or
95 changed, since this will not break binaries linked against the old
96 shared library. Correct versioning of dependencies on the newer shared
97 library by binaries that use the new interfaces is handled via the
98 :ref:```symbols`` or ``shlibs`` system <s-sharedlibs-depends>`.
100 The package should install the shared libraries under their normal
101 names. For example, the libgdbm3 package should install
102 ``libgdbm.so.3.0.0`` as ``/usr/lib/libgdbm.so.3.0.0``. The files should
103 not be renamed or re-linked by any ``prerm`` or ``postrm`` scripts;
104 ``dpkg`` will take care of renaming things safely without affecting
105 running programs, and attempts to interfere with this are likely to lead
106 to problems.
108 Shared libraries should not be installed executable, since the dynamic
109 linker does not require this and trying to execute a shared library
110 usually results in a core dump.
112 The run-time library package should include the symbolic link for the
113 ``SONAME`` that ``ldconfig`` would create for the shared libraries. For
114 example, the libgdbm3 package should include a symbolic link from
115 ``/usr/lib/libgdbm.so.3`` to ``libgdbm.so.3.0.0``. This is needed so
116 that the dynamic linker (for example ``ld.so`` or ``ld-linux.so.*``) can
117 find the library between the time that ``dpkg`` installs it and the time
118 that ``ldconfig`` is run in the ``postinst`` script.  [61]_
120 .. _s-ldconfig:
122 ``ldconfig``
123 ~~~~~~~~~~~~
125 Any package installing shared libraries in one of the default library
126 directories of the dynamic linker (which are currently ``/usr/lib`` and
127 ``/lib``) or a directory that is listed in ``/etc/ld.so.conf``  [#]_
128 must use ``ldconfig`` to update the shared library system.
130 Any such package must have the line ``activate-noawait ldconfig`` in its
131 ``triggers`` control file (i.e. ``DEBIAN/triggers``
133 .. _s-sharedlibs-support-files:
135 Shared library support files
136 ----------------------------
138 If your package contains files whose names do not change with each
139 change in the library shared object version, you must not put them in
140 the shared library package. Otherwise, several versions of the shared
141 library cannot be installed at the same time without filename clashes,
142 making upgrades and transitions unnecessarily difficult.
144 It is recommended that supporting files and run-time support programs
145 that do not need to be invoked manually by users, but are nevertheless
146 required for the package to function, be placed (if they are binary) in
147 a subdirectory of ``/usr/lib``, preferably under
148 ``/usr/lib/``\ package-name. If the program or file is architecture
149 independent, the recommendation is for it to be placed in a subdirectory
150 of ``/usr/share`` instead, preferably under
151 ``/usr/share/``\ package-name. Following the package-name naming
152 convention ensures that the file names change when the shared object
153 version changes.
155 Run-time support programs that use the shared library but are not
156 required for the library to function or files used by the shared library
157 that can be used by any version of the shared library package should
158 instead be put in a separate package. This package might typically be
159 named libraryname-tools; note the absence of the soversion in the
160 package name.
162 Files and support programs only useful when compiling software against
163 the library should be included in the development package for the
164 library.  [#]_
166 .. _s-sharedlibs-static:
168 Static libraries
169 ----------------
171 The static library (``libraryname.a``) is usually provided in addition
172 to the shared version. It is placed into the development package (see
173 below).
175 In some cases, it is acceptable for a library to be available in static
176 form only; these cases include:
178 -  libraries for languages whose shared library support is immature or
179    unstable
181 -  libraries whose interfaces are in flux or under development (commonly
182    the case when the library's major version number is zero, or where
183    the ABI breaks across patchlevels)
185 -  libraries which are explicitly intended to be available only in
186    static form by their upstream author(s)
188 .. _s-sharedlibs-dev:
190 Development files
191 -----------------
193 If there are development files associated with a shared library, the
194 source package needs to generate a binary development package named
195 libraryname-dev, or if you need to support multiple development versions
196 at a time, librarynameapiversion-dev. Installing the development package
197 must result in installation of all the development files necessary for
198 compiling programs against that shared library.  [#]_
200 In case several development versions of a library exist, you may need to
201 use ``dpkg``'s Conflicts mechanism (see
202 `section\_title <#s-conflicts>`__) to ensure that the user only installs
203 one development version at a time (as different development versions are
204 likely to have the same header files in them, which would cause a
205 filename clash if both were unpacked).
207 The development package should contain a symlink for the associated
208 shared library without a version number. For example, the libgdbm-dev
209 package should include a symlink from ``/usr/lib/libgdbm.so`` to
210 ``libgdbm.so.3.0.0``. This symlink is needed by the linker (``ld``) when
211 compiling packages, as it will only look for ``libgdbm.so`` when
212 compiling dynamically.
214 If the package provides Ada Library Information (``*.ali``) files for
215 use with GNAT, these files must be installed read-only (mode 0444) so
216 that GNAT will not attempt to recompile them. This overrides the normal
217 file mode requirements given in
218 :ref:`s-permissions-owners`.
220 .. _s-sharedlibs-intradeps:
222 Dependencies between the packages of the same library
223 -----------------------------------------------------
225 Typically the development version should have an exact version
226 dependency on the runtime library, to make sure that compilation and
227 linking happens correctly. The ``${binary:Version}`` substitution
228 variable can be useful for this purpose.  [#]_
230 .. _s-sharedlibs-depends:
232 Dependencies between the library and other packages
233 ---------------------------------------------------
235 If a package contains a binary or library which links to a shared
236 library, we must ensure that, when the package is installed on the
237 system, all of the libraries needed are also installed. These
238 dependencies must be added to the binary package when it is built, since
239 they may change based on which version of a shared library the binary or
240 library was linked with even if there are no changes to the source of
241 the binary (for example, symbol versions change, macros become functions
242 or vice versa, or the binary package may determine at compile-time
243 whether new library interfaces are available and can be called). To
244 allow these dependencies to be constructed, shared libraries must
245 provide either a ``symbols`` file or a ``shlibs`` file. These provide
246 information on the package dependencies required to ensure the presence
247 of interfaces provided by this library. Any package with binaries or
248 libraries linking to a shared library must use these files to determine
249 the required dependencies when it is built. Other packages which use a
250 shared library (for example using ``dlopen()``) should compute
251 appropriate dependencies using these files at build time as well.
253 The two mechanisms differ in the degree of detail that they provide. A
254 ``symbols`` file documents, for each symbol exported by a library, the
255 minimal version of the package any binary using this symbol will need.
256 This is typically the version of the package in which the symbol was
257 introduced. This information permits detailed analysis of the symbols
258 used by a particular package and construction of an accurate dependency,
259 but it requires the package maintainer to track more information about
260 the shared library.
262 A ``shlibs`` file, in contrast, only documents the last time the library
263 ABI changed in any way. It only provides information about the library
264 as a whole, not individual symbols. When a package is built using a
265 shared library with only a ``shlibs`` file, the generated dependency
266 will require a version of the shared library equal to or newer than the
267 version of the last ABI change. This generates unnecessarily restrictive
268 dependencies compared to ``symbols`` files if none of the symbols used
269 by the package have changed. This, in turn, may make upgrades needlessly
270 complex and unnecessarily restrict use of the package on systems with
271 older versions of the shared libraries.
273 ``shlibs`` files also only support a limited range of library SONAMEs,
274 making it difficult to use ``shlibs`` files in some unusual corner
275 cases.  [#]_
277 ``symbols`` files are therefore recommended for most shared library
278 packages since they provide more accurate dependencies. For most C
279 libraries, the additional detail required by ``symbols`` files is not
280 too difficult to maintain. However, maintaining exhaustive symbols
281 information for a C++ library can be quite onerous, so ``shlibs`` files
282 may be more appropriate for most C++ libraries. Libraries with a
283 corresponding udeb must also provide a ``shlibs`` file, since the udeb
284 infrastructure does not use ``symbols`` files.
286 .. _s-dpkg-shlibdeps:
288 Generating dependencies on shared libraries
289 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
291 When a package that contains any shared libraries or compiled binaries
292 is built, it must run ``dpkg-shlibdeps`` on each shared library and
293 compiled binary to determine the libraries used and hence the
294 dependencies needed by the package. [#]_ To do this, put a call to
295 ``dpkg-shlibdeps`` into your ``debian/rules`` file in the source
296 package. List all of the compiled binaries, libraries, or loadable
297 modules in your package.  [68]_ ``dpkg-shlibdeps`` will use the
298 ``symbols`` or ``shlibs`` files installed by the shared libraries to
299 generate dependency information. The package must then provide a
300 substitution variable into which the discovered dependency information
301 can be placed.
303 If you are creating a udeb for use in the Debian Installer, you will
304 need to specify that ``dpkg-shlibdeps`` should use the dependency line
305 of type ``udeb`` by adding the ``-tudeb`` option.  [69]_ If there is no
306 dependency line of type ``udeb`` in the ``shlibs`` file,
307 ``dpkg-shlibdeps`` will fall back to the regular dependency line.
309 ``dpkg-shlibdeps`` puts the dependency information into the
310 ``debian/substvars`` file by default, which is then used by
311 ``dpkg-gencontrol``. You will need to place a ``${shlibs:Depends}``
312 variable in the ``Depends`` field in the control file of every binary
313 package built by this source package that contains compiled binaries,
314 libraries, or loadable modules. If you have multiple binary packages,
315 you will need to call ``dpkg-shlibdeps`` on each one which contains
316 compiled libraries or binaries. For example, you could use the ``-T``
317 option to the ``dpkg`` utilities to specify a different ``substvars``
318 file for each binary package.  [70]_
320 For more details on ``dpkg-shlibdeps``, see dpkg-shlibdeps1.
322 We say that a binary ``foo`` *directly* uses a library ``libbar`` if it
323 is explicitly linked with that library (that is, the library is listed
324 in the ELF ``NEEDED`` attribute, caused by adding ``-lbar`` to the link
325 line when the binary is created). Other libraries that are needed by
326 ``libbar`` are linked *indirectly* to ``foo``, and the dynamic linker
327 will load them automatically when it loads ``libbar``. A package should
328 depend on the libraries it directly uses, but not the libraries it only
329 uses indirectly. The dependencies for the libraries used directly will
330 automatically pull in the indirectly-used libraries. ``dpkg-shlibdeps``
331 will handle this logic automatically, but package maintainers need to be
332 aware of this distinction between directly and indirectly using a
333 library if they have to override its results for some reason.  [#]_
335 .. _s-sharedlibs-updates:
337 Shared library ABI changes
338 ~~~~~~~~~~~~~~~~~~~~~~~~~~
340 Maintaining a shared library package using either ``symbols`` or
341 ``shlibs`` files requires being aware of the exposed ABI of the shared
342 library and any changes to it. Both ``symbols`` and ``shlibs`` files
343 record every change to the ABI of the shared library; ``symbols`` files
344 do so per public symbol, whereas ``shlibs`` files record only the last
345 change for the entire library.
347 There are two types of ABI changes: ones that are backward-compatible
348 and ones that are not. An ABI change is backward-compatible if any
349 reasonable program or library that was linked with the previous version
350 of the shared library will still work correctly with the new version of
351 the shared library.  [#]_ Adding new symbols to the shared library is a
352 backward-compatible change. Removing symbols from the shared library is
353 not. Changing the behavior of a symbol may or may not be
354 backward-compatible depending on the change; for example, changing a
355 function to accept a new enum constant not previously used by the
356 library is generally backward-compatible, but changing the members of a
357 struct that is passed into library functions is generally not unless the
358 library takes special precautions to accept old versions of the data
359 structure.
361 ABI changes that are not backward-compatible normally require changing
362 the ``SONAME`` of the library and therefore the shared library package
363 name, which forces rebuilding all packages using that shared library to
364 update their dependencies and allow them to use the new version of the
365 shared library. For more information, see
366 :ref:`s-sharedlibs-runtime`. The remainder of this
367 section will deal with backward-compatible changes.
369 Backward-compatible changes require either updating or recording the
370 minimal-version for that symbol in ``symbols`` files or updating the
371 version in the dependencies in ``shlibs`` files. For more information on
372 how to do this in the two formats, see :ref:`s-symbols`
373 and :ref:`s-shlibs`. Below are general rules that apply
374 to both files.
376 The easy case is when a public symbol is added. Simply add the version
377 at which the symbol was introduced (for ``symbols`` files) or update the
378 dependency version (for ``shlibs``) files. But special care should be
379 taken to update dependency versions when the behavior of a public symbol
380 changes. This is easy to neglect, since there is no automated method of
381 determining such changes, but failing to update versions in this case
382 may result in binary packages with too-weak dependencies that will fail
383 at runtime, possibly in ways that can cause security vulnerabilities. If
384 the package maintainer believes that a symbol behavior change may have
385 occurred but isn't sure, it's safer to update the version rather than
386 leave it unmodified. This may result in unnecessarily strict
387 dependencies, but it ensures that packages whose dependencies are
388 satisfied will work properly.
390 A common example of when a change to the dependency version is required
391 is a function that takes an enum or struct argument that controls what
392 the function does. For example:
396     enum library_op { OP_FOO, OP_BAR };
397     int library_do_operation(enum library_op);
399 If a new operation, ``OP_BAZ``, is added, the minimal-version of
400 ``library_do_operation`` (for ``symbols`` files) or the version in the
401 dependency for the shared library (for ``shlibs`` files) must be
402 increased to the version at which ``OP_BAZ`` was introduced. Otherwise,
403 a binary built against the new version of the library (having detected
404 at compile-time that the library supports ``OP_BAZ``) may be installed
405 with a shared library that doesn't support ``OP_BAZ`` and will fail at
406 runtime when it tries to pass ``OP_BAZ`` into this function.
408 Dependency versions in either ``symbols`` or ``shlibs`` files normally
409 should not contain the Debian revision of the package, since the library
410 behavior is normally fixed for a particular upstream version and any
411 Debian packaging of that upstream version will have the same behavior.
412 In the rare case that the library behavior was changed in a particular
413 Debian revision, appending ``~`` to the end of the version that includes
414 the Debian revision is recommended, since this allows backports of the
415 shared library package using the normal backport versioning convention
416 to satisfy the dependency.
418 .. _s-sharedlibs-symbols:
420 The ``symbols`` system
421 ~~~~~~~~~~~~~~~~~~~~~~
423 In the following sections, we will first describe where the various
424 ``symbols`` files are to be found, then the ``symbols`` file format, and
425 finally how to create ``symbols`` files if your package contains a
426 shared library.
428 .. _s-symbols-paths:
430 The ``symbols`` files present on the system
431 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
433 ``symbols`` files for a shared library are normally provided by the
434 shared library package as a control file, but there are several override
435 paths that are checked first in case that information is wrong or
436 missing. The following list gives them in the order in which they are
437 read by ``dpkg-shlibdeps`` The first one that contains the required
438 information is used.
440 ``debian/*/DEBIAN/symbols``
441     During the package build, if the package itself contains shared
442     libraries with ``symbols`` files, they will be generated in these
443     staging directories by ``dpkg-gensymbols`` (see
444     `section\_title <#s-providing-symbols>`__). ``symbols`` files found
445     in the build tree take precedence over ``symbols`` files from other
446     binary packages.
448     These files must exist before ``dpkg-shlibdeps`` is run or the
449     dependencies of binaries and libraries from a source package on
450     other libraries from that same source package will not be correct.
451     In practice, this means that ``dpkg-gensymbols`` must be run before
452     ``dpkg-shlibdeps`` during the package build.  [#]_
454 ``/etc/dpkg/symbols/package.symbols.arch`` and ``/etc/dpkg/symbols/package.symbols``
455     Per-system overrides of shared library dependencies. These files
456     normally do not exist. They are maintained by the local system
457     administrator and must not be created by any Debian package.
459 ``symbols`` control files for packages installed on the system
460     The ``symbols`` control files for all the packages currently
461     installed on the system are searched last. This will be the most
462     common source of shared library dependency information. These files
463     can be read with ``dpkg-query --control-show package symbols``.
465 Be aware that if a ``debian/shlibs.local`` exists in the source package,
466 it will override any ``symbols`` files. This is the only case where a
467 ``shlibs`` is used despite ``symbols`` files being present. See
468 :ref:`s-shlibs-paths` and
469 :ref:`s-sharedlibs-shlibdeps` for more information.
471 .. \_s-symbols:
473 The ``symbols`` File Format
474 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
476 The following documents the format of the ``symbols`` control file as
477 included in binary packages. These files are built from template
478 ``symbols`` files in the source package by ``dpkg-gensymbols``. The
479 template files support a richer syntax that allows ``dpkg-gensymbols``
480 to do some of the tedious work involved in maintaining ``symbols``
481 files, such as handling C++ symbols or optional symbols that may not
482 exist on particular architectures. When writing ``symbols`` files for a
483 shared library package, refer to dpkg-gensymbols1 for the richer syntax.
485 A ``symbols`` may contain one or more entries, one for each shared
486 library contained in the package corresponding to that ``symbols``. Each
487 entry has the following format:
491     library-soname main-dependency-template
492      [| alternative-dependency-template]
493      [...]
494      [* field-name: field-value]
495      [...]
496      symbol minimal-version[ id-of-dependency-templa.. [#]
498 To explain this format, we'll use the ``zlib1g`` package as an example,
499 which (at the time of writing) installs the shared library
500 ``/usr/lib/libz.so.1.2.3.4``. Mandatory lines will be described first,
501 followed by optional lines.
503 library-soname must contain exactly the value of the ELF ``SONAME``
504 attribute of the shared library. In our example, this is ``libz.so.1``.
505 [#]_
507 main-dependency-template has the same syntax as a dependency field in a
508 binary package control file, except that the string ``#MINVER#`` is
509 replaced by a version restriction like ``(>= version)`` or by nothing if an unversioned dependency is
510 deemed sufficient. The version restriction will be based on which
511 symbols from the shared library are referenced and the version at which
512 they were introduced (see below). In nearly all cases,
513 main-dependency-template will be ``package #MINVER#``, where package is the name of the binary package
514 containing the shared library. This adds a simple, possibly-versioned
515 dependency on the shared library package. In some rare cases, such as
516 when multiple packages provide the same shared library ABI, the
517 dependency template may need to be more complex.
519 In our example, the first line of the ``zlib1g`` ``symbols`` file would
524     libz.so.1 zlib1g #MINVER#
526 Each public symbol exported by the shared library must have a
527 corresponding symbol line, indented by one space. symbol is the exported
528 symbol (which, for C++, means the mangled symbol) followed by ``@`` and
529 the symbol version, or the string ``Base`` if there is no symbol
530 version. minimal-version is the most recent version of the shared
531 library that changed the behavior of that symbol, whether by adding it,
532 changing its function signature (the parameters, their types, or the
533 return type), or changing its behavior in a way that is visible to a
534 caller. id-of-dependency-template is an optional field that references
535 an alternative-dependency-template; see below for a full description.
537 For example, ``libz.so.1`` contains the symbols ``compress`` and
538 ``compressBound``. ``compress`` has no symbol version and last changed
539 its behavior in upstream version ``1:1.1.4``. ``compressBound`` has the
540 symbol version ``ZLIB_1.2.0``, was introduced in upstream version
541 ``1:1.2.0``, and has not changed its behavior. Its ``symbols`` file
542 therefore contains the lines:
546     compress@Base 1:1.1.4
547     compressBound@ZLIB_1.2.0 1:1.2.0
549 Packages using only ``compress`` would then get a dependency on
550 ``zlib1g (>= 1:1.1.4)``, but packages using ``compressBound`` would get
551 a dependency on ``zlib1g (>= 1:1.2.0)``.
553 One or more alternative-dependency-template lines may be provided. These
554 are used in cases where some symbols in the shared library should use
555 one dependency template while others should use a different template.
556 The alternative dependency templates are used only if a symbol line
557 contains the id-of-dependency-template field. The first alternative
558 dependency template is numbered 1, the second 2, and so forth.  [#]_
560 Finally, the entry for the library may contain one or more metadata
561 fields. Currently, the only supported field-name is
562 ``Build-Depends-Package``, whose value lists the `library development
563 package <#s-sharedlibs-dev>`_ on which packages using this shared
564 library declare a build dependency. If this field is present,
565 ``dpkg-shlibdeps`` uses it to ensure that the resulting binary package
566 dependency on the shared library is at least as strict as the source
567 package dependency on the shared library development package.  [#]_ For
568 our example, the ``zlib1g`` ``symbols`` file would contain:
572     * Build-Depends-Package: zlib1g-dev
574 Also see ``deb-symbols(5)``.
576 .. _s-providing-symbols:
578 Providing a ``symbols`` file
579 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
581 If your package provides a shared library, you should arrange to include
582 a ``symbols`` control file following the format described above in that
583 package. You must include either a ``symbols`` control file or a
584 ``shlibs`` control file.
586 Normally, this is done by creating a ``symbols`` in the source package
587 named ``debian/package.symbols`` or ``debian/symbols``, possibly with
588 ``.arch`` appended if the symbols information varies by architecture.
589 This file may use the extended syntax documented in dpkg-gensymbols1.
590 Then, call ``dpkg-gensymbols`` as part of the package build process. It
591 will create ``symbols`` files in the package staging area based on the
592 binaries and libraries in the package staging area and the ``symbols``
593 files in the source package. [#]_
595 Packages that provide ``symbols`` files must keep them up-to-date to
596 ensure correct dependencies in packages that use the shared libraries.
597 This means updating the ``symbols`` file whenever a new public symbol is
598 added, changing the minimal-version field whenever a symbol changes
599 behavior or signature in a backward-compatible way (see
600 :ref:`s-sharedlibs-updates`), and changing the
601 library-soname and main-dependency-template, and probably all of the
602 minimal-version fields, when the library changes ``SONAME``. Removing a
603 public symbol from the ``symbols`` file because it's no longer provided
604 by the library normally requires changing the ``SONAME`` of the library.
605 See :ref:`s-sharedlibs-runtime` for more information on
606 ``SONAME``\ s.
608 .. _s-sharedlibs-shlibdeps:
610 The ``shlibs`` system
611 ~~~~~~~~~~~~~~~~~~~~~
613 The ``shlibs`` system is a simpler alternative to the ``symbols`` system
614 for declaring dependencies for shared libraries. It may be more
615 appropriate for C++ libraries and other cases where tracking individual
616 symbols is too difficult. It predated the ``symbols`` system and is
617 therefore frequently seen in older packages. It is also required for
618 udebs, which do not support ``symbols``.
620 In the following sections, we will first describe where the various
621 ``shlibs`` files are to be found, then how to use ``dpkg-shlibdeps``,
622 and finally the ``shlibs`` file format and how to create them.
624 .. _s-shlibs-paths:
626 The ``shlibs`` files present on the system
627 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
629 There are several places where ``shlibs`` files are found. The following
630 list gives them in the order in which they are read by
631 ``dpkg-shlibdeps``. (The first one which gives the required information
632 is used.)
634 ``debian/shlibs.local``
635     This lists overrides for this package. This file should normally not
636     be used, but may be needed temporarily in unusual situations to work
637     around bugs in other packages, or in unusual cases where the
638     normally declared dependency information in the installed ``shlibs``
639     file for a library cannot be used. This file overrides information
640     obtained from any other source.
642 ``/etc/dpkg/shlibs.override``
643     This lists global overrides. This list is normally empty. It is
644     maintained by the local system administrator.
646 ``DEBIAN/shlibs`` files in the "build directory"
647     These files are generated as part of the package build process and
648     staged for inclusion as control files in the binary packages being
649     built. They provide details of any shared libraries included in the
650     same package.
652 ``shlibs`` control files for packages installed on the system
653     The ``shlibs`` control files for all the packages currently
654     installed on the system. These files can be read using ``dpkg-query --control-show package shlibs``.
656 ``/etc/dpkg/shlibs.default``
657     This file lists any shared libraries whose packages have failed to
658     provide correct ``shlibs`` files. It was used when the ``shlibs``
659     setup was first introduced, but it is now normally empty. It is
660     maintained by the ``dpkg`` maintainer.
662 If a ``symbols`` file for a shared library package is available,
663 ``dpkg-shlibdeps`` will always use it in preference to a ``shlibs``,
664 with the exception of ``debian/shlibs.local``. The latter overrides any
665 other ``shlibs`` or ``symbols`` files.
667 .. _s-shlibs:
669 The ``shlibs`` File Format
670 ^^^^^^^^^^^^^^^^^^^^^^^^^^
672 Each ``shlibs`` file has the same format. Lines beginning with ``#`` are
673 considered to be comments and are ignored. Each line is of the form:
677     [typ.. [#]library-name soname-version dependencies ...
679 We will explain this by reference to the example of the ``zlib1g``
680 package, which (at the time of writing) installs the shared library
681 ``/usr/lib/libz.so.1.2.3.4``.
683 type is an optional element that indicates the type of package for which
684 the line is valid. The only type currently in use is ``udeb``. The colon
685 and space after the type are required.
687 library-name is the name of the shared library, in this case ``libz``.
688 (This must match the name part of the soname, see below.)
690 soname-version is the version part of the ELF ``SONAME`` attribute of
691 the library, determined the same way that the soversion component of the
692 recommended shared library package name is determined. See
693 :ref:`s-sharedlibs-runtime` for the details.
695 dependencies has the same syntax as a dependency field in a binary
696 package control file. It should give details of which packages are
697 required to satisfy a binary built against the version of the library
698 contained in the package. See :ref:`s-depsyntax` for
699 details on the syntax, and :ref:`s-sharedlibs-updates`
700 for details on how to maintain the dependency version constraint.
702 In our example, if the last change to the ``zlib1g`` package that could
703 change behavior for a client of that library was in version
704 ``1:1.2.3.3.dfsg-1``, then the ``shlibs`` entry for this library could
705 say:
709     libz 1 zlib1g (>= 1:1.2.3.3.dfsg)
711 This version restriction must be new enough that any binary built
712 against the current version of the library will work with any version of
713 the shared library that satisfies that dependency.
715 As zlib1g also provides a udeb containing the shared library, there
716 would also be a second line:
720     udeb: libz 1 zlib1g-udeb (>= 1:1.2.3.3.dfsg)
722 .. _s8.6.4.3:
724 Providing a ``shlibs`` file
725 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
727 To provide a ``shlibs`` file for a shared library binary package, create
728 a ``shlibs`` file following the format described above and place it in
729 the ``DEBIAN`` directory for that package during the build. It will then
730 be included as a control file for that package.  [#]_
732 Since ``dpkg-shlibdeps`` reads the ``DEBIAN/shlibs`` files in all of the
733 binary packages being built from this source package, all of the
734 ``DEBIAN/shlibs`` files should be installed before ``dpkg-shlibdeps`` is
735 called on any of the binary packages.