如何确定最快的链接顺序? [英] How do I determine the fastest link order?

查看:109
本文介绍了如何确定最快的链接顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大约50个不同的静态库链接到我的c ++项目中,并且链接平均需要70秒钟.

I have about 50 different static libraries being linked into my c++ project and the linking takes on average 70s.

我发现,按照库的链接顺序移动这次会发生变化.我想这是可以预期的,如果链接器不必在到目前为止已建立的整个符号表中继续搜索一组符号.

I've found that moving around with the link order of the libraries changes this time. This is expected I guess if the linker doesn't have to keep searching for a set of symbols throughout the entire symbol table it has built upto that point.

我想我可以使用"nm"来获取静态库之间的依赖关系图.但是,那只会给我一个正确"的链接顺序.获取最快的链接顺序会涉及哪些因素?

I suppose I could use "nm" to get a dependency graph between the static libraries. However, that would only give me one "correct" link order. What would be the factors involved in obtaining the fastest link order?

我感觉到,通过遍历将试图最小化某些数量的遍历,它与上述依赖关系图有关,但是我真的不确定是哪一个.

I get the feeling that it would have something to do with the above-mentioned dependency graph by getting a traversal that would try to minimize some quantity but I'm really not sure which.

任何帮助将不胜感激.

Any help would be appreciated.

我主要时不时使用intel编译器和gcc编译器.当我与top一起检查时,它们似乎都在使用GNU ld链接器.希望这对您有帮助...

I am primarily using the intel compiler and also the gcc compiler every now and then. Both of them seem to be using the GNU ld linker when I check it with top. Hope this helps...

因此,为了澄清我想问的问题,我已经知道如何从一组静态库中获得1-pass排序.我自己编写了这个脚本,但是正如下面奥拉夫的答案所暗示的那样,有一些知名的工具可以执行此操作.

So just to clarify a bit more on what I'm trying to ask, I already know how to get a 1-pass ordering from a set of static libraries. I'd written this script myself but as Olaf's answer below suggests, there are well-known tools for doing this.

我的问题是,我已经有两个1-pass链接顺序,其中一个在〜85s内运行,另一个在〜70s内运行.很明显,我们仍然可以在1次通过订单中进行更多优化.

My question is, I already have two 1-pass link orderings one of which runs in ~85s and the other one runs in ~70s. So clearly, there is still some more optimization that we can do within 1-pass orders.

推荐答案

作为替代方案,为什么不尝试将您的库编译为共享库而不是静态库?

As an alternative, why not try compiling your libraries to shared libraries rather than static libraries?

在我工作的地方,一个大型项目的链接时间约为6分钟,而这仅适用于5个库!

Where I work, one large projects link time was around 6 minutes, this was for only 5 libraries!

我的解决方案是(对于调试版本),按字母顺序创建.so文件(libA.so,libB.so等),以使每个单独的链接都不太长,并且最终链接要短得多,因为所有(部分)链接之前已完成.该发行版本是用老式的方式构建的,因为我的新方法存在一种危险".

My solution was (for a debug version), create .so files alphabetically (libA.so, libB.so etc) so each indivdual link wasn't too long, and the final link was much shorter, because all the (partial) linking had been done previously. The release version was built in the old fashioned way because there was a perceived 'danger' with my new method.

使用这种方法,我设法将1个模块的编译/链接周期从6分钟缩短到10秒.

I managed to get a 1 module compile/link cycle down from 6 minutes to 10 seconds using this method.

这篇关于如何确定最快的链接顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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