diff --git a/Makefile b/Makefile index bc2f75f..228240d 100644 --- a/Makefile +++ b/Makefile @@ -140,7 +140,7 @@ test_relocate_dll: build_and_check_test_sample mkdir tmp_lib move test\calc.dll tmp_bin\calc.dll move test\calc.lib tmp_lib\calc.lib - test\relocate.exe --pe tmp_bin\calc.dll --coff tmp_lib\calc.lib --export + test\relocate.exe --pe tmp_bin\calc.dll --coff tmp_lib\calc.lib cd test del tester.exe link main.obj ..\tmp_lib\calc.lib /out:tester.exe @@ -209,7 +209,7 @@ test_relocate_long_paths: test_long_paths mkdir tmp_lib move evenlongersubdirectoryname\verylongfilepathnamethatwilldefinitelybegreaterthanonehundredandfourtyfourcharacters.dll tmp_bin\verylongfilepathnamethatwilldefinitelybegreaterthanonehundredandfourtyfourcharacters.dll move evenlongersubdirectoryname\verylongfilepathnamethatwilldefinitelybegreaterthanonehundredandfourtyfourcharacters.lib tmp_lib\verylongfilepathnamethatwilldefinitelybegreaterthanonehundredandfourtyfourcharacters.lib - evenlongersubdirectoryname\relocate.exe --pe tmp_bin\verylongfilepathnamethatwilldefinitelybegreaterthanonehundredandfourtyfourcharacters.dll --coff tmp_lib\verylongfilepathnamethatwilldefinitelybegreaterthanonehundredandfourtyfourcharacters.lib --export + evenlongersubdirectoryname\relocate.exe --pe tmp_bin\verylongfilepathnamethatwilldefinitelybegreaterthanonehundredandfourtyfourcharacters.dll --coff tmp_lib\verylongfilepathnamethatwilldefinitelybegreaterthanonehundredandfourtyfourcharacters.lib cd evenlongersubdirectoryname del tester.exe link main.obj ..\tmp_lib\verylongfilepathnamethatwilldefinitelybegreaterthanonehundredandfourtyfourcharacters.lib /out:tester.exe diff --git a/src/commandline.cxx b/src/commandline.cxx index 38bd760..df2bff1 100644 --- a/src/commandline.cxx +++ b/src/commandline.cxx @@ -86,14 +86,6 @@ bool print_help() { "said library is regenerated and the old imp lib\n"; std::cout << " " "replaced.\n"; - std::cout << " --export|--deploy = " - "Mutually exclusive command modifier.\n"; - std::cout << " " - "Instructs relocate to either prepare the\n"; - std::cout << " " - "dynamic library for exporting to build cache\n"; - std::cout << " " - "or for extraction from bc onto new host system\n"; std::cout << " --report = " "Report information about the parsed PE/Coff files\n"; std::cout << " --debug|-d = " @@ -149,24 +141,6 @@ std::map ParseRelocate(const char** args, int argc) { return opts; } opts.insert(std::pair("full", "full")); - } else if (!strcmp(args[i], "--export")) { - // export and deploy are mutually exclusive, if one is defined - // the other cannot be - if (redefinedArgCheck(opts, "export", "--export") || - redefinedArgCheck(opts, "deploy", "--deploy")) { - opts.clear(); - return opts; - } - opts.insert(std::pair("cmd", "export")); - } else if (!strcmp(args[i], "--deploy")) { - // export and deploy are mutually exclusive, if one is defined - // the other cannot be - if (redefinedArgCheck(opts, "export", "--export") || - redefinedArgCheck(opts, "deploy", "--deploy")) { - opts.clear(); - return opts; - } - opts.insert(std::pair("cmd", "deploy")); } else if (!strcmp(args[i], "--debug") || !strcmp(args[i], "-d")) { opts.insert(std::pair("debug", "on")); } else if (!strcmp(args[i], "--verify")) { diff --git a/src/main.cxx b/src/main.cxx index 1fb0b63..7fa7708 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -33,8 +33,6 @@ int main(int argc, const char* argv[]) { return -1; } bool const full = !(patch_args.find("full") == patch_args.end()); - bool const deploy = !(patch_args.find("cmd") == patch_args.end()) && - patch_args.at("cmd") == "deploy"; bool const report = !(patch_args.find("report") == patch_args.end()); bool const has_pe = !(patch_args.find("pe") == patch_args.end()); bool const debug = !(patch_args.find("debug") == patch_args.end()); @@ -77,12 +75,11 @@ int main(int argc, const char* argv[]) { std::unique_ptr rpath_lib; try { if (has_coff) { - rpath_lib = std::make_unique(patch_args.at("pe"), - patch_args.at("coff"), - full, deploy, true); + rpath_lib = std::make_unique( + patch_args.at("pe"), patch_args.at("coff"), full, true); } else { rpath_lib = std::make_unique(patch_args.at("pe"), - full, deploy, true); + full, true); } } catch (const NameTooLongError& e) { std::cerr << "Cannot Rename PE file " << patch_args.at("pe") @@ -104,8 +101,8 @@ int main(int argc, const char* argv[]) { } if (report_args.find("pe") != report_args.end()) { try { - LibRename portable_executable( - report_args.at("pe"), std::string(), false, false, true); + LibRename portable_executable(report_args.at("pe"), + std::string(), false, true); portable_executable.ExecuteRename(); } catch (const NameTooLongError& e) { std::cerr diff --git a/src/winrpath.cxx b/src/winrpath.cxx index c895315..d474b32 100644 --- a/src/winrpath.cxx +++ b/src/winrpath.cxx @@ -4,7 +4,6 @@ * SPDX-License-Identifier: (Apache-2.0 OR MIT) */ #include -#include #include // NOLINT #include "winrpath.h" #include @@ -39,20 +38,7 @@ * */ bool LibRename::SpackCheckForDll(const std::string& dll_path) const { - if (this->deploy) { - return hasPathCharacters(dll_path); - } - // First check for the case we're relocating out of a buildcache - bool reloc_spack = false; - if (!(dll_path.find("") == std::string::npos) || - !(dll_path.find("") == std::string::npos)) { - reloc_spack = true; - } - // If not, maybe we're just relocating a binary on the same system - if (!reloc_spack) { - reloc_spack = hasPathCharacters(dll_path); - } - return reloc_spack; + return hasPathCharacters(dll_path); } /* @@ -68,61 +54,45 @@ bool LibRename::SpackCheckForDll(const std::string& dll_path) const { * */ bool LibRename::RenameDll(char* name_loc, const std::string& dll_path) const { - if (this->deploy) { - int const padding_len = get_padding_length(dll_path); - if (padding_len < MIN_PADDING_THRESHOLD) { - // path is too long to mark as a Spack path - // use shorter sigil - char short_sigil[] = ""; - // use _snprintf as it does not null terminate and we're writing into the middle - // of a null terminated string we want to later read from properly - _snprintf(name_loc, sizeof(short_sigil) - 1, "%s", short_sigil); - } else { - char long_sigil[] = ""; - // See _snprintf comment above for use context - _snprintf(name_loc, sizeof(long_sigil) - 1, "%s", long_sigil); - } - } else { - if (SpackInstalledLib(dll_path)) { - return true; - } - std::string const file_name = basename(dll_path); - if (file_name.empty()) { - std::cerr << "Unable to extract filename from dll for relocation" - << "\n"; + if (SpackInstalledLib(dll_path)) { + return true; + } + std::string const file_name = basename(dll_path); + if (file_name.empty()) { + std::cerr << "Unable to extract filename from dll for relocation" + << "\n"; + return false; + } + LibraryFinder lib_finder; + std::string new_library_loc = + lib_finder.FindLibrary(file_name, dll_path); + if (new_library_loc.empty()) { + std::cerr << "Unable to find library " << file_name << " from " + << dll_path << " for relocation" << "\n"; + return false; + } + if (new_library_loc.length() > MAX_NAME_LEN) { + try { + new_library_loc = short_name(new_library_loc); + } catch (NameTooLongError& e) { return false; - } - LibraryFinder lib_finder; - std::string new_library_loc = - lib_finder.FindLibrary(file_name, dll_path); - if (new_library_loc.empty()) { - std::cerr << "Unable to find library " << file_name << " from " - << dll_path << " for relocation" << "\n"; + } catch (FileNotExist &e) { return false; - } - if (new_library_loc.length() > MAX_NAME_LEN) { - try { - new_library_loc = short_name(new_library_loc); - } catch (NameTooLongError& e) { - return false; - } catch (FileNotExist &e) { - return false; - } catch (SFNProcessingError &e) { - return false; - } - } - char* new_lib_pth = - pad_path(new_library_loc.c_str(), - static_cast(new_library_loc.size())); - if (!new_lib_pth) { + } catch (SFNProcessingError &e) { return false; } - replace_special_characters(new_lib_pth, MAX_NAME_LEN); - - // c_str returns a proper (i.e. null terminated) value, so we dont need to worry about - // size differences w.r.t the path to the new library - snprintf(name_loc, MAX_NAME_LEN + 1, "%s", new_lib_pth); } + char* new_lib_pth = + pad_path(new_library_loc.c_str(), + static_cast(new_library_loc.size())); + if (!new_lib_pth) { + return false; + } + replace_special_characters(new_lib_pth, MAX_NAME_LEN); + + // c_str returns a proper (i.e. null terminated) value, so we dont need to worry about + // size differences w.r.t the path to the new library + snprintf(name_loc, MAX_NAME_LEN + 1, "%s", new_lib_pth); return true; } @@ -249,15 +219,15 @@ bool LibRename::FindDllAndRename(HANDLE& pe_in) { * \param replace a flag indicating if we're replacing the renamed import lib or making a copy with absolute dll names * \param report a flag indicating if we should be reporting the contents of the PE/COFF file we're parsing to stdout */ -LibRename::LibRename(std::string p_exe, bool full, bool deploy, bool replace) - : replace(replace), full(full), pe(std::move(p_exe)), deploy(deploy) {} +LibRename::LibRename(std::string p_exe, bool full, bool replace) + : replace(replace), full(full), pe(std::move(p_exe)) { +} LibRename::LibRename(std::string p_exe, std::string coff, bool full, - bool deploy, bool replace) + bool replace) : replace(replace), full(full), pe(std::move(p_exe)), - deploy(deploy), coff(std::move(coff)) { std::string const coff_path = stem(this->coff); this->tmp_def_file = coff_path + "-tmp.def"; @@ -364,7 +334,7 @@ bool LibRename::ExecuteRename() { // exes // We do not bother with defs for things that don't have // import libraries - if (!this->deploy && !this->coff.empty()) { + if (!this->coff.empty()) { // Extract DLL if (!this->ComputeDefFile()) { debug("Failed to compute def file"); diff --git a/src/winrpath.h b/src/winrpath.h index e166465..0e5061f 100644 --- a/src/winrpath.h +++ b/src/winrpath.h @@ -31,9 +31,8 @@ class LibRename { public: - LibRename(std::string p_exe, std::string coff, bool full, bool deploy, - bool replace); - LibRename(std::string p_exe, bool full, bool deploy, bool replace); + LibRename(std::string p_exe, std::string coff, bool full, bool replace); + LibRename(std::string p_exe, bool full, bool replace); bool ExecuteRename(); bool ExecuteLibRename(); bool ExecutePERename(); @@ -53,6 +52,5 @@ class LibRename { std::string def_file; std::string tmp_def_file; bool full; - bool deploy; bool replace; };