Weak characters and dlopen () with clang vs. gcc

I have a library that defines something like this:

    //singleton.hpp
    class Singleton
    {
    public:
      static Singleton* getInstance()
      {
        static Singleton* mInstance=0;
        if (!mInstance)
        {
            mInstance=new Singleton();
        }
        return mInstance;
      }
    };

I include this header when creating multiple shared object libraries. When I create these shared object libraries using gcc (Ubuntu), the static data becomes marked as unique: (nm output)

0000000000045780 u Singleton :: mInstance

When I create shared libraries with clang, the same character becomes marked as weak:

0000000000045780 V Singleton :: mInstance

dlopen (..., RT_NOW) gcc-built shared objects, , , mInstance. , dlopen (..., RT_NOW) clang-built shared objects, , singleton . ? , , gcc?

+4

Source: https://habr.com/ru/post/1658342/


All Articles