Expand downwards only if there is enough space
authornorly <ny-git@enpas.org>
Wed, 26 Jun 2013 17:44:42 +0000 (18:44 +0100)
committernorly <ny-git@enpas.org>
Wed, 26 Jun 2013 17:44:42 +0000 (18:44 +0100)
src/libelfu/modelops/layout.c

index 4026e58ce3e1e1a341201fe861bf8424b933aa17..f8a30ed4e2d66b4a40eebbfd45fb70e77abeeb84 100644 (file)
@@ -240,7 +240,8 @@ GElf_Addr elfu_mLayoutGetSpaceInPhdr(ElfuElf *me, GElf_Word size,
   } else if (((w && (lowestAddr->phdr.p_flags & PF_W))
               || (x && (lowestAddr->phdr.p_flags & PF_X)))
              && /* Enough space to expand downwards? */
-             (lowestAddr->phdr.p_vaddr > 3 * lowestAddr->phdr.p_align)
+             (lowestAddr->phdr.p_vaddr >= ((2 * lowestAddr->phdr.p_align)
+                                           + ROUNDUP(size, lowestAddr->phdr.p_align)))
              /* Merging only works if the LOAD is the first both in file and mem */
              && lowestAddr == lowestOffs) {
     /* Need to prepend or split up the PHDR. */