linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] FLAT: make sure data section is aligned at 32 bytes
@ 2009-05-27  7:58 Mike Frysinger
  2009-05-27 21:10 ` [uClinux-dev] " Mike Frysinger
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Frysinger @ 2009-05-27  7:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: uclinux-dev, uclinux-dist-devel, Jie Zhang

From: Jie Zhang <jie.zhang@analog.com>

If a structure in the data section attempts to force a larger alignment,
the FLAT loader will break this when working with shared flat libraries
by inserting a few words before the data section.

URL: http://blackfin.uclinux.org/gf/tracker/4854
Signed-off-by: Jie Zhang <jie.zhang@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 fs/binfmt_flat.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index 5cebf0b..51d2e0e 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -542,7 +542,9 @@ static int load_flat_file(struct linux_binprm * bprm,
 			goto err;
 		}
 
-		len = data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long);
+		len = MAX_SHARED_LIBS * sizeof(unsigned long);
+		len = ALIGN(len, 0x20);
+		len = data_len + extra;
 		len = PAGE_ALIGN(len);
 		down_write(&current->mm->mmap_sem);
 		realdatastart = do_mmap(0, 0, len,
@@ -559,6 +561,7 @@ static int load_flat_file(struct linux_binprm * bprm,
 			goto err;
 		}
 		datapos = realdatastart + MAX_SHARED_LIBS * sizeof(unsigned long);
+		datapos = ALIGN(datapos, 0x20);
 
 		DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%d bytes): %x\n",
 				(int)(data_len + bss_len + stack_len), (int)datapos);
@@ -577,7 +580,7 @@ static int load_flat_file(struct linux_binprm * bprm,
 		if (result >= (unsigned long)-4096) {
 			printk("Unable to read data+bss, errno %d\n", (int)-result);
 			do_munmap(current->mm, textpos, text_len);
-			do_munmap(current->mm, realdatastart, data_len + extra);
+			do_munmap(current->mm, realdatastart, len);
 			ret = result;
 			goto err;
 		}
@@ -587,7 +590,8 @@ static int load_flat_file(struct linux_binprm * bprm,
 		memp_size = len;
 	} else {
 
-		len = text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long);
+		len = text_len + MAX_SHARED_LIBS * sizeof(unsigned long);
+		len = ALIGN(len, 0x20) + data_len + extra;
 		len = PAGE_ALIGN(len);
 		down_write(&current->mm->mmap_sem);
 		textpos = do_mmap(0, 0, len,
@@ -605,8 +609,8 @@ static int load_flat_file(struct linux_binprm * bprm,
 
 		realdatastart = textpos + ntohl(hdr->data_start);
 		datapos = realdatastart + MAX_SHARED_LIBS * sizeof(unsigned long);
-		reloc = (unsigned long *) (textpos + ntohl(hdr->reloc_start) +
-				MAX_SHARED_LIBS * sizeof(unsigned long));
+		datapos = ALIGN(datapos, 0x20);
+		reloc = (unsigned long *) (datapos + ntohl(hdr->reloc_start) - text_len);
 		memp = textpos;
 		memp_size = len;
 #ifdef CONFIG_BINFMT_ZFLAT
@@ -643,8 +647,7 @@ static int load_flat_file(struct linux_binprm * bprm,
 		}
 		if (result >= (unsigned long)-4096) {
 			printk("Unable to read code+data+bss, errno %d\n",(int)-result);
-			do_munmap(current->mm, textpos, text_len + data_len + extra +
-				MAX_SHARED_LIBS * sizeof(unsigned long));
+			do_munmap(current->mm, textpos, len);
 			ret = result;
 			goto err;
 		}
@@ -892,7 +895,7 @@ static int load_flat_binary(struct linux_binprm * bprm, struct pt_regs * regs)
 #ifdef CONFIG_BINFMT_SHARED_FLAT
 	for (i = MAX_SHARED_LIBS-1; i>0; i--) {
 		if (libinfo.lib_list[i].loaded) {
-			/* Push previos first to call address */
+			/* Push previous first to call address */
 			--sp;	put_user(start_addr, sp);
 			start_addr = libinfo.lib_list[i].entry;
 		}
-- 
1.6.3.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [uClinux-dev] [PATCH] FLAT: make sure data section is aligned at 32 bytes
  2009-05-27  7:58 [PATCH] FLAT: make sure data section is aligned at 32 bytes Mike Frysinger
@ 2009-05-27 21:10 ` Mike Frysinger
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Frysinger @ 2009-05-27 21:10 UTC (permalink / raw)
  To: uclinux-dev; +Cc: linux-kernel, uclinux-dist-devel, Jie Zhang

On Wednesday 27 May 2009 03:58:22 Mike Frysinger wrote:
> From: Jie Zhang <jie.zhang@analog.com>
>
> If a structure in the data section attempts to force a larger alignment,
> the FLAT loader will break this when working with shared flat libraries
> by inserting a few words before the data section.

i guess ignore this due to the resurrected "flat: fix data sections alignment" 
thread.  once that gets merged, we'll recheck the need for this patch.
-mike

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-05-27 21:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-27  7:58 [PATCH] FLAT: make sure data section is aligned at 32 bytes Mike Frysinger
2009-05-27 21:10 ` [uClinux-dev] " Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).