Skip to content

Commit 0d53d3c

Browse files
committed
Update LTO post based on feedback.
1 parent ad25039 commit 0d53d3c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

posts/inside-rust/2020-06-24-lto-improvements.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ These changes have been added incrementally over the past three months, with the
1515

1616
## Background
1717

18-
When compiling a library, `rustc` saves the output in an `rlib` file which is an [archive file]. This has historically contained these two things (among others):
18+
When compiling a library, `rustc` saves the output in an `rlib` file which is an [archive file]. This has historically contained the following:
1919

2020
* Object code, which is the result of code generation. This is used during regular linking.
2121
* [LLVM bitcode], which is a binary representation of LLVM's intermediate representation. This can be used for [Link Time Optimization] (LTO).
22+
* Rust-specific metadata, which covers [a wide range of data][metadata] about the crate.
2223

2324
LTO is an optimization technique that can perform whole-program analysis. It analyzes all of the bitcode from every library at once, and performs optimizations and code generation. `rustc` supports several forms of LTO:
2425

@@ -37,7 +38,7 @@ Two `rustc` flags are now available to control how the rlib is constructed:
3738
* [`-C linker-plugin-lto`] causes `rustc` to only place bitcode in the `.o` files, and skips code generation. Cargo uses this when the rlib is only intended for use with LTO. This can also be used when doing cross-language LTO.
3839
* [`-C embed-bitcode=no`] causes `rustc` to avoid placing bitcode in the rlib altogether. Cargo uses this when LTO is not being used, which reduces some disk space usage.
3940

40-
Additionally, the method in which bitcode is embedded in the rlib has changed. Previously, `rustc` would place compressed bitcode as a `.bc.z` file in the rlib archive. Now, the bitcode is placed as an uncompressed section within each `.o` [object file] in the rlib archive. This avoids a small performance hit for compressing the bitcode, and also matches the standard format used by clang.
41+
Additionally, the method in which bitcode is embedded in the rlib has changed. Previously, `rustc` would place compressed bitcode as a `.bc.z` file in the rlib archive. Now, the bitcode is placed as an uncompressed section within each `.o` [object file] in the rlib archive. This can sometimes be a small performance benefit, because it avoids cost of compressing the bitcode, and sometimes can be slower due to needing to write more data to disk. This change helped simplify the implementation, and also matches the behavior of clang's `-fembed-bitcode` option (typically used with Apple's iOS-based operating systems).
4142

4243
## Improvements
4344

@@ -87,3 +88,4 @@ Although this is a conceptually simple change (LTO=bitcode, non-LTO=object code)
8788
[object file]: https://en.wikipedia.org/wiki/Object_file
8889
[`-C linker-plugin-lto`]: https://doc.rust-lang.org/nightly/rustc/codegen-options/#linker-plugin-lto
8990
[`-C embed-bitcode=no`]: https://doc.rust-lang.org/nightly/rustc/codegen-options/#embed-bitcode
91+
[metadata]: https://github.com/rust-lang/rust/blob/0b66a89735305ebac93894461559576495ab920e/src/librustc_metadata/rmeta/mod.rs#L172-L214

0 commit comments

Comments
 (0)