[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Clean up symtab loading in elf loader.



ChangeSet 1.1442, 2005/04/03 12:22:11+01:00, kaf24@viper.(none)

        Clean up symtab loading in elf loader.
        Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>



 tools/libxc/xc_linux_build.c |   29 +++++-----
 tools/libxc/xc_vmx_build.c   |  117 -------------------------------------------
 xen/arch/x86/domain_build.c  |   13 +---
 xen/common/elf.c             |  114 +++++++++++++++++++++--------------------
 xen/include/xen/elf.h        |    5 -
 xen/include/xen/sched.h      |    9 ++-
 6 files changed, 85 insertions(+), 202 deletions(-)


diff -Nru a/tools/libxc/xc_linux_build.c b/tools/libxc/xc_linux_build.c
--- a/tools/libxc/xc_linux_build.c      2005-04-03 08:03:09 -04:00
+++ b/tools/libxc/xc_linux_build.c      2005-04-03 08:03:09 -04:00
@@ -22,8 +22,7 @@
     unsigned long v_kernend;
     unsigned long v_kernentry;
 
-    unsigned int load_bsd_symtab;
-
+    unsigned int  load_symtab;
     unsigned long symtab_addr;
     unsigned long symtab_len;
 };
@@ -34,7 +33,7 @@
 static int
 loadelfimage(
     char *elfbase, int xch, u32 dom, unsigned long *parray,
-    unsigned long vstart);
+    struct domain_setup_info *dsi);
 static int
 loadelfsymtab(
     char *elfbase, int xch, u32 dom, unsigned long *parray,
@@ -87,9 +86,6 @@
     if ( rc != 0 )
         goto error_out;
 
-    if (dsi.load_bsd_symtab)
-        loadelfsymtab(image, xc_handle, dom, NULL, &dsi);
-
     if ( (dsi.v_start & (PAGE_SIZE-1)) != 0 )
     {
         PERROR("Guest OS must load to a page boundary.\n");
@@ -160,10 +156,7 @@
         goto error_out;
     }
 
-    loadelfimage(image, xc_handle, dom, page_array, dsi.v_start);
-
-    if (dsi.load_bsd_symtab)
-        loadelfsymtab(image, xc_handle, dom, page_array, &dsi);
+    loadelfimage(image, xc_handle, dom, page_array, &dsi);
 
     /* Load the initial ramdisk image. */
     if ( initrd_len != 0 )
@@ -581,21 +574,22 @@
         dsi->v_start = strtoul(p+10, &p, 0);
 
     if ( (p = strstr(guestinfo, "BSD_SYMTAB")) != NULL )
-        dsi->load_bsd_symtab = 1;
+        dsi->load_symtab = 1;
 
     dsi->v_kernstart = kernstart;
     dsi->v_kernend   = kernend;
     dsi->v_kernentry = ehdr->e_entry;
-
     dsi->v_end       = dsi->v_kernend;
 
+    loadelfsymtab(elfbase, 0, 0, NULL, dsi);
+
     return 0;
 }
 
 static int
 loadelfimage(
     char *elfbase, int xch, u32 dom, unsigned long *parray,
-    unsigned long vstart)
+    struct domain_setup_info *dsi)
 {
     Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase;
     Elf_Phdr *phdr;
@@ -612,7 +606,7 @@
         
         for ( done = 0; done < phdr->p_filesz; done += chunksz )
         {
-            pa = (phdr->p_paddr + done) - vstart;
+            pa = (phdr->p_paddr + done) - dsi->v_start;
             va = xc_map_foreign_range(
                 xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]);
             chunksz = phdr->p_filesz - done;
@@ -625,7 +619,7 @@
 
         for ( ; done < phdr->p_memsz; done += chunksz )
         {
-            pa = (phdr->p_paddr + done) - vstart;
+            pa = (phdr->p_paddr + done) - dsi->v_start;
             va = xc_map_foreign_range(
                 xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]);
             chunksz = phdr->p_memsz - done;
@@ -636,6 +630,8 @@
         }
     }
 
+    loadelfsymtab(elfbase, xch, dom, parray, dsi);
+
     return 0;
 }
 
@@ -651,6 +647,9 @@
     unsigned long maxva, symva;
     char *p;
     int h, i;
+
+    if ( !dsi->load_symtab )
+        return 0;
 
     p = malloc(sizeof(int) + sizeof(Elf_Ehdr) +
                ehdr->e_shnum * sizeof(Elf_Shdr));
diff -Nru a/tools/libxc/xc_vmx_build.c b/tools/libxc/xc_vmx_build.c
--- a/tools/libxc/xc_vmx_build.c        2005-04-03 08:03:09 -04:00
+++ b/tools/libxc/xc_vmx_build.c        2005-04-03 08:03:09 -04:00
@@ -26,11 +26,6 @@
     unsigned long v_kernstart;
     unsigned long v_kernend;
     unsigned long v_kernentry;
-
-    unsigned int load_bsd_symtab;
-
-    unsigned long symtab_addr;
-    unsigned long symtab_len;
 };
 
 static int
