aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjakub <jakub@94c539fb-cf18-0410-b60f-edeeb537fa16>2006-07-18 13:57:15 +0000
committerjakub <jakub@94c539fb-cf18-0410-b60f-edeeb537fa16>2006-07-18 13:57:15 +0000
commit9dc4649e65978f7ec724166cc886a445c86f6bca (patch)
tree81e6c64f2fd499cce753c31fa3901851712b893c
parent4893b1774c16c69c3d92e11d9e7e90391e038904 (diff)
downloadprelink-cross-9dc4649e65978f7ec724166cc886a445c86f6bca.tar.gz
prelink-cross-9dc4649e65978f7ec724166cc886a445c86f6bca.tar.bz2
prelink-cross-9dc4649e65978f7ec724166cc886a445c86f6bca.zip
20041012
git-svn-id: http://sourceware.org/svn/prelink@121 94c539fb-cf18-0410-b60f-edeeb537fa16
-rw-r--r--src/execstack.c63
-rw-r--r--src/space.c7
2 files changed, 48 insertions, 22 deletions
diff --git a/src/execstack.c b/src/execstack.c
index 1f50acd..9f8bf7e 100644
--- a/src/execstack.c
+++ b/src/execstack.c
@@ -283,6 +283,16 @@ execstack_set (DSO *dso, int flag)
{
/* There is enough space for the headers even without reshuffling
anything. */
+ for (i = 0; i < dso->ehdr.e_phnum; ++i)
+ if (dso->phdr[i].p_type == PT_PHDR)
+ {
+ if (dso->phdr[i].p_filesz
+ == dso->ehdr.e_phnum * dso->ehdr.e_phentsize)
+ dso->phdr[i].p_filesz += dso->ehdr.e_phentsize;
+ if (dso->phdr[i].p_memsz
+ == dso->ehdr.e_phnum * dso->ehdr.e_phentsize)
+ dso->phdr[i].p_memsz += dso->ehdr.e_phentsize;
+ }
i = dso->ehdr.e_phnum++;
ret = execstack_make_rdwr (dso, flag);
if (ret != -1)
@@ -308,28 +318,37 @@ execstack_set (DSO *dso, int flag)
to overlap on the same page. */
last = -1;
for (i = 0; i < dso->ehdr.e_phnum; ++i)
- if (dso->phdr[i].p_type == PT_LOAD
- && dso->phdr[i].p_vaddr + dso->phdr[i].p_memsz >= start)
- {
- if (last != -1
- && (((dso->phdr[last].p_vaddr + dso->phdr[last].p_memsz - 1)
- ^ dso->phdr[i].p_vaddr)
- & ~(dso->arch->max_page_size - 1))
- && !(((dso->phdr[last].p_vaddr + dso->phdr[last].p_memsz
- + adjust - 1)
- ^ (dso->phdr[i].p_vaddr + adjust))
- & ~(dso->arch->max_page_size - 1)))
- {
- if (align >= dso->arch->max_page_size)
- {
- error (0, 0, "%s: Cannot grow reloc sections", dso->filename);
- goto error_out;
- }
- adjust = (adjust + dso->arch->max_page_size - 1)
- & ~(dso->arch->max_page_size - 1);
- }
- last = i;
- }
+ if (dso->phdr[i].p_type == PT_LOAD
+ && dso->phdr[i].p_vaddr + dso->phdr[i].p_memsz >= start)
+ {
+ if (last != -1
+ && (((dso->phdr[last].p_vaddr + dso->phdr[last].p_memsz - 1)
+ ^ dso->phdr[i].p_vaddr)
+ & ~(dso->arch->max_page_size - 1))
+ && !(((dso->phdr[last].p_vaddr + dso->phdr[last].p_memsz
+ + adjust - 1)
+ ^ (dso->phdr[i].p_vaddr + adjust))
+ & ~(dso->arch->max_page_size - 1)))
+ {
+ if (align >= dso->arch->max_page_size)
+ {
+ error (0, 0, "%s: Cannot grow reloc sections", dso->filename);
+ goto error_out;
+ }
+ adjust = (adjust + dso->arch->max_page_size - 1)
+ & ~(dso->arch->max_page_size - 1);
+ }
+ last = i;
+ }
+
+ for (i = 0; i < dso->ehdr.e_phnum; ++i)
+ if (dso->phdr[i].p_type == PT_PHDR)
+ {
+ if (dso->phdr[i].p_filesz == dso->ehdr.e_phnum * dso->ehdr.e_phentsize)
+ dso->phdr[i].p_filesz += dso->ehdr.e_phentsize;
+ if (dso->phdr[i].p_memsz == dso->ehdr.e_phnum * dso->ehdr.e_phentsize)
+ dso->phdr[i].p_memsz += dso->ehdr.e_phentsize;
+ }
i = dso->ehdr.e_phnum++;
ret = execstack_make_rdwr (dso, flag);
diff --git a/src/space.c b/src/space.c
index 7ceb131..bf76a41 100644
--- a/src/space.c
+++ b/src/space.c
@@ -635,6 +635,13 @@ find_readonly_space (DSO *dso, GElf_Shdr *add, GElf_Ehdr *ehdr,
for (i = 0, j = 0; i < ehdr->e_phnum; ++i)
if (phdr[i].p_type == PT_LOAD)
j = i;
+ else if (phdr[i].p_type == PT_PHDR)
+ {
+ if (phdr[i].p_filesz == ehdr->e_phnum * ehdr->e_phentsize)
+ phdr[i].p_filesz += ehdr->e_phentsize;
+ if (phdr[i].p_memsz == ehdr->e_phnum * ehdr->e_phentsize)
+ phdr[i].p_memsz += ehdr->e_phentsize;
+ }
memmove (&phdr[j + 2], &phdr[j + 1],
(ehdr->e_phnum - j - 1) * sizeof (GElf_Phdr));