将 -rdynamic 链接器选项添加到 gcc/g++ 会影响性能吗? [英] Will adding the -rdynamic linker option to gcc/g++ impact performance?

查看:22
本文介绍了将 -rdynamic 链接器选项添加到 gcc/g++ 会影响性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在应用程序崩溃时获取堆栈跟踪.我知道 -rdynamic 选项可以使用函数名称获取完整的堆栈跟踪.但我担心是否会对我的应用程序的性能产生任何影响.

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.

推荐答案

是的,虽然它非常具体,通常不会引起关注.

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

-rdynamic 选项指示链接器将运行时通常不需要的符号添加到符号表中.这意味着动态链接器需要在运行时清除更多(可能更多)符号以进行符号解析.

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.

具体来说,由于基于 GNU 的系统中的符号表查找是使用散列实现的,因此具有更多符号会增加发生散列冲突的机会.由于在哈希表中发生冲突的所有符号都位于一个列表中,因此运行时链接器需要遍历该列表并使用 memcmp 比较每个符号名称.有更多符号在哈希中发生冲突意味着列表更长,因此解析每个动态符号需要更多时间.

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.

这种情况对于 C++ 来说比 C 稍差,由于类名的原因,有大量前缀相同的符号名.

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.

在极少数情况下,您的应用程序如此庞大,可以使用 prelinking 之类的技巧来克服开销.

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

这篇关于将 -rdynamic 链接器选项添加到 gcc/g++ 会影响性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