You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: posts/inside-rust/2020-06-24-lto-improvements.md
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -15,10 +15,11 @@ These changes have been added incrementally over the past three months, with the
15
15
16
16
## Background
17
17
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:
19
19
20
20
* Object code, which is the result of code generation. This is used during regular linking.
21
21
*[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.
22
23
23
24
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:
24
25
@@ -37,7 +38,7 @@ Two `rustc` flags are now available to control how the rlib is constructed:
37
38
*[`-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.
38
39
*[`-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.
39
40
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).
41
42
42
43
## Improvements
43
44
@@ -87,3 +88,4 @@ Although this is a conceptually simple change (LTO=bitcode, non-LTO=object code)
0 commit comments