[Qbs] Question about linking (linux-gcc)
Christian Kandeler
christian.kandeler at qt.io
Thu Nov 23 11:21:18 CET 2017
On Thu, 23 Nov 2017 13:00:56 +1300
Christian Gagneraud <chgans at gmail.com> wrote:
> First the simple one:
> What is the best way to choose which binutils linker to use? I would
> like to activate the gold linker instead of the bfd one (default), gcc
> option for this is "-fuse-ld=gold", I think this option *has* to be
> passed to gcc, so i wonder if cpp.linkerFlags is the correct place, I
> know it works, but i'm curious to know if there's a better way to do it.
It's conceptually wrong, but will in practice work for C and C++
projects, because it's always the gcc/g++ executable that gets invoked.
In 1.11, there will be cpp.driverLinkerFlags, which is the correct property for this.
One might also think about introducing a dedicated convenience property for this. Not sure if it's worth it.
> My 2nd question requires a bit of explanation first:
> I need to link an app against lots of static libraries. Each static
> library has a list of Depends (mostly Qt deps).
> Qbs generate a link command for my app by simply appending all the libs'
> depends. So I endup with a very-very long command line that contains
> hundreds of duplicated Qt linking fragments.
> The actual link command is 49384 character longs!
Yes, this is an "interesting" problem. We cannot simply remove duplicate libraries, due to the way ld works. But there could still be a way to do some safe reductions there. You might want to create a task for that, preferably with a full example command line attached.
> Is it possible to work this around?
I can't think of anything right now. Since the linker does not fail outright, but is just very slow, I guess this problem is not the raw command line length, but the number of libraries, which seem to get processed over and over again.
> I have the feeling that it might be due to the use of lto, as the g++
> sub-process starts with: /usr/bin/ld -plugin .../liblto_plugin.co
>
> When I use the gold linker (with qbs) I do not have this problem, even
> tho the subprocess starts with /usr/bin/ld.gold -plugin .../liblto_plugin.co
>
> Any idea about that, is it a qbs issue or should I blame it on the bfd
> linker?
Well, I suppose both are trying a little less hard than they could be...
Christian
More information about the Qbs
mailing list