bug-grub
[Top][All Lists]
Advanced

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

Fw: Grub + elf section table


From: OKUJI Yoshinori
Subject: Fw: Grub + elf section table
Date: Mon, 02 Apr 2001 20:29:14 +0900

--- Begin Message --- Subject: Grub + elf section table Date: Fri, 30 Mar 2001 12:37:29 +0200
Last week, you told me on the bug-grub mailing list that if I wanted to
be able to use the elf section table with grub, I should post a patch.
So that is what I have done :-)

This little patch is to be applied on a grub-0.5.96.1 source tree, that
I download on the Web.

I have tested it with my kernel, and it seems to work fine. 

If you found some bug, or if my patch would not fit the "way of
thinking" of grub, please let me know and I will be very happy to try to
improve it and to make it more useful.

Best regards.

Julien
diff -cr grub.old/stage2/boot.c grub/stage2/boot.c
*** grub.old/stage2/boot.c      Mon Mar 26 22:06:45 2001
--- grub/stage2/boot.c  Fri Mar 30 01:29:01 2001
***************
*** 493,499 ****
    else
      /* ELF executable */
      {
!       int loaded = 0, memaddr, memsiz, filesiz;
        Elf32_Phdr *phdr;
  
        /* reset this to zero for now */
--- 493,500 ----
    else
      /* ELF executable */
      {
!       int loaded = 0, memaddr = 0, memsiz, filesiz, symtab_err = 0;
!       int tab_size = 0, sec_size = 0;
        Elf32_Phdr *phdr;
  
        /* reset this to zero for now */
***************
*** 548,554 ****
            errnum = ERR_EXEC_FORMAT;
          else
            {
!             /* FIXME: load ELF symbols */
            }
        }
      }
--- 549,624 ----
            errnum = ERR_EXEC_FORMAT;
          else
            {
!             Elf32_Shdr * shdr = NULL; 
!             int j;
! 
!             mbi.syms.e.num   = pu.elf->e_shnum;
!             mbi.syms.e.size  = pu.elf->e_shentsize;
!             mbi.syms.e.shndx = pu.elf->e_shstrndx;
! 
!             /* we should align to a 4K boundary here for good measure */
!             if (align_4k)
!               cur_addr = (cur_addr + 0xFFF) & 0xFFFFF000;
! 
!             tab_size = pu.elf->e_shentsize * pu.elf->e_shnum;
! 
!             grub_seek(pu.elf->e_shoff);
!             if (grub_read ((char *) RAW_ADDR (cur_addr), tab_size)
!                 == tab_size)
!               {
!                 mbi.syms.e.addr  = cur_addr;
!                 shdr = (Elf32_Shdr *) mbi.syms.e.addr;
!                 cur_addr += tab_size;
! 
!                 printf (", shtab=0x%x", cur_addr);
!                 
!                 for ( j = 0; j < mbi.syms.e.num; j++ )
!                   {
!                     /* This section is a loaded section, so we don't care */
!                     if (shdr[j].sh_addr != 0)
!                       continue;
! 
!                     /* This section is empty, so we don't care */
!                     if (shdr[j].sh_size == 0)
!                       continue;
! 
!                     /* Align the section to a sh_addralign bits boundary */
!                     cur_addr = (cur_addr + shdr[j].sh_addralign) & 
!                                - (int) shdr[j].sh_addralign;
! 
!                     grub_seek(shdr[j].sh_offset);
! 
!                     sec_size = shdr[j].sh_size;
! 
!                     if (! (memcheck(cur_addr,sec_size) && 
!                            (grub_read ((char *) RAW_ADDR(cur_addr), sec_size)
!                             == sec_size) ))
!                       {
!                         symtab_err = 1;
!                         break;
!                       }
! 
!                     shdr[j].sh_addr = cur_addr;
!                     cur_addr += sec_size;
!                   }
!               }
!             else 
!               symtab_err = 1;
! 
!             if ( mbi.syms.e.addr < RAW_ADDR(0x10000) ) 
!               symtab_err = 1;
! 
!             if ( symtab_err ) 
!               {
!                 printf ("(bad)");
!                 mbi.syms.e.num   = 0;
!                 mbi.syms.e.size  = 0;
!                 mbi.syms.e.addr  = 0;
!                 mbi.syms.e.shndx = 0;
!                 cur_addr = 0;
!               }
!             else
!               mbi.flags |= MB_INFO_ELF_SHDR;
            }
        }
      }
diff -cr grub.old/stage2/i386-elf.h grub/stage2/i386-elf.h
*** grub.old/stage2/i386-elf.h  Mon Mar 26 22:06:45 2001
--- grub/stage2/i386-elf.h      Fri Mar 30 01:20:34 2001
***************
*** 95,100 ****
--- 95,114 ----
    & (h.e_ident[EI_VERSION] == EV_CURRENT) & (h.e_type == ET_EXEC) \
    & (h.e_machine == EM_386) & (h.e_version == EV_CURRENT))
  
+ /* section table - ? */
+ typedef struct
+ {
+   Elf32_Word  sh_name;                /* Section name (string tbl index) */
+   Elf32_Word  sh_type;                /* Section type */
+   Elf32_Word  sh_flags;               /* Section flags */
+   Elf32_Addr  sh_addr;                /* Section virtual addr at execution */
+   Elf32_Off   sh_offset;              /* Section file offset */
+   Elf32_Word  sh_size;                /* Section size in bytes */
+   Elf32_Word  sh_link;                /* Link to another section */
+   Elf32_Word  sh_info;                /* Additional section information */
+   Elf32_Word  sh_addralign;           /* Section alignment */
+   Elf32_Word  sh_entsize;             /* Entry size if section holds table */
+ } Elf32_Shdr;
  
  /* symbol table - page 4-25, figure 4-15 */
  typedef struct

--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]