Skip to content

Commit

Permalink
Auto merge of rust-lang#71716 - alexcrichton:bitcode-follow-up, r=nne…
Browse files Browse the repository at this point in the history
…thercote

Rename `bitcode-in-rlib` option to `embed-bitcode`

This commit finishes work first pioneered in rust-lang#70458 and started in rust-lang#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.
  • Loading branch information
bors committed May 2, 2020
2 parents 19ae74d + e1832fa commit dae90c1
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 48 deletions.
6 changes: 3 additions & 3 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,16 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, stage: u32, ca
}
}

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

Expand Down
60 changes: 27 additions & 33 deletions src/doc/rustc/src/codegen-options/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,6 @@ a version of this list for your exact compiler by running `rustc -C help`.

This option is deprecated and does nothing.

## bitcode-in-rlib

This flag controls whether or not the compiler puts LLVM bitcode into generated
rlibs. It takes one of the following values:

* `y`, `yes`, `on`, or no value: put bitcode in rlibs (the default).
* `n`, `no`, or `off`: omit bitcode from rlibs.

LLVM bitcode is only needed when link-time optimization (LTO) is being
performed, but it is enabled by default for backwards compatibility reasons.

The use of `-C bitcode-in-rlib=no` can significantly improve compile times and
reduce generated file sizes. For these reasons, Cargo uses `-C
bitcode-in-rlib=no` whenever possible. Likewise, if you are building directly
with `rustc` we recommend using `-C bitcode-in-rlib=no` whenever you are not
using LTO.

If combined with `-C lto`, `-C bitcode-in-rlib=no` will cause `rustc` to abort
at start-up, because the combination is invalid.

> **Note**: the implementation of this flag today is to enable the
> `-Zembed-bitcode` option. When bitcode is embedded into an rlib then all
> object files within the rlib will have a special section (typically named
> `.llvmbc`, depends on the platform though) which contains LLVM bytecode. This
> section of the object file will not appear in the final linked artifact.
## code-model

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

## embed-bitcode

This flag controls whether or not the compiler puts LLVM bitcode into generated
rlibs. It takes one of the following values:

* `y`, `yes`, `on`, or no value: put bitcode in rlibs (the default).
* `n`, `no`, or `off`: omit bitcode from rlibs.

LLVM bitcode is only needed when link-time optimization (LTO) is being
performed, but it is enabled by default for backwards compatibility reasons.

The use of `-C embed-bitcode=no` can significantly improve compile times and
reduce generated file sizes. For these reasons, Cargo uses `-C
embed-bitcode=no` whenever possible. Likewise, if you are building directly
with `rustc` we recommend using `-C embed-bitcode=no` whenever you are not
using LTO.

If combined with `-C lto`, `-C embed-bitcode=no` will cause `rustc` to abort
at start-up, because the combination is invalid.

## extra-filename

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

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

#### Special relocation models

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

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

If the relocation model is `pic` and the current target supports position-independent executables
(PIE), the linker will be instructed (`-pie`) to produce one.
(PIE), the linker will be instructed (`-pie`) to produce one. \
If the target doesn't support both position-independent and statically linked executables,
then `-C target-feature=+crt-static` "wins" over `-C relocation-model=pic`,
and the linker is instructed (`-static`) to produce a statically linked
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl ModuleConfig {
|| sess.opts.cg.linker_plugin_lto.enabled()
{
EmitObj::Bitcode
} else if sess.opts.debugging_opts.embed_bitcode || need_crate_bitcode_for_rlib(sess) {
} else if need_crate_bitcode_for_rlib(sess) {
let force_full = need_crate_bitcode_for_rlib(sess);
match sess.opts.optimize {
config::OptLevel::No | config::OptLevel::Less if !force_full => {
Expand Down Expand Up @@ -374,7 +374,7 @@ pub struct CompiledModules {
}

fn need_crate_bitcode_for_rlib(sess: &Session) -> bool {
sess.opts.cg.bitcode_in_rlib
sess.opts.cg.embed_bitcode
&& sess.crate_types.borrow().contains(&config::CrateType::Rlib)
&& sess.opts.output_types.contains_key(&OutputType::Exe)
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_interface/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ fn test_codegen_options_tracking_hash() {

// Make sure that changing a [TRACKED] option changes the hash.
// This list is in alphabetical order.
tracked!(bitcode_in_rlib, false);
tracked!(code_model, Some(String::from("code model")));
tracked!(debug_assertions, Some(true));
tracked!(debuginfo, 0xdeadbeef);
tracked!(embed_bitcode, false);
tracked!(force_frame_pointers, Some(false));
tracked!(inline_threshold, Some(0xf007ba11));
tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
Expand Down Expand Up @@ -529,7 +529,6 @@ fn test_debugging_options_tracking_hash() {
tracked!(debug_macros, true);
tracked!(dep_info_omit_d_target, true);
tracked!(dual_proc_macros, true);
tracked!(embed_bitcode, true);
tracked!(fewer_names, true);
tracked!(force_overflow_checks, Some(true));
tracked!(force_unstable_if_unmarked, true);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1677,12 +1677,12 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
);
}

if !cg.bitcode_in_rlib {
if !cg.embed_bitcode {
match cg.lto {
LtoCli::No | LtoCli::Unspecified => {}
LtoCli::Yes | LtoCli::NoParam | LtoCli::Thin | LtoCli::Fat => early_error(
error_format,
"options `-C bitcode-in-rlib=no` and `-C lto` are incompatible",
"options `-C embed-bitcode=no` and `-C lto` are incompatible",
),
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_session/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,6 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,

ar: String = (String::new(), parse_string, [UNTRACKED],
"this option is deprecated and does nothing"),
bitcode_in_rlib: bool = (true, parse_bool, [TRACKED],
"emit bitcode in rlibs (default: yes)"),
code_model: Option<String> = (None, parse_opt_string, [TRACKED],
"choose the code model to use (`rustc --print code-models` for details)"),
codegen_units: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
Expand All @@ -664,6 +662,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
2 = full debug info with variable and type information; default: 0)"),
default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
"allow the linker to link its default libraries (default: no)"),
embed_bitcode: bool = (true, parse_bool, [TRACKED],
"emit bitcode in rlibs (default: yes)"),
extra_filename: String = (String::new(), parse_string, [UNTRACKED],
"extra data to put in each output filename"),
force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
Expand Down Expand Up @@ -806,8 +806,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"exclude the pass number when dumping MIR (used in tests) (default: no)"),
dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
"in addition to `.mir` files, create graphviz `.dot` files (default: no)"),
embed_bitcode: bool = (false, parse_bool, [TRACKED],
"embed LLVM bitcode in object files (default: no)"),
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
"emit a section containing stack size metadata (default: no)"),
fewer_names: bool = (false, parse_bool, [TRACKED],
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/lto-and-no-bitcode-in-rlib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// compile-flags: -C lto -C bitcode-in-rlib=no
// compile-flags: -C lto -C embed-bitcode=no

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/lto-and-no-bitcode-in-rlib.stderr
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: options `-C bitcode-in-rlib=no` and `-C lto` are incompatible
error: options `-C embed-bitcode=no` and `-C lto` are incompatible

0 comments on commit dae90c1

Please sign in to comment.