From c28507de2ab51ec58c5efbe0d7b116ea47ce1da9 Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Tue, 2 Jul 2024 21:31:54 -0400 Subject: [PATCH] Add option to control unpaired LO16 warnings --- include/recomp_port.h | 1 + src/config.cpp | 10 ++++++++++ src/main.cpp | 18 ++++++++++-------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/recomp_port.h b/include/recomp_port.h index 5934c88..e70f3ae 100644 --- a/include/recomp_port.h +++ b/include/recomp_port.h @@ -68,6 +68,7 @@ namespace RecompPort { bool uses_mips3_float_mode; bool single_file_output; bool use_absolute_symbols; + bool unpaired_lo16_warnings; std::filesystem::path elf_path; std::filesystem::path symbols_file_path; std::filesystem::path func_reference_syms_file_path; diff --git a/src/config.cpp b/src/config.cpp index 8fffef2..a3241a2 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -390,6 +390,7 @@ RecompPort::Config::Config(const char* path) { manual_functions = get_manual_funcs(array); } + // Output binary path when using an elf file input, includes patching reference symbol MIPS32 relocs (optional) std::optional output_binary_path_opt = input_data["output_binary_path"].value(); if (output_binary_path_opt.has_value()) { output_binary_path = concat_if_not_empty(basedir, output_binary_path_opt.value()); @@ -398,6 +399,15 @@ RecompPort::Config::Config(const char* path) { output_binary_path = ""; } + // Control whether the recompiler warns about unpaired LO16 relocs (optional, defaults to true) + std::optional unpaired_lo16_warnings_opt = input_data["unpaired_lo16_warnings"].value(); + if (unpaired_lo16_warnings_opt.has_value()) { + unpaired_lo16_warnings = unpaired_lo16_warnings_opt.value(); + } + else { + unpaired_lo16_warnings = true; + } + // Patches section (optional) toml::node_view patches_data = config_data["patches"]; if (patches_data.is_table()) { diff --git a/src/main.cpp b/src/main.cpp index 1fffea1..d95ad65 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1183,17 +1183,19 @@ ELFIO::section* read_sections(RecompPort::Context& context, const RecompPort::Co } else { // Orphaned LO16 reloc warnings. - if (prev_lo) { - // Don't warn if multiple LO16 in a row reference the same symbol, as some linkers will use this behavior. - if (prev_hi_symbol != rel_symbol) { - fmt::print(stderr, "[WARN] LO16 reloc index {} in section {} referencing symbol {} with offset 0x{:08X} follows LO16 with different symbol\n", + if (config.unpaired_lo16_warnings) { + if (prev_lo) { + // Don't warn if multiple LO16 in a row reference the same symbol, as some linkers will use this behavior. + if (prev_hi_symbol != rel_symbol) { + fmt::print(stderr, "[WARN] LO16 reloc index {} in section {} referencing symbol {} with offset 0x{:08X} follows LO16 with different symbol\n", + i, section_out.name, reloc_out.symbol_index, reloc_out.address); + } + } + else { + fmt::print(stderr, "[WARN] Unpaired LO16 reloc index {} in section {} referencing symbol {} with offset 0x{:08X}\n", i, section_out.name, reloc_out.symbol_index, reloc_out.address); } } - else { - fmt::print(stderr, "[WARN] Unpaired LO16 reloc index {} in section {} referencing symbol {} with offset 0x{:08X}\n", - i, section_out.name, reloc_out.symbol_index, reloc_out.address); - } // Even though this is an orphaned LO16 reloc, the previous calculation for the addend still follows the MIPS System V ABI documentation: // "R_MIPS_LO16 entries without an R_MIPS_HI16 entry immediately preceding are orphaned and the previously defined // R_MIPS_HI16 is used for computing the addend."