From 33433c2d6412f15b018593e6ba72aec6571e12e8 Mon Sep 17 00:00:00 2001 From: whh8b <whh8b@git.zephyr-software.com> Date: Mon, 6 Oct 2014 20:33:54 +0000 Subject: [PATCH] Add objcopy option --- include/zipr_options.h | 10 +++++++++- src/zipr.cpp | 2 +- src/zipr_options.cpp | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/zipr_options.h b/include/zipr_options.h index 0f3c11af2..02ded7073 100644 --- a/include/zipr_options.h +++ b/include/zipr_options.h @@ -39,7 +39,13 @@ class Options_t { public: - Options_t() : m_outname("b.out") { verbose=false; m_var_id=-1; } + Options_t() : + m_outname("b.out"), + m_objcopy_path("/usr/bin/objcopy") + { + verbose=false; + m_var_id=-1; + } static Options_t* parse_args(int p_argc, char* p_argv[]); static void print_usage(int p_argc, char *p_argv[]); @@ -48,6 +54,7 @@ class Options_t std::string GetCallbackFileName() { return m_callbackname; } int GetVariantID() { return m_var_id; } int GetVerbose() { return verbose; } + std::string GetObjcopyPath() { return m_objcopy_path; }; void EnableOptimization(Optimizations_t::OptimizationName_t opt) { @@ -62,6 +69,7 @@ class Options_t private: std::string m_outname; std::string m_callbackname; + std::string m_objcopy_path; bool verbose; int m_var_id; int EnabledOptimizations[Optimizations_t::NumberOfOptimizations]; diff --git a/src/zipr.cpp b/src/zipr.cpp index 0dc708227..d331c6dcf 100644 --- a/src/zipr.cpp +++ b/src/zipr.cpp @@ -1409,7 +1409,7 @@ void Zipr_t::InsertNewSegmentIntoExe(string rewritten_file, string bin_to_add, R // system("$stratafier/add_strata_segment $newfile $exe_copy ") == 0 or die (" command failed : $? \n"); string cmd= - string("/usr/bin/i386-linux-cgc-objcopy --add-section .strata=")+bin_to_add+ + m_opts.GetObjcopyPath() + string(" --add-section .strata=")+bin_to_add+ string(" --change-section-address .strata=")+to_string(sec_start)+ string(" --set-section-flags .strata=alloc,code ")+ // --set-start $textoffset // set-start not needed, as we aren't changing the entry point. diff --git a/src/zipr_options.cpp b/src/zipr_options.cpp index 32c7da6a4..972d9650d 100644 --- a/src/zipr_options.cpp +++ b/src/zipr_options.cpp @@ -14,6 +14,8 @@ void Options_t::print_usage(int p_argc, char *p_argv[]) "Output file name. Optional. Default: b.out.\n"); printf("\t-z optimization\t--optimize optimization: " "Enable an optimization. Repeatable. Optional. \n"); + printf("\t-j path\t\t--objcopy path: " + "Set the path of objcopy to use. Optional. \n"); } Options_t* Options_t::parse_args(int p_argc, char* p_argv[]) @@ -31,6 +33,7 @@ Options_t* Options_t::parse_args(int p_argc, char* p_argv[]) {"output", required_argument, NULL, 'o'}, {"variant", required_argument, NULL, 'v'}, {"callbacks", required_argument, NULL, 'c'}, + {"objcopy", required_argument, NULL, 'j'}, {NULL, no_argument, NULL, '\0'}, // end-of-array marker }; @@ -68,6 +71,10 @@ Options_t* Options_t::parse_args(int p_argc, char* p_argv[]) } break; } + case 'j': + { + opt->m_objcopy_path = std::string(::optarg); + } case 'o': { opt->m_outname = std::string(::optarg); -- GitLab