diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index eb779e6382f4b..7d1206565b712 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1135,6 +1135,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, [TRACKED], "panic strategy to compile crate with"), incremental: Option = (None, parse_opt_string, [UNTRACKED], "enable incremental compilation"), + default_linker_libraries: Option = (None, parse_opt_bool, [UNTRACKED], + "allow the linker to link its default libraries"), } options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, diff --git a/src/librustc_codegen_llvm/back/link.rs b/src/librustc_codegen_llvm/back/link.rs index ce52fe00b0eb2..9fac343b846e4 100644 --- a/src/librustc_codegen_llvm/back/link.rs +++ b/src/librustc_codegen_llvm/back/link.rs @@ -1138,12 +1138,16 @@ fn link_args(cmd: &mut dyn Linker, // Pass debuginfo flags down to the linker. cmd.debuginfo(); - // We want to prevent the compiler from accidentally leaking in any system - // libraries, so we explicitly ask gcc to not link to any libraries by - // default. Note that this does not happen for windows because windows pulls - // in some large number of libraries and I couldn't quite figure out which - // subset we wanted. - if t.options.no_default_libraries { + // We want to, by default, prevent the compiler from accidentally leaking in + // any system libraries, so we may explicitly ask linkers to not link to any + // libraries by default. Note that this does not happen for windows because + // windows pulls in some large number of libraries and I couldn't quite + // figure out which subset we wanted. + // + // This is all naturally configurable via the standard methods as well. + if !sess.opts.cg.default_linker_libraries.unwrap_or(false) && + t.options.no_default_libraries + { cmd.no_default_libraries(); }