Received: from list by lists.gnu.org with archive (Exim 4.71) id 1eoaue-0006Hg-Uu for mharc-grub-devel@gnu.org; Wed, 21 Feb 2018 15:22:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54243) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoau0-00062Q-V0 for grub-devel@gnu.org; Wed, 21 Feb 2018 15:22:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eoasW-0003NN-Ds for grub-devel@gnu.org; Wed, 21 Feb 2018 15:22:08 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40578 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eoasV-0003MT-QS for grub-devel@gnu.org; Wed, 21 Feb 2018 15:20:36 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5071740201A0; Wed, 21 Feb 2018 20:20:35 +0000 (UTC) Received: from trillian.uncooperative.org.com (dhcp-10-20-1-221.bss.redhat.com [10.20.1.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D71C10A970C; Wed, 21 Feb 2018 20:20:35 +0000 (UTC) From: Peter Jones To: grub-devel@gnu.org Cc: Daniel Kiper , Peter Jones Subject: [PATCH v3 4/7] mkimage: make locate_sections() set up vaddresses as well. Date: Wed, 21 Feb 2018 15:20:26 -0500 Message-Id: <20180221202029.31419-4-pjones@redhat.com> In-Reply-To: <20180221202029.31419-1-pjones@redhat.com> References: <20180221201833.prjf4yvfldjltptp@redhat.com> <20180221202029.31419-1-pjones@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Feb 2018 20:20:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Feb 2018 20:20:35 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pjones@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Feb 2018 20:22:47 -0000 This puts both kinds of address initialization at the same place, and also lets us iterate through the section list one time fewer. Signed-off-by: Peter Jones --- util/grub-mkimagexx.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index e00a831e0ca..0b7c00e2297 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -1783,18 +1783,19 @@ SUFFIX (put_section) (Elf_Shdr *s, int i, return current_address; } -/* Locate section addresses by merging code sections and data sections - into .text and .data, respectively. Return the array of section - addresses. */ -static Elf_Addr * +/* + * Locate section addresses by merging code sections and data sections + * into .text and .data, respectively. + */ +static void SUFFIX (locate_sections) (Elf_Ehdr *e, const char *kernel_path, Elf_Shdr *sections, Elf_Half section_entsize, - Elf_Half num_sections, const char *strtab, + Elf_Half num_sections, Elf_Addr *section_addresses, + Elf_Addr *section_vaddresses, const char *strtab, struct grub_mkimage_layout *layout, const struct grub_install_image_target_desc *image_target) { int i; - Elf_Addr *section_addresses; Elf_Shdr *s; layout->align = 1; @@ -1802,8 +1803,6 @@ SUFFIX (locate_sections) (Elf_Ehdr *e, const char *kernel_path, if (image_target->elf_target == EM_AARCH64) layout->align = 4096; - section_addresses = xmalloc (sizeof (*section_addresses) * num_sections); - memset (section_addresses, 0, sizeof (*section_addresses) * num_sections); layout->kernel_size = 0; @@ -1879,12 +1878,16 @@ SUFFIX (locate_sections) (Elf_Ehdr *e, const char *kernel_path, for (i = 0, s = sections; i < num_sections; i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) - if (SUFFIX (is_bss_section) (s, image_target)) - layout->end = SUFFIX (put_section) (s, i, - layout->end, - section_addresses, - strtab, - image_target); + { + if (SUFFIX (is_bss_section) (s, image_target)) + layout->end = SUFFIX (put_section) (s, i, layout->end, + section_addresses, strtab, + image_target); + /* + * This must to be in the last time this function passes through the loop. + */ + section_vaddresses[i] = section_addresses[i] + image_target->vaddr_offset; + } layout->end = ALIGN_UP (layout->end + image_target->vaddr_offset, image_target->section_align) - image_target->vaddr_offset; @@ -1895,8 +1898,6 @@ SUFFIX (locate_sections) (Elf_Ehdr *e, const char *kernel_path, */ if (image_target->id == IMAGE_EFI || !is_relocatable (image_target)) layout->kernel_size = layout->end; - - return section_addresses; } char * @@ -1945,16 +1946,14 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path, + grub_host_to_target16 (e->e_shstrndx) * section_entsize); strtab = (char *) e + grub_host_to_target_addr (s->sh_offset); - section_addresses = SUFFIX (locate_sections) (e, kernel_path, - sections, section_entsize, - num_sections, strtab, - layout, - image_target); + section_addresses = xmalloc (sizeof (*section_addresses) * num_sections); + memset (section_addresses, 0, sizeof (*section_addresses) * num_sections); + section_vaddresses = xmalloc (sizeof (*section_vaddresses) * num_sections); + memset (section_vaddresses, 0, sizeof (*section_vaddresses) * num_sections); - section_vaddresses = xmalloc (sizeof (*section_addresses) * num_sections); - - for (i = 0; i < num_sections; i++) - section_vaddresses[i] = section_addresses[i] + image_target->vaddr_offset; + SUFFIX (locate_sections) (e, kernel_path, sections, section_entsize, num_sections, + section_addresses, section_vaddresses, strtab, layout, + image_target); if (!is_relocatable (image_target)) { -- 2.15.0