A new user interface for you! Read more...

File grub2-ppc64le-16-Add-grub_dl_find_section_addr.patch of Package grub2

From ca7d011e65c6dc1b633c85b7105c807b929598f1 Mon Sep 17 00:00:00 2001
From: Anton Blanchard <anton@samba.org>
Date: Wed, 29 Jan 2014 10:42:12 +1100
Subject: [PATCH 16/23] Add grub_dl_find_section_addr

ppc64 needs to find the address of the toc section.
Create grub_dl_find_section_addr to do this.

We also need grub_dl_find_section, so make it global.

Signed-off-by: Ram Pai <linuxram@us.ibm.com>
From: Anton Blanchard <anton@samba.org>
---
 grub-core/kern/dl.c | 27 ++++++++++++++++++++++++++-
 include/grub/dl.h   |  2 ++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
index 6850e04..de2d0ed 100644
--- a/grub-core/kern/dl.c
+++ b/grub-core/kern/dl.c
@@ -191,6 +191,31 @@ grub_dl_get_section_addr (grub_dl_t mod, unsigned n)
   return 0;
 }
 
+void *grub_dl_find_section_addr (grub_dl_t mod, Elf_Ehdr *e, const char *name)
+{
+  Elf_Shdr *s;
+  const char *str;
+  unsigned i;
+  grub_dl_segment_t seg;
+
+  s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shstrndx * e->e_shentsize);
+  str = (char *) e + s->sh_offset;
+
+  for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
+       i < e->e_shnum;
+       i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
+    {
+      if (grub_strcmp (str + s->sh_name, name) == 0)
+	{
+	  for (seg = mod->segment; seg; seg = seg->next)
+	    if (seg->section == i)
+	      return seg->addr;
+	}
+    }
+
+  return 0;
+}
+
 /* Check if EHDR is a valid ELF header.  */
 static grub_err_t
 grub_dl_check_header (void *ehdr, grub_size_t size)
@@ -427,7 +452,7 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)
   return GRUB_ERR_NONE;
 }
 
-static Elf_Shdr *
+Elf_Shdr *
 grub_dl_find_section (Elf_Ehdr *e, const char *name)
 {
   Elf_Shdr *s;
diff --git a/include/grub/dl.h b/include/grub/dl.h
index 9562fa6..39c73a7 100644
--- a/include/grub/dl.h
+++ b/include/grub/dl.h
@@ -250,6 +250,8 @@ grub_err_t grub_arch_dl_check_header (void *ehdr);
 grub_err_t
 grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
 			       Elf_Shdr *s, grub_dl_segment_t seg);
+Elf_Shdr * grub_dl_find_section (Elf_Ehdr *e, const char *name);
+void *grub_dl_find_section_addr (grub_dl_t mod, Elf_Ehdr *e, const char *name);
 #endif
 
 #if defined (_mips)
-- 
1.8.3.1