Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion N64Recomp
1 change: 1 addition & 0 deletions librecomp/include/librecomp/overlays.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace recomp {
void init_overlays();
const std::unordered_map<uint32_t, uint16_t>& get_vrom_to_section_map();
uint32_t get_section_ram_addr(uint16_t code_section_index);
std::optional<uint32_t> get_section_got_ram_addr(uint16_t code_section_index);
std::span<const RelocEntry> get_section_relocs(uint16_t code_section_index);
recomp_func_t* get_func_by_section_rom_function_vram(uint32_t section_rom, uint32_t function_vram);
bool get_func_entry_by_section_index_function_offset(uint16_t code_section_index, uint32_t function_offset, FuncEntry& func_out);
Expand Down
2 changes: 2 additions & 0 deletions librecomp/include/librecomp/sections.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef __SECTIONS_H__
#define __SECTIONS_H__

#include <optional>
#include <stdint.h>
#include "recomp.h"

Expand Down Expand Up @@ -43,6 +44,7 @@ typedef struct {
RelocEntry* relocs;
size_t num_relocs;
size_t index;
std::optional<uint32_t> got_ram_addr;
} SectionTableEntry;

typedef struct {
Expand Down
8 changes: 7 additions & 1 deletion librecomp/src/mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,7 @@ struct RegeneratedSection {
size_t first_func_index;
size_t first_reloc_index;
bool relocatable;
std::optional<uint32_t> got_ram_addr;
};

struct RegeneratedFunction {
Expand Down Expand Up @@ -1323,6 +1324,7 @@ N64Recomp::Context context_from_regenerated_list(const RegeneratedList& regenlis
section_out.executable = true;
section_out.relocatable = section_in.relocatable;
section_out.has_mips32_relocs = false;
section_out.got_ram_addr = section_in.got_ram_addr;

std::vector<size_t>& section_funcs_out = ret.section_functions[section_index];
section_funcs_out.resize(cur_num_funcs);
Expand Down Expand Up @@ -1856,14 +1858,17 @@ std::vector<recomp::mods::ModLoadErrorDetails> build_regen_list(

uint16_t section_index = find_section_it->second;
uint32_t section_ram_addr;
std::optional<uint32_t> got_ram_addr;

if constexpr (patched_regenlist) {
section_ram_addr = recomp::overlays::get_patch_section_ram_addr(section_index);
cur_section_relocs = recomp::overlays::get_patch_section_relocs(section_index);
got_ram_addr = std::nullopt;
}
else {
section_ram_addr = recomp::overlays::get_section_ram_addr(section_index);
cur_section_relocs = recomp::overlays::get_section_relocs(section_index);
got_ram_addr = recomp::overlays::get_section_got_ram_addr(section_index);
}

// Allocate a new section.
Expand All @@ -1874,7 +1879,8 @@ std::vector<recomp::mods::ModLoadErrorDetails> build_regen_list(
.first_func_index = regenlist.functions.size(),
.first_reloc_index = regenlist.relocs.size(),
// Patch sections are never relocatable, so a section is relocatable if it has any relocs and is not a base patch section.
.relocatable = !patched_regenlist && !cur_section_relocs.empty()
.relocatable = !patched_regenlist && !cur_section_relocs.empty(),
.got_ram_addr = got_ram_addr
});

// Update the tracked section fields.
Expand Down
4 changes: 4 additions & 0 deletions librecomp/src/overlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ uint32_t recomp::overlays::get_section_ram_addr(uint16_t code_section_index) {
return sections_info.code_sections[code_section_index].ram_addr;
}

std::optional<uint32_t> recomp::overlays::get_section_got_ram_addr(uint16_t code_section_index) {
return sections_info.code_sections[code_section_index].got_ram_addr;
}

std::span<const RelocEntry> recomp::overlays::get_section_relocs(uint16_t code_section_index) {
if (code_section_index < sections_info.num_code_sections) {
const auto& section = sections_info.code_sections[code_section_index];
Expand Down
Loading