refactor add_gcc_ld_path
into its final form
This commit is contained in:
parent
0fb80715bb
commit
1da271b6d0
2 changed files with 67 additions and 50 deletions
|
@ -12,7 +12,7 @@ use rustc_metadata::fs::{copy_to_stdout, emit_wrapper_file, METADATA_FILENAME};
|
||||||
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
|
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
|
||||||
use rustc_middle::middle::dependency_format::Linkage;
|
use rustc_middle::middle::dependency_format::Linkage;
|
||||||
use rustc_middle::middle::exported_symbols::SymbolExportKind;
|
use rustc_middle::middle::exported_symbols::SymbolExportKind;
|
||||||
use rustc_session::config::{self, CFGuard, CrateType, DebugInfo, LdImpl, Strip};
|
use rustc_session::config::{self, CFGuard, CrateType, DebugInfo, Strip};
|
||||||
use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, SplitDwarfKind};
|
use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, SplitDwarfKind};
|
||||||
use rustc_session::cstore::DllImport;
|
use rustc_session::cstore::DllImport;
|
||||||
use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename};
|
use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename};
|
||||||
|
@ -2246,7 +2246,8 @@ fn add_order_independent_options(
|
||||||
out_filename: &Path,
|
out_filename: &Path,
|
||||||
tmpdir: &Path,
|
tmpdir: &Path,
|
||||||
) {
|
) {
|
||||||
add_gcc_ld_path(cmd, sess, flavor);
|
// Take care of the flavors and CLI options requesting the `lld` linker.
|
||||||
|
add_lld_args(cmd, sess, flavor);
|
||||||
|
|
||||||
add_apple_sdk(cmd, sess, flavor);
|
add_apple_sdk(cmd, sess, flavor);
|
||||||
|
|
||||||
|
@ -2948,16 +2949,31 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, errors::AppleSdkRootErro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
|
/// When using the linker flavors opting in to `lld`, or the unstable `-Zgcc-ld=lld` flag, add the
|
||||||
if let Some(ld_impl) = sess.opts.unstable_opts.gcc_ld {
|
/// necessary paths and arguments to invoke it:
|
||||||
if let LinkerFlavor::Gnu(Cc::Yes, _)
|
/// - when the self-contained linker flag is active: the build of `lld` distributed with rustc,
|
||||||
| LinkerFlavor::Darwin(Cc::Yes, _)
|
/// - or any `lld` available to `cc`.
|
||||||
| LinkerFlavor::WasmLld(Cc::Yes) = flavor
|
fn add_lld_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
|
||||||
{
|
let unstable_use_lld = sess.opts.unstable_opts.gcc_ld.is_some();
|
||||||
match ld_impl {
|
debug!("add_lld_args requested, flavor: '{flavor:?}', `-Zgcc-ld=lld`: {unstable_use_lld}");
|
||||||
LdImpl::Lld => {
|
|
||||||
// Implement the "self-contained" part of -Zgcc-ld
|
// Sanity check: using the old unstable `-Zgcc-ld=lld` option requires a `cc`-using flavor.
|
||||||
// by adding rustc distribution directories to the tool search path.
|
let flavor_uses_cc = flavor.uses_cc();
|
||||||
|
if unstable_use_lld && !flavor_uses_cc {
|
||||||
|
sess.emit_fatal(errors::OptionGccOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the flavor doesn't use a C/C++ compiler to invoke the linker, or doesn't opt in to `lld`,
|
||||||
|
// we don't need to do anything.
|
||||||
|
let use_lld = flavor.uses_lld() || unstable_use_lld;
|
||||||
|
if !flavor_uses_cc || !use_lld {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Implement the "self-contained" part of this feature by adding rustc distribution
|
||||||
|
// directories to the tool's search path.
|
||||||
|
let self_contained_linker = sess.opts.cg.link_self_contained.linker() || unstable_use_lld;
|
||||||
|
if self_contained_linker {
|
||||||
for path in sess.get_tools_search_paths(false) {
|
for path in sess.get_tools_search_paths(false) {
|
||||||
cmd.arg({
|
cmd.arg({
|
||||||
let mut arg = OsString::from("-B");
|
let mut arg = OsString::from("-B");
|
||||||
|
@ -2965,8 +2981,10 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
|
||||||
arg
|
arg
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Implement the "linker flavor" part of -Zgcc-ld
|
}
|
||||||
// by asking cc to use some kind of lld.
|
|
||||||
|
// 2. Implement the "linker flavor" part of this feature by asking `cc` to use some kind of
|
||||||
|
// `lld` as the linker.
|
||||||
cmd.arg("-fuse-ld=lld");
|
cmd.arg("-fuse-ld=lld");
|
||||||
|
|
||||||
if !flavor.is_gnu() {
|
if !flavor.is_gnu() {
|
||||||
|
@ -2994,9 +3012,3 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sess.emit_fatal(errors::OptionGccOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -307,6 +307,11 @@ impl LinkSelfContained {
|
||||||
on.set_all_explicitly(true);
|
on.set_all_explicitly(true);
|
||||||
on
|
on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns whether the self-contained linker component is enabled.
|
||||||
|
pub fn linker(&self) -> bool {
|
||||||
|
self.components.contains(LinkSelfContainedComponents::LINKER)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used with `-Z assert-incr-state`.
|
/// Used with `-Z assert-incr-state`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue