@@ -62,24 +62,40 @@ the linker.
62
62
63
63
## embed-bitcode
64
64
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:
67
67
68
68
* ` y ` , ` yes ` , ` on ` , or no value: put bitcode in rlibs (the default).
69
69
* ` n ` , ` no ` , or ` off ` : omit bitcode from rlibs.
70
70
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 ` .
73
76
74
77
The 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.
79
83
80
84
If combined with ` -C lto ` , ` -C embed-bitcode=no ` will cause ` rustc ` to abort
81
85
at start-up, because the combination is invalid.
82
86
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
+
83
99
## extra-filename
84
100
85
101
This option allows you to put extra data in each output filename. It takes a
@@ -199,6 +215,18 @@ the following values:
199
215
* ` n ` , ` no ` , or ` off ` : disable linker plugin LTO (the default).
200
216
* A path to the linker plugin.
201
217
218
+ More specifically this flag will cause the compiler to replace its typical
219
+ object file output with LLVM bitcode files. For example an rlib produced with
220
+ ` -Clinker-plugin-lto ` will still have ` *.o ` files in it, but they'll all be LLVM
221
+ bitcode instead of actual machine code. It is expected that the native platform
222
+ linker is capable of loading these LLVM bitcode files and generating code at
223
+ link time (typically after performing optimizations).
224
+
225
+ Note that rustc can also read its own object files produced with
226
+ ` -Clinker-plugin-lto ` . If an rlib is only ever going to get used later with a
227
+ ` -Clto ` compilation then you can pass ` -Clinker-plugin-lto ` to speed up
228
+ compilation and avoid generating object files that aren't used.
229
+
202
230
## llvm-args
203
231
204
232
This flag can be used to pass a list of arguments directly to LLVM.
0 commit comments