确定哪些对象文件导致 .dll 大小增加 [C++]

发布于 2024-07-21 20:18:35 字数 232 浏览 5 评论 0原文

我正在开发一个大型的 C++ 构建库,该库最近增长了很多。 由于其尺寸较大,导致尺寸增加的原因尚不清楚。

您是否有任何可以帮助确定增长来自何处的工具(msvc 或 gcc)建议。

编辑 我尝试过的事情:转储最终的 dll、obj 文件、创建映射文件并翻阅它。

再次编辑 所以 objdump 和 python 脚本似乎已经完成了我想要的。

I'm working on a large c++ built library that has grown by a significant amount recently. Due to it's size, it is not obvious what has caused this size increase.

Do you have any suggestions of tools (msvc or gcc) that could help determine where the growth has come from.

edit
Things i've tried: Dumpbin the final dll, the obj files, creating a map file and ripping through it.

edit again
So objdump along with a python script seems to have done what I want.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

邮友 2024-07-28 20:18:35

如果是 gcc,则 objdump。 如果是 Visual Studio,则为 dumpbin

我建议对旧(小)库和新(大)库的工具输出进行比较。

If gcc, objdump. If visual studio, dumpbin.

I'd suggest doing a diff of the output of the tool for the old (small) library, vs. the new (large) library.

微凉徒眸意 2024-07-28 20:18:35

keyersoze 的答案(比较 objdump 或 dumpbin 的输出)是正确的。 另一种方法是告诉链接器生成一个映射文件,并比较映射文件中的 DLL 的新旧版本。

  • MSVC: link.exe /MAP< /code>
  • GCC 和 binutils:ld -M(或gcc -Wl,-M

keysersoze's answer (compare the output of objdump or dumpbin) is correct. Another approach is to tell the linker to produce a map file, and compare the map files for the old and new versions of the DLL.

  • MSVC: link.exe /MAP
  • GCC and binutils: ld -M (or gcc -Wl,-M)
玉环 2024-07-28 20:18:35

在 Linux 上,应该很容易通过递归差异查看是否添加了新文件。 他们肯定会增加图书馆的规模。 然后,您可以在 Linux 上使用 size 命令行工具来获取每个新对象文件的大小并将其相加。 然后将该总和与您的图书馆增量进行比较,并检查其差异有多大。

On Linux it should be quite easy to see if new files have been added with a recursive diff. They would certainly create an increase in the library size. You can then go an use the size command line tool on Linux to get the sizes of each of the new object files and sum them up. Then compare that sum to your library increase and check how much it differs.

追星践月 2024-07-28 20:18:35

天哪,

如果您有任何以前版本的目标文件,您可以运行 size 命令来查看哪个段已增长吗?

有几个问题:

  • 您使用的是 *nix 平台还是 Windows 平台?
  • 您使用哪个编译器?
  • 最近是否更改了编译器?
  • 最近添加了 -g 标志吗? (明显的问题1)
  • 该物体之前是否被剥离过? (明显的问题2)
  • 该对象以前是动态链接的吗? (明显的问题 3)

编辑:如果代码位于 SCM 下,您能否查看为您提供较小对象的源版本。 然后比较:

  1. 通过在旧源树上执行 du -sk ,然后在新源树上执行 du -sk 来比较源树的大小,而无需构建任何内容。
  2. 通过执行类似 find ./tree_top ( -name *.h -o -name *.cpp ) | 的操作来计算文件数量 wc -l 通过执行 find ./tree_top ( -name *.h -o -name *.cpp ) -print | wc -l 来
  3. 增加文件数量的位置 排序> treelist 然后对新的更大的树执行相同的操作。 执行简单的 sdiff 将显示大量新文件。
  4. 代码库的大小,即使是简单的尾随分号计数也会为您提供一个很好的基本机制来比较两者。
  5. Makefiles 或构建环境。 以便项目查看不同的选项或设置是否已渗透到构建本身中。

HTH

顺便说一句 请在此处发布您的发现,因为我确信很多人对您的发现感兴趣。

干杯,

G'day,

If you have any previous versions of the object file laying around can you run the size command to see which segment has grown?

Couple of questions:

  • Are you on a *nix platform or a Windows platform?
  • Which compiler are you using?
  • Was the compiler recently changed?
  • Was the -g flag added recently? (obvious question 1)
  • Was the object previously stripped? (obvious question 2)
  • Was the object dynamically linked previously? (obvious question 3)

Edit: If the code is under SCM, can you check out a version of the source that gave you the smaller object. Then compare:

  1. the size of the source trees by doing a du -sk on the old source tree and then the new source tree without having built anything.
  2. the number of files by doing something like find ./tree_top ( -name *.h -o -name *.cpp ) | wc -l
  3. the location of an increased number of files by doing a find ./tree_top ( -name *.h -o -name *.cpp ) -print | sort > treelist and then do the same for the new larger tree. Doing a simple sdiff will show any large number of new files.
  4. the size of code base, even a simple count of trailing semi-colons will give you a good basic mechanism for comparison between the two.
  5. the Makefiles or build env. for the project to see if different options or settings have crept in to the build itself.

HTH

BTW Please post your findings here as I'm sure many people are interested in what you find out.

cheers,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文