From d33896ecd246000dc43024d72d2e35af996100f3 Mon Sep 17 00:00:00 2001 From: York Jasper Niebuhr Date: Mon, 27 Oct 2025 18:27:59 +0100 Subject: [PATCH] Finalizer spslr file parsing --- finalize/CMakeLists.txt | 3 +- finalize/accumulation.cpp | 232 ++++++++++++++++++++++++++++++ finalize/accumulation.h | 48 +++++++ finalize/finalize.cpp | 63 +++----- pinpoint/final/on_finish_unit.cpp | 5 +- 5 files changed, 307 insertions(+), 44 deletions(-) create mode 100644 finalize/accumulation.cpp create mode 100644 finalize/accumulation.h diff --git a/finalize/CMakeLists.txt b/finalize/CMakeLists.txt index b3d0e7d..7bb8957 100644 --- a/finalize/CMakeLists.txt +++ b/finalize/CMakeLists.txt @@ -1,4 +1,5 @@ find_package(LIEF REQUIRED) -add_executable(spslr_finalize finalize.cpp) +add_executable(spslr_finalize finalize.cpp accumulation.cpp) target_link_libraries(spslr_finalize PRIVATE LIEF::LIEF) +set_target_properties(spslr_finalize PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO) diff --git a/finalize/accumulation.cpp b/finalize/accumulation.cpp new file mode 100644 index 0000000..51ca6e1 --- /dev/null +++ b/finalize/accumulation.cpp @@ -0,0 +1,232 @@ +#include "accumulation.h" + +#include +#include +#include + +namespace fs = std::filesystem; + +static std::size_t next_global_target_uid = 0; + +std::unordered_map targets; +std::unordered_map global_dpins; +std::unordered_map units; + +static bool global_target_field_cmp(const TARGET& a, const TARGET& b) { + // TODO + return true; +} + +static bool global_target_cmp(const TARGET& a, const TARGET& b) { + // Note -> Later, use hash of type (generated by pinpoint plugin) + + if (a.name != b.name) + return false; + + if (a.size != b.size || !global_target_field_cmp(a, b)) { + std::cerr << "WARNING: Got different definitions of \"" << a.name << "\" -> detached randomization" << std::endl; + return false; + } + + return true; +} + +static std::size_t accumulate_global_target(TARGET&& target) { + for (const auto& [guid, gtarget] : targets) { + if (global_target_cmp(gtarget, target)) + return guid; + } + + std::size_t guid = next_global_target_uid++; + targets.emplace(guid, std::move(target)); + return guid; +} + +/* +.spslr: + +SPSLR +target +f +f +... +ipin