Skip to contentSkip to conversation

Load elf symbols for Dom0 when BSD_SYMTAB=yes

PATCH New Christoph Egger 1 participant 1 message Aug 1, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Load elf symbols for Dom0 when BSD_SYMTAB=yes

Hi!

When Dom0 specifies BSD_SYMTAB=yes, then Xen loads the ELF symbols for it. This works with Xen 3.0.4, but not with Xen 3.1.
During the libelf work between Xen 3.0.4 and Xen 3.1 the loading got broken in the way, that BSD_SYMTAB gets parsed but not handled.

The attached patch handles the loading. With it, NetBSD Dom0 has the symbols back. The kernel debugger is a lot more useful with symbols. :-)

Signature · 12 lines
AMD Saxony, Dresden, Germany
Operating System Research Center

Legal Information:
AMD Saxony Limited Liability Company & Co. KG
Sitz (Geschäftsanschrift):
   Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland
Registergericht Dresden: HRA 4896
vertretungsberechtigter Komplementär:
   AMD Saxony LLC (Sitz Wilmington, Delaware, USA)
Geschäftsführer der AMD Saxony LLC:
   Dr. Hans-R. Deppe, Thomas McCoy
xen/arch/x86/domain_build.c +5 -2
diff -r 7c5c3aa858cc xen/arch/x86/domain_build.c
@@ -316,6 +316,9 @@ int __init construct_dom0(
            parms.pae       ? ", PAE"  : "",
            elf_msb(&elf)   ? "msb"    : "lsb",
            elf.pstart, elf.pend);
+    if (parms.bsd_symtab)
+        printk(" Dom0 symbol map 0x%" PRIx64 " -> 0x%" PRIx64 "\n",
+               elf.sstart, elf.send);
 
     if ( !compatible )
     {
@@ -385,7 +388,7 @@ int __init construct_dom0(
     v_start          = parms.virt_base;
     vkern_start      = parms.virt_kstart;
     vkern_end        = parms.virt_kend;
-    vinitrd_start    = round_pgup(vkern_end);
+    vinitrd_start    = round_pgup(parms.virt_end);
     vinitrd_end      = vinitrd_start + initrd_len;
     vphysmap_start   = round_pgup(vinitrd_end);
     vphysmap_end     = vphysmap_start + (nr_pages * (!is_pv_32on64_domain(d) ?
@@ -795,7 +798,7 @@ int __init construct_dom0(
 
     /* Copy the OS image and free temporary buffer. */
     elf.dest = (void*)vkern_start;
-    elf_load_binary(&elf);
+    elf_xen_dom_load_binary(&elf, &parms);
 
     if ( UNSET_ADDR != parms.virt_hypercall )
     {
xen/common/libelf/libelf-dominfo.c +101 -1

128 lines not on this page · raw message

xen/common/libelf/libelf-loader.c +33 -0
diff -r 7c5c3aa858cc xen/common/libelf/libelf-loader.c
@@ -10,6 +10,8 @@ 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;
 
     if ( !elf_is_elfbinary(image) )
     {
@@ -24,6 +26,10 @@ int elf_init(struct elf_binary *elf, con
     elf->class = elf->ehdr->e32.e_ident[EI_CLASS];
     elf->data = elf->ehdr->e32.e_ident[EI_DATA];
 
+#ifdef VERBOSE
+    elf_set_verbose(elf);
+#endif
+
     /* sanity check phdr */
     offset = elf_uval(elf, elf->ehdr, e_phoff) +
         elf_uval(elf, elf->ehdr, e_phentsize) * elf_phdr_count(elf);
@@ -54,19 +60,46 @@ int elf_init(struct elf_binary *elf, con
     count = elf_shdr_count(elf);
     for ( i = 0; i < count; i++ )
     {
+        const char * sh_symend, *sh_strend;
+
         shdr = elf_shdr_by_index(elf, i);
         if ( elf_uval(elf, shdr, sh_type) != SHT_SYMTAB )
             continue;
         elf->sym_tab = shdr;
+        sh_symend = (const char *)elf_section_end(elf, shdr);
         shdr = elf_shdr_by_index(elf, elf_uval(elf, shdr, sh_link));
         if ( shdr == NULL )
         {
             elf->sym_tab = NULL;
+            sh_symend = 0;
             continue;
         }
         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;
+
+        elf_msg(elf, "%s: shdr: sym_tab=%p size=0x%" PRIx64 "\n",
+		__FUNCTION__,
+		elf->sym_tab, elf_uval(elf, elf->sym_tab, sh_size));
+        elf_msg(elf, "%s: shdr: str_tab=%p size=0x%" PRIx64 "\n",
+		__FUNCTION__,
+		elf->sym_strtab, elf_uval(elf, shdr, sh_size));
         break;
     }
+    elf->sstart = low;
+    elf->send = high;
+
+    elf_msg(elf, "%s: symbol map: 0x%" PRIx64 " -> 0x%" PRIx64 "\n",
+            __FUNCTION__, elf->sstart, elf->send);
     return 0;
 }
 
xen/common/libelf/libelf-tools.c +104 -0

110 lines not on this page · raw message

xen/include/public/libelf.h +17 -1
diff -r 7c5c3aa858cc xen/include/public/libelf.h
@@ -65,6 +65,8 @@ struct elf_binary {
 
     /* loaded to */
     char *dest;
+    uint64_t sstart;
+    uint64_t send;
     uint64_t pstart;
     uint64_t pend;
     uint64_t reloc_offset;
@@ -148,6 +150,16 @@ const elf_note *elf_note_next(struct elf
 
 int elf_is_elfbinary(const void *image);
 int elf_phdr_is_loadable(struct elf_binary *elf, const elf_phdr * phdr);
+
+unsigned long elf_copy_ehdr(struct elf_binary *elf, void *dest);
+unsigned long elf_copy_shdr(struct elf_binary *elf, void *dest);
+unsigned long elf_copy_section(struct elf_binary *elf,
+                               const elf_shdr *shdr, void *dest);
+
+#ifndef NDEBUG
+void elf_ehdr_dump(struct elf_binary *elf, unsigned long addr);
+void elf_shdr_dump(struct elf_binary *elf, unsigned long addr);
+#endif
 
 /* ------------------------------------------------------------------------ */
 /* xc_libelf_loader.c                                                       */
@@ -215,7 +227,8 @@ struct elf_dom_parms {
     /* calculated */
     uint64_t virt_offset;
     uint64_t virt_kstart;
-    uint64_t virt_kend;
+    uint64_t virt_kend; /* end of kernel image */
+    uint64_t virt_end;  /* = virt_kend + sizeof symtab */
 };
 
 static inline void elf_xen_feature_set(int nr, uint32_t * addr)
@@ -238,4 +251,7 @@ int elf_xen_parse(struct elf_binary *elf
 int elf_xen_parse(struct elf_binary *elf,
 		  struct elf_dom_parms *parms);
 
+int elf_xen_dom_load_binary(struct elf_binary *elf,
+                            struct elf_dom_parms *parms);
+
 #endif /* __XC_LIBELF__ */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel