From d3406c7b1a2cc5befe44f31ccda363a933216a9e Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Fri, 2 May 2025 15:01:49 -0400 Subject: [PATCH] Fix native exports not getting cleared and bss sometimes not getting zero'd --- librecomp/src/mods.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/librecomp/src/mods.cpp b/librecomp/src/mods.cpp index c37aea3..d55e4e2 100644 --- a/librecomp/src/mods.cpp +++ b/librecomp/src/mods.cpp @@ -327,6 +327,7 @@ recomp::mods::CodeModLoadError recomp::mods::ModHandle::load_native_library(cons return api_error; } + native_library_exports.clear(); for (const std::string& export_name : lib_manifest.exports) { recomp_func_t* cur_func; if (native_library_exports.contains(export_name)) { @@ -2097,8 +2098,14 @@ recomp::mods::CodeModLoadError recomp::mods::ModContext::init_mod_code(uint8_t* MEM_B(i, (gpr)cur_section_addr) = binary_data[section.rom_addr + i]; } mod.section_load_addresses[section_index] = cur_section_addr; - // Calculate the next section's address based on the size of this section and its bss. - cur_section_addr += section.size + section.bss_size; + // Calculate the bss section's address based on the size of this section. + cur_section_addr += section.size; + // Zero the bss section. + for (size_t i = 0; i < section.bss_size; i++) { + MEM_B(i, (gpr)cur_section_addr) = 0; + } + // Calculate the next section's address based on the size of the bss section. + cur_section_addr += section.bss_size; // Align the next section's address to 16 bytes. cur_section_addr = (cur_section_addr + 15) & ~15; // Add some empty space between mods to act as a buffer for misbehaving mods that have out of bounds accesses.