Skip to content

Commit 3efcba6

Browse files
authored
Rollup merge of #71897 - alexcrichton:embed-bitcode-docs, r=nnethercote
Improve docs for embed-bitcode and linker-plugin-lto Follow-up from #71716 I wasn't able to add in time.
2 parents 67a7b7a + 0b35692 commit 3efcba6

File tree

1 file changed

+36
-8
lines changed
  • src/doc/rustc/src/codegen-options

1 file changed

+36
-8
lines changed

src/doc/rustc/src/codegen-options/index.md

+36-8
Original file line numberDiff line numberDiff line change
@@ -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

7477
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.
7983

8084
If combined with `-C lto`, `-C embed-bitcode=no` will cause `rustc` to abort
8185
at 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

85101
This option allows you to put extra data in each output filename. It takes a
@@ -199,6 +215,18 @@ the following values:
199215
* `n`, `no`, or `off`: disable linker plugin LTO (the default).
200216
* A path to the linker plugin.
201217

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+
202230
## llvm-args
203231

204232
This flag can be used to pass a list of arguments directly to LLVM.

0 commit comments

Comments
 (0)