From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mh7mg-0003gp-Bm for qemu-devel@nongnu.org; Fri, 28 Aug 2009 16:10:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mh7mb-0003a2-LW for qemu-devel@nongnu.org; Fri, 28 Aug 2009 16:10:53 -0400 Received: from [199.232.76.173] (port=42637 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mh7mb-0003ZP-5C for qemu-devel@nongnu.org; Fri, 28 Aug 2009 16:10:49 -0400 Received: from mail-ew0-f223.google.com ([209.85.219.223]:58867) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mh7ma-0002C8-Nb for qemu-devel@nongnu.org; Fri, 28 Aug 2009 16:10:48 -0400 Received: by ewy23 with SMTP id 23so2743753ewy.8 for ; Fri, 28 Aug 2009 13:10:46 -0700 (PDT) From: Max Filippov Subject: Re: [Qemu-devel] Patch to fix mapping of elf pheaders specifying both .data and .bss segments Date: Sat, 29 Aug 2009 00:10:34 +0400 References: <20090812150630.GA9000@kos.to> In-Reply-To: <20090812150630.GA9000@kos.to> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200908290010.35653.jcmvbkbc@gmail.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Riku Voipio Cc: Kai Backman , qemu-devel@nongnu.org Hello. > On Thu, Aug 06, 2009 at 03:41:02PM -0700, Kai Backman wrote: > > On Thu, Jun 18, 2009 at 11:57 AM, Riku Voipio wrote: > > > The patch attached is totally messed up thou. > > > > Sorry for the delay. I was vacationing in Finland (incidentally).. > > > > To restart the thread, I've re-attached the patch. > > I see Max Filippov has touched the same function for possibly the same > issue? > > http://lists.gnu.org/archive/html/qemu-devel/2009-07/msg00902.html > You're right, the same issue. But the patch doesn't fix it for me: elf_interpreter mentioned in the last hunk is always set to "/lib/ld.so.1". Having this condition removed it works perfectly. > > diff --git a/linux-user/elfload.c b/linux-user/elfload.c > > index 190ad14..e4e75d5 100644 > > --- a/linux-user/elfload.c > > +++ b/linux-user/elfload.c > > @@ -1211,7 +1211,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, > > abi_ulong mapped_addr; > > struct elf_phdr * elf_ppnt; > > struct elf_phdr *elf_phdata; > > - abi_ulong elf_bss, k, elf_brk; > > + abi_ulong elf_bss, last_bss, mapped_bss, k, elf_brk; > > int retval; > > char * elf_interpreter; > > abi_ulong elf_entry, interp_load_addr = 0; > > @@ -1271,6 +1271,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, > > elf_ppnt = elf_phdata; > > > > elf_bss = 0; > > + last_bss = 0; > > elf_brk = 0; > > > > > > @@ -1495,12 +1496,24 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, > > k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz; > > if (k > elf_bss) > > elf_bss = k; > > + k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz; > > + if (k > last_bss) > > + last_bss = k; > > if ((elf_ppnt->p_flags & PF_X) && end_code < k) > > end_code = k; > > if (end_data < k) > > end_data = k; > > k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz; > > if (k > elf_brk) elf_brk = k; > > + if (!elf_interpreter && last_bss > elf_bss) { > > + padzero(elf_bss, last_bss); > > + mapped_bss = TARGET_ELF_PAGESTART(elf_bss + qemu_host_page_size - 1); > > + > > + /* Map the last of the bss segment */ > > + target_mmap(load_bias + mapped_bss, last_bss-mapped_bss, > > + PROT_READ|PROT_WRITE|PROT_EXEC, > > + MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); > > + } > > } > > > > elf_entry += load_bias; > > Thanks. -- Max