Fix export names not being set on functions when parsing mod syms, add missing returns to mod parsing

This commit is contained in:
Mr-Wiseguy 2024-08-30 01:21:43 -04:00
parent 131157dad8
commit 747cd9f6ac
2 changed files with 29 additions and 1 deletions

View file

@ -185,9 +185,14 @@ int main(int argc, const char** argv) {
output_file << "// Array of this mod's loaded section addresses.\n"; output_file << "// Array of this mod's loaded section addresses.\n";
output_file << "RECOMP_EXPORT int32_t section_addresses[" << std::max(size_t{1}, num_sections) << "] = {0};\n\n"; output_file << "RECOMP_EXPORT int32_t section_addresses[" << std::max(size_t{1}, num_sections) << "] = {0};\n\n";
// Create a set of the export indices to avoid renaming them.
std::unordered_set<size_t> export_indices{mod_context.exported_funcs.begin(), mod_context.exported_funcs.end()};
for (size_t func_index = 0; func_index < mod_context.functions.size(); func_index++) { for (size_t func_index = 0; func_index < mod_context.functions.size(); func_index++) {
auto& func = mod_context.functions[func_index]; auto& func = mod_context.functions[func_index];
func.name = "mod_func_" + std::to_string(func_index); if (!export_indices.contains(func_index)) {
func.name = "mod_func_" + std::to_string(func_index);
}
N64Recomp::recompile_function(mod_context, func, output_file, static_funcs_by_section, true); N64Recomp::recompile_function(mod_context, func, output_file, static_funcs_by_section, true);
} }

View file

@ -234,6 +234,7 @@ bool parse_v1(std::span<const char> data, const std::unordered_map<uint32_t, uin
if (reloc_target_section >= mod_context.sections.size()) { if (reloc_target_section >= mod_context.sections.size()) {
printf("Reloc %zu in section %zu references local section %u, but only %zu exist\n", printf("Reloc %zu in section %zu references local section %u, but only %zu exist\n",
reloc_index, section_index, reloc_target_section, mod_context.sections.size()); reloc_index, section_index, reloc_target_section, mod_context.sections.size());
return false;
} }
} }
else { else {
@ -269,6 +270,7 @@ bool parse_v1(std::span<const char> data, const std::unordered_map<uint32_t, uin
if (mod_id_start + mod_id_size > string_data_size) { if (mod_id_start + mod_id_size > string_data_size) {
printf("Dependency %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n", printf("Dependency %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n",
dependency_index, mod_id_start, mod_id_size, string_data_size); dependency_index, mod_id_start, mod_id_size, string_data_size);
return false;
} }
std::string_view mod_id{ string_data + mod_id_start, string_data + mod_id_start + mod_id_size }; std::string_view mod_id{ string_data + mod_id_start, string_data + mod_id_start + mod_id_size };
@ -290,11 +292,13 @@ bool parse_v1(std::span<const char> data, const std::unordered_map<uint32_t, uin
if (name_start + name_size > string_data_size) { if (name_start + name_size > string_data_size) {
printf("Import %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n", printf("Import %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n",
import_index, name_start, name_size, string_data_size); import_index, name_start, name_size, string_data_size);
return false;
} }
if (dependency_index >= num_dependencies) { if (dependency_index >= num_dependencies) {
printf("Import %zu belongs to dependency %u, but only %zu dependencies were specified\n", printf("Import %zu belongs to dependency %u, but only %zu dependencies were specified\n",
import_index, dependency_index, num_dependencies); import_index, dependency_index, num_dependencies);
return false;
} }
std::string_view import_name{ string_data + name_start, string_data + name_start + name_size }; std::string_view import_name{ string_data + name_start, string_data + name_start + name_size };
@ -317,6 +321,7 @@ bool parse_v1(std::span<const char> data, const std::unordered_map<uint32_t, uin
if (name_start + name_size > string_data_size) { if (name_start + name_size > string_data_size) {
printf("Dependency event %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n", printf("Dependency event %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n",
dependency_event_index, name_start, name_size, string_data_size); dependency_event_index, name_start, name_size, string_data_size);
return false;
} }
std::string_view dependency_event_name{ string_data + name_start, string_data + name_start + name_size }; std::string_view dependency_event_name{ string_data + name_start, string_data + name_start + name_size };
@ -355,15 +360,29 @@ bool parse_v1(std::span<const char> data, const std::unordered_map<uint32_t, uin
if (func_index >= mod_context.functions.size()) { if (func_index >= mod_context.functions.size()) {
printf("Export %zu has a function index of %u, but the symbol file only has %zu functions\n", printf("Export %zu has a function index of %u, but the symbol file only has %zu functions\n",
export_index, func_index, mod_context.functions.size()); export_index, func_index, mod_context.functions.size());
return false;
} }
if (name_start + name_size > string_data_size) { if (name_start + name_size > string_data_size) {
printf("Export %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n", printf("Export %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n",
export_index, name_start, name_size, string_data_size); export_index, name_start, name_size, string_data_size);
return false;
}
std::string_view export_name_view{ string_data + name_start, string_data + name_start + name_size };
std::string export_name{export_name_view};
if (!mod_context.functions[func_index].name.empty()) {
printf("Function %u is exported twice (%s and %s)\n",
func_index, mod_context.functions[func_index].name.c_str(), export_name.c_str());
return false;
} }
// Add the function to the exported function list. // Add the function to the exported function list.
mod_context.exported_funcs[export_index] = func_index; mod_context.exported_funcs[export_index] = func_index;
// Set the function's name to the export name.
mod_context.functions[func_index].name = std::move(export_name);
} }
const CallbackV1* callbacks = reinterpret_data<CallbackV1>(data, offset, num_callbacks); const CallbackV1* callbacks = reinterpret_data<CallbackV1>(data, offset, num_callbacks);
@ -380,15 +399,18 @@ bool parse_v1(std::span<const char> data, const std::unordered_map<uint32_t, uin
if (dependency_event_index >= num_dependency_events) { if (dependency_event_index >= num_dependency_events) {
printf("Callback %zu is connected to dependency event %u, but only %zu dependency events were specified\n", printf("Callback %zu is connected to dependency event %u, but only %zu dependency events were specified\n",
callback_index, dependency_event_index, num_dependency_events); callback_index, dependency_event_index, num_dependency_events);
return false;
} }
if (function_index >= mod_context.functions.size()) { if (function_index >= mod_context.functions.size()) {
printf("Callback %zu uses function %u, but only %zu functions were specified\n", printf("Callback %zu uses function %u, but only %zu functions were specified\n",
callback_index, function_index, mod_context.functions.size()); callback_index, function_index, mod_context.functions.size());
return false;
} }
if (!mod_context.add_callback(dependency_event_index, function_index)) { if (!mod_context.add_callback(dependency_event_index, function_index)) {
printf("Failed to add callback %zu\n", callback_index); printf("Failed to add callback %zu\n", callback_index);
return false;
} }
} }
@ -406,6 +428,7 @@ bool parse_v1(std::span<const char> data, const std::unordered_map<uint32_t, uin
if (name_start + name_size > string_data_size) { if (name_start + name_size > string_data_size) {
printf("Event %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n", printf("Event %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n",
event_index, name_start, name_size, string_data_size); event_index, name_start, name_size, string_data_size);
return false;
} }
std::string_view import_name{ string_data + name_start, string_data + name_start + name_size }; std::string_view import_name{ string_data + name_start, string_data + name_start + name_size };