静态链接系统库、libc、pthreads,以帮助调试 [英] Statically linking system libraries, libc, pthreads, to aid in debugging

查看:34
本文介绍了静态链接系统库、libc、pthreads,以帮助调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图避免 Stackoverflow 条目中描述的情况:调试客户盒子上生成的核心文件.如果我静态编译所有库,我会避免在核心转储时始终收集共享库吗?我基本上想处于一种可以使用 gdb 加载核心文件并检查崩溃的应用程序的情况.

I am trying to avoid the situation described in this Stackoverflow entry: Debugging core files generated on a Customer's box. If I compile all the libraries statically will I avoid having to always gather the shared libraries when it core dumps? I essentially want to be in a situation where I can just load up the core file with gdb and examine the crashed application.

如果我走静态链接我们需要的所有库的路线,我应该注意什么.我认为 glib 和 pthreads 可能会导致最大的问题.

What should I watch out for if I go down the route of statically linking all the libraries we need. I figure glib and pthreads might cause the biggest problems.

Valgrind 会不再有用吗?如果我针对所有静态编译的二进制文件加载 Valgrind,它会发现错误吗?或者我们应该维护一个非静态编译的二进制文件,以便 Valgrind 继续工作.strace 呢?

Will Valgrind cease to be useful? If I load up Valgrind against the binary which has everything statically compiled will it find errors? Or shall we maintain a binary that isn't statically compiled so Valgrind continues to work. How about strace?

我们经常崩溃,因为我们拥有庞大的安装基础,而且它也是一个遗留应用程序.收集所有共享库变得难以处理 - 我需要另一个解决方案.

We crashes quite often as we have a large install base and it is also a legacy application. Gathering up all the shared libraries is becoming intractable - I need another solution.

修正错字.

推荐答案

如果我静态编译所有库,我将避免在核心转储时始终收集共享库

If I compile all the libraries statically will I avoid having to always gather the shared libraries when it core dumps

是的.

然而,与流行的看法相反,静态链接的二进制文件比动态链接的二进制文件更不便携(至少在 Linux 上).

However, contrary to popular belief, statically linked binaries are less portable than dynamically linked ones (at least on Linux).

特别是,如果您使用以下任何函数:gethostbynamegethostbyaddrgetpwentgetpwnamgetpwuid(还有更多),您将在链接时收到警告,类似于:

In particular, if you use any of these functions: gethostbyname, gethostbyaddr, getpwent, getpwnam, getpwuid (and a whole lot more), you will get a warning at link time, similar to this:

Using 'getpwuid' in statically linked applications requires at runtime
the shared libraries from the glibc version used for linking.

此警告的意思是 IF 您的客户安装的 glibc 版本与您在链接时使用的版本不同(即不同于 您的 系统 libc),那么您的程序可能会崩溃.由于这显然比您当前的情况更糟,因此我认为静态链接对您来说不是一个好的解决方案.

What this warning means is that IF your customer has a different version of glibc installed from the one you used at link time (i.e. different from your system libc), THEN your program will likely crash. Since that is a clearly worse situation than your current one, I don't believe static linking is a good solution for you.

这篇关于静态链接系统库、libc、pthreads,以帮助调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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