Files
FEX-Emu--FEX/Source/Linux/Utils/ELFSymbolDatabase.h
T
Ryan Houdek f161e3bfb0 Massive amount of IWYU cleanup
This isn't quite a 100% clean sweep of IWYU.
There are some false positives where clang fails.
Additionally there are still a few missed in the frontend side of things
that I didn't get to
2021-08-28 00:32:15 -07:00

76 lines
2.1 KiB
C++

#pragma once
#include "Linux/Utils/ELFContainer.h"
#include <cstdint>
#include <functional>
#include <map>
#include <string>
#include <unordered_map>
#include <utility>
#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);
};
}