UPDATE - migrate linker.rs to new diagnostics infra
This commit is contained in:
parent
0a2d7f83cb
commit
086e70f13e
3 changed files with 77 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
|||
use super::command::Command;
|
||||
use super::symbol_export;
|
||||
use crate::errors::LibDefWriteFailure;
|
||||
use crate::errors;
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
use std::ffi::{OsStr, OsString};
|
||||
|
@ -91,13 +91,13 @@ pub fn get_linker<'a>(
|
|||
arg.push(format!("{}\\lib\\{}\\store", root_lib_path.display(), a));
|
||||
cmd.arg(&arg);
|
||||
} else {
|
||||
warn!("arch is not supported");
|
||||
sess.emit_warning(errors::UnsupportedArch);
|
||||
}
|
||||
} else {
|
||||
warn!("MSVC root path lib location not found");
|
||||
sess.emit_warning(errors::MsvcPathNotFound);
|
||||
}
|
||||
} else {
|
||||
warn!("link.exe not found");
|
||||
sess.emit_warning(errors::LinkExeNotFound);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -435,11 +435,11 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
// FIXME(81490): ld64 doesn't support these flags but macOS 11
|
||||
// has -needed-l{} / -needed_library {}
|
||||
// but we have no way to detect that here.
|
||||
self.sess.warn("`as-needed` modifier not implemented yet for ld64");
|
||||
self.sess.emit_warning(errors::Ld64UnimplementedModifier);
|
||||
} else if self.is_gnu && !self.sess.target.is_like_windows {
|
||||
self.linker_arg("--no-as-needed");
|
||||
} else {
|
||||
self.sess.warn("`as-needed` modifier not supported for current linker");
|
||||
self.sess.emit_warning(errors::LinkerUnsupportedModifier);
|
||||
}
|
||||
}
|
||||
self.hint_dynamic();
|
||||
|
@ -493,7 +493,7 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
// FIXME(81490): ld64 as of macOS 11 supports the -needed_framework
|
||||
// flag but we have no way to detect that here.
|
||||
// self.cmd.arg("-needed_framework").arg(framework);
|
||||
self.sess.warn("`as-needed` modifier not implemented yet for ld64");
|
||||
self.sess.emit_warning(errors::Ld64UnimplementedModifier);
|
||||
}
|
||||
self.cmd.arg("-framework").arg(framework);
|
||||
}
|
||||
|
@ -667,7 +667,7 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
}
|
||||
};
|
||||
if let Err(error) = res {
|
||||
self.sess.emit_fatal(LibDefWriteFailure { error });
|
||||
self.sess.emit_fatal(errors::LibDefWriteFailure { error });
|
||||
}
|
||||
} else if is_windows {
|
||||
let res: io::Result<()> = try {
|
||||
|
@ -682,7 +682,7 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
}
|
||||
};
|
||||
if let Err(error) = res {
|
||||
self.sess.emit_fatal(LibDefWriteFailure { error });
|
||||
self.sess.emit_fatal(errors::LibDefWriteFailure { error });
|
||||
}
|
||||
} else {
|
||||
// Write an LD version script
|
||||
|
@ -698,8 +698,8 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
}
|
||||
writeln!(f, "\n local:\n *;\n}};")?;
|
||||
};
|
||||
if let Err(e) = res {
|
||||
self.sess.fatal(&format!("failed to write version script: {}", e));
|
||||
if let Err(error) = res {
|
||||
self.sess.emit_fatal(errors::VersionScriptWriteFailure { error });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -916,9 +916,8 @@ impl<'a> Linker for MsvcLinker<'a> {
|
|||
self.cmd.arg(arg);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
self.sess
|
||||
.warn(&format!("error enumerating natvis directory: {}", err));
|
||||
Err(error) => {
|
||||
self.sess.emit_warning(errors::NoNatvisDirectory { error });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -973,7 +972,7 @@ impl<'a> Linker for MsvcLinker<'a> {
|
|||
}
|
||||
};
|
||||
if let Err(error) = res {
|
||||
self.sess.emit_fatal(LibDefWriteFailure { error });
|
||||
self.sess.emit_fatal(errors::LibDefWriteFailure { error });
|
||||
}
|
||||
let mut arg = OsString::from("/DEF:");
|
||||
arg.push(path);
|
||||
|
@ -1436,7 +1435,7 @@ impl<'a> Linker for L4Bender<'a> {
|
|||
|
||||
fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[String]) {
|
||||
// ToDo, not implemented, copy from GCC
|
||||
self.sess.warn("exporting symbols not implemented yet for L4Bender");
|
||||
self.sess.emit_warning(errors::L4BenderExportingSymbolsUnimplemented);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1728,8 +1727,8 @@ impl<'a> Linker for BpfLinker<'a> {
|
|||
writeln!(f, "{}", sym)?;
|
||||
}
|
||||
};
|
||||
if let Err(e) = res {
|
||||
self.sess.fatal(&format!("failed to write symbols file: {}", e));
|
||||
if let Err(error) = res {
|
||||
self.sess.emit_fatal(errors::SymbolFileWriteFailure { error });
|
||||
} else {
|
||||
self.cmd.arg("--export-symbols").arg(&path);
|
||||
}
|
||||
|
|
|
@ -14,3 +14,45 @@ pub struct MissingNativeStaticLibrary<'a> {
|
|||
pub struct LibDefWriteFailure {
|
||||
pub error: Error,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_ssa::version_script_write_failure)]
|
||||
pub struct VersionScriptWriteFailure {
|
||||
pub error: Error,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_ssa::symbol_file_write_failure)]
|
||||
pub struct SymbolFileWriteFailure {
|
||||
pub error: Error,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_ssa::unsupported_arch)]
|
||||
pub struct UnsupportedArch;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_ssa::msvc_path_not_found)]
|
||||
pub struct MsvcPathNotFound;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_ssa::link_exe_not_found)]
|
||||
pub struct LinkExeNotFound;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_ssa::ld64_unimplemented_modifier)]
|
||||
pub struct Ld64UnimplementedModifier;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_ssa::linker_unsupported_modifier)]
|
||||
pub struct LinkerUnsupportedModifier;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_ssa::L4Bender_exporting_symbols_unimplemented)]
|
||||
pub struct L4BenderExportingSymbolsUnimplemented;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(codegen_ssa::no_natvis_directory)]
|
||||
pub struct NoNatvisDirectory {
|
||||
pub error: Error,
|
||||
}
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
codegen_ssa_missing_native_static_library = could not find native static library `{$library_name}`, perhaps an -L flag is missing?
|
||||
|
||||
codegen_ssa_lib_def_write_failure = failed to write lib.def file: {$error}
|
||||
|
||||
codegen_ssa_version_script_write_failure = failed to write version script: {$error}
|
||||
|
||||
codegen_ssa_symbol_file_write_failure = failed to write symbols file: {$error}
|
||||
|
||||
codegen_ssa_unsupported_arch = arch is not supported
|
||||
|
||||
codegen_ssa_msvc_path_not_found = MSVC root path lib location not found
|
||||
|
||||
codegen_ssa_link_exe_not_found = link.exe not found
|
||||
|
||||
codegen_ssa_ld64_unimplemented_modifier = `as-needed` modifier not implemented yet for ld64
|
||||
|
||||
codegen_ssa_linker_unsupported_modifier = `as-needed` modifier not supported for current linker
|
||||
|
||||
codegen_ssa_L4Bender_exporting_symbols_unimplemented = exporting symbols not implemented yet for L4Bender
|
||||
|
||||
codegen_ssa_no_natvis_directory = error enumerating natvis directory: {$error}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue