Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a downside to using -Bsymbolic-functions?

I recently discovered the linker option "-Bsymbolic-functions" in GNU ld:

-Bsymbolic   When creating a shared library, bind references to global symbols to the    definition within the shared library, if any. Normally, it is possible    for a program linked against a shared library to override the definition    within the shared library.     This option is only meaningful on ELF platforms which support shared libraries.  -Bsymbolic-functions   When creating a shared library, bind references to global function symbols    to the definition within the shared library, if any.      This option is only meaningful on ELF platforms which support shared libraries. 

This seems to be the inverse of the GCC option -fvisibility=hidden, in that instead of preventing the export of the referenced function to other shared objects, it prevents library-internal references to that function from being bound to an an exported function of a different shared object. I informed myself that -Bsymbolic-functions will prevent the creation of PLT entries for the functions, which is a nice side effect.

  1. But I was wondering whether there is perhaps a finer-grained control over this, like overwriting -Bsymbolic for individual function definitions of a library.

  2. Should I be aware of any pitfalls of using -Bsymbolic-functions? I plan to only use that, because the -Bsymbolic will break exceptions, I think (it will make it so that references to typeinfo objects are not unified, I think).

Thanks!

like image 801
Johannes Schaub - litb Avatar asked Aug 27 '11 19:08

Johannes Schaub - litb


1 Answers

Answering my own question because I just earned a Tumbleweed badge for it... and I found out subsequently

But I was wondering whether there is perhaps a finer-grained control over this, like overwriting -Bsymbolic for individual function definitions of a library.

Yes, there is the option --dynamic-list which does exactly that

Should I be aware of any pitfalls of using -Bsymbolic-functions? I plan to only use that, because the -Bsymbolic will break exceptions, I think (it will make it so that references to typeinfo objects are not unified, I think).

I looked more into it, and it seems there is no issue. The libstdc++ library apparently does it or at least did consider it and they only had to add --dynamic-list-cpp-new to still have operator new unified (to prevent issues with multiple allocator / deallocators mixing up in a program but I would argue such programs are broken anyway). Ubuntu uses it or used it by default, and it seems it causes conflicts with some packages. But overall it should work nicely I expect.

like image 155
Johannes Schaub - litb Avatar answered Sep 19 '22 18:09

Johannes Schaub - litb