mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 13:00:15 +02:00
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.
This commit is contained in:
1 parent
36b5863c7c
commit
069e279a18
14 files changed
+39
-29
No files matched your search
-2
@@ -124,8 +124,6 @@ set (SRCS
|
||||
Interface/IR/Passes/SyscallOptimization.cpp
|
||||
Utils/Allocator.cpp
|
||||
Utils/Allocator/64BitAllocator.cpp
|
||||
Utils/ELFContainer.cpp
|
||||
Utils/ELFSymbolDatabase.cpp
|
||||
Utils/LogManager.cpp
|
||||
Utils/Threads.cpp
|
||||
)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
add_subdirectory(Common/)
|
||||
add_subdirectory(CommonCore/)
|
||||
add_subdirectory(Linux/)
|
||||
add_subdirectory(Tests/)
|
||||
add_subdirectory(Tools/)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
set (SRCS
|
||||
Utils/ELFContainer.cpp
|
||||
Utils/ELFSymbolDatabase.cpp
|
||||
)
|
||||
|
||||
add_library(FEX_Utils OBJECT ${SRCS})
|
||||
target_link_libraries(FEX_Utils FEXCore)
|
||||
|
||||
target_include_directories(FEX_Utils PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Source/)
|
||||
target_include_directories(FEX_Utils PRIVATE ${CMAKE_BINARY_DIR}/generated)
|
||||
+2
-2
@@ -5,8 +5,8 @@ desc: Loads and parses an elf to memory. Also handles some loading & logic.
|
||||
$end_info$
|
||||
*/
|
||||
|
||||
#include <FEXCore/Utils/Common/MathUtils.h>
|
||||
#include <FEXCore/Utils/ELFContainer.h>
|
||||
#include "Common/MathUtils.h"
|
||||
#include "Linux/Utils/ELFContainer.h"
|
||||
#include <FEXCore/Utils/LogManager.h>
|
||||
#include <cstring>
|
||||
#include <elf.h>
|
||||
File renamed without changes.
+11
-11
@@ -6,7 +6,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ELFContainer.h"
|
||||
#include "Linux/Utils/ELFContainer.h"
|
||||
|
||||
/*
|
||||
Simpler elf parser, checks for the elf MAGIC COOKIE
|
||||
@@ -31,9 +31,9 @@ struct ELFParser {
|
||||
std::ifstream elf(file);
|
||||
|
||||
fd = ::open(file.c_str(), O_RDONLY);
|
||||
|
||||
|
||||
if (fd == -1) {
|
||||
LogMan::Msg::E("Failed to open '%s'", file.c_str());
|
||||
// Likely just doesn't exist
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -82,12 +82,12 @@ struct ELFParser {
|
||||
LogMan::Msg::E("Invalid e_phentsize32 from '%s'", file.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Convert to 64 bit header
|
||||
for (int i = 0; i < EI_NIDENT; i++)
|
||||
ehdr.e_ident[i] = hdr32.e_ident[i];
|
||||
|
||||
#define COPY(name) ehdr.name = hdr32.name
|
||||
#define COPY(name) ehdr.name = hdr32.name
|
||||
COPY(e_type);
|
||||
COPY(e_machine);
|
||||
COPY(e_version);
|
||||
@@ -112,7 +112,7 @@ struct ELFParser {
|
||||
|
||||
} else if (header[EI_CLASS] == ELFCLASS64) {
|
||||
elf.read((char*)&ehdr, sizeof(ehdr));
|
||||
|
||||
|
||||
if (!elf.good()) {
|
||||
LogMan::Msg::E("Failed to read Ehdr64 from '%s'", file.c_str());
|
||||
return false;
|
||||
@@ -158,12 +158,12 @@ struct ELFParser {
|
||||
if (type == ::ELFLoader::ELFContainer::TYPE_X86_32) {
|
||||
Elf32_Phdr phdrs32[ehdr.e_phnum];
|
||||
elf.read((char*)phdrs32, sizeof(Elf32_Phdr) * ehdr.e_phnum);
|
||||
|
||||
|
||||
if (!elf.good()) {
|
||||
LogMan::Msg::E("Failed to read phdr32 from '%s'", file.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Convert to 64 bit program headers
|
||||
phdrs.resize(ehdr.e_phnum);
|
||||
|
||||
@@ -185,13 +185,13 @@ struct ELFParser {
|
||||
phdrs.resize(ehdr.e_phnum);
|
||||
|
||||
elf.read((char*)&phdrs[0], sizeof(Elf64_Phdr) * ehdr.e_phnum);
|
||||
|
||||
|
||||
if (!elf.good()) {
|
||||
LogMan::Msg::E("Failed to read phdr64 from '%s'", file.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (auto phdr : phdrs) {
|
||||
if (phdr.p_type == PT_INTERP) {
|
||||
elf.seekg(phdr.p_offset);
|
||||
@@ -219,4 +219,4 @@ struct ELFParser {
|
||||
~ELFParser() {
|
||||
Closefd();
|
||||
}
|
||||
};
|
||||
};
|
||||
+3
-2
@@ -5,10 +5,11 @@ desc: Part of our now defunct ld-linux replacement, keeps tracks of all symbols,
|
||||
$end_info$
|
||||
*/
|
||||
|
||||
#include <FEXCore/Utils/ELFSymbolDatabase.h>
|
||||
#include "Common/MathUtils.h"
|
||||
#include "Linux/Utils/ELFSymbolDatabase.h"
|
||||
|
||||
#include <FEXCore/Utils/Allocator.h>
|
||||
#include <FEXCore/Utils/LogManager.h>
|
||||
#include <FEXCore/Utils/Common/MathUtils.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <elf.h>
|
||||
+2
-3
@@ -1,13 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <FEXCore/Utils/CompilerDefs.h>
|
||||
#include <FEXCore/Utils/ELFContainer.h>
|
||||
#include "Linux/Utils/ELFContainer.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace ELFLoader {
|
||||
class FEX_DEFAULT_VISIBILITY ELFSymbolDatabase final {
|
||||
class ELFSymbolDatabase final {
|
||||
public:
|
||||
ELFSymbolDatabase(::ELFLoader::ELFContainer *file);
|
||||
~ELFSymbolDatabase();
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include "Common/Config.h"
|
||||
#include "Common/MathUtils.h"
|
||||
#include "Linux/Utils/ELFContainer.h"
|
||||
#include "Linux/Utils/ELFSymbolDatabase.h"
|
||||
|
||||
#include <FEXCore/Core/CodeLoader.h>
|
||||
#include <array>
|
||||
@@ -15,8 +17,6 @@
|
||||
#include <FEXCore/Core/X86Enums.h>
|
||||
#include <FEXCore/Utils/Allocator.h>
|
||||
#include <FEXCore/Utils/LogManager.h>
|
||||
#include <FEXCore/Utils/ELFContainer.h>
|
||||
#include <FEXCore/Utils/ELFSymbolDatabase.h>
|
||||
|
||||
namespace FEX::HarnessHelper {
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#pragma once
|
||||
#include "Common/Config.h"
|
||||
#include "Common/MathUtils.h"
|
||||
#include "Linux/Utils/ELFParser.h"
|
||||
#include "Linux/Utils/ELFSymbolDatabase.h"
|
||||
|
||||
#include <FEXCore/Core/CodeLoader.h>
|
||||
#include <array>
|
||||
@@ -16,8 +18,6 @@
|
||||
#include <FEXCore/Core/CoreState.h>
|
||||
#include <FEXCore/Core/X86Enums.h>
|
||||
#include <FEXCore/Utils/LogManager.h>
|
||||
#include <FEXCore/Utils/ELFParser.h>
|
||||
#include <FEXCore/Utils/ELFSymbolDatabase.h>
|
||||
|
||||
#include <elf.h>
|
||||
#include <sys/personality.h>
|
||||
|
||||
@@ -14,12 +14,12 @@ $end_info$
|
||||
#include "Tests/LinuxSyscalls/x32/Syscalls.h"
|
||||
#include "Tests/LinuxSyscalls/x64/Syscalls.h"
|
||||
#include "Tests/LinuxSyscalls/SignalDelegator.h"
|
||||
#include "Linux/Utils/ELFContainer.h"
|
||||
|
||||
#include <FEXCore/Config/Config.h>
|
||||
#include <FEXCore/Core/CodeLoader.h>
|
||||
#include <FEXCore/Core/Context.h>
|
||||
#include <FEXCore/Utils/Allocator.h>
|
||||
#include <FEXCore/Utils/ELFContainer.h>
|
||||
#include <FEXCore/Utils/LogManager.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "Common/Config.h"
|
||||
#include "Common/MathUtils.h"
|
||||
#include "Linux/Utils/ELFContainer.h"
|
||||
#include "Linux/Utils/ELFSymbolDatabase.h"
|
||||
|
||||
#include <array>
|
||||
#include <bitset>
|
||||
@@ -17,8 +19,6 @@
|
||||
#include <FEXCore/Utils/Allocator.h>
|
||||
#include <FEXCore/Utils/BitUtils.h>
|
||||
#include <FEXCore/Utils/CompilerDefs.h>
|
||||
#include <FEXCore/Utils/ELFContainer.h>
|
||||
#include <FEXCore/Utils/ELFSymbolDatabase.h>
|
||||
#include <FEXCore/Utils/LogManager.h>
|
||||
|
||||
namespace FEX::HarnessHelper {
|
||||
|
||||
@@ -57,7 +57,7 @@ add_library(LinuxEmulation STATIC
|
||||
Syscalls/Stubs.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(LinuxEmulation FEXCore pthread)
|
||||
target_link_libraries(LinuxEmulation FEXCore pthread FEX_Utils)
|
||||
target_include_directories(LinuxEmulation PRIVATE ${CMAKE_BINARY_DIR}/generated)
|
||||
target_include_directories(LinuxEmulation PRIVATE ${PROJECT_SOURCE_DIR}/External/drm-headers/include/)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ $end_info$
|
||||
|
||||
#include <FEXCore/Utils/LogManager.h>
|
||||
#include "Common/MathUtils.h"
|
||||
#include "Linux/Utils/ELFContainer.h"
|
||||
|
||||
#include "Tests/LinuxSyscalls/Syscalls.h"
|
||||
#include "Tests/LinuxSyscalls/Syscalls/Thread.h"
|
||||
@@ -18,7 +19,6 @@ $end_info$
|
||||
#include <FEXCore/Core/CodeLoader.h>
|
||||
#include <FEXCore/Debug/InternalThreadState.h>
|
||||
#include <FEXCore/Utils/Allocator.h>
|
||||
#include <FEXCore/Utils/ELFContainer.h>
|
||||
#include <fcntl.h>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
Reference in new issue
Block a user