use super::command::Command;
use super::symbol_export;
use crate::errors;
use rustc_span::symbol::sym;
use std::ffi::{OsStr, OsString};
use std::fs::{self, File};
use std::io::prelude::*;
use std::io::{self, BufWriter};
use std::path::{Path, PathBuf};
use std::{env, iter, mem, str};
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_metadata::find_native_static_library;
use rustc_middle::bug;
use rustc_middle::middle::dependency_format::Linkage;
use rustc_middle::middle::exported_symbols;
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo, SymbolExportKind};
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip};
use rustc_session::Session;
use rustc_target::spec::{Cc, LinkOutputKind, LinkerFlavor, Lld};
use cc::windows_registry;
use tracing::{debug, warn};
pub fn disable_localization(linker: &mut Command) {
linker.env("LC_ALL", "C");
linker.env("VSLANG", "1033");
}
pub fn get_linker<'a>(
sess: &'a Session,
linker: &Path,
flavor: LinkerFlavor,
self_contained: bool,
target_cpu: &'a str,
) -> Box<dyn Linker + 'a> {
let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.triple(), "link.exe");
let mut cmd = match linker.to_str() {
Some(linker) if cfg!(windows) && linker.ends_with(".bat") => Command::bat_script(linker),
_ => match flavor {
LinkerFlavor::Gnu(Cc::No, Lld::Yes)
| LinkerFlavor::Darwin(Cc::No, Lld::Yes)
| LinkerFlavor::WasmLld(Cc::No)
| LinkerFlavor::Msvc(Lld::Yes) => Command::lld(linker, flavor.lld_flavor()),
LinkerFlavor::Msvc(Lld::No)
if sess.opts.cg.linker.is_none() && sess.target.linker.is_none() =>
{
Command::new(msvc_tool.as_ref().map_or(linker, |t| t.path()))
}
_ => Command::new(linker),
},
};
let t = &sess.target;
if matches!(flavor, LinkerFlavor::Msvc(..)) && t.vendor == "uwp" {
if let Some(ref tool) = msvc_tool {
let original_path = tool.path();
if let Some(root_lib_path) = original_path.ancestors().nth(4) {
let arch = match t.arch.as_ref() {
"x86_64" => Some("x64"),
"x86" => Some("x86"),
"aarch64" => Some("arm64"),
"arm" => Some("arm"),
_ => None,
};
if let Some(ref a) = arch {
let mut arg = OsString::from("/LIBPATH:");
arg.push(format!("{}\\lib\\{}\\store", root_lib_path.display(), a));
cmd.arg(&arg);
} else {
warn!("arch is not supported");
}
} else {
warn!("MSVC root path lib location not found");
}
} else {
warn!("link.exe not found");
}
}
let mut new_path = sess.get_tools_search_paths(self_contained);
let mut msvc_changed_path = false;
if sess.target.is_like_msvc {
if let Some(ref tool) = msvc_tool {
cmd.args(tool.args());
for (k, v) in tool.env() {
if k == "PATH" {
new_path.extend(env::split_paths(v));
msvc_changed_path = true;
} else {
cmd.env(k, v);
}
}
}
}
if !msvc_changed_path {
if let Some(path) = env::var_os("PATH") {
new_path.extend(env::split_paths(&path));
}
}
cmd.env("PATH", env::join_paths(new_path).unwrap());
assert!(cmd.get_args().is_empty() || sess.target.vendor == "uwp");
match flavor {
LinkerFlavor::Unix(Cc::No) if sess.target.os == "l4re" => {
Box::new(L4Bender::new(cmd, sess)) as Box<dyn Linker>
}
LinkerFlavor::Unix(Cc::No) if sess.target.os == "aix" => {
Box::new(AixLinker::new(cmd, sess)) as Box<dyn Linker>
}
LinkerFlavor::WasmLld(Cc::No) => Box::new(WasmLd::new(cmd, sess)) as Box<dyn Linker>,
LinkerFlavor::Gnu(cc, _)
| LinkerFlavor::Darwin(cc, _)
| LinkerFlavor::WasmLld(cc)
| LinkerFlavor::Unix(cc) => Box::new(GccLinker {
cmd,
sess,
target_cpu,
hinted_static: None,
is_ld: cc == Cc::No,
is_gnu: flavor.is_gnu(),
}) as Box<dyn Linker>,
LinkerFlavor::Msvc(..) => Box::new(MsvcLinker { cmd, sess }) as Box<dyn Linker>,
LinkerFlavor::EmCc => Box::new(EmLinker { cmd, sess }) as Box<dyn Linker>,
LinkerFlavor::Bpf => Box::new(BpfLinker { cmd, sess }) as Box<dyn Linker>,
LinkerFlavor::Llbc => Box::new(LlbcLinker { cmd, sess }) as Box<dyn Linker>,
LinkerFlavor::Ptx => Box::new(PtxLinker { cmd, sess }) as Box<dyn Linker>,
}
}
fn verbatim_args<L: Linker + ?Sized>(
l: &mut L,
args: impl IntoIterator<Item: AsRef<OsStr>>,
) -> &mut L {
for arg in args {
l.cmd().arg(arg);
}
l
}
fn link_args<L: Linker + ?Sized>(
l: &mut L,
args: impl IntoIterator<Item: AsRef<OsStr>, IntoIter: ExactSizeIterator>,
) -> &mut L {
let args = args.into_iter();
if !l.is_cc() {
verbatim_args(l, args);
} else if args.len() != 0 {
let mut combined_arg = OsString::from("-Wl");
for arg in args {
combined_arg.push(",");
combined_arg.push(arg);
}
l.cmd().arg(combined_arg);
}
l
}
fn cc_args<L: Linker + ?Sized>(l: &mut L, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut L {
assert!(l.is_cc());
verbatim_args(l, args)
}
fn link_or_cc_args<L: Linker + ?Sized>(
l: &mut L,
args: impl IntoIterator<Item: AsRef<OsStr>>,
) -> &mut L {
verbatim_args(l, args)
}
macro_rules! generate_arg_methods {
($($ty:ty)*) => { $(
impl $ty {
pub fn verbatim_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
verbatim_args(self, args)
}
pub fn verbatim_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
verbatim_args(self, iter::once(arg))
}
pub fn link_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>, IntoIter: ExactSizeIterator>) -> &mut Self {
link_args(self, args)
}
pub fn link_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
link_args(self, iter::once(arg))
}
pub fn cc_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
cc_args(self, args)
}
pub fn cc_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
cc_args(self, iter::once(arg))
}
pub fn link_or_cc_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
link_or_cc_args(self, args)
}
pub fn link_or_cc_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
link_or_cc_args(self, iter::once(arg))
}
}
)* }
}
generate_arg_methods! {
GccLinker<'_>
MsvcLinker<'_>
EmLinker<'_>
WasmLd<'_>
L4Bender<'_>
AixLinker<'_>
LlbcLinker<'_>
PtxLinker<'_>
BpfLinker<'_>
dyn Linker + '_
}
pub trait Linker {
fn cmd(&mut self) -> &mut Command;
fn is_cc(&self) -> bool {
false
}
fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path);
fn link_dylib_by_name(&mut self, _name: &str, _verbatim: bool, _as_needed: bool) {
bug!("dylib linked with unsupported linker")
}
fn link_dylib_by_path(&mut self, _path: &Path, _as_needed: bool) {
bug!("dylib linked with unsupported linker")
}
fn link_framework_by_name(&mut self, _name: &str, _verbatim: bool, _as_needed: bool) {
bug!("framework linked with unsupported linker")
}
fn link_staticlib_by_name(&mut self, name: &str, verbatim: bool, whole_archive: bool);
fn link_staticlib_by_path(&mut self, path: &Path, whole_archive: bool);
fn include_path(&mut self, path: &Path) {
link_or_cc_args(link_or_cc_args(self, &["-L"]), &[path]);
}
fn framework_path(&mut self, _path: &Path) {
bug!("framework path set with unsupported linker")
}
fn output_filename(&mut self, path: &Path) {
link_or_cc_args(link_or_cc_args(self, &["-o"]), &[path]);
}
fn add_object(&mut self, path: &Path) {
link_or_cc_args(self, &[path]);
}
fn gc_sections(&mut self, keep_metadata: bool);
fn no_gc_sections(&mut self);
fn full_relro(&mut self);
fn partial_relro(&mut self);
fn no_relro(&mut self);
fn optimize(&mut self);
fn pgo_gen(&mut self);
fn control_flow_guard(&mut self);
fn ehcont_guard(&mut self);
fn debuginfo(&mut self, strip: Strip, natvis_debugger_visualizers: &[PathBuf]);
fn no_crt_objects(&mut self);
fn no_default_libraries(&mut self);
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]);
fn subsystem(&mut self, subsystem: &str);
fn linker_plugin_lto(&mut self);
fn add_eh_frame_header(&mut self) {}
fn add_no_exec(&mut self) {}
fn add_as_needed(&mut self) {}
fn reset_per_library_state(&mut self) {}
}
impl dyn Linker + '_ {
pub fn take_cmd(&mut self) -> Command {
mem::replace(self.cmd(), Command::new(""))
}
}
pub struct GccLinker<'a> {
cmd: Command,
sess: &'a Session,
target_cpu: &'a str,
hinted_static: Option<bool>, is_ld: bool,
is_gnu: bool,
}
impl<'a> GccLinker<'a> {
fn takes_hints(&self) -> bool {
!self.sess.target.is_like_osx && !self.sess.target.is_like_wasm
}
fn hint_static(&mut self) {
if !self.takes_hints() {
return;
}
if self.hinted_static != Some(true) {
self.link_arg("-Bstatic");
self.hinted_static = Some(true);
}
}
fn hint_dynamic(&mut self) {
if !self.takes_hints() {
return;
}
if self.hinted_static != Some(false) {
self.link_arg("-Bdynamic");
self.hinted_static = Some(false);
}
}
fn push_linker_plugin_lto_args(&mut self, plugin_path: Option<&OsStr>) {
if let Some(plugin_path) = plugin_path {
let mut arg = OsString::from("-plugin=");
arg.push(plugin_path);
self.link_arg(&arg);
}
let opt_level = match self.sess.opts.optimize {
config::OptLevel::No => "O0",
config::OptLevel::Less => "O1",
config::OptLevel::Default | config::OptLevel::Size | config::OptLevel::SizeMin => "O2",
config::OptLevel::Aggressive => "O3",
};
if let Some(path) = &self.sess.opts.unstable_opts.profile_sample_use {
self.link_arg(&format!("-plugin-opt=sample-profile={}", path.display()));
};
self.link_args(&[
&format!("-plugin-opt={opt_level}"),
&format!("-plugin-opt=mcpu={}", self.target_cpu),
]);
}
fn build_dylib(&mut self, out_filename: &Path) {
if self.sess.target.is_like_osx {
if !self.is_ld {
self.cc_arg("-dynamiclib");
}
self.link_arg("-dylib");
if self.sess.opts.cg.rpath || self.sess.opts.unstable_opts.osx_rpath_install_name {
let mut rpath = OsString::from("@rpath/");
rpath.push(out_filename.file_name().unwrap());
self.link_arg("-install_name").link_arg(rpath);
}
} else {
self.link_or_cc_arg("-shared");
if let Some(name) = out_filename.file_name() {
if self.sess.target.is_like_windows {
let mut implib_name = OsString::from(&*self.sess.target.staticlib_prefix);
implib_name.push(name);
implib_name.push(&*self.sess.target.staticlib_suffix);
let mut out_implib = OsString::from("--out-implib=");
out_implib.push(out_filename.with_file_name(implib_name));
self.link_arg(out_implib);
} else {
let mut soname = OsString::from("-soname=");
soname.push(name);
self.link_arg(soname);
}
}
}
}
fn with_as_needed(&mut self, as_needed: bool, f: impl FnOnce(&mut Self)) {
if !as_needed {
if self.sess.target.is_like_osx {
self.sess.dcx().emit_warn(errors::Ld64UnimplementedModifier);
} else if self.is_gnu && !self.sess.target.is_like_windows {
self.link_arg("--no-as-needed");
} else {
self.sess.dcx().emit_warn(errors::LinkerUnsupportedModifier);
}
}
f(self);
if !as_needed {
if self.sess.target.is_like_osx {
} else if self.is_gnu && !self.sess.target.is_like_windows {
self.link_arg("--as-needed");
}
}
}
}
impl<'a> Linker for GccLinker<'a> {
fn cmd(&mut self) -> &mut Command {
&mut self.cmd
}
fn is_cc(&self) -> bool {
!self.is_ld
}
fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path) {
match output_kind {
LinkOutputKind::DynamicNoPicExe => {
if !self.is_ld && self.is_gnu {
self.cc_arg("-no-pie");
}
}
LinkOutputKind::DynamicPicExe => {
if !self.sess.target.is_like_windows {
self.link_or_cc_arg("-pie");
}
}
LinkOutputKind::StaticNoPicExe => {
self.link_or_cc_arg("-static");
if !self.is_ld && self.is_gnu {
self.cc_arg("-no-pie");
}
}
LinkOutputKind::StaticPicExe => {
if !self.is_ld {
self.cc_arg("-static-pie");
} else {
self.link_args(&["-static", "-pie", "--no-dynamic-linker", "-z", "text"]);
}
}
LinkOutputKind::DynamicDylib => self.build_dylib(out_filename),
LinkOutputKind::StaticDylib => {
self.link_or_cc_arg("-static");
self.build_dylib(out_filename);
}
LinkOutputKind::WasiReactorExe => {
self.link_args(&["--entry", "_initialize"]);
}
}
if self.sess.target.os == "vxworks"
&& matches!(
output_kind,
LinkOutputKind::StaticNoPicExe
| LinkOutputKind::StaticPicExe
| LinkOutputKind::StaticDylib
)
{
self.cc_arg("--static-crt");
}
}
fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, as_needed: bool) {
if self.sess.target.os == "illumos" && name == "c" {
return;
}
self.hint_dynamic();
self.with_as_needed(as_needed, |this| {
let colon = if verbatim && this.is_gnu { ":" } else { "" };
this.link_or_cc_arg(format!("-l{colon}{name}"));
});
}
fn link_dylib_by_path(&mut self, path: &Path, as_needed: bool) {
self.hint_dynamic();
self.with_as_needed(as_needed, |this| {
this.link_or_cc_arg(path);
})
}
fn link_framework_by_name(&mut self, name: &str, _verbatim: bool, as_needed: bool) {
self.hint_dynamic();
if !as_needed {
self.sess.dcx().emit_warn(errors::Ld64UnimplementedModifier);
}
self.link_or_cc_args(&["-framework", name]);
}
fn link_staticlib_by_name(&mut self, name: &str, verbatim: bool, whole_archive: bool) {
self.hint_static();
let colon = if verbatim && self.is_gnu { ":" } else { "" };
if !whole_archive {
self.link_or_cc_arg(format!("-l{colon}{name}"));
} else if self.sess.target.is_like_osx {
self.link_arg("-force_load");
self.link_arg(find_native_static_library(name, verbatim, self.sess));
} else {
self.link_arg("--whole-archive")
.link_or_cc_arg(format!("-l{colon}{name}"))
.link_arg("--no-whole-archive");
}
}
fn link_staticlib_by_path(&mut self, path: &Path, whole_archive: bool) {
self.hint_static();
if !whole_archive {
self.link_or_cc_arg(path);
} else if self.sess.target.is_like_osx {
self.link_arg("-force_load").link_arg(path);
} else {
self.link_arg("--whole-archive").link_arg(path).link_arg("--no-whole-archive");
}
}
fn framework_path(&mut self, path: &Path) {
self.link_or_cc_arg("-F").link_or_cc_arg(path);
}
fn full_relro(&mut self) {
self.link_args(&["-z", "relro", "-z", "now"]);
}
fn partial_relro(&mut self) {
self.link_args(&["-z", "relro"]);
}
fn no_relro(&mut self) {
self.link_args(&["-z", "norelro"]);
}
fn gc_sections(&mut self, keep_metadata: bool) {
if self.sess.target.is_like_osx {
self.link_arg("-dead_strip");
} else if (self.is_gnu || self.sess.target.is_like_wasm) && !keep_metadata {
self.link_arg("--gc-sections");
}
}
fn no_gc_sections(&mut self) {
if self.is_gnu || self.sess.target.is_like_wasm {
self.link_arg("--no-gc-sections");
}
}
fn optimize(&mut self) {
if !self.is_gnu && !self.sess.target.is_like_wasm {
return;
}
if self.sess.opts.optimize == config::OptLevel::Default
|| self.sess.opts.optimize == config::OptLevel::Aggressive
{
self.link_arg("-O1");
}
}
fn pgo_gen(&mut self) {
if !self.is_gnu {
return;
}
self.link_or_cc_args(&["-u", "__llvm_profile_runtime"]);
}
fn control_flow_guard(&mut self) {}
fn ehcont_guard(&mut self) {}
fn debuginfo(&mut self, strip: Strip, _: &[PathBuf]) {
if self.sess.target.is_like_osx {
return;
}
match strip {
Strip::None => {}
Strip::Debuginfo => {
if !self.sess.target.is_like_solaris {
self.link_arg("--strip-debug");
}
}
Strip::Symbols => {
self.link_arg("--strip-all");
}
}
match self.sess.opts.unstable_opts.debuginfo_compression {
config::DebugInfoCompression::None => {}
config::DebugInfoCompression::Zlib => {
self.link_arg("--compress-debug-sections=zlib");
}
config::DebugInfoCompression::Zstd => {
self.link_arg("--compress-debug-sections=zstd");
}
}
}
fn no_crt_objects(&mut self) {
if !self.is_ld {
self.cc_arg("-nostartfiles");
}
}
fn no_default_libraries(&mut self) {
if !self.is_ld {
self.cc_arg("-nodefaultlibs");
}
}
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]) {
if crate_type == CrateType::Executable {
let should_export_executable_symbols =
self.sess.opts.unstable_opts.export_executable_symbols;
if self.sess.target.override_export_symbols.is_none()
&& !should_export_executable_symbols
{
return;
}
}
if !self.sess.target.limit_rdylib_exports {
return;
}
let is_windows = self.sess.target.is_like_windows;
let path = tmpdir.join(if is_windows { "list.def" } else { "list" });
debug!("EXPORTED SYMBOLS:");
if self.sess.target.is_like_osx {
let res: io::Result<()> = try {
let mut f = BufWriter::new(File::create(&path)?);
for sym in symbols {
debug!(" _{sym}");
writeln!(f, "_{sym}")?;
}
};
if let Err(error) = res {
self.sess.dcx().emit_fatal(errors::LibDefWriteFailure { error });
}
} else if is_windows {
let res: io::Result<()> = try {
let mut f = BufWriter::new(File::create(&path)?);
writeln!(f, "EXPORTS")?;
for symbol in symbols {
debug!(" _{symbol}");
writeln!(f, " {symbol}")?;
}
};
if let Err(error) = res {
self.sess.dcx().emit_fatal(errors::LibDefWriteFailure { error });
}
} else {
let res: io::Result<()> = try {
let mut f = BufWriter::new(File::create(&path)?);
writeln!(f, "{{")?;
if !symbols.is_empty() {
writeln!(f, " global:")?;
for sym in symbols {
debug!(" {sym};");
writeln!(f, " {sym};")?;
}
}
writeln!(f, "\n local:\n *;\n}};")?;
};
if let Err(error) = res {
self.sess.dcx().emit_fatal(errors::VersionScriptWriteFailure { error });
}
}
if self.sess.target.is_like_osx {
self.link_arg("-exported_symbols_list").link_arg(path);
} else if self.sess.target.is_like_solaris {
self.link_arg("-M").link_arg(path);
} else {
if is_windows {
self.link_arg(path);
} else {
let mut arg = OsString::from("--version-script=");
arg.push(path);
self.link_arg(arg).link_arg("--no-undefined-version");
}
}
}
fn subsystem(&mut self, subsystem: &str) {
self.link_args(&["--subsystem", subsystem]);
}
fn reset_per_library_state(&mut self) {
self.hint_dynamic(); }
fn linker_plugin_lto(&mut self) {
match self.sess.opts.cg.linker_plugin_lto {
LinkerPluginLto::Disabled => {
}
LinkerPluginLto::LinkerPluginAuto => {
self.push_linker_plugin_lto_args(None);
}
LinkerPluginLto::LinkerPlugin(ref path) => {
self.push_linker_plugin_lto_args(Some(path.as_os_str()));
}
}
}
fn add_eh_frame_header(&mut self) {
self.link_arg("--eh-frame-hdr");
}
fn add_no_exec(&mut self) {
if self.sess.target.is_like_windows {
self.link_arg("--nxcompat");
} else if self.is_gnu {
self.link_args(&["-z", "noexecstack"]);
}
}
fn add_as_needed(&mut self) {
if self.is_gnu && !self.sess.target.is_like_windows {
self.link_arg("--as-needed");
} else if self.sess.target.is_like_solaris {
self.link_args(&["-z", "ignore"]);
}
}
}
pub struct MsvcLinker<'a> {
cmd: Command,
sess: &'a Session,
}
impl<'a> Linker for MsvcLinker<'a> {
fn cmd(&mut self) -> &mut Command {
&mut self.cmd
}
fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path) {
match output_kind {
LinkOutputKind::DynamicNoPicExe
| LinkOutputKind::DynamicPicExe
| LinkOutputKind::StaticNoPicExe
| LinkOutputKind::StaticPicExe => {}
LinkOutputKind::DynamicDylib | LinkOutputKind::StaticDylib => {
self.link_arg("/DLL");
let mut arg: OsString = "/IMPLIB:".into();
arg.push(out_filename.with_extension("dll.lib"));
self.link_arg(arg);
}
LinkOutputKind::WasiReactorExe => {
panic!("can't link as reactor on non-wasi target");
}
}
}
fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, _as_needed: bool) {
self.link_arg(format!("{}{}", name, if verbatim { "" } else { ".lib" }));
}
fn link_dylib_by_path(&mut self, path: &Path, _as_needed: bool) {
let implib_path = path.with_extension("dll.lib");
if implib_path.exists() {
self.link_or_cc_arg(implib_path);
}
}
fn link_staticlib_by_name(&mut self, name: &str, verbatim: bool, whole_archive: bool) {
let prefix = if whole_archive { "/WHOLEARCHIVE:" } else { "" };
let suffix = if verbatim { "" } else { ".lib" };
self.link_arg(format!("{prefix}{name}{suffix}"));
}
fn link_staticlib_by_path(&mut self, path: &Path, whole_archive: bool) {
if !whole_archive {
self.link_arg(path);
} else {
let mut arg = OsString::from("/WHOLEARCHIVE:");
arg.push(path);
self.link_arg(arg);
}
}
fn gc_sections(&mut self, _keep_metadata: bool) {
if self.sess.opts.optimize != config::OptLevel::No {
self.link_arg("/OPT:REF,ICF");
} else {
self.link_arg("/OPT:REF,NOICF");
}
}
fn no_gc_sections(&mut self) {
self.link_arg("/OPT:NOREF,NOICF");
}
fn full_relro(&mut self) {
}
fn partial_relro(&mut self) {
}
fn no_relro(&mut self) {
}
fn no_crt_objects(&mut self) {
}
fn no_default_libraries(&mut self) {
self.link_arg("/NODEFAULTLIB");
}
fn include_path(&mut self, path: &Path) {
let mut arg = OsString::from("/LIBPATH:");
arg.push(path);
self.link_arg(&arg);
}
fn output_filename(&mut self, path: &Path) {
let mut arg = OsString::from("/OUT:");
arg.push(path);
self.link_arg(&arg);
}
fn optimize(&mut self) {
}
fn pgo_gen(&mut self) {
}
fn control_flow_guard(&mut self) {
self.link_arg("/guard:cf");
}
fn ehcont_guard(&mut self) {
if self.sess.target.pointer_width == 64 {
self.link_arg("/guard:ehcont");
}
}
fn debuginfo(&mut self, _strip: Strip, natvis_debugger_visualizers: &[PathBuf]) {
self.link_arg("/DEBUG");
self.link_arg("/PDBALTPATH:%_PDB%");
let natvis_dir_path = self.sess.sysroot.join("lib\\rustlib\\etc");
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
for entry in natvis_dir {
match entry {
Ok(entry) => {
let path = entry.path();
if path.extension() == Some("natvis".as_ref()) {
let mut arg = OsString::from("/NATVIS:");
arg.push(path);
self.link_arg(arg);
}
}
Err(error) => {
self.sess.dcx().emit_warn(errors::NoNatvisDirectory { error });
}
}
}
}
for path in natvis_debugger_visualizers {
let mut arg = OsString::from("/NATVIS:");
arg.push(path);
self.link_arg(arg);
}
}
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]) {
if crate_type == CrateType::Executable {
let should_export_executable_symbols =
self.sess.opts.unstable_opts.export_executable_symbols;
if !should_export_executable_symbols {
return;
}
}
let path = tmpdir.join("lib.def");
let res: io::Result<()> = try {
let mut f = BufWriter::new(File::create(&path)?);
writeln!(f, "LIBRARY")?;
writeln!(f, "EXPORTS")?;
for symbol in symbols {
debug!(" _{symbol}");
writeln!(f, " {symbol}")?;
}
};
if let Err(error) = res {
self.sess.dcx().emit_fatal(errors::LibDefWriteFailure { error });
}
let mut arg = OsString::from("/DEF:");
arg.push(path);
self.link_arg(&arg);
}
fn subsystem(&mut self, subsystem: &str) {
self.link_arg(&format!("/SUBSYSTEM:{subsystem}"));
if subsystem == "windows" {
self.link_arg("/ENTRY:mainCRTStartup");
}
}
fn linker_plugin_lto(&mut self) {
}
fn add_no_exec(&mut self) {
self.link_arg("/NXCOMPAT");
}
}
pub struct EmLinker<'a> {
cmd: Command,
sess: &'a Session,
}
impl<'a> Linker for EmLinker<'a> {
fn cmd(&mut self) -> &mut Command {
&mut self.cmd
}
fn is_cc(&self) -> bool {
true
}
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
fn link_dylib_by_name(&mut self, name: &str, _verbatim: bool, _as_needed: bool) {
self.link_or_cc_args(&["-l", name]);
}
fn link_dylib_by_path(&mut self, path: &Path, _as_needed: bool) {
self.link_or_cc_arg(path);
}
fn link_staticlib_by_name(&mut self, name: &str, _verbatim: bool, _whole_archive: bool) {
self.link_or_cc_args(&["-l", name]);
}
fn link_staticlib_by_path(&mut self, path: &Path, _whole_archive: bool) {
self.link_or_cc_arg(path);
}
fn full_relro(&mut self) {
}
fn partial_relro(&mut self) {
}
fn no_relro(&mut self) {
}
fn gc_sections(&mut self, _keep_metadata: bool) {
}
fn no_gc_sections(&mut self) {
}
fn optimize(&mut self) {
self.cc_arg(match self.sess.opts.optimize {
OptLevel::No => "-O0",
OptLevel::Less => "-O1",
OptLevel::Default => "-O2",
OptLevel::Aggressive => "-O3",
OptLevel::Size => "-Os",
OptLevel::SizeMin => "-Oz",
});
}
fn pgo_gen(&mut self) {
}
fn control_flow_guard(&mut self) {}
fn ehcont_guard(&mut self) {}
fn debuginfo(&mut self, _strip: Strip, _: &[PathBuf]) {
self.cc_arg(match self.sess.opts.debuginfo {
DebugInfo::None => "-g0",
DebugInfo::Limited | DebugInfo::LineTablesOnly | DebugInfo::LineDirectivesOnly => {
"--profiling-funcs"
}
DebugInfo::Full => "-g",
});
}
fn no_crt_objects(&mut self) {}
fn no_default_libraries(&mut self) {
self.cc_arg("-nodefaultlibs");
}
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
debug!("EXPORTED SYMBOLS:");
self.cc_arg("-s");
let mut arg = OsString::from("EXPORTED_FUNCTIONS=");
let encoded = serde_json::to_string(
&symbols.iter().map(|sym| "_".to_owned() + sym).collect::<Vec<_>>(),
)
.unwrap();
debug!("{encoded}");
arg.push(encoded);
self.cc_arg(arg);
}
fn subsystem(&mut self, _subsystem: &str) {
}
fn linker_plugin_lto(&mut self) {
}
}
pub struct WasmLd<'a> {
cmd: Command,
sess: &'a Session,
}
impl<'a> WasmLd<'a> {
fn new(cmd: Command, sess: &'a Session) -> WasmLd<'a> {
let mut wasm_ld = WasmLd { cmd, sess };
if sess.target_features.contains(&sym::atomics) {
wasm_ld.link_args(&["--shared-memory", "--max-memory=1073741824", "--import-memory"]);
if sess.target.os == "unknown" {
wasm_ld.link_args(&[
"--export=__wasm_init_tls",
"--export=__tls_size",
"--export=__tls_align",
"--export=__tls_base",
]);
}
}
wasm_ld
}
}
impl<'a> Linker for WasmLd<'a> {
fn cmd(&mut self) -> &mut Command {
&mut self.cmd
}
fn set_output_kind(&mut self, output_kind: LinkOutputKind, _out_filename: &Path) {
match output_kind {
LinkOutputKind::DynamicNoPicExe
| LinkOutputKind::DynamicPicExe
| LinkOutputKind::StaticNoPicExe
| LinkOutputKind::StaticPicExe => {}
LinkOutputKind::DynamicDylib | LinkOutputKind::StaticDylib => {
self.link_arg("--no-entry");
}
LinkOutputKind::WasiReactorExe => {
self.link_args(&["--entry", "_initialize"]);
}
}
}
fn link_dylib_by_name(&mut self, name: &str, _verbatim: bool, _as_needed: bool) {
self.link_or_cc_args(&["-l", name]);
}
fn link_dylib_by_path(&mut self, path: &Path, _as_needed: bool) {
self.link_or_cc_arg(path);
}
fn link_staticlib_by_name(&mut self, name: &str, _verbatim: bool, whole_archive: bool) {
if !whole_archive {
self.link_or_cc_args(&["-l", name]);
} else {
self.link_arg("--whole-archive")
.link_or_cc_args(&["-l", name])
.link_arg("--no-whole-archive");
}
}
fn link_staticlib_by_path(&mut self, path: &Path, whole_archive: bool) {
if !whole_archive {
self.link_or_cc_arg(path);
} else {
self.link_arg("--whole-archive").link_or_cc_arg(path).link_arg("--no-whole-archive");
}
}
fn full_relro(&mut self) {}
fn partial_relro(&mut self) {}
fn no_relro(&mut self) {}
fn gc_sections(&mut self, _keep_metadata: bool) {
self.link_arg("--gc-sections");
}
fn no_gc_sections(&mut self) {
self.link_arg("--no-gc-sections");
}
fn optimize(&mut self) {
self.link_arg(match self.sess.opts.optimize {
OptLevel::No => "-O0",
OptLevel::Less => "-O1",
OptLevel::Default => "-O2",
OptLevel::Aggressive => "-O3",
OptLevel::Size => "-O2",
OptLevel::SizeMin => "-O2",
});
}
fn pgo_gen(&mut self) {}
fn debuginfo(&mut self, strip: Strip, _: &[PathBuf]) {
match strip {
Strip::None => {}
Strip::Debuginfo => {
self.link_arg("--strip-debug");
}
Strip::Symbols => {
self.link_arg("--strip-all");
}
}
}
fn control_flow_guard(&mut self) {}
fn ehcont_guard(&mut self) {}
fn no_crt_objects(&mut self) {}
fn no_default_libraries(&mut self) {}
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
for sym in symbols {
self.link_args(&["--export", sym]);
}
if self.sess.target.os == "unknown" {
self.link_args(&["--export=__heap_base", "--export=__data_end"]);
}
}
fn subsystem(&mut self, _subsystem: &str) {}
fn linker_plugin_lto(&mut self) {
match self.sess.opts.cg.linker_plugin_lto {
LinkerPluginLto::Disabled => {
}
LinkerPluginLto::LinkerPluginAuto => {
self.push_linker_plugin_lto_args();
}
LinkerPluginLto::LinkerPlugin(_) => {
self.push_linker_plugin_lto_args();
}
}
}
}
impl<'a> WasmLd<'a> {
fn push_linker_plugin_lto_args(&mut self) {
let opt_level = match self.sess.opts.optimize {
config::OptLevel::No => "O0",
config::OptLevel::Less => "O1",
config::OptLevel::Default => "O2",
config::OptLevel::Aggressive => "O3",
config::OptLevel::Size | config::OptLevel::SizeMin => "O2",
};
self.link_arg(&format!("--lto-{opt_level}"));
}
}
pub struct L4Bender<'a> {
cmd: Command,
sess: &'a Session,
hinted_static: bool,
}
impl<'a> Linker for L4Bender<'a> {
fn cmd(&mut self) -> &mut Command {
&mut self.cmd
}
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
fn link_staticlib_by_name(&mut self, name: &str, _verbatim: bool, whole_archive: bool) {
self.hint_static();
if !whole_archive {
self.link_arg(format!("-PC{name}"));
} else {
self.link_arg("--whole-archive")
.link_or_cc_arg(format!("-l{name}"))
.link_arg("--no-whole-archive");
}
}
fn link_staticlib_by_path(&mut self, path: &Path, whole_archive: bool) {
self.hint_static();
if !whole_archive {
self.link_or_cc_arg(path);
} else {
self.link_arg("--whole-archive").link_or_cc_arg(path).link_arg("--no-whole-archive");
}
}
fn full_relro(&mut self) {
self.link_args(&["-z", "relro", "-z", "now"]);
}
fn partial_relro(&mut self) {
self.link_args(&["-z", "relro"]);
}
fn no_relro(&mut self) {
self.link_args(&["-z", "norelro"]);
}
fn gc_sections(&mut self, keep_metadata: bool) {
if !keep_metadata {
self.link_arg("--gc-sections");
}
}
fn no_gc_sections(&mut self) {
self.link_arg("--no-gc-sections");
}
fn optimize(&mut self) {
if self.sess.opts.optimize == config::OptLevel::Default
|| self.sess.opts.optimize == config::OptLevel::Aggressive
{
self.link_arg("-O1");
}
}
fn pgo_gen(&mut self) {}
fn debuginfo(&mut self, strip: Strip, _: &[PathBuf]) {
match strip {
Strip::None => {}
Strip::Debuginfo => {
self.link_arg("--strip-debug");
}
Strip::Symbols => {
self.link_arg("--strip-all");
}
}
}
fn no_default_libraries(&mut self) {
self.cc_arg("-nostdlib");
}
fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[String]) {
self.sess.dcx().emit_warn(errors::L4BenderExportingSymbolsUnimplemented);
return;
}
fn subsystem(&mut self, subsystem: &str) {
self.link_arg(&format!("--subsystem {subsystem}"));
}
fn reset_per_library_state(&mut self) {
self.hint_static(); }
fn linker_plugin_lto(&mut self) {}
fn control_flow_guard(&mut self) {}
fn ehcont_guard(&mut self) {}
fn no_crt_objects(&mut self) {}
}
impl<'a> L4Bender<'a> {
pub fn new(cmd: Command, sess: &'a Session) -> L4Bender<'a> {
L4Bender { cmd, sess: sess, hinted_static: false }
}
fn hint_static(&mut self) {
if !self.hinted_static {
self.link_or_cc_arg("-static");
self.hinted_static = true;
}
}
}
pub struct AixLinker<'a> {
cmd: Command,
sess: &'a Session,
hinted_static: Option<bool>,
}
impl<'a> AixLinker<'a> {
pub fn new(cmd: Command, sess: &'a Session) -> AixLinker<'a> {
AixLinker { cmd, sess: sess, hinted_static: None }
}
fn hint_static(&mut self) {
if self.hinted_static != Some(true) {
self.link_arg("-bstatic");
self.hinted_static = Some(true);
}
}
fn hint_dynamic(&mut self) {
if self.hinted_static != Some(false) {
self.link_arg("-bdynamic");
self.hinted_static = Some(false);
}
}
fn build_dylib(&mut self, _out_filename: &Path) {
self.link_args(&["-bM:SRE", "-bnoentry"]);
self.link_arg("-bexpfull");
}
}
impl<'a> Linker for AixLinker<'a> {
fn cmd(&mut self) -> &mut Command {
&mut self.cmd
}
fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path) {
match output_kind {
LinkOutputKind::DynamicDylib => {
self.hint_dynamic();
self.build_dylib(out_filename);
}
LinkOutputKind::StaticDylib => {
self.hint_static();
self.build_dylib(out_filename);
}
_ => {}
}
}
fn link_dylib_by_name(&mut self, name: &str, _verbatim: bool, _as_needed: bool) {
self.hint_dynamic();
self.link_or_cc_arg(format!("-l{name}"));
}
fn link_dylib_by_path(&mut self, path: &Path, _as_needed: bool) {
self.hint_dynamic();
self.link_or_cc_arg(path);
}
fn link_staticlib_by_name(&mut self, name: &str, verbatim: bool, whole_archive: bool) {
self.hint_static();
if !whole_archive {
self.link_or_cc_arg(format!("-l{name}"));
} else {
let mut arg = OsString::from("-bkeepfile:");
arg.push(find_native_static_library(name, verbatim, self.sess));
self.link_or_cc_arg(arg);
}
}
fn link_staticlib_by_path(&mut self, path: &Path, whole_archive: bool) {
self.hint_static();
if !whole_archive {
self.link_or_cc_arg(path);
} else {
let mut arg = OsString::from("-bkeepfile:");
arg.push(path);
self.link_arg(arg);
}
}
fn full_relro(&mut self) {}
fn partial_relro(&mut self) {}
fn no_relro(&mut self) {}
fn gc_sections(&mut self, _keep_metadata: bool) {
self.link_arg("-bgc");
}
fn no_gc_sections(&mut self) {
self.link_arg("-bnogc");
}
fn optimize(&mut self) {}
fn pgo_gen(&mut self) {
self.link_arg("-bdbg:namedsects:ss");
}
fn control_flow_guard(&mut self) {}
fn ehcont_guard(&mut self) {}
fn debuginfo(&mut self, _: Strip, _: &[PathBuf]) {}
fn no_crt_objects(&mut self) {}
fn no_default_libraries(&mut self) {}
fn export_symbols(&mut self, tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
let path = tmpdir.join("list.exp");
let res: io::Result<()> = try {
let mut f = BufWriter::new(File::create(&path)?);
for symbol in symbols {
debug!(" _{symbol}");
writeln!(f, " {symbol}")?;
}
};
if let Err(e) = res {
self.sess.dcx().fatal(format!("failed to write export file: {e}"));
}
self.link_arg(format!("-bE:{}", path.to_str().unwrap()));
}
fn subsystem(&mut self, _subsystem: &str) {}
fn reset_per_library_state(&mut self) {
self.hint_dynamic();
}
fn linker_plugin_lto(&mut self) {}
fn add_eh_frame_header(&mut self) {}
fn add_no_exec(&mut self) {}
fn add_as_needed(&mut self) {}
}
fn for_each_exported_symbols_include_dep<'tcx>(
tcx: TyCtxt<'tcx>,
crate_type: CrateType,
mut callback: impl FnMut(ExportedSymbol<'tcx>, SymbolExportInfo, CrateNum),
) {
for &(symbol, info) in tcx.exported_symbols(LOCAL_CRATE).iter() {
callback(symbol, info, LOCAL_CRATE);
}
let formats = tcx.dependency_formats(());
let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap();
for (index, dep_format) in deps.iter().enumerate() {
let cnum = CrateNum::new(index + 1);
if *dep_format == Linkage::Static {
for &(symbol, info) in tcx.exported_symbols(cnum).iter() {
callback(symbol, info, cnum);
}
}
}
}
pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
if let Some(ref exports) = tcx.sess.target.override_export_symbols {
return exports.iter().map(ToString::to_string).collect();
}
if let CrateType::ProcMacro = crate_type {
exported_symbols_for_proc_macro_crate(tcx)
} else {
exported_symbols_for_non_proc_macro(tcx, crate_type)
}
}
fn exported_symbols_for_non_proc_macro(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
let mut symbols = Vec::new();
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
if info.level.is_below_threshold(export_threshold) {
symbols.push(symbol_export::exporting_symbol_name_for_instance_in_crate(
tcx, symbol, cnum,
));
}
});
symbols
}
fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec<String> {
if !tcx.sess.opts.output_types.should_codegen() {
return Vec::new();
}
let stable_crate_id = tcx.stable_crate_id(LOCAL_CRATE);
let proc_macro_decls_name = tcx.sess.generate_proc_macro_decls_symbol(stable_crate_id);
let metadata_symbol_name = exported_symbols::metadata_symbol_name(tcx);
vec![proc_macro_decls_name, metadata_symbol_name]
}
pub(crate) fn linked_symbols(
tcx: TyCtxt<'_>,
crate_type: CrateType,
) -> Vec<(String, SymbolExportKind)> {
match crate_type {
CrateType::Executable | CrateType::Cdylib | CrateType::Dylib => (),
CrateType::Staticlib | CrateType::ProcMacro | CrateType::Rlib => {
return Vec::new();
}
}
let mut symbols = Vec::new();
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
if info.level.is_below_threshold(export_threshold) || info.used {
symbols.push((
symbol_export::linking_symbol_name_for_instance_in_crate(tcx, symbol, cnum),
info.kind,
));
}
});
symbols
}
pub struct PtxLinker<'a> {
cmd: Command,
sess: &'a Session,
}
impl<'a> Linker for PtxLinker<'a> {
fn cmd(&mut self) -> &mut Command {
&mut self.cmd
}
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
fn link_staticlib_by_name(&mut self, _name: &str, _verbatim: bool, _whole_archive: bool) {
panic!("staticlibs not supported")
}
fn link_staticlib_by_path(&mut self, path: &Path, _whole_archive: bool) {
self.link_arg("--rlib").link_arg(path);
}
fn debuginfo(&mut self, _strip: Strip, _: &[PathBuf]) {
self.link_arg("--debug");
}
fn add_object(&mut self, path: &Path) {
self.link_arg("--bitcode").link_arg(path);
}
fn optimize(&mut self) {
match self.sess.lto() {
Lto::Thin | Lto::Fat | Lto::ThinLocal => {
self.link_arg("-Olto");
}
Lto::No => {}
}
}
fn full_relro(&mut self) {}
fn partial_relro(&mut self) {}
fn no_relro(&mut self) {}
fn gc_sections(&mut self, _keep_metadata: bool) {}
fn no_gc_sections(&mut self) {}
fn pgo_gen(&mut self) {}
fn no_crt_objects(&mut self) {}
fn no_default_libraries(&mut self) {}
fn control_flow_guard(&mut self) {}
fn ehcont_guard(&mut self) {}
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, _symbols: &[String]) {}
fn subsystem(&mut self, _subsystem: &str) {}
fn linker_plugin_lto(&mut self) {}
}
pub struct LlbcLinker<'a> {
cmd: Command,
sess: &'a Session,
}
impl<'a> Linker for LlbcLinker<'a> {
fn cmd(&mut self) -> &mut Command {
&mut self.cmd
}
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
fn link_staticlib_by_name(&mut self, _name: &str, _verbatim: bool, _whole_archive: bool) {
panic!("staticlibs not supported")
}
fn link_staticlib_by_path(&mut self, path: &Path, _whole_archive: bool) {
self.link_or_cc_arg(path);
}
fn debuginfo(&mut self, _strip: Strip, _: &[PathBuf]) {
self.link_arg("--debug");
}
fn optimize(&mut self) {
match self.sess.opts.optimize {
OptLevel::No => "-O0",
OptLevel::Less => "-O1",
OptLevel::Default => "-O2",
OptLevel::Aggressive => "-O3",
OptLevel::Size => "-Os",
OptLevel::SizeMin => "-Oz",
};
}
fn full_relro(&mut self) {}
fn partial_relro(&mut self) {}
fn no_relro(&mut self) {}
fn gc_sections(&mut self, _keep_metadata: bool) {}
fn no_gc_sections(&mut self) {}
fn pgo_gen(&mut self) {}
fn no_crt_objects(&mut self) {}
fn no_default_libraries(&mut self) {}
fn control_flow_guard(&mut self) {}
fn ehcont_guard(&mut self) {}
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
match _crate_type {
CrateType::Cdylib => {
for sym in symbols {
self.link_args(&["--export-symbol", sym]);
}
}
_ => (),
}
}
fn subsystem(&mut self, _subsystem: &str) {}
fn linker_plugin_lto(&mut self) {}
}
pub struct BpfLinker<'a> {
cmd: Command,
sess: &'a Session,
}
impl<'a> Linker for BpfLinker<'a> {
fn cmd(&mut self) -> &mut Command {
&mut self.cmd
}
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
fn link_staticlib_by_name(&mut self, _name: &str, _verbatim: bool, _whole_archive: bool) {
panic!("staticlibs not supported")
}
fn link_staticlib_by_path(&mut self, path: &Path, _whole_archive: bool) {
self.link_or_cc_arg(path);
}
fn debuginfo(&mut self, _strip: Strip, _: &[PathBuf]) {
self.link_arg("--debug");
}
fn optimize(&mut self) {
self.link_arg(match self.sess.opts.optimize {
OptLevel::No => "-O0",
OptLevel::Less => "-O1",
OptLevel::Default => "-O2",
OptLevel::Aggressive => "-O3",
OptLevel::Size => "-Os",
OptLevel::SizeMin => "-Oz",
});
}
fn full_relro(&mut self) {}
fn partial_relro(&mut self) {}
fn no_relro(&mut self) {}
fn gc_sections(&mut self, _keep_metadata: bool) {}
fn no_gc_sections(&mut self) {}
fn pgo_gen(&mut self) {}
fn no_crt_objects(&mut self) {}
fn no_default_libraries(&mut self) {}
fn control_flow_guard(&mut self) {}
fn ehcont_guard(&mut self) {}
fn export_symbols(&mut self, tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
let path = tmpdir.join("symbols");
let res: io::Result<()> = try {
let mut f = BufWriter::new(File::create(&path)?);
for sym in symbols {
writeln!(f, "{sym}")?;
}
};
if let Err(error) = res {
self.sess.dcx().emit_fatal(errors::SymbolFileWriteFailure { error });
} else {
self.link_arg("--export-symbols").link_arg(&path);
}
}
fn subsystem(&mut self, _subsystem: &str) {}
fn linker_plugin_lto(&mut self) {}
}