Skip to content

Commit e1832fa

Browse files
committed
Rename bitcode-in-rlib option to embed-bitcode
This commit finishes work first pioneered in #70458 and started in #71528. The `-C bitcode-in-rlib` option, which has not yet reached stable, is renamed to `-C embed-bitcode` since that more accurately reflects what it does now anyway. Various tests and such are updated along the way as well. This'll also need to be backported to the beta channel to ensure we don't accidentally stabilize `-Cbitcode-in-rlib` as well.
1 parent eece58a commit e1832fa

File tree

8 files changed

+39
-48
lines changed

8 files changed

+39
-48
lines changed

src/bootstrap/compile.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,16 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, stage: u32, ca
232232
}
233233
}
234234

235-
// By default, rustc uses `-Cbitcode-in-rlib=yes`, and Cargo overrides that
236-
// with `-Cbitcode-in-rlib=no` for non-LTO builds. However, libstd must be
235+
// By default, rustc uses `-Cembed-bitcode=yes`, and Cargo overrides that
236+
// with `-Cembed-bitcode=no` for non-LTO builds. However, libstd must be
237237
// built with bitcode so that the produced rlibs can be used for both LTO
238238
// builds (which use bitcode) and non-LTO builds (which use object code).
239239
// So we override the override here!
240240
//
241241
// But we don't bother for the stage 0 compiler because it's never used
242242
// with LTO.
243243
if stage >= 1 {
244-
cargo.rustflag("-Cbitcode-in-rlib=yes");
244+
cargo.rustflag("-Cembed-bitcode=yes");
245245
}
246246
}
247247

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

+27-33
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,6 @@ a version of this list for your exact compiler by running `rustc -C help`.
77

88
This option is deprecated and does nothing.
99

10-
## bitcode-in-rlib
11-
12-
This flag controls whether or not the compiler puts LLVM bitcode into generated
13-
rlibs. It takes one of the following values:
14-
15-
* `y`, `yes`, `on`, or no value: put bitcode in rlibs (the default).
16-
* `n`, `no`, or `off`: omit bitcode from rlibs.
17-
18-
LLVM bitcode is only needed when link-time optimization (LTO) is being
19-
performed, but it is enabled by default for backwards compatibility reasons.
20-
21-
The use of `-C bitcode-in-rlib=no` can significantly improve compile times and
22-
reduce generated file sizes. For these reasons, Cargo uses `-C
23-
bitcode-in-rlib=no` whenever possible. Likewise, if you are building directly
24-
with `rustc` we recommend using `-C bitcode-in-rlib=no` whenever you are not
25-
using LTO.
26-
27-
If combined with `-C lto`, `-C bitcode-in-rlib=no` will cause `rustc` to abort
28-
at start-up, because the combination is invalid.
29-
30-
> **Note**: the implementation of this flag today is to enable the
31-
> `-Zembed-bitcode` option. When bitcode is embedded into an rlib then all
32-
> object files within the rlib will have a special section (typically named
33-
> `.llvmbc`, depends on the platform though) which contains LLVM bytecode. This
34-
> section of the object file will not appear in the final linked artifact.
35-
3610
## code-model
3711

3812
This option lets you choose which code model to use.
@@ -86,6 +60,26 @@ It takes one of the following values:
8660
For example, for gcc flavor linkers, this issues the `-nodefaultlibs` flag to
8761
the linker.
8862

63+
## embed-bitcode
64+
65+
This flag controls whether or not the compiler puts LLVM bitcode into generated
66+
rlibs. It takes one of the following values:
67+
68+
* `y`, `yes`, `on`, or no value: put bitcode in rlibs (the default).
69+
* `n`, `no`, or `off`: omit bitcode from rlibs.
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.
73+
74+
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.
79+
80+
If combined with `-C lto`, `-C embed-bitcode=no` will cause `rustc` to abort
81+
at start-up, because the combination is invalid.
82+
8983
## extra-filename
9084

9185
This option allows you to put extra data in each output filename. It takes a
@@ -355,21 +349,21 @@ Supported values for this option are:
355349
- `static` - non-relocatable code, machine instructions may use absolute addressing modes.
356350

357351
- `pic` - fully relocatable position independent code,
358-
machine instructions need to use relative addressing modes.
352+
machine instructions need to use relative addressing modes. \
359353
Equivalent to the "uppercase" `-fPIC` or `-fPIE` options in other compilers,
360-
depending on the produced crate types.
354+
depending on the produced crate types. \
361355
This is the default model for majority of supported targets.
362356

363357
#### Special relocation models
364358

365-
- `dynamic-no-pic` - relocatable external references, non-relocatable code.
366-
Only makes sense on Darwin and is rarely used.
359+
- `dynamic-no-pic` - relocatable external references, non-relocatable code. \
360+
Only makes sense on Darwin and is rarely used. \
367361
If StackOverflow tells you to use this as an opt-out of PIC or PIE, don't believe it,
368362
use `-C relocation-model=static` instead.
369363
- `ropi`, `rwpi` and `ropi-rwpi` - relocatable code and read-only data, relocatable read-write data,
370-
and combination of both, respectively.
364+
and combination of both, respectively. \
371365
Only makes sense for certain embedded ARM targets.
372-
- `default` - relocation model default to the current target.
366+
- `default` - relocation model default to the current target. \
373367
Only makes sense as an override for some other explicitly specified relocation model
374368
previously set on the command line.
375369

@@ -380,7 +374,7 @@ Supported values can also be discovered by running `rustc --print relocation-mod
380374
In addition to codegen effects, `relocation-model` has effects during linking.
381375

382376
If the relocation model is `pic` and the current target supports position-independent executables
383-
(PIE), the linker will be instructed (`-pie`) to produce one.
377+
(PIE), the linker will be instructed (`-pie`) to produce one. \
384378
If the target doesn't support both position-independent and statically linked executables,
385379
then `-C target-feature=+crt-static` "wins" over `-C relocation-model=pic`,
386380
and the linker is instructed (`-static`) to produce a statically linked

src/librustc_codegen_ssa/back/write.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl ModuleConfig {
148148
|| sess.opts.cg.linker_plugin_lto.enabled()
149149
{
150150
EmitObj::Bitcode
151-
} else if sess.opts.debugging_opts.embed_bitcode || need_crate_bitcode_for_rlib(sess) {
151+
} else if need_crate_bitcode_for_rlib(sess) {
152152
let force_full = need_crate_bitcode_for_rlib(sess);
153153
match sess.opts.optimize {
154154
config::OptLevel::No | config::OptLevel::Less if !force_full => {
@@ -374,7 +374,7 @@ pub struct CompiledModules {
374374
}
375375

376376
fn need_crate_bitcode_for_rlib(sess: &Session) -> bool {
377-
sess.opts.cg.bitcode_in_rlib
377+
sess.opts.cg.embed_bitcode
378378
&& sess.crate_types.borrow().contains(&config::CrateType::Rlib)
379379
&& sess.opts.output_types.contains_key(&OutputType::Exe)
380380
}

src/librustc_interface/tests.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,10 @@ fn test_codegen_options_tracking_hash() {
410410

411411
// Make sure that changing a [TRACKED] option changes the hash.
412412
// This list is in alphabetical order.
413-
tracked!(bitcode_in_rlib, false);
414413
tracked!(code_model, Some(String::from("code model")));
415414
tracked!(debug_assertions, Some(true));
416415
tracked!(debuginfo, 0xdeadbeef);
416+
tracked!(embed_bitcode, false);
417417
tracked!(force_frame_pointers, Some(false));
418418
tracked!(inline_threshold, Some(0xf007ba11));
419419
tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
@@ -529,7 +529,6 @@ fn test_debugging_options_tracking_hash() {
529529
tracked!(debug_macros, true);
530530
tracked!(dep_info_omit_d_target, true);
531531
tracked!(dual_proc_macros, true);
532-
tracked!(embed_bitcode, true);
533532
tracked!(fewer_names, true);
534533
tracked!(force_overflow_checks, Some(true));
535534
tracked!(force_unstable_if_unmarked, true);

src/librustc_session/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1677,12 +1677,12 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
16771677
);
16781678
}
16791679

1680-
if !cg.bitcode_in_rlib {
1680+
if !cg.embed_bitcode {
16811681
match cg.lto {
16821682
LtoCli::No | LtoCli::Unspecified => {}
16831683
LtoCli::Yes | LtoCli::NoParam | LtoCli::Thin | LtoCli::Fat => early_error(
16841684
error_format,
1685-
"options `-C bitcode-in-rlib=no` and `-C lto` are incompatible",
1685+
"options `-C embed-bitcode=no` and `-C lto` are incompatible",
16861686
),
16871687
}
16881688
}

src/librustc_session/options.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,6 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
651651

652652
ar: String = (String::new(), parse_string, [UNTRACKED],
653653
"this option is deprecated and does nothing"),
654-
bitcode_in_rlib: bool = (true, parse_bool, [TRACKED],
655-
"emit bitcode in rlibs (default: yes)"),
656654
code_model: Option<String> = (None, parse_opt_string, [TRACKED],
657655
"choose the code model to use (`rustc --print code-models` for details)"),
658656
codegen_units: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
@@ -664,6 +662,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
664662
2 = full debug info with variable and type information; default: 0)"),
665663
default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
666664
"allow the linker to link its default libraries (default: no)"),
665+
embed_bitcode: bool = (true, parse_bool, [TRACKED],
666+
"emit bitcode in rlibs (default: yes)"),
667667
extra_filename: String = (String::new(), parse_string, [UNTRACKED],
668668
"extra data to put in each output filename"),
669669
force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
@@ -806,8 +806,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
806806
"exclude the pass number when dumping MIR (used in tests) (default: no)"),
807807
dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
808808
"in addition to `.mir` files, create graphviz `.dot` files (default: no)"),
809-
embed_bitcode: bool = (false, parse_bool, [TRACKED],
810-
"embed LLVM bitcode in object files (default: no)"),
811809
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
812810
"emit a section containing stack size metadata (default: no)"),
813811
fewer_names: bool = (false, parse_bool, [TRACKED],
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// compile-flags: -C lto -C bitcode-in-rlib=no
1+
// compile-flags: -C lto -C embed-bitcode=no
22

33
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: options `-C bitcode-in-rlib=no` and `-C lto` are incompatible
1+
error: options `-C embed-bitcode=no` and `-C lto` are incompatible
22

0 commit comments

Comments
 (0)