Lawrence Crowl, 2006-10-19, N2117=06-0187
The construction and use of dynamic libraries has become a significant requirement on modern software development. Unforutunatly, their interaction with C++ varies between implementations and is often underspecified on any given implementation.
This paper outlines a proposal that addresses these problems. The proposal is based on prior art, the Sun (and by extension System V) and Microsoft platforms.
When a dynamic library is statically linked, the programmer may specify a list of other dynamic libraries, upon which the current library depends.
The first feature required is a means to control the visibility of function, variable, and class symbols to references in other dynamic libraries. There are these categories of visibility.
The Unix default visibility for symbol definitions is global/interposable. The Microsoft default is hidden. The principle of least exposure says the default should be hidden.
The Unix default visibility for symbol references is global. The Microsoft default is hidden. Again, the principle of least exposure says the default should be hidden. However, this default essentially makes it impossible to share a header between the client of a library and the implementation of a library and to use existing headers. Therefore, the proposed default for references is noninterposable.
In order to handle symbol declaration in a common header and a definition within the library, symbols may be redeclared with a more restrictive visibility.
Syntactically, these visibilities most naturally match storage classes.
The one-definition rule must be modified somewhat to make hidden visibility viable. In particular, the one-definition rule must apply to symbols defined within a dynamic library, to symbols referenceable from other dynamic libraries. A consequence of this rule is that hidden types must yield typeids unique to the dynamic library of its definition.
The opening of a dynamic library will execute the dynamic initializers for namespace-scope static-duration variables defined within the dynamic library. The opening of a library will not return until the initialization is complete.
The closing of a dynamic library will execute the destructors for namespace-scope static-duration variables defined within the dynamic library. The closing of a library will not return until the destruction is complete.