From: Peter Jones <pjones@redhat.com>
To: grub-devel@gnu.org
Cc: Daniel Kiper <dkiper@net-space.pl>, Peter Jones <pjones@redhat.com>
Subject: [PATCH v3 4/7] mkimage: make locate_sections() set up vaddresses as well.
Date: Wed, 21 Feb 2018 15:20:26 -0500 [thread overview]
Message-ID: <20180221202029.31419-4-pjones@redhat.com> (raw)
In-Reply-To: <20180221202029.31419-1-pjones@redhat.com>
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 <pjones@redhat.com>
---
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
next prev parent reply other threads:[~2018-02-21 20:22 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-31 16:26 [PATCH 1/2] mkimage: avoid copying relocations for sections that won't be copied Peter Jones
2018-01-31 16:27 ` [PATCH 2/2] .mod files: Strip annobin annotations and .eh_frame, and their relocations Peter Jones
2018-02-15 22:03 ` Vladimir 'phcoder' Serbinenko
2018-02-20 14:51 ` Daniel Kiper
2018-02-20 23:29 ` Peter Jones
2018-02-15 21:52 ` [PATCH 1/2] mkimage: avoid copying relocations for sections that won't be copied Peter Jones
2018-02-15 22:03 ` Vladimir 'phcoder' Serbinenko
2018-02-20 14:48 ` Daniel Kiper
2018-02-20 23:25 ` [PATCH v2 1/3] mkimage: refactor a bunch of section data into a struct Peter Jones
2018-02-20 23:25 ` [PATCH v2 2/3] mkimage: avoid copying relocations for sections that won't be copied Peter Jones
2018-02-21 11:18 ` Daniel Kiper
2018-02-20 23:25 ` [PATCH v2 3/3] .mod files: Strip annobin annotations and .eh_frame, and their relocations Peter Jones
2018-02-21 11:22 ` Daniel Kiper
2018-02-21 11:07 ` [PATCH v2 1/3] mkimage: refactor a bunch of section data into a struct Daniel Kiper
2018-02-21 20:18 ` Peter Jones
2018-02-21 20:20 ` [PATCH v3 1/7] aout.h: Fix missing include Peter Jones
2018-02-21 20:20 ` [PATCH v3 2/7] mkimage: make it easier to run syntax checkers on grub-mkimagexx.c Peter Jones
2018-02-23 14:27 ` Daniel Kiper
2018-02-21 20:20 ` [PATCH v3 3/7] mkimage: rename a couple of things to be less confusing later Peter Jones
2018-02-23 14:29 ` Daniel Kiper
2018-02-21 20:20 ` Peter Jones [this message]
2018-02-23 14:38 ` [PATCH v3 4/7] mkimage: make locate_sections() set up vaddresses as well Daniel Kiper
2018-02-21 20:20 ` [PATCH v3 5/7] mkimage: refactor a bunch of section data into a struct Peter Jones
2018-02-23 14:51 ` Daniel Kiper
2018-02-23 15:27 ` Peter Jones
2018-02-21 20:20 ` [PATCH v3 6/7] mkimage: avoid copying relocations for sections that won't be copied Peter Jones
2018-02-23 14:54 ` Daniel Kiper
2018-02-21 20:20 ` [PATCH v3 7/7] .mod files: Strip annobin annotations and .eh_frame, and their relocations Peter Jones
2018-02-23 14:54 ` Daniel Kiper
2018-02-23 14:56 ` Daniel Kiper
2018-02-23 14:15 ` [PATCH v3 1/7] aout.h: Fix missing include Daniel Kiper
2018-02-20 23:26 ` [PATCH 1/2] mkimage: avoid copying relocations for sections that won't be copied Peter Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180221202029.31419-4-pjones@redhat.com \
--to=pjones@redhat.com \
--cc=dkiper@net-space.pl \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).