2022-10-04 17:23:53 +00:00
|
|
|
//! Errors emitted by codegen_ssa
|
|
|
|
|
2022-10-03 03:21:15 +00:00
|
|
|
use crate::back::command::Command;
|
|
|
|
use rustc_errors::{
|
|
|
|
fluent, DiagnosticArgValue, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic,
|
|
|
|
IntoDiagnosticArg,
|
|
|
|
};
|
2022-09-10 17:16:37 +00:00
|
|
|
use rustc_macros::Diagnostic;
|
2022-10-03 03:21:15 +00:00
|
|
|
use rustc_span::{Span, Symbol};
|
2022-08-28 23:58:12 +00:00
|
|
|
use std::borrow::Cow;
|
2022-08-27 00:21:55 +00:00
|
|
|
use std::io::Error;
|
2022-08-28 23:58:12 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
2022-10-03 03:21:15 +00:00
|
|
|
use std::process::ExitStatus;
|
2022-10-04 17:23:53 +00:00
|
|
|
|
2022-09-10 17:16:37 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-08-25 03:40:07 +00:00
|
|
|
#[diag(codegen_ssa::lib_def_write_failure)]
|
|
|
|
pub struct LibDefWriteFailure {
|
2022-08-27 00:21:55 +00:00
|
|
|
pub error: Error,
|
2022-08-25 03:40:07 +00:00
|
|
|
}
|
2022-10-07 14:03:45 +00:00
|
|
|
|
2022-09-10 17:16:37 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-07 14:03:45 +00:00
|
|
|
#[diag(codegen_ssa::version_script_write_failure)]
|
|
|
|
pub struct VersionScriptWriteFailure {
|
|
|
|
pub error: Error,
|
|
|
|
}
|
|
|
|
|
2022-09-10 17:16:37 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-07 14:03:45 +00:00
|
|
|
#[diag(codegen_ssa::symbol_file_write_failure)]
|
|
|
|
pub struct SymbolFileWriteFailure {
|
|
|
|
pub error: Error,
|
|
|
|
}
|
|
|
|
|
2022-09-10 17:16:37 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-07 14:03:45 +00:00
|
|
|
#[diag(codegen_ssa::ld64_unimplemented_modifier)]
|
|
|
|
pub struct Ld64UnimplementedModifier;
|
|
|
|
|
2022-09-10 17:16:37 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-07 14:03:45 +00:00
|
|
|
#[diag(codegen_ssa::linker_unsupported_modifier)]
|
|
|
|
pub struct LinkerUnsupportedModifier;
|
|
|
|
|
2022-09-10 17:16:37 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-07 14:03:45 +00:00
|
|
|
#[diag(codegen_ssa::L4Bender_exporting_symbols_unimplemented)]
|
|
|
|
pub struct L4BenderExportingSymbolsUnimplemented;
|
|
|
|
|
2022-09-10 17:16:37 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-07 14:03:45 +00:00
|
|
|
#[diag(codegen_ssa::no_natvis_directory)]
|
|
|
|
pub struct NoNatvisDirectory {
|
|
|
|
pub error: Error,
|
|
|
|
}
|
2022-08-28 23:58:12 +00:00
|
|
|
|
2022-09-10 17:16:37 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-08-28 23:58:12 +00:00
|
|
|
#[diag(codegen_ssa::copy_path_buf)]
|
|
|
|
pub struct CopyPathBuf {
|
|
|
|
pub source_file: PathBuf,
|
|
|
|
pub output_path: PathBuf,
|
|
|
|
pub error: Error,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reports Paths using `Debug` implementation rather than Path's `Display` implementation.
|
2022-09-10 17:16:37 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-08-28 23:58:12 +00:00
|
|
|
#[diag(codegen_ssa::copy_path)]
|
|
|
|
pub struct CopyPath<'a> {
|
|
|
|
from: DebugArgPath<'a>,
|
|
|
|
to: DebugArgPath<'a>,
|
|
|
|
error: Error,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> CopyPath<'a> {
|
|
|
|
pub fn new(from: &'a Path, to: &'a Path, error: Error) -> CopyPath<'a> {
|
2022-10-03 03:21:15 +00:00
|
|
|
CopyPath { from: DebugArgPath(from), to: DebugArgPath(to), error }
|
2022-08-28 23:58:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-03 03:21:15 +00:00
|
|
|
struct DebugArgPath<'a>(pub &'a Path);
|
2022-08-28 23:58:12 +00:00
|
|
|
|
|
|
|
impl IntoDiagnosticArg for DebugArgPath<'_> {
|
|
|
|
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
|
2022-10-03 03:21:15 +00:00
|
|
|
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
|
2022-08-28 23:58:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-10 17:16:37 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-08-28 23:58:12 +00:00
|
|
|
#[diag(codegen_ssa::ignoring_emit_path)]
|
|
|
|
pub struct IgnoringEmitPath {
|
|
|
|
pub extension: String,
|
|
|
|
}
|
|
|
|
|
2022-09-10 17:16:37 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-08-28 23:58:12 +00:00
|
|
|
#[diag(codegen_ssa::ignoring_output)]
|
|
|
|
pub struct IgnoringOutput {
|
|
|
|
pub extension: String,
|
|
|
|
}
|
2022-10-03 03:21:15 +00:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_ssa::create_temp_dir)]
|
|
|
|
pub struct CreateTempDir {
|
|
|
|
pub error: Error,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_ssa::incompatible_linking_modifiers)]
|
|
|
|
pub struct IncompatibleLinkingModifiers;
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_ssa::add_native_library)]
|
2022-10-04 17:25:13 +00:00
|
|
|
pub struct AddNativeLibrary {
|
|
|
|
pub library_path: PathBuf,
|
2022-10-03 03:21:15 +00:00
|
|
|
pub error: Error,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(codegen_ssa::multiple_external_func_decl)]
|
|
|
|
pub struct MultipleExternalFuncDecl<'a> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub function: Symbol,
|
|
|
|
pub library_name: &'a str,
|
|
|
|
}
|
|
|
|
|
2022-10-04 17:25:13 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-03 03:21:15 +00:00
|
|
|
pub enum LinkRlibError {
|
2022-10-04 17:25:13 +00:00
|
|
|
#[diag(codegen_ssa::rlib_missing_format)]
|
2022-10-03 03:21:15 +00:00
|
|
|
MissingFormat,
|
2022-10-04 17:25:13 +00:00
|
|
|
|
|
|
|
#[diag(codegen_ssa::rlib_only_rmeta_found)]
|
2022-10-03 03:21:15 +00:00
|
|
|
OnlyRmetaFound { crate_name: Symbol },
|
|
|
|
|
2022-10-04 17:25:13 +00:00
|
|
|
#[diag(codegen_ssa::rlib_not_found)]
|
|
|
|
NotFound { crate_name: Symbol },
|
2022-10-03 03:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ThorinErrorWrapper(pub thorin::Error);
|
|
|
|
|
2022-10-04 17:21:22 +00:00
|
|
|
impl IntoDiagnostic<'_> for ThorinErrorWrapper {
|
|
|
|
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
|
|
|
let mut diag;
|
|
|
|
match self.0 {
|
|
|
|
thorin::Error::ReadInput(_) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_read_input_failure);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::ParseFileKind(_) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_input_file_kind);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::ParseObjectFile(_) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_input_object_file);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::ParseArchiveFile(_) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_input_archive_file);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::ParseArchiveMember(_) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_archive_member);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::InvalidInputKind => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_invalid_input_kind);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::DecompressData(_) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_decompress_data);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::NamelessSection(_, offset) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_section_without_name);
|
|
|
|
diag.set_arg("offset", format!("0x{:08x}", offset));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::RelocationWithInvalidSymbol(section, offset) => {
|
|
|
|
diag =
|
|
|
|
handler.struct_err(fluent::codegen_ssa::thorin_relocation_with_invalid_symbol);
|
|
|
|
diag.set_arg("section", section);
|
|
|
|
diag.set_arg("offset", format!("0x{:08x}", offset));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::MultipleRelocations(section, offset) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_multiple_relocations);
|
|
|
|
diag.set_arg("section", section);
|
|
|
|
diag.set_arg("offset", format!("0x{:08x}", offset));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::UnsupportedRelocation(section, offset) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_unsupported_relocation);
|
|
|
|
diag.set_arg("section", section);
|
|
|
|
diag.set_arg("offset", format!("0x{:08x}", offset));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::MissingDwoName(id) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_missing_dwo_name);
|
|
|
|
diag.set_arg("id", format!("0x{:08x}", id));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::NoCompilationUnits => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_no_compilation_units);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::NoDie => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_no_die);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::TopLevelDieNotUnit => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_top_level_die_not_unit);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::MissingRequiredSection(section) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_missing_required_section);
|
|
|
|
diag.set_arg("section", section);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::ParseUnitAbbreviations(_) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_unit_abbreviations);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::ParseUnitAttribute(_) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_unit_attribute);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::ParseUnitHeader(_) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_unit_header);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::ParseUnit(_) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_unit);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::IncompatibleIndexVersion(section, format, actual) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_incompatible_index_version);
|
|
|
|
diag.set_arg("section", section);
|
|
|
|
diag.set_arg("actual", actual);
|
|
|
|
diag.set_arg("format", format);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::OffsetAtIndex(_, index) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_offset_at_index);
|
|
|
|
diag.set_arg("index", index);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::StrAtOffset(_, offset) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_str_at_offset);
|
|
|
|
diag.set_arg("offset", format!("0x{:08x}", offset));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::ParseIndex(_, section) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_index);
|
|
|
|
diag.set_arg("section", section);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::UnitNotInIndex(unit) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_unit_not_in_index);
|
|
|
|
diag.set_arg("unit", format!("0x{:08x}", unit));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::RowNotInIndex(_, row) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_row_not_in_index);
|
|
|
|
diag.set_arg("row", row);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::SectionNotInRow => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_section_not_in_row);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::EmptyUnit(unit) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_empty_unit);
|
|
|
|
diag.set_arg("unit", format!("0x{:08x}", unit));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::MultipleDebugInfoSection => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_multiple_debug_info_section);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::MultipleDebugTypesSection => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_multiple_debug_types_section);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::NotSplitUnit => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_not_split_unit);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::DuplicateUnit(unit) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_duplicate_unit);
|
|
|
|
diag.set_arg("unit", format!("0x{:08x}", unit));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::MissingReferencedUnit(unit) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_missing_referenced_unit);
|
|
|
|
diag.set_arg("unit", format!("0x{:08x}", unit));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::NoOutputObjectCreated => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_not_output_object_created);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::MixedInputEncodings => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_mixed_input_encodings);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::Io(e) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_io);
|
|
|
|
diag.set_arg("error", format!("{e}"));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::ObjectRead(e) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_object_read);
|
|
|
|
diag.set_arg("error", format!("{e}"));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::ObjectWrite(e) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_object_write);
|
|
|
|
diag.set_arg("error", format!("{e}"));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::GimliRead(e) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_gimli_read);
|
|
|
|
diag.set_arg("error", format!("{e}"));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
thorin::Error::GimliWrite(e) => {
|
|
|
|
diag = handler.struct_err(fluent::codegen_ssa::thorin_gimli_write);
|
|
|
|
diag.set_arg("error", format!("{e}"));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
_ => unimplemented!("Untranslated thorin error"),
|
|
|
|
}
|
2022-10-03 03:21:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct LinkingFailed<'a> {
|
|
|
|
pub linker_path: &'a PathBuf,
|
|
|
|
pub exit_status: ExitStatus,
|
|
|
|
pub command: &'a Command,
|
|
|
|
pub escaped_output: &'a str,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoDiagnostic<'_> for LinkingFailed<'_> {
|
|
|
|
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
|
|
|
let mut diag = handler.struct_err(fluent::codegen_ssa::linking_failed);
|
|
|
|
diag.set_arg("linker_path", format!("{}", self.linker_path.display()));
|
|
|
|
diag.set_arg("exit_status", format!("{}", self.exit_status));
|
|
|
|
|
|
|
|
diag.note(format!("{:?}", self.command)).note(self.escaped_output);
|
|
|
|
|
|
|
|
// Trying to match an error from OS linkers
|
|
|
|
// which by now we have no way to translate.
|
|
|
|
if self.escaped_output.contains("undefined reference to") {
|
|
|
|
diag.note(fluent::codegen_ssa::extern_funcs_not_found)
|
|
|
|
.note(fluent::codegen_ssa::specify_libraries_to_link)
|
|
|
|
.note(fluent::codegen_ssa::use_cargo_directive);
|
|
|
|
}
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
}
|