c++elf

What is the difference of weak and unique symbol binding?


A c++17 inline variable will be compiled to a unique symbol by gcc. If use clang it will be a weak symbol.

I found documentation of symbol binding at Oracle Linker, but there is no unique binding in it. So what does unique binding mean?


Solution

  • "Unique symbols" are an older GCC hack. Clang doesn't need them, and GCC can be configured not to use them either.

    The linker handles them by not loading the same symbol twice, i.e. merging multiple symbols into one. This prevents the library defining them from being unloaded, as it may have been the source of the merged symbol.