Search code examples
gccshared-librariessymbolselfdynamic-linking

Why do we need -rdynamic option in gcc?


By default all symbols are exported to dynamic table, so why would we use -rdynamic flag? Even if we hide some symbols via attributes/-fvisibility=hidden - -rdynamic doesn't change result, it doesn't unhide previously hidden symbols. So what's the point in it?


Solution

  • Symbols are only exported by default from shared libraries. -rdynamic tells linker to do the same for executables. Normally that's a bad idea but sometimes you want to provide APIs for dynamically loaded plugins and then this comes handy (even though one much better off using explicit visibility annotations, version script or dynamic export file).