@@ -62,24 +62,40 @@ the linker.
6262
6363## embed-bitcode
6464
65- This flag controls whether or not the compiler puts LLVM bitcode into generated
66- rlibs . It takes one of the following values:
65+ This flag controls whether or not the compiler embeds LLVM bitcode into object
66+ files . It takes one of the following values:
6767
6868* ` y ` , ` yes ` , ` on ` , or no value: put bitcode in rlibs (the default).
6969* ` n ` , ` no ` , or ` off ` : omit bitcode from rlibs.
7070
71- LLVM bitcode is only needed when link-time optimization (LTO) is being
72- performed, but it is enabled by default for backwards compatibility reasons.
71+ LLVM bitcode is required when rustc is performing link-time optimization (LTO).
72+ It is also required on some targets like iOS ones where vendors look for LLVM
73+ bitcode. Embedded bitcode will appear in rustc-generated object files inside of
74+ a section whose name is defined by the target platform. Most of the time this is
75+ ` .llvmbc ` .
7376
7477The use of ` -C embed-bitcode=no ` can significantly improve compile times and
75- reduce generated file sizes. For these reasons, Cargo uses `-C
76- embed-bitcode=no` whenever possible. Likewise, if you are building directly
77- with ` rustc ` we recommend using ` -C embed-bitcode=no ` whenever you are not
78- using LTO.
78+ reduce generated file sizes if your compilation does not actually need bitcode
79+ (e.g. if you're not compiling for iOS or you're not performing LTO). For these
80+ reasons, Cargo uses ` -C embed-bitcode=no ` whenever possible. Likewise, if you
81+ are building directly with ` rustc ` we recommend using ` -C embed-bitcode=no `
82+ whenever you are not using LTO.
7983
8084If combined with ` -C lto ` , ` -C embed-bitcode=no ` will cause ` rustc ` to abort
8185at start-up, because the combination is invalid.
8286
87+ > ** Note** : if you're building Rust code with LTO then you probably don't even
88+ > need the ` embed-bitcode ` option turned on. You'll likely want to use
89+ > ` -Clinker-plugin-lto ` instead which skips generating object files entirely and
90+ > simply replaces object files with LLVM bitcode. The only purpose for
91+ > ` -Cembed-bitcode ` is when you're generating an rlib that is both being used
92+ > with and without LTO. For example Rust's standard library ships with embedded
93+ > bitcode since users link to it both with and without LTO.
94+ >
95+ > This also may make you wonder why the default is ` yes ` for this option. The
96+ > reason for that is that it's how it was for rustc 1.44 and prior. In 1.45 this
97+ > option was added to turn off what had always been the default.
98+
8399## extra-filename
84100
85101This option allows you to put extra data in each output filename. It takes a
@@ -187,6 +203,18 @@ the following values:
187203* ` n ` , ` no ` , or ` off ` : disable linker plugin LTO (the default).
188204* A path to the linker plugin.
189205
206+ More specifically this flag will cause the compiler to replace its typical
207+ object file output with LLVM bitcode files. For example an rlib produced with
208+ ` -Clinker-plugin-lto ` will still have ` *.o ` files in it, but they'll all be LLVM
209+ bitcode instead of actual machine code. It is expected that the native platform
210+ linker is capable of loading these LLVM bitcode files and generating code at
211+ link time (typically after performing optimizations).
212+
213+ Note that rustc can also read its own object files produced with
214+ ` -Clinker-plugin-lto ` . If an rlib is only ever going to get used later with a
215+ ` -Clto ` compilation then you can pass ` -Clinker-plugin-lto ` to speed up
216+ compilation and avoid generating object files that aren't used.
217+
190218## llvm-args
191219
192220This flag can be used to pass a list of arguments directly to LLVM.
0 commit comments