From e1832fa4e4700a5f8935ac3e88f7688a15e17df0 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 30 Apr 2020 10:53:16 -0700 Subject: [PATCH] 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. --- src/bootstrap/compile.rs | 6 +- src/doc/rustc/src/codegen-options/index.md | 60 +++++++++---------- src/librustc_codegen_ssa/back/write.rs | 4 +- src/librustc_interface/tests.rs | 3 +- src/librustc_session/config.rs | 4 +- src/librustc_session/options.rs | 6 +- src/test/ui/lto-and-no-bitcode-in-rlib.rs | 2 +- src/test/ui/lto-and-no-bitcode-in-rlib.stderr | 2 +- 8 files changed, 39 insertions(+), 48 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 06ab0a9c310af..f50ddf8c96710 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -232,8 +232,8 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned, 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! @@ -241,7 +241,7 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned, stage: u32, ca // 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"); } } diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index 6b31430f7ec4e..08b5ab1081704 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -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. @@ -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 @@ -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. @@ -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 diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index 094c57b240127..31bf064ad9179 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -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 => { @@ -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) } diff --git a/src/librustc_interface/tests.rs b/src/librustc_interface/tests.rs index 0b3ba73f86a86..0a200426e38ea 100644 --- a/src/librustc_interface/tests.rs +++ b/src/librustc_interface/tests.rs @@ -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); @@ -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); diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index 0dfc391d9cd3b..8a690621a6e8f 100644 --- a/src/librustc_session/config.rs +++ b/src/librustc_session/config.rs @@ -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", ), } } diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs index be78d46b98196..b03fc00d93db2 100644 --- a/src/librustc_session/options.rs +++ b/src/librustc_session/options.rs @@ -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 = (None, parse_opt_string, [TRACKED], "choose the code model to use (`rustc --print code-models` for details)"), codegen_units: Option = (None, parse_opt_uint, [UNTRACKED], @@ -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 = (None, parse_opt_bool, [TRACKED], @@ -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], diff --git a/src/test/ui/lto-and-no-bitcode-in-rlib.rs b/src/test/ui/lto-and-no-bitcode-in-rlib.rs index 1dd11ce3d2467..f381240e70a44 100644 --- a/src/test/ui/lto-and-no-bitcode-in-rlib.rs +++ b/src/test/ui/lto-and-no-bitcode-in-rlib.rs @@ -1,3 +1,3 @@ -// compile-flags: -C lto -C bitcode-in-rlib=no +// compile-flags: -C lto -C embed-bitcode=no fn main() {} diff --git a/src/test/ui/lto-and-no-bitcode-in-rlib.stderr b/src/test/ui/lto-and-no-bitcode-in-rlib.stderr index 2221fc1645d61..11e370e914c8e 100644 --- a/src/test/ui/lto-and-no-bitcode-in-rlib.stderr +++ b/src/test/ui/lto-and-no-bitcode-in-rlib.stderr @@ -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