@@ -40,10 +35,6 @@
 loadelfimage(
     char *elfbase, int xch, u32 dom, unsigned long *parray,
     unsigned long vstart);
-static int
-loadelfsymtab(
-    char *elfbase, int xch, u32 dom, unsigned long *parray,
-    struct domain_setup_info *dsi);
 
 static void build_e820map(struct mem_map *mem_mapp, unsigned long mem_size)
 {
@@ -193,13 +184,9 @@
 
     memset(&dsi, 0, sizeof(struct domain_setup_info));
 
-    rc = parseelfimage(image, image_size, &dsi);
-    if ( rc != 0 )
+    if ( (rc = parseelfimage(image, image_size, &dsi)) != 0 )
         goto error_out;
 
-    if (dsi.load_bsd_symtab)
-        loadelfsymtab(image, xc_handle, dom, NULL, &dsi);
-
     if ( (dsi.v_start & (PAGE_SIZE-1)) != 0 )
     {
         PERROR("Guest OS must load to a page boundary.\n");
@@ -269,9 +256,6 @@
 
     loadelfimage(image, xc_handle, dom, page_array, dsi.v_start);
 
-    if (dsi.load_bsd_symtab)
-        loadelfsymtab(image, xc_handle, dom, page_array, &dsi);
-
     /* Load the initial ramdisk image. */
     if ( initrd_len != 0 )
     {
@@ -708,7 +692,6 @@
     }
 
     dsi->v_start = 0x00000000;
-    dsi->load_bsd_symtab = 0;
 
     dsi->v_kernstart = kernstart - LINUX_PAGE_OFFSET;
     dsi->v_kernend   = kernend - LINUX_PAGE_OFFSET;
@@ -766,104 +749,6 @@
             munmap(va, PAGE_SIZE);
         }
     }
-
-    return 0;
-}
-
-
-#define ELFROUND (ELFSIZE / 8)
-
-static int
-loadelfsymtab(
-    char *elfbase, int xch, u32 dom, unsigned long *parray,
-    struct domain_setup_info *dsi)
-{
-    Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase, *sym_ehdr;
-    Elf_Shdr *shdr;
-    unsigned long maxva, symva;
-    char *p;
-    int h, i;
-
-    p = malloc(sizeof(int) + sizeof(Elf_Ehdr) +
-               ehdr->e_shnum * sizeof(Elf_Shdr));
-    if (p == NULL)
-        return 0;
-
-    maxva = (dsi->v_kernend + ELFROUND - 1) & ~(ELFROUND - 1);
-    symva = maxva;
-    maxva += sizeof(int);
-    dsi->symtab_addr = maxva;
-    dsi->symtab_len = 0;
-    maxva += sizeof(Elf_Ehdr) + ehdr->e_shnum * sizeof(Elf_Shdr);
-    maxva = (maxva + ELFROUND - 1) & ~(ELFROUND - 1);
-
-    shdr = (Elf_Shdr *)(p + sizeof(int) + sizeof(Elf_Ehdr));
-    memcpy(shdr, elfbase + ehdr->e_shoff, ehdr->e_shnum * sizeof(Elf_Shdr));
-
-    for ( h = 0; h < ehdr->e_shnum; h++ ) 
-    {
-        if ( shdr[h].sh_type == SHT_STRTAB )
-        {
-            /* Look for a strtab @i linked to symtab @h. */
-            for ( i = 0; i < ehdr->e_shnum; i++ )
-                if ( (shdr[i].sh_type == SHT_SYMTAB) &&
-                     (shdr[i].sh_link == h) )
-                    break;
-            /* Skip symtab @h if we found no corresponding strtab @i. */
-            if ( i == ehdr->e_shnum )
-            {
-                shdr[h].sh_offset = 0;
-                continue;
-            }
-        }
-
-        if ( (shdr[h].sh_type == SHT_STRTAB) ||
-             (shdr[h].sh_type == SHT_SYMTAB) )
-        {
-            if ( parray != NULL )
-                xc_map_memcpy(maxva, elfbase + shdr[h].sh_offset, 
shdr[h].sh_size,
-                           xch, dom, parray, dsi->v_start);
-
-            /* Mangled to be based on ELF header location. */
-            shdr[h].sh_offset = maxva - dsi->symtab_addr;
-
-            dsi->symtab_len += shdr[h].sh_size;
-            maxva += shdr[h].sh_size;
-            maxva = (maxva + ELFROUND - 1) & ~(ELFROUND - 1);
-        }
-
-        shdr[h].sh_name = 0;  /* Name is NULL. */
-    }
-
-    if ( dsi->symtab_len == 0 )
-    {
-        dsi->symtab_addr = 0;
-        goto out;
-    }
-
-    if ( parray != NULL )
-    {
-        *(int *)p = maxva - dsi->symtab_addr;
-        sym_ehdr = (Elf_Ehdr *)(p + sizeof(int));
-        memcpy(sym_ehdr, ehdr, sizeof(Elf_Ehdr));

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.