Restriction of symbols in a shared library.
I have an application which links to two libraries, a static library, “libstatic.a” and a dynamic library, “libdynamic.so”. The dynamic library “libdynamic.so” also internally links to “libstatic.a”.
A global variable is defined in libstatic.a and is accessed in both test application and libdynamic.so.
I'm exporting required symbols of libdynamic.so to the application using libdynamic.map file with --version-scripts linker option. libdynamic.map file is defined as:
When there is no restriction of symbols by libdynamic.so, there is only one copy of libstatic.a used by both test application and libstatic library.
When libdynamic.so exports its required symbols to the test application, there will be two copies of libstatic in the memory. In this case, libdynamic.so resolves its global libstatic symbols in its own copy while the test application looks into its copy of libstatic.
Is there a way/option to force libdynamic.so use the libstatic.a which is
used by the application, so that there is only one copy of libstatic.a in
I understand that the simpler workaround in this case is to export libstatic
global symbols along with its symbols by libdynamic.so. But I do not prefer
this as I have to keep track of all globals in libstatic library. Is there any better solution?