Binary Compatibility of Shared Libraries Implemented in C++ on GNU / Linux Systems
A shared library is a ﬁle that contains library code and data in binary form. Application built against the library references the data via symbols and the contents of what’s being referenced get known only during the application startup. Library is shipped with header ﬁle(s) the program is compiled with. The problem of the binary compatibility arises when the new version of library is installed into system and the program, having not been recompiled, is attempted to run in the environment with the new library. The incompatibility may result in fatal errors during the startup or even during the runtime. In this article we deduce the rules that must be followed in order to keep the binary compatibility of a shared library. Unlike most of researches in this area, we also assume that the library may contain its own restrictions upon its usage, more powerful than restrictions of C++ language itself. So the possible restrictions are analyzed as well, and we attempt to weaken the rules of binary compatibility when such restrictions are enforced. As a conclusion we list the rules a programmer should follow to keep his or her library binary compatible. We also conclude that possible restrictions limiting the use of library allow to weaken these rules in relatively small number of cases. For the purpose of this study, we create formal notation for the process of building and using a library, introduce formal deﬁnitions of source and binary compatibility and of program behavior. We base the assumptions about mapping source code entities to binary level on the Itanium C++ ABI standard, which describes gcc’s way of emitting binary code and data.