6069 libdisasm: instrlen arch op should have a sane default
[illumos-gate.git] / usr / src / lib / README.mapfiles
blobab6650c48537fd2f3e6e9b977ec6c7a09628aca2
2 # CDDL HEADER START
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
19 # CDDL HEADER END
22 # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
25 Mapfiles and versioning in illumos
26 ==================================
28 1.0 Objective of this README
30 This README describes the engineering practices of creating and updating
31 visible library interfaces.  It describes various kinds of actions that
32 typically occur as libraries are evolved, and shows how interface
33 specifications are affected or updated in accordance.  It tells you what
34 you must do as a shared library developer if you:
36         1. Make interface additions to an existing library
37                 - add a Public interface
38                 - add a Private interface
39         2. Update an interface in an existing library
40                 - remove an existing interface
41                 - promote a Private interface to Public
42                 - scope a Private interface to local
43                 - move an interface from one library to another
44                 - copy interfaces which are part of the standard to a new or
45                   existing library
46         3. Introduce a new library
47                 - source directory hierarchy
48                 - creation of the "mapfile-vers" file
49                 - Makefiles
50         4. Make an entire library obsolete before end-of-life
51                 - introduce SUNWobsolete to the "mapfile-vers" file
53 -------------------------------------------------------------------------------
55 2.0 What's a mapfile?
57 Mapfiles are used to tell the link-editor ("ld") all sorts of things about
58 how to generate an executable file or a shared object from a collection of
59 relocatable objects, such as generated by a compiler.  For all the gory
60 details, see the Solaris Linker and Libraries Guide.
62 There are two versions of the mapfile language accepted by the link-editor.
63 Version 1 derives from AT&T System V Release 4 Unix. Version 2 is a newer
64 syntax specific to Solaris and derivatives.  All mapfiles in illumos are
65 required to use version 2 syntax. Note that every mapfile using version 2
66 syntax must start with the line:
68         $mapfile_version 2
70 Here, we are only concerned with specifying externally-visible interfaces
71 for shared libraries (shared objects) and with specifying their versions
72 for ABI (Application Binary Interface) purposes.  For these purposes, we
73 only need to deal with a subset of the mapfile language.
75 There should be a "mapfile-vers" file associated with every shared library
76 and it should reside in the common source directory for that library, most
77 often in a "common" directory.  This is the usual layout of a library's
78 top-level directory (usr/src/lib/libwombat):
79         Makefile       amd64/         i386/          sparcv9/
80         Makefile.com   common/        sparc/
82 The "common" directory contains the source files and other common files
83 for the library:
84         bat.c              libwombat_impl.h   mapfile-vers       wom.c
85         libwombat.h        llib-lwombat       util.c             wombat.c
87 The mapfile's name is, by convention, "mapfile-vers" because it is used
88 for only two purposes: to specify externally-visible interface names while
89 suppressing visibility of all other names, and to specify their respective
90 unique version names.
92 -------------------------------------------------------------------------------
94 3.0 Contents of mapfile-vers
96 The structure of mapfile-vers is best explained by an example
97 (the license notification and copyright notice is omitted here
98 for brevity):
100 $mapfile_version 2
102 SYMBOL_VERSION ILLUMOS_0.2 {    # Second interface change in illumos
103     global:
104         wb_notify;
105 } ILLUMOS_0.1;
107 SYMBOL_VERSION ILLUMOS_0.1 {    # First interface change in illumos
108     global:
109         wb_poll;
110 } SUNW_1.2;    
112 SYMBOL_VERSION SUNW_1.2 {       # update to libwombat, Solaris 10
113     global:
114         wb_readv;
115         wb_stat;
116         wb_writev;
117 } SUNW_1.1;
119 SYMBOL_VERSION SUNW_1.1 {       # first release of libwombat, Solaris 9
120     global:
121         wb_read;
122         wb_write;
125 SYMBOL_VERSION SUNWprivate {    # private libwombat symbols
126     global:
127         wb_add;
128         wb_delete;
129         wb_search;
130     local:
131         *;
134 Each of these sections is a version declaration describing an ABI version of
135 the library containing the set of symbols exposed by the library to
136 external callers.
138 ABI versions must be constant, that is version ILLUMOS_0.2 in a given
139 library must always describe the same interface such that applications may
140 safely state their dependencies in terms of these versions and have a
141 constant and predictable ABI be exposed.  This in effect means that once a
142 version is publicly visible, it may never be removed or have symbols added
143 to or removed from it.
145 ABI versions with the same major number should be upward compatible, that is
146 ILLUMOS_0.3 of a given library must contain all the interfaces in
147 ILLUMOS_0.2, and they must be compatible.
149 The private version, however, is special, and describes any private yet
150 exposed symbols within a library, and may change at any time (and without
151 notice).  It exists purely to allow certain symbols to be of global scope
152 but not Public.  Similarly, any symbols scoped local are private and may
153 change safely, even if the local statement happens to be within a public
154 version.
156 Interface changes made in illumos should be done with ILLUMOS_0.* versions,
157 introducing one version per interface change.  In illumos, unlike Solaris,
158 symbol versions are not release-specific because of the requirement that
159 each be constant.  No change should be made to add or remove symbols from
160 any pre-existing Public version.
162 The SUNW_*.* names were the Public version names of the library in Solaris.
163 There should be at most one version name for each release of Solaris, with
164 the minor number incremented by one over the previous version.  No changes
165 should ever be made to SUNW_1.* versions.
167 So, for example, to add a new interface to libwombat in illumos one would add:
169 SYMBOL_VERSION ILLUMOS_0.3 {    # Third update to libwombat in illumos
170     global:
171         wb_lseek;
172 } ILLUMOS_0.2;
174 Each version must inherit all symbols from its preceding version, specified at
175 the ending "}" for each version. The initial public version does not inherit
176 any symbols.  The private version named either "SUNWprivate" for libraries
177 with private symbols pre-existing illumos, or "ILLUMOSprivate" otherwise
178 stands alone, inheriting nothing and being inherited by nothing.
180 The two lines in SUNWprivate:
181     local:
182         *;
183 ensure that no symbols other than those listed in the mapfile are visible to
184 clients of the library.  If there is no private version, these two lines should
185 appear in the first public version.
187 For maintainability, the list of names in each version block should
188 be sorted in dictionary order (sort -d).  Please comply.
190 The version 2 mapfile language supports a simple mechanism for conditional
191 input, in which lines in the mapfile apply only to a specific platform or
192 ELFCLASS (32/64-bit). This mechanism works very much like the #if/#endif
193 feature of the C preprocessor. For instance, the following mapfile declares
194 a version SUNW_1.1 that always exports a symbol foo, and also exports
195 the symbol bar on 32-bit sparc platforms:
197 $mapfile_version 2
198 SYMBOL_VERSION SUNW_1.1 {
199         foo;
200 $if _sparc && _ELF32
201         bar;
202 $endif
205 Conditional input can be used if there are ISA-specific library interfaces
206 not common to all instances of the library. It is the preferred method for
207 expressing platform specific items, as long as the differences are simple
208 (which is almost always the case).  For example, see libproc, or, if you
209 are masochistic, libc or libnsl.  In general, use of this feature should be
210 minimal.
212 In addition to conditional input, there is a second heavier weight mechanism
213 for expressing ISA-specific differences. In addition to the common mapfile:
214         common/mapfile-vers
215 some libraries may have ISA-specific supplemental mapfiles, one in each
216 of the ISA directories:
217         amd64/mapfile-vers
218         i386/mapfile-vers
219         sparc/mapfile-vers
220         sparcv9/mapfile-vers
221 The ISA-specific mapfiles look like the common mapfile, except that only
222 the ISA-specific names appear.  The version names are the same as those
223 in the common mapfile, but only non-empty version instances are present
224 and no inheritance specification is present. The link-editor reads the
225 information from the common and ISA-specific mapfiles and merges them
226 in memory into a single description used to create the resulting object.
228 ISA-specific mapfiles were used with the version 1 mapfile language, which
229 lacked conditional input. Their use is rare now, as conditional input is
230 generally preferred. However, it is important to use conditional input
231 carefully, or the resulting mapfile can be extremly difficult to read.
233 -------------------------------------------------------------------------------
235 4.0 Making interface additions to an existing library
237 4.1 Adding a Public interface
239 Public interfaces should be added to a new ILLUMOS_ symbol version, with the
240 minor number incremented by one from the current highest version name. If
241 this is the first Public interface in the shared object, a new ILLUMOS_0.1
242 version name must be introduced.
244 The major revision number is incremented whenever an incompatible change is
245 made to an interface.  This could be the case if an API changes so
246 dramatically as to invalidate dependencies.  This should almost never occur
247 in practice.  It also requires changing the suffix of the shared object
248 from, say, .so.1 to .so.2 and introducing code to continue to ship the .so.1
249 version of the library.
251 The minor revision number is incremented whenever one or more new interfaces
252 is added to a library.  Once a version comes to exist in illumos, it is from
253 that point onward considered to be immutable.
255 4.2 Adding a Private interface
257 Private interfaces are the non-ABI interfaces of the library.  Unlike
258 introducing a Public interface, a new entry is simply added to the
259 private version.  No minor number increment is necessary.
261 If this interface happens to be the first Private interface introduced into
262 the library, the private version must be created (with no major.minor
263 version numbers).  It inherits nothing, nothing inherits from it and it
264 should be named ILLUMOSprivate.
266 If the library already has Private interfaces in a SUNWprivate version, you
267 should use that.  They may have numbered version names like SUNWprivate_m.n
268 (due to errors of the past).  If so, just use the highest numbered private
269 version name to version the new interface.  There is no need to introduce a
270 new private version name.  Be careful not to use a lower numbered private
271 version name; doing so can cause runtime errors (as opposed to load time
272 errors) when running an application with older versions of the library.
274 There are also libraries in illumos that contain only private interfaces. In
275 such libraries, the private versions maybe legitimately be versioned and
276 they may be incremented to ensure that the programs that depend on them are
277 built and delivered as a integrated unit. A notable example of this is
278 libld.so (usr/src/cmd/sgs/libld), which contains the implementation of the
279 link-editor, the public interface to which is provided by the ld
280 command. When making a modification to the interface of such a library, you
281 should follow the convention already in place.
283 4.3 Historical handling of Solaris update releases.
285 To aid the understanding of our existing mapfiles, it is useful to note how
286 interface versions were handled as they interacted with update releases of
287 Solaris.  Solaris update releases required careful coordination with the full
288 release currently under development to keep symbol versions constant between
289 releases.
291 Multiple update releases were generally shipped during the development of the
292 next full release of Solaris.  It was impossible to know in advance the full
293 set of new interfaces in the next full release until it was complete.  Some,
294 though not all, new interfaces were included in the intervening update
295 releases between full releases.
297 Consequently, the new version number for an update cannot be a minor
298 increment, but must be a micro increment to ensure that was a distinct
299 version between the two releases.  For example, if Release N had version
300 number SUNW_1.3 and Release N+1 had SUNW_1.4, then interfaces added to
301 an update of Release N must have micro numbers such as SUNW_1.3.1,
302 SUNW_1.3.2, etc.  (note that the micro number is not directly tied to the
303 update number: SUNW_1.3.1 may have appeared in Update 2).  The micro versions form
304 an inheritance chain that is inserted between two successive minor versions.
305 For example, the mapfile-vers file for minor release "N+1" to reflect its
306 inclusion of micro releases will look like the following:
308 $mapfile_version 2
310 SYMBOL_VERSION SUNW_1.4 {       # release N+1
311     global:
312         ...
313 } SUNW_1.3.2;
315 SYMBOL_VERSION SUNW_1.3.2 {     # micro release 2 (e.g., release NU3)
316     global:
317         ...
318 } SUNW_1.3.1;
320 SYMBOL_VERSION SUNW_1.3.1 {     # micro release 1 (e.g., release NU2)
321     global:
322         ...
323 } SUNW_1.3;
325 SYMBOL_VERSION SUNW_1.3 {       # release N
326     global:
327         ...
328 } SUNW_1.2;
330 SYMBOL_VERSION SUNW_1.2 {       # release N-1
331     global:
332         ...
333 } SUNW_1.1;
335 SYMBOL_VERSION SUNW_1.1 {       # first release
336     global:
337         ...
340 SYMBOL_VERSION SUNW_private {   # same in all releases
341     global:
342         ...
343     local:
344         *;
347 The corresponding update/patch mapfile-vers file will be identical
348 except for the exclusion of SUNW_1.4.
350 Those interfaces which are only present in Release N+1 are always put
351 into the next minor version set, SUNW_1.4.
353 Thus when adding a new Public interface to an update release, both the mapfiles
354 of the update release and next full release should have been modified to be
355 consistent.
357 There have been several cases of accidental deviation from this scheme, and
358 existing mapfiles sometimes reflect this unfortunate state of affairs.
360 -------------------------------------------------------------------------------
362 5.0 How to update an interface in an existing library
364 5.1 Removing an existing interface
366 5.1.1 Moving a Public interface
368 No Public interfaces should ever be removed from any mapfile, as this will
369 break all existing consumers of that interface.
371 To move an interface from one library to (say) libc, the code has to be
372 deleted from the library and added to libc, then the mapfile for the
373 library has to have the interface's entry changed from:
374         getfoobar;
376         getfoobar       { TYPE = FUNCTION; FILTER = libc.so.1 };
377 This is an exception to the immutability of public symbol versions.  See,
378 for example, libnsl's common/mapfile-vers file.
380 Follow the rules for adding a new interface for the necessary changes
381 to libc's mapfile to accommodate the moved interface, including creating a
382 new version in libc for the symbol.
384 When merging an entire library into libc, the mapfile is changed to specify
385 the type of each public symbol similarly to the above:
386         getfoobar;
388         getfoobar       { TYPE = FUNCTION };
390 But rather than specifying the library on which we filter for each symbol,
391 the link-editor is invoked with '-F libc.so.1' to specify that our entire
392 symbol table is a filter on libc.  For examples, see libaio and librt.
394 5.1.2 Removing a Private interface
396 Deletion of Private interfaces is allowed, but caution should be taken;
397 it should first be established that the interface is not being used.
398 To remove a Private interface, simply delete the corresponding entry
399 for that symbol from the mapfile's private version section.
401 Do not forget to delete these Public or Private interfaces from the library's
402 header files as well as from the code that implements the interfaces.
404 5.2 Promoting a Private interface to Public
406 This is similar to what's done when adding a Public interface.  Promoting an
407 existing Private interface to a Public one only requires a change to the
408 existing interface definition.  Private interfaces have the symbol version
409 name "ILLUMOSprivate" or "SUNWprivate" associated with them.  To make the
410 interface a Public one, the interface must be added as if it were a new
411 public symbol, following those same rules and removed from the private
412 version.
414 As an example, if we were modifying libwombat.so.1 and its existing latest
415 version were ILLUMOS_0.3, any new ABI would be put into a version called
416 ILLUMOS_0.4.  Therefore, whether you wish to promote an existing Private
417 interface to Public, or to introduce a new Public interface, this (next
418 successive minor numbered version level) would be the version that it would
419 be associated with.
421 5.3 Scoping a Private interface local
423 Any interfaces not present in the mapfile-vers file will be scoped local
424 due to the presence of the
425     local:
426         *;
427 lines discussed earlier. This ensures that such interfaces will not be visible
428 outside the library.  To move an interface from Private to local scope, simply
429 remove the Private interface from the mapfile-vers file and the header file
430 to prevent it from being exported.  This may require moving the Private
431 interface into a library-private header file.  Scope reduction of Public
432 interfaces is forbidden.
434 For the interface to be used in more than one file within the library, it
435 should be in a header file that can be included by each file in the library
436 that uses the interface.  For example:
438         #include "libprivate.h"
440 5.4 How to copy interfaces which are part of a standard to a new or existing
441     library
443 SYSVABI and SISCD are reserved version names for interfaces listed in the
444 System V Interface Definition and the Sparc Compliance Definition.  Avoid using
445 these version names when copying the implementation of standard interfaces to
446 another library.  Instead, use ILLUMOS_0.1 for a new library, and ILLUMOS_m.n for
447 an existing library (where m.n is the next version; i.e., if the
448 last version was ILLUMOS_0.8, then you should version the interfaces with
449 ILLUMOS_0.9).
451 -------------------------------------------------------------------------------
453 6.0 Introducing a new library
455 6.1 Directories
457 The normal discipline for introducing a new library in illumos is to create a
458 new subdirectory of usr/src/lib.  The interface definition discipline is to
459 create a common/mapfile-vers file for the new library.  If we were introducing
460 a new foo library, libfoo, we'd create usr/src/lib/libfoo containing:
461         Makefile       amd64/         i386/          sparcv9/
462         Makefile.com   common/        sparc/
463 The common subdirectory would contain the normal source files plus the
464 mapfile-vers file.  See usr/src/lib/README.Makefiles for directions on
465 how to organize the Makefiles.
467 6.2 The mapfile
469 The new common/mapfile-vers file would contain:
471 $mapfile_version 2
473 SYMBOL_VERSION ILLUMOS_0.1 {    # first release of libfoo
474     global:
475         ...
478 SYMBOL_VERSION ILLUMOSprivate {
479     global:
480         ...
481     local:
482         *;
485 If there are no Public interfaces, the ILLUMOS_0.1 section would be omitted.
486 If there are no Private interfaces, the ILLUMOSprivate section would be
487 omitted and the two lines:
488     local:
489         *;
490 would be moved into ILLUMOS_0.1.
492 To decide which interfaces are Public (part of the ABI) and which are
493 Private (unstable interfaces not intended to be used by third parties), the
494 heuristic which works to a first approximation is that if it has a man page
495 then it's Public.
497 For maintainability, the list of names in each version block should
498 be sorted in dictionary order (sort -d).  Please comply.
500 -------------------------------------------------------------------------------
502 7.0 Make an entire library obsolete
504 7.1 Introduce SUNWobsolete version
506 Use this version name not for specific interfaces but for marking an entire
507 library as obsolete.  The existing public/private version names are left
508 unchanged, but a new SUNWobsolete version is created with no symbols in it.
509 This becomes a tag by which the obsolescence of the library can be recognized.
510 There is no numbering of this version name.
512 $mapfile_version 2
514 SYMBOL_VERSION SUNWobsolete {
515     global:
516         SUNWobsolete;   # This is the only way to do it.
517 } SUNW_1.2;
519 SYMBOL_VERSION ILLUMOS_0.2 {
522 You should continue to use the name SUNWobsolete even in illumos.
524 -------------------------------------------------------------------------------
526 8.0 Documentation
528 For further information, please refer to the following documents:
530         "Solaris Linker and Libraries Guide"