From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1WIjHW-0002EW-Bi for mharc-grub-devel@gnu.org; Wed, 26 Feb 2014 13:32:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43024) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIjHM-0001vc-F3 for grub-devel@gnu.org; Wed, 26 Feb 2014 13:32:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WIjHE-0001Eg-MA for grub-devel@gnu.org; Wed, 26 Feb 2014 13:32:24 -0500 Received: from e39.co.us.ibm.com ([32.97.110.160]:53636) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIjHE-0001EW-Ey for grub-devel@gnu.org; Wed, 26 Feb 2014 13:32:16 -0500 Received: from /spool/local by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 26 Feb 2014 11:32:15 -0700 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e39.co.us.ibm.com (192.168.1.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 26 Feb 2014 11:32:13 -0700 Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 6F5211FF0043 for ; Wed, 26 Feb 2014 11:32:11 -0700 (MST) Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by b03cxnp08025.gho.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s1QIWBoG6226388 for ; Wed, 26 Feb 2014 19:32:11 +0100 Received: from d03av02.boulder.ibm.com (localhost [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s1QIWBcG017727 for ; Wed, 26 Feb 2014 11:32:11 -0700 Received: from ram.oc3035372033.ibm.com.com (sig-9-65-83-23.mts.ibm.com [9.65.83.23]) by d03av02.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s1QIVZLd014663; Wed, 26 Feb 2014 11:32:08 -0700 From: Ram Pai To: grub-devel@gnu.org Subject: [RFC PATCH 14/23] Add grub_dl_find_section_addr Date: Wed, 26 Feb 2014 10:31:13 -0800 Message-Id: <1393439482-20341-15-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1393439482-20341-1-git-send-email-linuxram@us.ibm.com> References: <1393439482-20341-1-git-send-email-linuxram@us.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14022618-9332-0000-0000-0000033B94AC X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 32.97.110.160 Cc: tlfalcon@linux.vnet.ibm.com, tbberry@us.ibm.com, anton@au1.ibm.com, linuxram@us.ibm.com, tonyb@au1.ibm.com, Anton Blanchard X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Feb 2014 18:32:32 -0000 From: Anton Blanchard ppc64 needs to find the address of the toc and opd sections. 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 From: Anton Blanchard --- 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.5.3