small development tip: Consider using the gold linker

Started by Andres Freundalmost 8 years ago5 messageshackers
Jump to latest
#1Andres Freund
andres@anarazel.de

Hi,

FWIW, I've lately noticed that I spend a fair time waiting for the
linker during edit-compile-test cycles. Due to an independent issue I
just used the gold linker, and the speedup is quite noticable.

Just relinking the backend, without rebuilding anything else, goes from
0m3.975s to 0m1.585s. Given ccache commonly prevents actually having to
recompile files, that works out to a noticable benefit.

For me just adding '-fuse-ld=gold' to CFLAGS works.

Unfortunately I get some spurious warnings, but I hope that's just a
debian unstable issue: /usr/bin/ld.gold: warning: discarding version
information for __cxa_finalize@GLIBC_2.2.5, defined in unused shared
library /lib/x86_64-linux-gnu/libc.so.6 (linked with --as-needed)

Greetings,

Andres Freund

In reply to: Andres Freund (#1)
Re: small development tip: Consider using the gold linker

On Mon, Jul 9, 2018 at 4:40 PM, Andres Freund <andres@anarazel.de> wrote:

FWIW, I've lately noticed that I spend a fair time waiting for the
linker during edit-compile-test cycles. Due to an independent issue I
just used the gold linker, and the speedup is quite noticable.

Just relinking the backend, without rebuilding anything else, goes from
0m3.975s to 0m1.585s. Given ccache commonly prevents actually having to
recompile files, that works out to a noticable benefit.

For me just adding '-fuse-ld=gold' to CFLAGS works.

I tried this out today. It makes quite a noticeable difference for me.
Thanks for the tip.

Unfortunately I get some spurious warnings, but I hope that's just a
debian unstable issue: /usr/bin/ld.gold: warning: discarding version
information for __cxa_finalize@GLIBC_2.2.5, defined in unused shared
library /lib/x86_64-linux-gnu/libc.so.6 (linked with --as-needed)

I didn't have this problem.

--
Peter Geoghegan

In reply to: Peter Geoghegan (#2)
Re: small development tip: Consider using the gold linker

On Fri, Jul 20, 2018 at 8:16 PM Peter Geoghegan <pg@bowt.ie> wrote:

On Mon, Jul 9, 2018 at 4:40 PM, Andres Freund <andres@anarazel.de> wrote:

FWIW, I've lately noticed that I spend a fair time waiting for the
linker during edit-compile-test cycles. Due to an independent issue I
just used the gold linker, and the speedup is quite noticable.
For me just adding '-fuse-ld=gold' to CFLAGS works.

I tried this out today. It makes quite a noticeable difference for me.
Thanks for the tip.

The 2022 version of the same tip: switching over to LLVM lld seems to
offer a further significant speedup over gold. Not surprising, since
lld is specifically promoted as a linker that is faster than gold [1]https://llvm.org/devmtg/2017-10/slides/Ueyama-lld.pdf - slide 14.
Again, this appears to just be a case of installing lld, and adding
'-fuse-ld=lld' to CFLAGS -- a very easy switch to make. Link time is
still a noticeable contributor to overall build time for me, even with
gold (I use ccache, of course).

There is another linker called mold [2]https://github.com/rui314/mold -- Peter Geoghegan. It claims to be faster than
lld (which was faster than gold, which was faster than ld). I didn't
bother trying it out.

[1]: https://llvm.org/devmtg/2017-10/slides/Ueyama-lld.pdf - slide 14
[2]: https://github.com/rui314/mold -- Peter Geoghegan
--
Peter Geoghegan

#4Andres Freund
andres@anarazel.de
In reply to: Peter Geoghegan (#3)
Re: small development tip: Consider using the gold linker

Hi,

On 2022-01-13 19:24:09 -0800, Peter Geoghegan wrote:

On Fri, Jul 20, 2018 at 8:16 PM Peter Geoghegan <pg@bowt.ie> wrote:

On Mon, Jul 9, 2018 at 4:40 PM, Andres Freund <andres@anarazel.de> wrote:

FWIW, I've lately noticed that I spend a fair time waiting for the
linker during edit-compile-test cycles. Due to an independent issue I
just used the gold linker, and the speedup is quite noticable.
For me just adding '-fuse-ld=gold' to CFLAGS works.

I tried this out today. It makes quite a noticeable difference for me.
Thanks for the tip.

The 2022 version of the same tip: switching over to LLVM lld seems to
offer a further significant speedup over gold. Not surprising, since
lld is specifically promoted as a linker that is faster than gold [1].

I've switched back and forth between gold and lld a couple times. Eventually I
always get frustrated by lld causing slowdowns and other issues for gdb. Did
you ever hit one of those?

Again, this appears to just be a case of installing lld, and adding
'-fuse-ld=lld' to CFLAGS -- a very easy switch to make. Link time is
still a noticeable contributor to overall build time for me, even with
gold (I use ccache, of course).

Yea. gold also isn't really maintained anymore, so it'd be nice to move on...

There is another linker called mold [2]. It claims to be faster than
lld (which was faster than gold, which was faster than ld). I didn't
bother trying it out.

Yea, didn't yet quite seem there yet last time I looked, and lld seems plenty
fast for our purposes.

Greetings,

Andres Freund

In reply to: Andres Freund (#4)
Re: small development tip: Consider using the gold linker

On Tue, Feb 22, 2022 at 4:26 PM Andres Freund <andres@anarazel.de> wrote:

I've switched back and forth between gold and lld a couple times. Eventually I
always get frustrated by lld causing slowdowns and other issues for gdb. Did
you ever hit one of those?

Now that you mention it...gdb was very slow the last few times I used
it, which wasn't for long enough for it to really matter. This must
have been why. I might have to rescind my recommendation of lld.

--
Peter Geoghegan