Files
FEX-Emu--FEX/Source/Linux/Utils/ELFSymbolDatabase.h
T
Ryan Houdek 069e279a18 Moves ELF handlers from FEXCore to frontend
Only the frontends need to deal with ELF files specifically.
The backend doesn't need to be aware of them at all.
Since the ELF handling is the frontend's responsibility, move all the code to the frontend.
2021-06-27 02:07:56 -07:00

71 lines
2.0 KiB
C++

#pragma once
#include "Linux/Utils/ELFContainer.h"
#include <unordered_map>
#include <vector>
namespace ELFLoader {
class ELFSymbolDatabase final {
public:
ELFSymbolDatabase(::ELFLoader::ELFContainer *file);
~ELFSymbolDatabase();
uint64_t GetElfBase() const;
void MapMemoryRegions(std::function<void*(uint64_t, uint64_t, bool)> Mapper);
void WriteLoadableSections(::ELFLoader::ELFContainer::MemoryWriter Writer);
uint64_t DefaultRIP() const;
using RangeType = std::pair<uint64_t, uint64_t>;
::ELFLoader::ELFSymbol const *GetSymbolInRange(RangeType Address);
::ELFLoader::ELFSymbol const *GetGlobalSymbolInRange(RangeType Address);
::ELFLoader::ELFSymbol const *GetNoWeakSymbolInRange(RangeType Address);
void GetInitLocations(std::vector<uint64_t> *Locations);
private:
::ELFLoader::ELFContainer *File;
struct ELFInfo {
std::string Name;
::ELFLoader::ELFContainer* Container;
::ELFLoader::ELFContainer::MemoryLayout CustomLayout;
void *ELFBase;
uint64_t GuestBase;
};
ELFInfo LocalInfo;
std::vector<ELFInfo*> DynamicELFInfo;
std::vector<ELFInfo*> InitializationOrder;
uint64_t ELFMemorySize{};
bool FixedNoReplace {true};
void *ELFBase{};
std::unordered_map<std::string, ELFInfo*> NameToELF;
std::vector<std::string> LibrarySearchPaths;
// Symbols
std::vector<ELFLoader::ELFSymbol*> Symbols;
using SymbolTableType = std::unordered_map<std::string, ELFLoader::ELFSymbol *>;
SymbolTableType SymbolMap;
SymbolTableType SymbolMapGlobalOnly;
SymbolTableType SymbolMapNoWeak;
SymbolTableType SymbolMapNoMain;
SymbolTableType SymbolMapNoMainNoWeak;
std::map<uint64_t, ELFLoader::ELFSymbol *> SymbolMapByAddress;
bool FindLibraryFile(std::string *Result, const char *Library);
void FillLibrarySearchPaths();
void FillMemoryLayouts(uint64_t DefinedBase);
void FillInitializationOrder();
void FillSymbols();
void HandleRelocations();
::ELFLoader::ELFSymbol const *GetSymbolFromTable(RangeType Address, std::unordered_map<std::string, ELFLoader::ELFSymbol *> &Table);
};
}