I am in the process of building a shared object which needs to link to a function to a shared object (libstdc++
). This function is exported as WEAK and has also a default version (func@@V1
).
When I build an executable I can use the gcc asm directive to forcefully link to that specific revision, i.e.
__asm__(".symver func,func@V1")
And the executable not only builds fine and looking as the symbols with readelf -Wa
I can see it’s requiring func@V1
.
If instead I try to build the same code as a shared object (with flags -fPIC
and -shared
), I get the following error:
No symbol version section for versioned symbol func@V1
If I then remove the __asm__ symver
directive I can link the shared object, but the linkage to func
is unversioned (i.e. looking at the shared object with readelf -Wa
I can see a reference to func
but not func@V1
).
Why is it?
Is there a way to have the shared object link to a versioned WEAK symbol?
Thanks
Ps. The function is a C++ function exported by libstdc++.so.6, but I wanted to keep the example simple to understand