https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92572
Alexander Monakov <amonakov at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amonakov at gcc dot gnu.org --- Comment #2 from Alexander Monakov <amonakov at gcc dot gnu.org> --- Please show output of 'cc -v' and attach assembly for main.cc. Providing vague linkage semantics with dynamic linking is a tricky area, especially when dlopen is in play, moreso with RTLD_LOCAL as in this example. For example, if you wanted vague-linkage objects to be unified across multiple dlopen'ed libraries (each with RTLD_LOCAL), you'd need special support from the toolchain and the dynamic linker. At some point GNU toolchain invented a new special ELF symbol binding type, STB_GNU_UNIQUE, but it turned out to cause other issues. It can be disabled in the compiler with --disable-gnu-unique-object, in which case the outcome you show here is expected. I think on non-GNU systems you'll likely get "1" rather than "2".