Skip to content

Commit c3ffe62

Browse files
committed
rewriteSectionsLibrary: assume all libraries may be executable; fixes #165
1 parent 7013e59 commit c3ffe62

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/patchelf.cc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ class ElfFile
106106

107107
bool changed = false;
108108

109-
bool isExecutable = false;
110-
111109
typedef std::string SectionName;
112110
typedef std::map<SectionName, std::string> ReplacedSections;
113111

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

417415
/* Copy the program and section headers. */
418-
for (int i = 0; i < rdi(hdr->e_phnum); ++i) {
416+
for (int i = 0; i < rdi(hdr->e_phnum); ++i)
419417
phdrs.push_back(* ((Elf_Phdr *) (contents + rdi(hdr->e_phoff)) + i));
420-
if (rdi(phdrs[i].p_type) == PT_INTERP) isExecutable = true;
421-
}
422418

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

749744
/* Add a segment that maps the replaced sections into memory. */
750745
wri(hdr->e_phoff, sizeof(Elf_Ehdr));

0 commit comments

Comments
 (0)