2024-02-23 22:32:32 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2024-02-27 23:10:34 +01:00
|
|
|
#include "common/logging/log.h"
|
2023-11-06 00:11:54 +01:00
|
|
|
#include "common/types.h"
|
|
|
|
#include "core/loader/symbols_resolver.h"
|
2023-06-26 17:12:19 +02:00
|
|
|
|
2023-11-06 00:11:54 +01:00
|
|
|
namespace Core::Loader {
|
|
|
|
|
|
|
|
void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr) {
|
2024-02-23 21:57:57 +01:00
|
|
|
SymbolRecord r{};
|
2023-07-11 17:50:29 +02:00
|
|
|
r.name = GenerateName(s);
|
2024-02-23 21:57:57 +01:00
|
|
|
r.virtual_address = virtual_addr;
|
|
|
|
m_symbols.push_back(r);
|
2023-07-11 17:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SymbolsResolver::GenerateName(const SymbolRes& s) {
|
2024-02-23 21:57:57 +01:00
|
|
|
return fmt::format("{} lib[{}_v{}]mod[{}_v{}.{}]", s.name, s.library, s.library_version,
|
2023-10-26 22:29:05 +02:00
|
|
|
s.module, s.module_version_major, s.module_version_minor);
|
2023-07-11 17:50:29 +02:00
|
|
|
}
|
|
|
|
|
2024-02-23 21:57:57 +01:00
|
|
|
const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const {
|
|
|
|
const std::string name = GenerateName(s);
|
2023-10-26 22:29:05 +02:00
|
|
|
for (u32 i = 0; i < m_symbols.size(); i++) {
|
|
|
|
if (m_symbols[i].name.compare(name) == 0) {
|
|
|
|
return &m_symbols[i];
|
2023-07-11 17:50:29 +02:00
|
|
|
}
|
|
|
|
}
|
2023-10-26 22:29:05 +02:00
|
|
|
|
2024-02-27 23:10:34 +01:00
|
|
|
LOG_INFO(Core_Linker, "Unresolved! {}", name);
|
2024-02-23 21:57:57 +01:00
|
|
|
return nullptr;
|
2023-10-26 22:29:05 +02:00
|
|
|
}
|
2023-11-06 00:11:54 +01:00
|
|
|
|
|
|
|
} // namespace Core::Loader
|