From 3ebfb38855c896d7e68eea6f7bebf5548235073f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 25 Apr 2024 11:46:40 +0000 Subject: [PATCH 1/8] add announcement for `rust-lld` on linux nightlies --- .../2024-05-01-enabling-rust-lld-on-linux.md | 83 ++++++++++++++++++ .../ripgrep-comparison.png | Bin 0 -> 10192 bytes 2 files changed, 83 insertions(+) create mode 100644 posts/inside-rust/2024-05-01-enabling-rust-lld-on-linux.md create mode 100644 static/images/inside-rust/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png diff --git a/posts/inside-rust/2024-05-01-enabling-rust-lld-on-linux.md b/posts/inside-rust/2024-05-01-enabling-rust-lld-on-linux.md new file mode 100644 index 000000000..12b0c5162 --- /dev/null +++ b/posts/inside-rust/2024-05-01-enabling-rust-lld-on-linux.md @@ -0,0 +1,83 @@ +--- +layout: post +title: Faster linking times on nightly on linux with `rust-lld` +author: Rémy Rakic +team: The compiler performance working group +--- + +TL;DR: rustc will use `rust-lld` by default on `x86_64-unknown-linux-gnu` on nightly to +significantly reduce linking times. + +#### Some context + +Linking time is often a big part of compilation time. When rustc needs to build a binary or a shared +library, it will usually call the default linker installed on the system to do that (this can be +changed on the command-line or by the target for which the code is compiled). + +The linkers do an important job, with concerns about stability, backwards-compatibility and so on. +For these and other reasons, on the most popular operating systems they usually are older programs, +designed when computers only had a single core. So, they usually tend to be slow on a modern +machine. For example, when building ripgrep 13 in debug mode on linux, roughly half of the time is +actually spent in the linker. + +There are different linkers, however, and the usual advice to improve linking times is to use one of +these newer and faster linkers, like LLVM's [`lld`](https://lld.llvm.org/) or Rui Ueyama's +[`mold`](https://github.com/rui314/mold). + +Some of rust's wasm and aarch64 targets already use `lld` by default. When using rustup, rustc ships +with a version of `lld` for this purpose. When CI builds LLVM to use in the compiler, it also builds +the linker and packages it. It's referred to as `rust-lld` to avoid colliding with any `lld` already +installed on the user's machine. + +Since improvements to linking times are substantial, it would be a good default to use in the most +popular targets. This has been discussed for a long time, for example in issues +[#39915](https://github.com/rust-lang/rust/issues/39915) and +[#71515](https://github.com/rust-lang/rust/issues/71515), and rustc already offers nightly flags to +use `rust-lld`. + +By now, we believe we've done all the internal testing that we could, on CI, crater, our +benchmarking infrastructure, and would like to expand testing and gather real-world feedback and +use-cases. Therefore, we will enable `rust-lld` to be the linker used by default on +`x86_64-unknown-linux-gnu` for nightly builds. + +#### Benefits + +While this also enables the compiler to use more linker features in the future, the most immediate +benefit is much improved linking times. + +Here are more details from the ripgrep example mentioned above: linking is reduced 7x, resulting in +a 40% reduction in end-to-end compilation times. + +![Before/after comparison of a `ripgrep` debug build](../../../../images/inside-rust/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png) + +Most binaries should see some improvements here, but it's especially significant with e.g. bigger +binaries, or when involving debuginfo. These usually see bottlenecks in the linker. + +Here's [a +link](https://perf.rust-lang.org/compare.html?start=b3e117044c7f707293edc040edb93e7ec5f7040a&end=baed03c51a68376c1789cc373581eea0daf89967&stat=instructions%3Au&tab=compile) +to the complete results from our benchmarks. + +If testing goes well, we can then stabilize using this faster linker by default for +`x86_64-unknown-linux-gnu` users, before maybe looking at other targets. + +#### Possible drawbacks + +From our prior testing, we don't really expect issues to happen in practice. it is a drop-in +replacement for the vast majority of cases, but `lld` is not _bug-for-bug_ compatible with GNU ld. + +In any case, using `rust-lld` can be disabled if any problem occurs: use the `-Z +linker-features=-lld` flag to revert to using the system's default linker. + +Some crates somehow relying on these differences could need additional link args. For example, we +saw <20 crates in the crater run failing to link because of a different default about [encapsulation +symbols](https://lld.llvm.org/ELF/start-stop-gc): these could require +`-Clink-arg=-Wl,-z,nostart-stop-gc` to match the legacy GNU ld behavior. + +Some of the big gains in performance come from parallelism, which could be undesirable in +resource-constrained environments. + +#### Summary + +rustc will use `rust-lld` on `x86_64-unknown-linux-gnu` nightlies, for much improved linking times. +Let us know if you encounter problems, by opening an issue on github. If that happens, you can +revert to the default linker with the `-Z linker-features=-lld` flag. diff --git a/static/images/inside-rust/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png b/static/images/inside-rust/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png new file mode 100644 index 0000000000000000000000000000000000000000..98ccf43de85774e6506a0f9feba40671a5babd90 GIT binary patch literal 10192 zcmeI2c{o)4|Nm`eP$5ZWmk=?HNReeo5=F8k%-q?_GTE~)VeBeIxtT#CWGpcTL)o)r zD*ISMG?p1*G7QG=Xt_W4=f1!H{jT42{r>p6u5q0+XU=$I9B(D6`G(r@SmY&go1M4J=D| zOz2r|3d1>MeQl5vzq(k#Xos&T2^DWbKa1|nAw};qhnMo)-}bQ^59rEJnOKa|9UjSv zxGsFoYc^qcd|YH0_44IO%pXfdmxGt5qMkl|dj9ifGm^V!Yb)qva-~!6v#hKvXkDfX z;#q5J>qm_d^g>ChK@t1|lk+)AF>uXU6_uWRgY@qHVhi?0L|o{N^HxshGFR}|1dqCS zvw-Lqqv5Whc9f6}8(Yj)=5f+$^6dc;F;e9L(Kf$~H)=~qRvDYZXUm8$=9)eExNzHn_F@VehUNgm9JlW zzY$7YkkRN%<918V+W>o{UEzIo;N&!ETxAVESy#}9&Hd9Sw7}zFAcH|`JGZFY2o81nr$f*Q)J?}ZjtGsevfJKLY)QgrW}CUsK&k^B zM;x&3IDE`S{xR8oruLT`+ml7PqiPo{o%evvF2>Y+Fu8A8Wg32)Yeco9))%J{eZON1 zQXH#WT~J}dj4AhMKUMjuy;IpPPjrQQd?ix_dIPUUtime)Nm9$Z|P|K&JJJ$~kl~=$!hiMl{ z*&mx_77kJKS`tSWY%f(i@kMBae;?7y6ZK3vZBy_}f~3Zu^zO`FsHQ)pecG49x?z+O zq@LBI@K)3FONSOgAa*tbPdm>Qz>8jaW=dG=4A39DIE! zcLy{G;v4M>Ry7irBsrXVmy&xoToH=kx_&3KsWusl-Zr_qog$#Aptpe|F)9oOPJr7^ zkZ!EBqd{YT%qcGhYpgw&jC|vq#Tg02&K=9w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Slo#Fe+YI<^7M)%OB$p4x!t~n&`pfPS0%Y7P z;n-Q7-{1Ty@l6Y#7QrZplj$GdGqHI}hM{{QcZc@ Date: Sat, 27 Apr 2024 17:43:07 +0000 Subject: [PATCH 2/8] add link to open an issue --- posts/inside-rust/2024-05-01-enabling-rust-lld-on-linux.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/posts/inside-rust/2024-05-01-enabling-rust-lld-on-linux.md b/posts/inside-rust/2024-05-01-enabling-rust-lld-on-linux.md index 12b0c5162..d873327dc 100644 --- a/posts/inside-rust/2024-05-01-enabling-rust-lld-on-linux.md +++ b/posts/inside-rust/2024-05-01-enabling-rust-lld-on-linux.md @@ -79,5 +79,6 @@ resource-constrained environments. #### Summary rustc will use `rust-lld` on `x86_64-unknown-linux-gnu` nightlies, for much improved linking times. -Let us know if you encounter problems, by opening an issue on github. If that happens, you can +Let us know if you encounter problems, by [opening an +issue](https://github.com/rust-lang/rust/issues/new/choose) on github. If that happens, you can revert to the default linker with the `-Z linker-features=-lld` flag. From 162cc6bb3f1910a82419d0d298caaef6f3cead28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Sat, 27 Apr 2024 17:47:52 +0000 Subject: [PATCH 3/8] move post to main blog --- .../2024-05-01-enabling-rust-lld-on-linux.md | 6 +++--- .../ripgrep-comparison.png | Bin 2 files changed, 3 insertions(+), 3 deletions(-) rename posts/{inside-rust => }/2024-05-01-enabling-rust-lld-on-linux.md (96%) rename static/images/{inside-rust => }/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png (100%) diff --git a/posts/inside-rust/2024-05-01-enabling-rust-lld-on-linux.md b/posts/2024-05-01-enabling-rust-lld-on-linux.md similarity index 96% rename from posts/inside-rust/2024-05-01-enabling-rust-lld-on-linux.md rename to posts/2024-05-01-enabling-rust-lld-on-linux.md index d873327dc..1e51820bf 100644 --- a/posts/inside-rust/2024-05-01-enabling-rust-lld-on-linux.md +++ b/posts/2024-05-01-enabling-rust-lld-on-linux.md @@ -2,7 +2,7 @@ layout: post title: Faster linking times on nightly on linux with `rust-lld` author: Rémy Rakic -team: The compiler performance working group +team: the compiler performance working group --- TL;DR: rustc will use `rust-lld` by default on `x86_64-unknown-linux-gnu` on nightly to @@ -48,7 +48,7 @@ benefit is much improved linking times. Here are more details from the ripgrep example mentioned above: linking is reduced 7x, resulting in a 40% reduction in end-to-end compilation times. -![Before/after comparison of a `ripgrep` debug build](../../../../images/inside-rust/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png) +![Before/after comparison of a `ripgrep` debug build](../../../../images/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png) Most binaries should see some improvements here, but it's especially significant with e.g. bigger binaries, or when involving debuginfo. These usually see bottlenecks in the linker. @@ -62,7 +62,7 @@ If testing goes well, we can then stabilize using this faster linker by default #### Possible drawbacks -From our prior testing, we don't really expect issues to happen in practice. it is a drop-in +From our prior testing, we don't really expect issues to happen in practice. It is a drop-in replacement for the vast majority of cases, but `lld` is not _bug-for-bug_ compatible with GNU ld. In any case, using `rust-lld` can be disabled if any problem occurs: use the `-Z diff --git a/static/images/inside-rust/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png b/static/images/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png similarity index 100% rename from static/images/inside-rust/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png rename to static/images/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png From 3f860286be00f6c92825941f2993aeaba553f9b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Sat, 27 Apr 2024 18:08:46 +0000 Subject: [PATCH 4/8] expand on how to revert to system linker --- posts/2024-05-01-enabling-rust-lld-on-linux.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/posts/2024-05-01-enabling-rust-lld-on-linux.md b/posts/2024-05-01-enabling-rust-lld-on-linux.md index 1e51820bf..bcf016e21 100644 --- a/posts/2024-05-01-enabling-rust-lld-on-linux.md +++ b/posts/2024-05-01-enabling-rust-lld-on-linux.md @@ -80,5 +80,14 @@ resource-constrained environments. rustc will use `rust-lld` on `x86_64-unknown-linux-gnu` nightlies, for much improved linking times. Let us know if you encounter problems, by [opening an -issue](https://github.com/rust-lang/rust/issues/new/choose) on github. If that happens, you can -revert to the default linker with the `-Z linker-features=-lld` flag. +issue](https://github.com/rust-lang/rust/issues/new/choose) on GitHub. + +If that happens, you can revert to the default linker with the `-Z linker-features=-lld` flag. +Either by adding it to the usual `RUSTFLAGS` environment variable, or to a project's +[`.cargo/config.toml`](https://doc.rust-lang.org/cargo/reference/config.html) configuration file, +like so: + +```toml +[target.x86_64-unknown-linux-gnu] +rustflags = ["-Zlinker-features=-lld"] +``` From 51a0e16642e978884eb4fcc40aa0aff9ce683104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Tue, 30 Apr 2024 17:24:20 +0200 Subject: [PATCH 5/8] Update posts/2024-05-01-enabling-rust-lld-on-linux.md Co-authored-by: Felix S Klock II --- posts/2024-05-01-enabling-rust-lld-on-linux.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/posts/2024-05-01-enabling-rust-lld-on-linux.md b/posts/2024-05-01-enabling-rust-lld-on-linux.md index bcf016e21..e255e6310 100644 --- a/posts/2024-05-01-enabling-rust-lld-on-linux.md +++ b/posts/2024-05-01-enabling-rust-lld-on-linux.md @@ -35,8 +35,8 @@ popular targets. This has been discussed for a long time, for example in issues [#71515](https://github.com/rust-lang/rust/issues/71515), and rustc already offers nightly flags to use `rust-lld`. -By now, we believe we've done all the internal testing that we could, on CI, crater, our -benchmarking infrastructure, and would like to expand testing and gather real-world feedback and +By now, we believe we've done all the internal testing that we could, on CI, crater, and our +benchmarking infrastructure. We would now like to expand testing and gather real-world feedback and use-cases. Therefore, we will enable `rust-lld` to be the linker used by default on `x86_64-unknown-linux-gnu` for nightly builds. From 47a62eae1b9ebad9abe211a327351633a9f9b5b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 2 May 2024 15:32:36 +0200 Subject: [PATCH 6/8] Apply suggestions from code review Co-authored-by: David Wood --- posts/2024-05-01-enabling-rust-lld-on-linux.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/posts/2024-05-01-enabling-rust-lld-on-linux.md b/posts/2024-05-01-enabling-rust-lld-on-linux.md index e255e6310..d6e18a6fb 100644 --- a/posts/2024-05-01-enabling-rust-lld-on-linux.md +++ b/posts/2024-05-01-enabling-rust-lld-on-linux.md @@ -1,6 +1,6 @@ --- layout: post -title: Faster linking times on nightly on linux with `rust-lld` +title: Faster linking times on nightly on Linux using `rust-lld` author: Rémy Rakic team: the compiler performance working group --- @@ -17,14 +17,14 @@ changed on the command-line or by the target for which the code is compiled). The linkers do an important job, with concerns about stability, backwards-compatibility and so on. For these and other reasons, on the most popular operating systems they usually are older programs, designed when computers only had a single core. So, they usually tend to be slow on a modern -machine. For example, when building ripgrep 13 in debug mode on linux, roughly half of the time is +machine. For example, when building ripgrep 13 in debug mode on Linux, roughly half of the time is actually spent in the linker. There are different linkers, however, and the usual advice to improve linking times is to use one of these newer and faster linkers, like LLVM's [`lld`](https://lld.llvm.org/) or Rui Ueyama's [`mold`](https://github.com/rui314/mold). -Some of rust's wasm and aarch64 targets already use `lld` by default. When using rustup, rustc ships +Some of Rust's wasm and aarch64 targets already use `lld` by default. When using rustup, rustc ships with a version of `lld` for this purpose. When CI builds LLVM to use in the compiler, it also builds the linker and packages it. It's referred to as `rust-lld` to avoid colliding with any `lld` already installed on the user's machine. From ee913e7ee0074c955cc16077a9aeb7dcb0dd9ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 16 May 2024 19:00:30 +0000 Subject: [PATCH 7/8] update publication date --- ....md => 2024-05-17-enabling-rust-lld-on-linux.md} | 2 +- .../ripgrep-comparison.png | Bin 2 files changed, 1 insertion(+), 1 deletion(-) rename posts/{2024-05-01-enabling-rust-lld-on-linux.md => 2024-05-17-enabling-rust-lld-on-linux.md} (98%) rename static/images/{2024-05-01-enabling-rust-lld-on-linux => 2024-05-17-enabling-rust-lld-on-linux}/ripgrep-comparison.png (100%) diff --git a/posts/2024-05-01-enabling-rust-lld-on-linux.md b/posts/2024-05-17-enabling-rust-lld-on-linux.md similarity index 98% rename from posts/2024-05-01-enabling-rust-lld-on-linux.md rename to posts/2024-05-17-enabling-rust-lld-on-linux.md index d6e18a6fb..872481cb8 100644 --- a/posts/2024-05-01-enabling-rust-lld-on-linux.md +++ b/posts/2024-05-17-enabling-rust-lld-on-linux.md @@ -48,7 +48,7 @@ benefit is much improved linking times. Here are more details from the ripgrep example mentioned above: linking is reduced 7x, resulting in a 40% reduction in end-to-end compilation times. -![Before/after comparison of a `ripgrep` debug build](../../../../images/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png) +![Before/after comparison of a `ripgrep` debug build](../../../../images/2024-05-17-enabling-rust-lld-on-linux/ripgrep-comparison.png) Most binaries should see some improvements here, but it's especially significant with e.g. bigger binaries, or when involving debuginfo. These usually see bottlenecks in the linker. diff --git a/static/images/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png b/static/images/2024-05-17-enabling-rust-lld-on-linux/ripgrep-comparison.png similarity index 100% rename from static/images/2024-05-01-enabling-rust-lld-on-linux/ripgrep-comparison.png rename to static/images/2024-05-17-enabling-rust-lld-on-linux/ripgrep-comparison.png From ffdcad9a9d613d1288847413d8f0975d0ae7595a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Fri, 17 May 2024 12:27:38 +0000 Subject: [PATCH 8/8] mention starting nightly --- posts/2024-05-17-enabling-rust-lld-on-linux.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/posts/2024-05-17-enabling-rust-lld-on-linux.md b/posts/2024-05-17-enabling-rust-lld-on-linux.md index 872481cb8..fbb638b68 100644 --- a/posts/2024-05-17-enabling-rust-lld-on-linux.md +++ b/posts/2024-05-17-enabling-rust-lld-on-linux.md @@ -78,7 +78,8 @@ resource-constrained environments. #### Summary -rustc will use `rust-lld` on `x86_64-unknown-linux-gnu` nightlies, for much improved linking times. +rustc will use `rust-lld` on `x86_64-unknown-linux-gnu` nightlies, for much improved linking times, +starting in tomorrow's rustup nightly (`nightly-2024-05-18`). Let us know if you encounter problems, by [opening an issue](https://github.com/rust-lang/rust/issues/new/choose) on GitHub.