summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLinus Heckemann <git@sphalerite.org>2017-05-28 14:46:51 (GMT)
committerLinus Heckemann <git@sphalerite.org>2017-05-28 14:46:51 (GMT)
commit936bae418b77ee9e06a93cd3cd444f4204446973 (patch)
treee8ab35713ddde6232754028909ae495086931913 /src
parent2a9cefd7d637d160d12dc7946393778fa8abbc58 (diff)
downloadpatchelf-936bae418b77ee9e06a93cd3cd444f4204446973.zip
patchelf-936bae418b77ee9e06a93cd3cd444f4204446973.tar.gz
patchelf-936bae418b77ee9e06a93cd3cd444f4204446973.tar.bz2
Allow multiple filenames to patch
This makes behaviour less confusing when multiple filenames are passed — previously, any extra filenames would be ignored completely, as would any options passed after a filename. Now these are taken into account.
Diffstat (limited to 'src')
-rw-r--r--src/patchelf.cc29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index 55b38e3..cfa39e2 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -45,7 +45,7 @@ static bool debugMode = false;
static bool forceRPath = false;
-static std::string fileName;
+static std::vector<std::string> fileNames;
static int pageSize = PAGESIZE;
typedef std::shared_ptr<std::vector<unsigned char>> FileContents;
@@ -1546,7 +1546,7 @@ static bool printNeeded = false;
static bool noDefaultLib = false;
template<class ElfFile>
-static void patchElf2(ElfFile && elfFile)
+static void patchElf2(ElfFile && elfFile, std::string fileName)
{
if (printInterpreter)
printf("%s\n", elfFile.getInterpreter().c_str());
@@ -1588,17 +1588,19 @@ static void patchElf2(ElfFile && elfFile)
static void patchElf()
{
- if (!printInterpreter && !printRPath && !printSoname && !printNeeded)
- debug("patching ELF file '%s'\n", fileName.c_str());
+ for (auto fileName : fileNames) {
+ if (!printInterpreter && !printRPath && !printSoname && !printNeeded)
+ debug("patching ELF file '%s'\n", fileName.c_str());
- debug("Kernel page size is %u bytes\n", getPageSize());
+ debug("Kernel page size is %u bytes\n", getPageSize());
- auto fileContents = readFile(fileName);
+ auto fileContents = readFile(fileName);
- if (getElfType(fileContents).is32Bit)
- patchElf2(ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed>(fileContents));
- else
- patchElf2(ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off, Elf64_Dyn, Elf64_Sym, Elf64_Verneed>(fileContents));
+ if (getElfType(fileContents).is32Bit)
+ patchElf2(ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed>(fileContents), fileName);
+ else
+ patchElf2(ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off, Elf64_Dyn, Elf64_Sym, Elf64_Verneed>(fileContents), fileName);
+ }
}
@@ -1721,11 +1723,12 @@ int mainWrapped(int argc, char * * argv)
printf(PACKAGE_STRING "\n");
return 0;
}
- else break;
+ else {
+ fileNames.push_back(arg);
+ }
}
- if (i == argc) error("missing filename");
- fileName = argv[i];
+ if (fileNames.empty()) error("missing filename");
patchElf();