|
58 | 58 | static bool debugMode = false; |
59 | 59 |
|
60 | 60 | static bool forceRPath = false; |
| 61 | +static bool clobberOldSections = true; |
61 | 62 |
|
62 | 63 | static std::vector<std::string> fileNames; |
63 | 64 | static std::string outputFileName; |
@@ -664,14 +665,16 @@ template<ElfFileParams> |
664 | 665 | void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff, |
665 | 666 | Elf_Addr startAddr, Elf_Off startOffset) |
666 | 667 | { |
667 | | - /* Overwrite the old section contents with 'Z's. Do this |
668 | | - *before* writing the new section contents (below) to prevent |
669 | | - clobbering previously written new section contents. */ |
670 | | - for (auto & i : replacedSections) { |
671 | | - const std::string & sectionName = i.first; |
672 | | - const Elf_Shdr & shdr = findSectionHeader(sectionName); |
673 | | - if (rdi(shdr.sh_type) != SHT_NOBITS) |
674 | | - memset(fileContents->data() + rdi(shdr.sh_offset), 'Z', rdi(shdr.sh_size)); |
| 668 | + if (clobberOldSections) { |
| 669 | + /* Overwrite the old section contents with 'Z's. Do this |
| 670 | + *before* writing the new section contents (below) to prevent |
| 671 | + clobbering previously written new section contents. */ |
| 672 | + for (auto & i : replacedSections) { |
| 673 | + const std::string & sectionName = i.first; |
| 674 | + const Elf_Shdr & shdr = findSectionHeader(sectionName); |
| 675 | + if (rdi(shdr.sh_type) != SHT_NOBITS) |
| 676 | + memset(fileContents->data() + rdi(shdr.sh_offset), 'Z', rdi(shdr.sh_size)); |
| 677 | + } |
675 | 678 | } |
676 | 679 |
|
677 | 680 | std::set<unsigned int> noted_phdrs = {}; |
@@ -2505,6 +2508,7 @@ static void showHelp(const std::string & progName) |
2505 | 2508 | [--clear-execstack]\n\ |
2506 | 2509 | [--set-execstack]\n\ |
2507 | 2510 | [--rename-dynamic-symbols NAME_MAP_FILE]\tRenames dynamic symbols. The map file should contain two symbols (old_name new_name) per line\n\ |
| 2511 | + [--no-clobber-old-sections]\t\tDo not clobber old section values - only use when the binary expects to find section info at the old location.\n\ |
2508 | 2512 | [--output FILE]\n\ |
2509 | 2513 | [--debug]\n\ |
2510 | 2514 | [--version]\n\ |
@@ -2661,6 +2665,9 @@ static int mainWrapped(int argc, char * * argv) |
2661 | 2665 | symbolsToRename[*symbolsToRenameKeys.insert(from).first] = to; |
2662 | 2666 | } |
2663 | 2667 | } |
| 2668 | + else if (arg == "--no-clobber-old-sections") { |
| 2669 | + clobberOldSections = false; |
| 2670 | + } |
2664 | 2671 | else if (arg == "--help" || arg == "-h" ) { |
2665 | 2672 | showHelp(argv[0]); |
2666 | 2673 | return 0; |
|
0 commit comments