summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2009-01-30 15:23:10 (GMT)
committerEelco Dolstra <e.dolstra@tudelft.nl>2009-01-30 15:23:10 (GMT)
commitac63c25535739d91ad44035b8f954736cff2065b (patch)
tree8e5beda96803138aab0f605d119e4de3ee7d17f5 /src
parentfbaddb9b47e420f4442829d3e2501caeac08f864 (diff)
downloadpatchelf-ac63c25535739d91ad44035b8f954736cff2065b.zip
patchelf-ac63c25535739d91ad44035b8f954736cff2065b.tar.gz
patchelf-ac63c25535739d91ad44035b8f954736cff2065b.tar.bz2
* Handle PT_LOAD program headers that become unaligned after adding
an extra page to the start of the file. The dynamic loader doesn't like this (but the kernel doesn't mind).
Diffstat (limited to 'src')
-rw-r--r--src/patchelf.cc8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index 146c064..74ce47d 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -406,8 +406,14 @@ void ElfFile<ElfFileParamNames>::shiftFile(unsigned int extraPages, Elf_Addr sta
wri(shdrs[i].sh_offset, rdi(shdrs[i].sh_offset) + shift);
/* Update the offsets in the program headers. */
- for (int i = 0; i < rdi(hdr->e_phnum); ++i)
+ for (int i = 0; i < rdi(hdr->e_phnum); ++i) {
wri(phdrs[i].p_offset, rdi(phdrs[i].p_offset) + shift);
+ if ((phdrs[i].p_vaddr - phdrs[i].p_offset) % phdrs[i].p_align != 0) {
+ debug("changing alignment of program header %d from %d to %d\n", i,
+ phdrs[i].p_align, pageSize);
+ phdrs[i].p_align = pageSize;
+ }
+ }
/* Add a segment that maps the new program/section headers and
PT_INTERP segment into memory. Otherwise glibc will choke. */