Skip to content

Commit 7dc867a

Browse files
author
Rodger Combs
committed
rewriteSectionsLibrary: assume all libraries may be executable; fixes #165
1 parent 6066239 commit 7dc867a

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/patchelf.cc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ class ElfFile
104104

105105
bool changed = false;
106106

107-
bool isExecutable = false;
108-
109107
typedef std::string SectionName;
110108
typedef std::map<SectionName, std::string> ReplacedSections;
111109

@@ -414,10 +412,8 @@ ElfFile<ElfFileParamNames>::ElfFile(FileContents fileContents)
414412
error("program headers have wrong size");
415413

416414
/* Copy the program and section headers. */
417-
for (int i = 0; i < rdi(hdr->e_phnum); ++i) {
415+
for (int i = 0; i < rdi(hdr->e_phnum); ++i)
418416
phdrs.push_back(* ((Elf_Phdr *) (contents + rdi(hdr->e_phoff)) + i));
419-
if (rdi(phdrs[i].p_type) == PT_INTERP) isExecutable = true;
420-
}
421417

422418
for (int i = 0; i < rdi(hdr->e_shnum); ++i)
423419
shdrs.push_back(* ((Elf_Shdr *) (contents + rdi(hdr->e_shoff)) + i));
@@ -742,12 +738,10 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
742738
since DYN executables tend to start at virtual address 0, so
743739
rewriteSectionsExecutable() won't work because it doesn't have
744740
any virtual address space to grow downwards into. */
745-
if (isExecutable) {
746-
if (startOffset >= startPage) {
747-
debug("shifting new PT_LOAD segment by %d bytes to work around a Linux kernel bug\n", startOffset - startPage);
748-
}
749-
startPage = startOffset;
741+
if (startOffset >= startPage) {
742+
debug("shifting new PT_LOAD segment by %d bytes to work around a Linux kernel bug\n", startOffset - startPage);
750743
}
744+
startPage = startOffset;
751745

752746
/* Add a segment that maps the replaced sections into memory. */
753747
phdrs.resize(rdi(hdr->e_phnum) + 1);

0 commit comments

Comments
 (0)