Suppose an application myapp.exe is built using g++ and it uses the flag -static-libstdc++ so that it can be installed in enviroments without libstdc++.so. myapp.exe also adds plugin support for some function plugf that can be dynamically loading via dlopen from a shard library.
If libplug.so is such a plugin library that also links to libstdc++, how can it do so in a way to be able to work with myapp.exe?
This is straightforward if libstdc++ is linked in dynamically since both myapp.exe and libplug.so can use the same dynamically loaded standard library, but it's not clear to me how best to do this with statically linked standard libraries.
An approach I'm considering is to have libplug.so also use the flag -static-libstdc++ and then use the version script
{
global: plugf;
local: *;
};
to ensure that its version of the standard library is used, but that would mean there would be two copies of libstdc++ loaded into memory. I know this approach wouldn't be blessed by the C++ standard since it would have ORD violations, but is it something that libstdc++ supports in any way? The Multiple ABI testing section of its manual section does reference a scenario that sounds similar.
libplug.so- and yes, two copies would be loaded at runtime. And yes, you might get in trouble if your plugin returns a pointer with one version of libstdc++ and you free it with another version.-static-libstdc++doesn't causelibcto be linked in statically so they are both using the samelibc.so.__gnu_cxx::new_allocatorin libstdc++, perhaps as you point out they both go to the samelibc.so. From personal experience I've had the aforementioned problem using MSVC's RT.new int{123}callsoperator newwhich in libstdc++ is just a wrapper for malloc. (See here).