Finalizer spslr file list argument
This commit is contained in:
parent
1b8814ce0b
commit
0eba2ac3a1
@ -205,22 +205,25 @@ static bool accumulate_file(const fs::path& path) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool accumulate(const std::string& spslr_dir) {
|
bool accumulate(const std::vector<std::string>& spslr_files) {
|
||||||
fs::path spslr_root { spslr_dir };
|
for (const std::string& spslr_file : spslr_files) {
|
||||||
|
fs::path p { spslr_file };
|
||||||
|
|
||||||
if (!fs::exists(spslr_root) || !fs::is_directory(spslr_root))
|
if (!p.string().ends_with(".spslr")) {
|
||||||
|
std::cerr << "The file " << p << " does not appear to be a metadata file!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto& dir_entry : fs::recursive_directory_iterator(spslr_root)) {
|
if (!fs::exists(p) || !fs::is_regular_file(p)) {
|
||||||
if (!dir_entry.is_regular_file())
|
std::cerr << "Failed to open metadata file " << p << "!" << std::endl;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!dir_entry.path().string().ends_with(".spslr"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!accumulate_file(dir_entry.path()))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!accumulate_file(p)) {
|
||||||
|
std::cerr << "Failed to parse metadata file " << p << "!" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
struct IPIN {
|
struct IPIN {
|
||||||
struct HIT {
|
struct HIT {
|
||||||
@ -60,4 +61,4 @@ struct CU {
|
|||||||
extern std::unordered_map<std::size_t, TARGET> targets;
|
extern std::unordered_map<std::size_t, TARGET> targets;
|
||||||
extern std::unordered_map<std::string, CU> units;
|
extern std::unordered_map<std::string, CU> units;
|
||||||
|
|
||||||
bool accumulate(const std::string& spslr_dir);
|
bool accumulate(const std::vector<std::string>& spslr_files);
|
||||||
|
|||||||
@ -26,7 +26,6 @@ static bool assemble_patcher_program(uint64_t vaddr_pivot, std::vector<uint8_t>&
|
|||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
static option long_options[] = {
|
static option long_options[] = {
|
||||||
{ "help", no_argument, 0, 0 },
|
{ "help", no_argument, 0, 0 },
|
||||||
{ "spslr", required_argument, 0, 0 },
|
|
||||||
{ "bin", required_argument, 0, 0 },
|
{ "bin", required_argument, 0, 0 },
|
||||||
{ "out", required_argument, 0, 0 },
|
{ "out", required_argument, 0, 0 },
|
||||||
{ "strip", no_argument, 0, 0 },
|
{ "strip", no_argument, 0, 0 },
|
||||||
@ -36,20 +35,19 @@ int main(int argc, char** argv) {
|
|||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
std::string spslr_dir, bin_file, out_file;
|
std::vector<std::string> spslr_files;
|
||||||
|
std::string bin_file, out_file;
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "", long_options, &option_index)) == 0) {
|
while ((c = getopt_long(argc, argv, "hb:o:", long_options, &option_index)) == 0) {
|
||||||
const option& opt = long_options[option_index];
|
const option& opt = long_options[option_index];
|
||||||
std::string optname { opt.name };
|
std::string optname { opt.name };
|
||||||
|
|
||||||
if (optname == "help") {
|
if (optname == "help") {
|
||||||
std::cout << "To use spslr_finalize, supply these 3 arguments:" << std::endl;
|
std::cout << "To use spslr_finalize, supply these 3 arguments:" << std::endl;
|
||||||
std::cout << " --spslr=<dir> (the directory of .spslr files produced by spslr_pinpoint)" << std::endl;
|
|
||||||
std::cout << " --bin=<file> (the binary compiled with spslr_pinpoint to be finalized)" << std::endl;
|
std::cout << " --bin=<file> (the binary compiled with spslr_pinpoint to be finalized)" << std::endl;
|
||||||
std::cout << " --out=<file> (the finalized binary file to be written)" << std::endl;
|
std::cout << " --out=<file> (the finalized binary file to be written)" << std::endl;
|
||||||
|
std::cout << " <file>... (one or more .spslr metadata files)" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
} else if (optname == "spslr") {
|
|
||||||
spslr_dir = std::string{ optarg };
|
|
||||||
} else if (optname == "bin") {
|
} else if (optname == "bin") {
|
||||||
bin_file = std::string{ optarg };
|
bin_file = std::string{ optarg };
|
||||||
} else if (optname == "out") {
|
} else if (optname == "out") {
|
||||||
@ -63,11 +61,6 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spslr_dir.empty()) {
|
|
||||||
std::cerr << "Missing spslr directory, supply it via --spslr=<dir>!" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bin_file.empty()) {
|
if (bin_file.empty()) {
|
||||||
std::cerr << "Missing input file path, supply it via --bin=<file>!" << std::endl;
|
std::cerr << "Missing input file path, supply it via --bin=<file>!" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
@ -78,7 +71,15 @@ int main(int argc, char** argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!accumulate(spslr_dir)) {
|
for (int i = optind; i < argc; ++i)
|
||||||
|
spslr_files.emplace_back(argv[i]);
|
||||||
|
|
||||||
|
if (spslr_files.empty()) {
|
||||||
|
std::cerr << "Missing spslr files! Pass one or more .spslr files as positional arguments." << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!accumulate(spslr_files)) {
|
||||||
std::cerr << "Failed to accumulate data from spslr directory!" << std::endl;
|
std::cerr << "Failed to accumulate data from spslr directory!" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,17 +2,36 @@ add_executable(subject main.c second.c sub/second.c)
|
|||||||
target_include_directories(subject PRIVATE .)
|
target_include_directories(subject PRIVATE .)
|
||||||
add_dependencies(subject spslr_pinpoint spslr_finalize spslr_selfpatch)
|
add_dependencies(subject spslr_pinpoint spslr_finalize spslr_selfpatch)
|
||||||
target_link_libraries(subject PRIVATE spslr_selfpatch)
|
target_link_libraries(subject PRIVATE spslr_selfpatch)
|
||||||
|
|
||||||
|
set(SUBJECT_SPSLR_METADIR "${CMAKE_CURRENT_BINARY_DIR}/spslr")
|
||||||
|
set(SUBJECT_SPSLR_SRCROOT "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
|
||||||
target_compile_options(subject PRIVATE -O1 -fplugin=$<TARGET_FILE:spslr_pinpoint> -fdump-tree-separate_offset -fdump-tree-asm_offset
|
target_compile_options(subject PRIVATE -O1 -fplugin=$<TARGET_FILE:spslr_pinpoint> -fdump-tree-separate_offset -fdump-tree-asm_offset
|
||||||
-fplugin-arg-spslr_pinpoint-srcroot=${CMAKE_CURRENT_SOURCE_DIR}
|
-fplugin-arg-spslr_pinpoint-srcroot=${SUBJECT_SPSLR_SRCROOT}
|
||||||
-fplugin-arg-spslr_pinpoint-metadir=${CMAKE_CURRENT_BINARY_DIR}/spslr)
|
-fplugin-arg-spslr_pinpoint-metadir=${SUBJECT_SPSLR_METADIR})
|
||||||
|
|
||||||
|
file(MAKE_DIRECTORY "${SUBJECT_SPSLR_METADIR}")
|
||||||
|
|
||||||
# Apply spslr_finalizer to subject
|
# Apply spslr_finalizer to subject
|
||||||
|
|
||||||
|
get_target_property(SUBJECT_SOURCES subject SOURCES)
|
||||||
|
|
||||||
|
set(SUBJECT_SPSLR_FILES "")
|
||||||
|
foreach(src IN LISTS SUBJECT_SOURCES)
|
||||||
|
get_filename_component(abs_src "${src}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
file(RELATIVE_PATH rel_src "${SUBJECT_SPSLR_SRCROOT}" "${abs_src}")
|
||||||
|
file(TO_CMAKE_PATH "${rel_src}" rel_src)
|
||||||
|
list(APPEND SUBJECT_SPSLR_FILES "${SUBJECT_SPSLR_METADIR}/${rel_src}.spslr")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET subject
|
TARGET subject
|
||||||
POST_BUILD
|
POST_BUILD
|
||||||
COMMAND $<TARGET_FILE:spslr_finalize>
|
COMMAND $<TARGET_FILE:spslr_finalize>
|
||||||
--spslr=${CMAKE_CURRENT_BINARY_DIR}/spslr
|
|
||||||
--bin=$<TARGET_FILE:subject>
|
--bin=$<TARGET_FILE:subject>
|
||||||
--out=${CMAKE_BINARY_DIR}/subject_final
|
--out=${CMAKE_BINARY_DIR}/subject_final
|
||||||
|
${SUBJECT_SPSLR_FILES}
|
||||||
COMMAND chmod +x ${CMAKE_BINARY_DIR}/subject_final
|
COMMAND chmod +x ${CMAKE_BINARY_DIR}/subject_final
|
||||||
|
VERBATIM
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user