From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Christoph Egger" Subject: Re: [PATCH][ELF] Correct space calculation for symtab when BSD_SYMTAB=yes Date: Thu, 2 Aug 2007 14:26:58 +0200 Message-ID: <200708021426.59206.Christoph.Egger@amd.com> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Boundary-00=_T2csGYLMXLxYP7k" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Keir Fraser List-Id: xen-devel@lists.xenproject.org --Boundary-00=_T2csGYLMXLxYP7k Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Thursday 02 August 2007 10:49:57 Keir Fraser wrote: > On 2/8/07 09:03, "Christoph Egger" wrote: > > If there is a string table for section headers, it also gets loaded. > > Therefore take it into account in size calculation for kernel symtab. > > I don't see how this works. Basically, I do it the same way as Xen 3.0.4 did: First calculate the space you need, then fill the space with ELF header, ELF section headers and the symbol and string sections itself. > In fact the whole sstart,send calculation looks broken. Well, I did it analogous to elf_parse_binary() how it calculates the space for phdr. > What do the virtual addresses of the symtab/strtab sections have to=20 > do with their location in the final address space, after loading? And sin= ce > you pack the sections into the domain address space in > elf_xen_dom_load_binary(), should you not simply sum the sizes of the > sections, then sstart=3Dvirt_kend and send=3Dsstart+size_sum, rather than > taking max(end addresses in elf image) minus min(start addresses in elf > image). You're right. Attached is a patch, which does it that way. (Signed-off-by: Christoph Egger ) Oh and c/s 15677 in the staging tree removes the wrong elf_set_verbose() ca= ll. Without it, you will never see the elf_msg() in elf_init(). The correct duplicate to remove is the one right after the use of elf_init(= ).=20 My patch removes it. > Does the section-header string table have to be loaded, or is that just an > artefact of the loader code scanning for all SYMTAB/STRTAB? Shouldn't the > loader fix up e_shnum and symtab's sh_link in the Elf metadata that it > generates? I think, Xen should just pass to Dom0 what it has and let Dom0 decide what it wants to use. > Couldn't the loader just use the saved elf->sym_tab and=20 > elf->sym_strtab to directly find the interesting two sections, rather than > needing to do yet another full scan? It needs to go through it, because it must adjust the sh_offset accordingly in the section headers. > > Keir: Can you also apply changeset 15672 and this patch > > to Xen 3.1-stable, since these fixes an regression for Xen 3.1, please? > > I don't think so! I *do* think so :-) Look (I marked the most interesting lines with an arrow= ): With Xen 3.0.4 I get this: [...] (XEN) Xen is relinquishing VGA console. (XEN) *** Serial input -> DOM0 (type 'CTRL-a' three times to switch input t= o=20 Xen). (XEN) Freed 92kB init memory. Loaded initial symtab at 0xc09d7ad8, strtab at 0xc0a38cb4, # entries 23398 = <=3D Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc. All rights reserved. Copyright (c) 1982, 1986, 1989, 1991, 1993 The Regents of the University of California. All rights reserved. NetBSD 4.99.26 (XEN3_DOM0) #70: Wed Jul 25 15:54:08 UTC 2007 root@tulln:/usr/src/sys/arch/i386/compile/XEN3_DOM0 [...] With Xen 3.1 I get this: [...] (XEN) Xen is relinquishing VGA console. (XEN) *** Serial input -> DOM0 (type 'CTRL-a' three times to switch input t= o=20 Xen). (XEN) Freed 92kB init memory. [ Kernel symbol table missing! ] <=3D Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc. All rights reserved. Copyright (c) 1982, 1986, 1989, 1991, 1993 The Regents of the University of California. All rights reserved. NetBSD 4.99.26 (XEN3_DOM0) #74: Wed Aug 1 10:57:21 UTC 2007 root@tulln:/usr/src/sys/arch/i386/compile/XEN3_DOM0 [...] and in -unstable (with my patches) I get this: [...] (XEN) Xen is relinquishing VGA console. (XEN) *** Serial input -> DOM0 (type 'CTRL-a' three times to switch input t= o=20 Xen). (XEN) Freed 108kB init memory. Loaded initial symtab at 0xc09decd8, strtab at 0xc0a4001c, # entries 23398 = <=3D Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc. All rights reserved. Copyright (c) 1982, 1986, 1989, 1991, 1993 The Regents of the University of California. All rights reserved. NetBSD 4.99.26 (XEN3_DOM0) #74: Wed Aug 1 10:57:21 UTC 2007 root@tulln:/usr/src/sys/arch/i386/compile/XEN3_DOM0 [...] Christoph =2D-=20 AMD Saxony, Dresden, Germany Operating System Research Center Legal Information: AMD Saxony Limited Liability Company & Co. KG Sitz (Gesch=E4ftsanschrift): Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland Registergericht Dresden: HRA 4896 vertretungsberechtigter Komplement=E4r: AMD Saxony LLC (Sitz Wilmington, Delaware, USA) Gesch=E4ftsf=FChrer der AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy --Boundary-00=_T2csGYLMXLxYP7k Content-Type: text/x-diff; charset=iso-8859-1; name=xen_symtab.diff Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=xen_symtab.diff diff -r 88bb0d305308 xen/arch/x86/domain_build.c --- a/xen/arch/x86/domain_build.c Wed Aug 01 15:47:54 2007 +0100 +++ b/xen/arch/x86/domain_build.c Thu Aug 02 13:47:54 2007 +0200 @@ -268,9 +268,6 @@ int __init construct_dom0( if ( (rc = elf_init(&elf, image_start, image_len)) != 0 ) return rc; -#ifdef VERBOSE - elf_set_verbose(&elf); -#endif elf_parse_binary(&elf); if ( (rc = elf_xen_parse(&elf, &parms)) != 0 ) return rc; @@ -318,7 +315,7 @@ int __init construct_dom0( elf.pstart, elf.pend); if ( parms.bsd_symtab ) printk(" Dom0 symbol map 0x%" PRIx64 " -> 0x%" PRIx64 "\n", - elf.sstart, elf.send); + parms.virt_kend, parms.virt_end); if ( !compatible ) { diff -r 88bb0d305308 xen/common/libelf/libelf-dominfo.c --- a/xen/common/libelf/libelf-dominfo.c Wed Aug 01 15:47:54 2007 +0100 +++ b/xen/common/libelf/libelf-dominfo.c Thu Aug 02 13:46:24 2007 +0200 @@ -337,7 +337,7 @@ static void elf_xen_loadsymtab(struct el static void elf_xen_loadsymtab(struct elf_binary *elf, struct elf_dom_parms *parms) { - unsigned long maxva, len; + unsigned long maxva; if ( !parms->bsd_symtab ) return; @@ -353,8 +353,7 @@ static void elf_xen_loadsymtab(struct el maxva = elf_round_up(elf, maxva); /* Space for the symbol and string tabs */ - len = (unsigned long)elf->send - (unsigned long)elf->sstart; - maxva = elf_round_up(elf, maxva + len); + maxva = elf_round_up(elf, maxva + elf->symsize); /* The address the kernel must expanded to */ parms->virt_end = maxva; diff -r 88bb0d305308 xen/common/libelf/libelf-loader.c --- a/xen/common/libelf/libelf-loader.c Wed Aug 01 15:47:54 2007 +0100 +++ b/xen/common/libelf/libelf-loader.c Thu Aug 02 13:46:05 2007 +0200 @@ -10,8 +10,7 @@ int elf_init(struct elf_binary *elf, con { const elf_shdr *shdr; uint64_t i, count, section, offset; - uint64_t low = -1; - uint64_t high = 0; + uint64_t symsize = 0; if ( !elf_is_elfbinary(image) ) { @@ -53,8 +52,12 @@ int elf_init(struct elf_binary *elf, con /* Find section string table. */ section = elf_uval(elf, elf->ehdr, e_shstrndx); shdr = elf_shdr_by_index(elf, section); - if ( shdr != NULL ) + if ( shdr != NULL ) { elf->sec_strtab = elf_section_start(elf, shdr); + /* Size of section string table */ + symsize = ((unsigned long)elf_section_end(elf, shdr) + - (unsigned long)elf_section_start(elf, shdr)); + } /* Find symbol table and symbol string table. */ count = elf_shdr_count(elf); @@ -77,15 +80,10 @@ int elf_init(struct elf_binary *elf, con elf->sym_strtab = elf_section_start(elf, shdr); sh_strend = (const char *)elf_section_end(elf, shdr); - if ( low > (unsigned long)elf->sym_tab ) - low = (unsigned long)elf->sym_tab; - if ( low > (unsigned long)shdr ) - low = (unsigned long)shdr; - - if ( high < ((unsigned long)sh_symend) ) - high = (unsigned long)sh_symend; - if ( high < ((unsigned long)sh_strend) ) - high = (unsigned long)sh_strend; + /* Symbol and string table sizes */ + symsize += ((unsigned long)sh_strend - (unsigned long)elf->sym_strtab); + symsize += ((unsigned long)sh_symend + - (unsigned long)elf_section_start(elf, elf->sym_tab)); elf_msg(elf, "%s: shdr: sym_tab=%p size=0x%" PRIx64 "\n", __FUNCTION__, elf->sym_tab, @@ -93,10 +91,11 @@ int elf_init(struct elf_binary *elf, con elf_msg(elf, "%s: shdr: str_tab=%p size=0x%" PRIx64 "\n", __FUNCTION__, elf->sym_strtab, elf_uval(elf, shdr, sh_size)); - elf->sstart = low; - elf->send = high; + elf->symsize = symsize; elf_msg(elf, "%s: symbol map: 0x%" PRIx64 " -> 0x%" PRIx64 "\n", - __FUNCTION__, elf->sstart, elf->send); + __FUNCTION__, elf->pend, elf->pend + elf->symsize); + + break; } return 0; diff -r 88bb0d305308 xen/include/public/libelf.h --- a/xen/include/public/libelf.h Wed Aug 01 15:47:54 2007 +0100 +++ b/xen/include/public/libelf.h Thu Aug 02 13:27:11 2007 +0200 @@ -65,8 +65,7 @@ struct elf_binary { /* loaded to */ char *dest; - uint64_t sstart; - uint64_t send; + uint64_t symsize; uint64_t pstart; uint64_t pend; uint64_t reloc_offset; --Boundary-00=_T2csGYLMXLxYP7k Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --Boundary-00=_T2csGYLMXLxYP7k--