在C / C ++应用程序中分析过多代码大小的一些技术或工具是什么? [英] What are some techniques or tools for profiling excessive code size in C/C++ applications?

查看:139
本文介绍了在C / C ++应用程序中分析过多代码大小的一些技术或工具是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++库,可以生成更大的代码,我真正期望它能做什么。从少于50K行的源代码中,我得到几乎4MB的共享对象和9个静态存档。这是有问题的,因为库的二进制文件非常大,而且更糟糕的是,甚至连接它的简单应用程序通常也会增加500到1000 KB代码大小。用像-Os这样的标志编译这个库会有所帮助,但并不是非常有用。



我也尝试过使用GCC的-frepo命令(尽管所有文档都是'我们已经看到,在Linux上collect2会合并重复的模板),模板上的显式模板实例化似乎很可能会被重复,但在任何情况下都没有实际效果。当然,我会说很可能,因为与任何类型的分析一样,这种盲目猜测几乎总是错误的。

是否有一些工具可以轻松进行配置代码大小或其他方式,我可以弄清楚什么是占用这么多空间,或者更一般地说,我应该尝试其他任何事情?在Linux下运行的东西将是理想的,但我会尽我所能。

解决方案

如果你想知道什么正在被放入你的可执行文件,然后问你的工具。打开ld链接器的--print-map(或-M)选项以生成一个映射文件,其中显示了它在内存中的位置以及位置。如果你不是直接调用ld,而只是通过gcc命令行,你可以传递ld特定的选项在gcc命令行输入ld,前面加上 -Wl,


I have a C++ library that generates much larger code that I would really expect for what it is doing. From less than 50K lines of source I get shared objects that are almost 4 MB and static archives pushing 9. This is problematic both because the library binaries are quite large, and, much worse, even simple applications linking against it typically gain 500 to 1000 KB in code size. Compiling the library with flags like -Os helps this somewhat, but not really very much.

I have also experimented with GCC's -frepo command (even though all the documentation I've seen suggests that on Linux collect2 will merge duplicate templates anyway) and explicit template instantiation on templates that seemed "likely" to be duplicated a lot, but with no real effect in either case. Of course I say "likely" because, as with any kind of profiling, blind guessing like this is almost always wrong.

Is there some tool that makes it easy to profile code size, or some other way I can figure out what is taking up so much room, or, more generally, any other things I should try? Something that works under Linux would be ideal but I'll take what I can get.

解决方案

If you want to find out what is being put into your executable, then ask your tools. Turn on the ld linker's --print-map (or -M) option to produce a map file showing what it has put in memory and where. Doing this for the static linked example is probably more informative.

If you're not invoking ld directly, but only via the gcc command line, you can pass ld specific options to ld from the gcc command line by preceding them with -Wl,.

这篇关于在C / C ++应用程序中分析过多代码大小的一些技术或工具是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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