From 9536d04a2d1af8163a0ec772ec747a0e98a8e4db Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 29 Nov 2018 22:00:09 +0100 Subject: [PATCH] Stabilize `linker-flavor` flag. This commit moves the linker-flavor flag from a debugging option to a codegen option, thus stabilizing it. There are no feature flags associated with this flag. --- src/doc/rustc/src/codegen-options/index.md | 7 +++ .../src/compiler-flags/linker-flavor.md | 61 ------------------- src/librustc/session/config.rs | 4 +- src/librustc_codegen_ssa/back/link.rs | 6 +- src/test/compile-fail/issue-10755.rs | 2 +- .../compile-fail/nolink-with-link-args.rs | 2 +- .../feature-gate-linker-flavor.rs | 20 ------ .../feature-gate-linker-flavor.stderr | 8 --- 8 files changed, 12 insertions(+), 98 deletions(-) delete mode 100644 src/doc/unstable-book/src/compiler-flags/linker-flavor.md delete mode 100644 src/test/ui/feature-gates/feature-gate-linker-flavor.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-linker-flavor.stderr diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index 4fc5f42dd5527..94f21042c8fdd 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -22,6 +22,13 @@ This flag lets you append a single extra argument to the linker invocation. This flag lets you append multiple extra arguments to the linker invocation. The options should be separated by spaces. +## linker-flavor + +This flag lets you control the linker flavor used by `rustc`. If a linker is given with the +`-C linker` flag described above then the linker flavor is inferred from the value provided. If no +linker is given then the linker flavor is used to determine the linker to use. Every `rustc` target +defaults to some linker flavor. + ## link-dead-code Normally, the linker will remove dead code. This flag disables this behavior. diff --git a/src/doc/unstable-book/src/compiler-flags/linker-flavor.md b/src/doc/unstable-book/src/compiler-flags/linker-flavor.md deleted file mode 100644 index 39659602e015c..0000000000000 --- a/src/doc/unstable-book/src/compiler-flags/linker-flavor.md +++ /dev/null @@ -1,61 +0,0 @@ -# `linker-flavor` - -The tracking issue for this feature is: None - ------------------------- - -Every `rustc` target defaults to some linker. For example, Linux targets default -to gcc. In some cases, you may want to override the default; you can do that -with the unstable CLI argument: `-Z linker-flavor`. - -Here how you would use this flag to link a Rust binary for the -`thumbv7m-none-eabi` using LLD instead of GCC. - -``` text -$ xargo rustc --target thumbv7m-none-eabi -- \ - -C linker=ld.lld \ - -Z linker-flavor=ld \ - -Z print-link-args | tr ' ' '\n' -"ld.lld" -"-L" -"$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib" -"$PWD/target/thumbv7m-none-eabi/debug/deps/app-512e9dbf385f233c.0.o" -"-o" -"$PWD/target/thumbv7m-none-eabi/debug/deps/app-512e9dbf385f233c" -"--gc-sections" -"-L" -"$PWD/target/thumbv7m-none-eabi/debug/deps" -"-L" -"$PWD/target/debug/deps" -"-L" -"$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib" -"-Bstatic" -"$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib/libcore-e1ccb7dfb1cb9ebb.rlib" -"-Bdynamic" -``` - -Whereas the default is: - -``` text -$ xargo rustc --target thumbv7m-none-eabi -- \ - -C link-arg=-nostartfiles \ - -Z print-link-args | tr ' ' '\n' -"arm-none-eabi-gcc" -"-L" -"$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib" -"$PWD/target/thumbv7m-none-eabi/debug/deps/app-961e39416baa38d9.0.o" -"-o" -"$PWD/target/thumbv7m-none-eabi/debug/deps/app-961e39416baa38d9" -"-Wl,--gc-sections" -"-nodefaultlibs" -"-L" -"$PWD/target/thumbv7m-none-eabi/debug/deps" -"-L" -"$PWD/target/debug/deps" -"-L" -"$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib" -"-Wl,-Bstatic" -"$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib/libcore-e1ccb7dfb1cb9ebb.rlib" -"-nostartfiles" -"-Wl,-Bdynamic" -``` diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 480d4a8e48f0e..36281e319968e 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1136,6 +1136,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, "enable incremental compilation"), default_linker_libraries: Option = (None, parse_opt_bool, [UNTRACKED], "allow the linker to link its default libraries"), + linker_flavor: Option = (None, parse_linker_flavor, [UNTRACKED], + "Linker flavor"), } options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, @@ -1292,8 +1294,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "pass `-install_name @rpath/...` to the macOS linker"), sanitizer: Option = (None, parse_sanitizer, [TRACKED], "Use a sanitizer"), - linker_flavor: Option = (None, parse_linker_flavor, [UNTRACKED], - "Linker flavor"), fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED], "set the optimization fuel quota for a crate"), print_fuel: Option = (None, parse_opt_string, [TRACKED], diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 24a70dc797771..59102e09d4cbc 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -192,11 +192,7 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) { // linker and linker flavor specified via command line have precedence over what the target // specification specifies - if let Some(ret) = infer_from( - sess, - sess.opts.cg.linker.clone(), - sess.opts.debugging_opts.linker_flavor, - ) { + if let Some(ret) = infer_from(sess, sess.opts.cg.linker.clone(), sess.opts.cg.linker_flavor) { return ret; } diff --git a/src/test/compile-fail/issue-10755.rs b/src/test/compile-fail/issue-10755.rs index 57915bce456d9..bb77748a416bc 100644 --- a/src/test/compile-fail/issue-10755.rs +++ b/src/test/compile-fail/issue-10755.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: -C linker=llllll -Z linker-flavor=ld +// compile-flags: -C linker=llllll -C linker-flavor=ld // error-pattern: linker `llllll` not found fn main() { diff --git a/src/test/compile-fail/nolink-with-link-args.rs b/src/test/compile-fail/nolink-with-link-args.rs index 6dfd74f541e6e..95f827ecb6338 100644 --- a/src/test/compile-fail/nolink-with-link-args.rs +++ b/src/test/compile-fail/nolink-with-link-args.rs @@ -9,7 +9,7 @@ // except according to those terms. // error-pattern:aFdEfSeVEE -// compile-flags: -Z linker-flavor=ld +// compile-flags: -C linker-flavor=ld /* We're testing that link_args are indeed passed when nolink is specified. So we try to compile with junk link_args and make sure they are visible in diff --git a/src/test/ui/feature-gates/feature-gate-linker-flavor.rs b/src/test/ui/feature-gates/feature-gate-linker-flavor.rs deleted file mode 100644 index 56ede0104a5fd..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-linker-flavor.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// This is a fake compile fail test as there's no way to generate a -// `#![feature(linker_flavor)]` error. The only reason we have a `linker_flavor` -// feature gate is to be able to document `-Z linker-flavor` in the unstable -// book - -#[used] -//~^ ERROR attribute must be applied to a `static` variable -fn foo() {} - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-linker-flavor.stderr b/src/test/ui/feature-gates/feature-gate-linker-flavor.stderr deleted file mode 100644 index 7019a66654832..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-linker-flavor.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: attribute must be applied to a `static` variable - --> $DIR/feature-gate-linker-flavor.rs:16:1 - | -LL | #[used] - | ^^^^^^^ - -error: aborting due to previous error -