]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Handle module_license on windows.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 14 May 2011 15:47:59 +0000 (17:47 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 14 May 2011 15:47:59 +0000 (17:47 +0200)
* util/grub-pe2elf.c (MODLICENSE_SECTION): New definition. All following
sections shifted.
(insert_string): Make argument const char * instead of char *.
(write_section_data): Handle long section names.
Handle module_license.

ChangeLog
util/grub-pe2elf.c

index 466713bfecb2e37c60da42a7f2763b3a3415b69a..80f21841fab5a77d554cc9d872b5fd97edbc6965 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-05-14  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Handle module_license on windows.
+
+       * util/grub-pe2elf.c (MODLICENSE_SECTION): New definition. All following
+       sections shifted.
+       (insert_string): Make argument const char * instead of char *.
+       (write_section_data): Handle long section names.
+       Handle module_license.
+
 2011-05-14  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/commands/menuentry.c (grub_cmd_menuentry): Correctly
index cf690841f36a9ba872aa1b79de5b4100d3abef33..4b93faa052524affc9a4cb67a0b1621a75060dae 100644 (file)
@@ -79,11 +79,12 @@ Report bugs to <%s>.\n", program_name, PACKAGE_BUGREPORT);
 #define BSS_SECTION    4
 #define MODNAME_SECTION        5
 #define MODDEPS_SECTION        6
-#define SYMTAB_SECTION 7
-#define STRTAB_SECTION 8
+#define MODLICENSE_SECTION     7
+#define SYMTAB_SECTION 8
+#define STRTAB_SECTION 9
 
-#define REL_SECTION    9
-#define MAX_SECTIONS   12
+#define REL_SECTION    10
+#define MAX_SECTIONS    16
 
 #define STRTAB_BLOCK   256
 
@@ -96,7 +97,7 @@ int num_sections;
 grub_uint32_t offset;
 
 static int
-insert_string (char *name)
+insert_string (const char *name)
 {
   int len, result;
 
@@ -124,6 +125,8 @@ write_section_data (FILE* fp, char *image,
 {
   int *section_map;
   int i;
+  char *pe_strtab = (image + pe_chdr->symtab_offset
+                    + pe_chdr->num_symbols * sizeof (struct grub_pe32_symbol));
 
   section_map = xmalloc ((pe_chdr->num_sections + 1) * sizeof (int));
   section_map[0] = 0;
@@ -131,31 +134,42 @@ write_section_data (FILE* fp, char *image,
   for (i = 0; i < pe_chdr->num_sections; i++, pe_shdr++)
     {
       grub_uint32_t idx;
+      const char *name = pe_shdr->name;
 
-      if (! strcmp (pe_shdr->name, ".text"))
+      if (name[0] == '/' && isdigit (name[1]))
+      {
+        char t[sizeof (pe_shdr->name) + 1];
+        memcpy (t, name, sizeof (pe_shdr->name));
+        t[sizeof (pe_shdr->name)] = 0;
+        name = pe_strtab + atoi (t + 1);
+      }
+
+      if (! strcmp (name, ".text"))
         {
           idx = TEXT_SECTION;
           shdr[idx].sh_flags = SHF_ALLOC | SHF_EXECINSTR;
         }
-      else if (! strcmp (pe_shdr->name, ".rdata"))
+      else if (! strcmp (name, ".rdata"))
         {
           idx = RDATA_SECTION;
           shdr[idx].sh_flags = SHF_ALLOC;
         }
-      else if (! strcmp (pe_shdr->name, ".data"))
+      else if (! strcmp (name, ".data"))
         {
           idx = DATA_SECTION;
           shdr[idx].sh_flags = SHF_ALLOC | SHF_WRITE;
         }
-      else if (! strcmp (pe_shdr->name, ".bss"))
+      else if (! strcmp (name, ".bss"))
         {
           idx = BSS_SECTION;
           shdr[idx].sh_flags = SHF_ALLOC | SHF_WRITE;
         }
-      else if (! strcmp (pe_shdr->name, ".modname"))
+      else if (! strcmp (name, ".modname"))
         idx = MODNAME_SECTION;
-      else if (! strcmp (pe_shdr->name, ".moddeps"))
+      else if (! strcmp (name, ".moddeps"))
         idx = MODDEPS_SECTION;
+      else if (strcmp (name, ".module_license") == 0)
+        idx = MODLICENSE_SECTION;
       else
         {
           section_map[i + 1] = -1;
@@ -181,14 +195,14 @@ write_section_data (FILE* fp, char *image,
 
       if (pe_shdr->relocations_offset)
         {
-          char name[5 + strlen (pe_shdr->name)];
+          char relname[5 + strlen (name)];
 
           if (num_sections >= MAX_SECTIONS)
             grub_util_error ("too many sections");
 
-          sprintf (name, ".rel%s", pe_shdr->name);
+          sprintf (relname, ".rel%s", name);
 
-          shdr[num_sections].sh_name = insert_string (name);
+          shdr[num_sections].sh_name = insert_string (relname);
           shdr[num_sections].sh_link = i;
           shdr[num_sections].sh_info = idx;
 
@@ -197,7 +211,7 @@ write_section_data (FILE* fp, char *image,
           num_sections++;
         }
       else
-        shdr[idx].sh_name = insert_string (pe_shdr->name);
+        shdr[idx].sh_name = insert_string (name);
     }
 
   return section_map;