Skip to content

Commit 936bae4

Browse files
committed
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.
1 parent 2a9cefd commit 936bae4

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/patchelf.cc

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static bool debugMode = false;
4545

4646
static bool forceRPath = false;
4747

48-
static std::string fileName;
48+
static std::vector<std::string> fileNames;
4949
static int pageSize = PAGESIZE;
5050

5151
typedef std::shared_ptr<std::vector<unsigned char>> FileContents;
@@ -1546,7 +1546,7 @@ static bool printNeeded = false;
15461546
static bool noDefaultLib = false;
15471547

15481548
template<class ElfFile>
1549-
static void patchElf2(ElfFile && elfFile)
1549+
static void patchElf2(ElfFile && elfFile, std::string fileName)
15501550
{
15511551
if (printInterpreter)
15521552
printf("%s\n", elfFile.getInterpreter().c_str());
@@ -1588,17 +1588,19 @@ static void patchElf2(ElfFile && elfFile)
15881588

15891589
static void patchElf()
15901590
{
1591-
if (!printInterpreter && !printRPath && !printSoname && !printNeeded)
1592-
debug("patching ELF file '%s'\n", fileName.c_str());
1591+
for (auto fileName : fileNames) {
1592+
if (!printInterpreter && !printRPath && !printSoname && !printNeeded)
1593+
debug("patching ELF file '%s'\n", fileName.c_str());
15931594

1594-
debug("Kernel page size is %u bytes\n", getPageSize());
1595+
debug("Kernel page size is %u bytes\n", getPageSize());
15951596

1596-
auto fileContents = readFile(fileName);
1597+
auto fileContents = readFile(fileName);
15971598

1598-
if (getElfType(fileContents).is32Bit)
1599-
patchElf2(ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed>(fileContents));
1600-
else
1601-
patchElf2(ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off, Elf64_Dyn, Elf64_Sym, Elf64_Verneed>(fileContents));
1599+
if (getElfType(fileContents).is32Bit)
1600+
patchElf2(ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed>(fileContents), fileName);
1601+
else
1602+
patchElf2(ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off, Elf64_Dyn, Elf64_Sym, Elf64_Verneed>(fileContents), fileName);
1603+
}
16021604
}
16031605

16041606

@@ -1721,11 +1723,12 @@ int mainWrapped(int argc, char * * argv)
17211723
printf(PACKAGE_STRING "\n");
17221724
return 0;
17231725
}
1724-
else break;
1726+
else {
1727+
fileNames.push_back(arg);
1728+
}
17251729
}
17261730

1727-
if (i == argc) error("missing filename");
1728-
fileName = argv[i];
1731+
if (fileNames.empty()) error("missing filename");
17291732

17301733
patchElf();
17311734

0 commit comments

Comments
 (0)