All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Millan <rmh@aybabtu.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Cc: "Jonathan A. Kollasch" <jakllsch@kollasch.net>
Subject: Re: multiboot ELF section header table info passing missing in grub2?
Date: Mon, 8 Sep 2008 22:01:14 +0200	[thread overview]
Message-ID: <20080908200114.GA2863@thorin> (raw)
In-Reply-To: <20080812164829.GD23213@tazenda.kollasch.net>

[-- Attachment #1: Type: text/plain, Size: 830 bytes --]

On Tue, Aug 12, 2008 at 04:48:29PM +0000, Jonathan A. Kollasch wrote:
> hi,
> 
> Robert noted that I should mention this:
> 
> The ELF section header table MBI seems to not be implemented in grub2.
> NetBSD/i386 uses this to find symbol names in it's kernel debugger.

For the record (Jonathan already knows), I made this patch, which is supposed
to implement it using code from GRUB Legacy.

It needs some cleanup, but since I have no readily available testcase (NetBSD's
kernel seems to have some trouble involving MBI corruption), I can't finish it
yet.

I'm sending it here for reference.

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."

[-- Attachment #2: mb_elf_sym.diff --]
[-- Type: text/x-diff, Size: 3317 bytes --]

diff -ur grub2.old/include/grub/multiboot.h grub2/include/grub/multiboot.h
--- grub2.old/include/grub/multiboot.h	2008-09-07 19:02:04.000000000 +0200
+++ grub2/include/grub/multiboot.h	2008-09-08 15:35:44.000000000 +0200
@@ -1,7 +1,7 @@
 /* multiboot.h - multiboot header file with grub definitions. */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2003,2007,2008  Free Software Foundation, Inc.
+ *  Copyright (C) 2000,2003,2007,2008  Free Software Foundation, Inc.
  *
  *  GRUB is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -73,8 +73,27 @@
   grub_uint32_t mods_count;
   grub_uint32_t mods_addr;
   
-  grub_uint32_t syms[4];
-  
+  union
+  {
+    struct
+    {
+      /* a.out payload symbol table info */
+      grub_uint32_t tabsize;
+      grub_uint32_t strsize;
+      grub_uint32_t addr;
+      grub_uint32_t pad;
+    } aout;
+
+    struct
+    {
+      /* ELF payload section header table */
+      grub_uint32_t num;
+      grub_uint32_t size;
+      grub_uint32_t addr;
+      grub_uint32_t shndx;
+    } elf;
+  } syms;
+
   /* Memory Mapping buffer */
   grub_uint32_t mmap_length;
   grub_uint32_t mmap_addr;
diff -ur grub2.old/loader/i386/pc/multiboot.c grub2/loader/i386/pc/multiboot.c
--- grub2.old/loader/i386/pc/multiboot.c	2008-09-07 19:03:20.000000000 +0200
+++ grub2/loader/i386/pc/multiboot.c	2008-09-08 15:35:44.000000000 +0200
@@ -21,7 +21,7 @@
  *  FIXME: The following features from the Multiboot specification still
  *         need to be implemented:
  *  - VBE support
- *  - symbol table
+ *  - a.out symbol table
  *  - drives table
  *  - ROM configuration table
  *  - APM table
@@ -204,6 +204,60 @@
 
 #undef phdr
 
+  mbi->syms.elf.num = ehdr->e_shnum;
+  mbi->syms.elf.size = ehdr->e_shentsize;
+  mbi->syms.elf.shndx = ehdr->e_shstrndx;
+
+  grub_file_seek (file, ehdr->e_shoff);
+
+  /* FIXME: move to the relocatable block */
+  mbi->syms.elf.addr = (grub_uint32_t) grub_malloc (sizeof (Elf32_Shdr) * ehdr->e_shnum);
+
+  /* FIXME: get rid of cur_addr;  use proper types? */
+  grub_uint32_t cur_addr = mbi->syms.elf.addr;
+
+  grub_file_read (file, (void *) cur_addr, ehdr->e_shentsize * ehdr->e_shnum);
+  cur_addr += ehdr->e_shentsize * ehdr->e_shnum;
+
+  /* FIXME: does this belong here? */
+  grub_printf (", shtab=0x%x\n", cur_addr);
+
+  Elf32_Shdr *shdr = (Elf32_Shdr *) mbi->syms.elf.addr;
+
+  for (i = 0; i < ehdr->e_shnum; i++)
+    {
+      /* This section is a loaded section, so we don't care.  */
+      if (shdr[i].sh_addr != 0)
+	continue;
+
+      /* This section is empty, so we don't care.  */
+      if (shdr[i].sh_size == 0)
+	continue;
+
+      /* Align the section to a sh_addralign bits boundary.  */
+      cur_addr = ((cur_addr + shdr[i].sh_addralign) &
+		  - (int) shdr[i].sh_addralign);
+
+      grub_file_seek (file, shdr[i].sh_offset);
+
+      /* FIXME: is this useful? */
+#if 0
+      if (! (memcheck (cur_addr, shdr[i].sh_size)
+	     && (grub_read ((char *) RAW_ADDR (cur_addr),
+			    shdr[i].sh_size)
+		 == shdr[i].sh_size)))
+	{
+	  symtab_err = 1;
+	  break;
+	}
+#endif
+
+      shdr[i].sh_addr = cur_addr;
+      cur_addr += shdr[i].sh_size;
+    }
+
+  mbi->flags |= MULTIBOOT_INFO_ELF_SHDR;
+
   return grub_errno;
 }
 

      reply	other threads:[~2008-09-08 20:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-12 16:48 multiboot ELF section header table info passing missing in grub2? Jonathan A. Kollasch
2008-09-08 20:01 ` Robert Millan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080908200114.GA2863@thorin \
    --to=rmh@aybabtu.com \
    --cc=grub-devel@gnu.org \
    --cc=jakllsch@kollasch.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.