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