Will adding the -rdynamic linker option to gcc/g++ impact performance?
Asked Answered
O

1

23

I want to get the stack trace when the application crashes. I understand that the -rdynamic option enables to get the complete stack trace with the function names. But I'm concerned if there will be any impact on the performance of my application.

Outherod answered 28/9, 2012 at 5:31 Comment(0)
B
30

Yes, there is, although it is very specific and normally not a cause of concern.

The -rdynamic option instructs the linker to add symbols to the symbol tables that are not normally needed at run time. It means there are more, possibly many more, symbols that the dynamic linker needs to weed through at run time for symbol resolution.

Specifically, since symbol table lookups in GNU based systems are implemented using a hash, having more symbols increases the chance that there would be hash collisions. Since all symols that collide in the hash table sit in a list, the run time linker needs to traverse the list and compare, using memcmp, each symbol name. Having more symbols collide in the hash meaning having longer lists and so it will take more time to resolve each dynamic symbol.

This situation is slightly worse for C++ then C, with the multitude of identically prefixed symbol names due to class names.

In practice, this only effects the very first time that a symbol is used and so, unless your application is very large and contains a lot of symbols, it will not be felt.

In the rare case that your application is that large, tricks like prelinking can be used to overcome the overhead.

Balikpapan answered 28/9, 2012 at 8:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.