[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 1/3] mkimage: refactor a bunch of section data into a struct.
From: |
Peter Jones |
Subject: |
[PATCH v2 1/3] mkimage: refactor a bunch of section data into a struct. |
Date: |
Tue, 20 Feb 2018 18:25:31 -0500 |
This basically moves a bunch of the section information we pass around a
lot into a struct, and passes a pointer to a single one of those
instead.
Because it's more convenient, it also puts the section_vaddresses
calculations in locate_section(), which no longer returns the allocation
for section_addresses directly either.
This shouldn't change the binary file output or the "grub-mkimage -v"
output in any way.
Signed-off-by: Peter Jones <address@hidden>
---
util/grub-mkimagexx.c | 282 ++++++++++++++++++++++----------------------------
1 file changed, 123 insertions(+), 159 deletions(-)
diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
index a2bb05439f0..5c787ec56bf 100644
--- a/util/grub-mkimagexx.c
+++ b/util/grub-mkimagexx.c
@@ -84,6 +84,17 @@ struct fixup_block_list
#define ALIGN_ADDR(x) (ALIGN_UP((x), image_target->voidp_sizeof))
+struct section_metadata
+{
+ Elf_Half num_sections;
+ Elf_Shdr *sections;
+ Elf_Addr *addresses;
+ Elf_Addr *vaddresses;
+ Elf_Half section_entsize;
+ Elf_Shdr *symtab;
+ const char *strtab;
+};
+
static int
is_relocatable (const struct grub_install_image_target_desc *image_target)
{
@@ -499,9 +510,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct
grub_install_image_target_desc
/* Relocate symbols; note that this function overwrites the symbol table.
Return the address of a start symbol. */
static Elf_Addr
-SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections,
- Elf_Shdr *symtab_section, Elf_Addr
*section_addresses,
- Elf_Half section_entsize, Elf_Half num_sections,
+SUFFIX (relocate_symbols) (Elf_Ehdr *e, struct section_metadata *sdata,
void *jumpers, Elf_Addr jumpers_addr,
Elf_Addr bss_start, Elf_Addr end,
const struct grub_install_image_target_desc
*image_target)
@@ -511,19 +520,18 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr
*sections,
Elf_Addr start_address = (Elf_Addr) -1;
Elf_Sym *sym;
Elf_Word i;
- Elf_Shdr *strtab_section;
- const char *strtab;
+ Elf_Shdr *symtab_section;
+ const char *symtab;
grub_uint64_t *jptr = jumpers;
- strtab_section
- = (Elf_Shdr *) ((char *) sections
- + (grub_target_to_host32 (symtab_section->sh_link)
- * section_entsize));
- strtab = (char *) e + grub_target_to_host (strtab_section->sh_offset);
+ symtab_section = (Elf_Shdr *) ((char *) sdata->sections
+ + grub_target_to_host32
(sdata->symtab->sh_link)
+ * sdata->section_entsize);
+ symtab = (char *) e + grub_target_to_host (symtab_section->sh_offset);
- symtab_size = grub_target_to_host (symtab_section->sh_size);
- sym_size = grub_target_to_host (symtab_section->sh_entsize);
- symtab_offset = grub_target_to_host (symtab_section->sh_offset);
+ symtab_size = grub_target_to_host (sdata->symtab->sh_size);
+ sym_size = grub_target_to_host (sdata->symtab->sh_entsize);
+ symtab_offset = grub_target_to_host (sdata->symtab->sh_offset);
num_syms = symtab_size / sym_size;
for (i = 0, sym = (Elf_Sym *) ((char *) e + symtab_offset);
@@ -533,7 +541,7 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections,
Elf_Section cur_index;
const char *name;
- name = strtab + grub_target_to_host32 (sym->st_name);
+ name = symtab + grub_target_to_host32 (sym->st_name);
cur_index = grub_target_to_host16 (sym->st_shndx);
if (cur_index == STN_ABS)
@@ -551,12 +559,12 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr
*sections,
else
continue;
}
- else if (cur_index >= num_sections)
+ else if (cur_index >= sdata->num_sections)
grub_util_error ("section %d does not exist", cur_index);
else
{
sym->st_value = (grub_target_to_host (sym->st_value)
- + section_addresses[cur_index]);
+ + sdata->vaddresses[cur_index]);
}
if (image_target->elf_target == EM_IA_64 && ELF_ST_TYPE (sym->st_info)
@@ -571,7 +579,7 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections,
grub_util_info ("locating %s at 0x%" GRUB_HOST_PRIxLONG_LONG
" (0x%" GRUB_HOST_PRIxLONG_LONG ")", name,
(unsigned long long) sym->st_value,
- (unsigned long long) section_addresses[cur_index]);
+ (unsigned long long) sdata->vaddresses[cur_index]);
if (start_address == (Elf_Addr)-1)
if (strcmp (name, "_start") == 0 || strcmp (name, "start") == 0)
@@ -713,12 +721,8 @@ arm_get_trampoline_size (Elf_Ehdr *e,
addresses can be fully resolved. Absolute addresses must be relocated
again by a PE32 relocator when loaded. */
static void
-SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
- Elf_Addr *section_addresses,
- Elf_Half section_entsize, Elf_Half num_sections,
- const char *strtab,
- char *pe_target, Elf_Addr tramp_off,
- Elf_Addr got_off,
+SUFFIX (relocate_addresses) (Elf_Ehdr *e, struct section_metadata *sdata,
+ char *pe_target, Elf_Addr tramp_off, Elf_Addr
got_off,
const struct grub_install_image_target_desc
*image_target)
{
Elf_Half i;
@@ -732,33 +736,29 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr
*sections,
grub_uint32_t *tr = (void *) (pe_target + tramp_off);
#endif
- for (i = 0, s = sections;
- i < num_sections;
- i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
+ for (i = 0, s = sdata->sections;
+ i < sdata->num_sections;
+ i++, s = (Elf_Shdr *) ((char *) s + sdata->section_entsize))
if ((s->sh_type == grub_host_to_target32 (SHT_REL)) ||
(s->sh_type == grub_host_to_target32 (SHT_RELA)))
{
Elf_Rela *r;
Elf_Word rtab_size, r_size, num_rs;
Elf_Off rtab_offset;
- Elf_Shdr *symtab_section;
Elf_Word target_section_index;
Elf_Addr target_section_addr;
Elf_Shdr *target_section;
Elf_Word j;
- symtab_section = (Elf_Shdr *) ((char *) sections
- + (grub_target_to_host32 (s->sh_link)
- * section_entsize));
target_section_index = grub_target_to_host32 (s->sh_info);
- target_section_addr = section_addresses[target_section_index];
- target_section = (Elf_Shdr *) ((char *) sections
+ target_section_addr = sdata->addresses[target_section_index];
+ target_section = (Elf_Shdr *) ((char *) sdata->sections
+ (target_section_index
- * section_entsize));
+ * sdata->section_entsize));
grub_util_info ("dealing with the relocation section %s for %s",
- strtab + grub_target_to_host32 (s->sh_name),
- strtab + grub_target_to_host32
(target_section->sh_name));
+ sdata->strtab + grub_target_to_host32 (s->sh_name),
+ sdata->strtab + grub_target_to_host32
(target_section->sh_name));
rtab_size = grub_target_to_host (s->sh_size);
r_size = grub_target_to_host (s->sh_entsize);
@@ -779,7 +779,7 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr
*sections,
target = SUFFIX (get_target_address) (e, target_section,
offset, image_target);
info = grub_target_to_host (r->r_info);
- sym_addr = SUFFIX (get_symbol_address) (e, symtab_section,
+ sym_addr = SUFFIX (get_symbol_address) (e, sdata->symtab,
ELF_R_SYM (info),
image_target);
addend = (s->sh_type == grub_target_to_host32 (SHT_RELA)) ?
@@ -909,8 +909,8 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr
*sections,
Elf_Sym *sym;
sym = (Elf_Sym *) ((char *) e
- + grub_target_to_host
(symtab_section->sh_offset)
- + ELF_R_SYM (info) * grub_target_to_host
(symtab_section->sh_entsize));
+ + grub_target_to_host
(sdata->symtab->sh_offset)
+ + ELF_R_SYM (info) * grub_target_to_host
(sdata->symtab->sh_entsize));
if (ELF_ST_TYPE (sym->st_info) == STT_FUNC)
sym_addr = grub_target_to_host64 (*(grub_uint64_t *)
(pe_target
+
sym->st_value
@@ -1095,8 +1095,8 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr
*sections,
- (char *) e),
sym_addr);
sym = (Elf_Sym *) ((char *) e
- + grub_target_to_host
(symtab_section->sh_offset)
- + ELF_R_SYM (info) *
grub_target_to_host (symtab_section->sh_entsize));
+ + grub_target_to_host
(sdata->symtab->sh_offset)
+ + ELF_R_SYM (info) *
grub_target_to_host (sdata->symtab->sh_entsize));
if (ELF_ST_TYPE (sym->st_info) != STT_FUNC)
sym_addr |= 1;
if (!(sym_addr & 1))
@@ -1634,9 +1634,7 @@ create_u64_fixups (struct translate_context *ctx,
/* Make a .reloc section. */
static void
make_reloc_section (Elf_Ehdr *e, struct grub_mkimage_layout *layout,
- Elf_Addr *section_addresses, Elf_Shdr *sections,
- Elf_Half section_entsize, Elf_Half num_sections,
- const char *strtab,
+ struct section_metadata *sdata,
const struct grub_install_image_target_desc *image_target)
{
unsigned i;
@@ -1645,8 +1643,8 @@ make_reloc_section (Elf_Ehdr *e, struct
grub_mkimage_layout *layout,
translate_reloc_start (&ctx, image_target);
- for (i = 0, s = sections; i < num_sections;
- i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
+ for (i = 0, s = sdata->sections; i < sdata->num_sections;
+ i++, s = (Elf_Shdr *) ((char *) s + sdata->section_entsize))
if ((grub_target_to_host32 (s->sh_type) == SHT_REL) ||
(grub_target_to_host32 (s->sh_type) == SHT_RELA))
{
@@ -1657,14 +1655,14 @@ make_reloc_section (Elf_Ehdr *e, struct
grub_mkimage_layout *layout,
Elf_Word j;
grub_util_info ("translating the relocation section %s",
- strtab + grub_le_to_cpu32 (s->sh_name));
+ sdata->strtab + grub_le_to_cpu32 (s->sh_name));
rtab_size = grub_target_to_host (s->sh_size);
r_size = grub_target_to_host (s->sh_entsize);
rtab_offset = grub_target_to_host (s->sh_offset);
num_rs = rtab_size / r_size;
- section_address = section_addresses[grub_le_to_cpu32 (s->sh_info)];
+ section_address = sdata->vaddresses[grub_le_to_cpu32 (s->sh_info)];
for (j = 0, r = (Elf_Rel *) ((char *) e + rtab_offset);
j < num_rs;
@@ -1751,12 +1749,11 @@ SUFFIX (check_elf_header) (Elf_Ehdr *e, size_t size,
const struct grub_install_i
static Elf_Addr
SUFFIX (put_section) (Elf_Shdr *s, int i,
Elf_Addr current_address,
- Elf_Addr *section_addresses,
- const char *strtab,
+ struct section_metadata *sdata,
const struct grub_install_image_target_desc *image_target)
{
Elf_Word align = grub_host_to_target_addr (s->sh_addralign);
- const char *name = strtab + grub_host_to_target32 (s->sh_name);
+ const char *name = sdata->strtab + grub_host_to_target32 (s->sh_name);
if (align)
current_address = ALIGN_UP (current_address +
image_target->vaddr_offset,
@@ -1768,24 +1765,23 @@ SUFFIX (put_section) (Elf_Shdr *s, int i,
name, (unsigned long long) current_address);
if (!is_relocatable (image_target))
current_address = grub_host_to_target_addr (s->sh_addr)
- - image_target->link_addr;
- section_addresses[i] = current_address;
+ - image_target->link_addr;
+ sdata->addresses[i] = current_address;
current_address += grub_host_to_target_addr (s->sh_size);
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,
+ struct section_metadata *sdata,
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;
@@ -1793,30 +1789,23 @@ 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;
- for (i = 0, s = sections;
- i < num_sections;
- i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
- if ((grub_target_to_host (s->sh_flags) & SHF_ALLOC)
+ for (i = 0, s = sdata->sections;
+ i < sdata->num_sections;
+ i++, s = (Elf_Shdr *) ((char *) s + sdata->section_entsize))
+ if ((grub_target_to_host (s->sh_flags) & SHF_ALLOC)
&& grub_host_to_target32 (s->sh_addralign) > layout->align)
layout->align = grub_host_to_target32 (s->sh_addralign);
-
/* .text */
- for (i = 0, s = sections;
- i < num_sections;
- i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
+ for (i = 0, s = sdata->sections;
+ i < sdata->num_sections;
+ i++, s = (Elf_Shdr *) ((char *) s + sdata->section_entsize))
if (SUFFIX (is_text_section) (s, image_target))
{
- layout->kernel_size = SUFFIX (put_section) (s, i,
- layout->kernel_size,
- section_addresses,
- strtab,
- image_target);
+ layout->kernel_size = SUFFIX (put_section) (s, i, layout->kernel_size,
+ sdata, image_target);
if (!is_relocatable (image_target) &&
grub_host_to_target_addr (s->sh_addr) != image_target->link_addr)
{
@@ -1836,15 +1825,12 @@ SUFFIX (locate_sections) (Elf_Ehdr *e, const char
*kernel_path,
layout->exec_size = layout->kernel_size;
/* .data */
- for (i = 0, s = sections;
- i < num_sections;
- i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
+ for (i = 0, s = sdata->sections;
+ i < sdata->num_sections;
+ i++, s = (Elf_Shdr *) ((char *) s + sdata->section_entsize))
if (SUFFIX (is_data_section) (s, image_target))
- layout->kernel_size = SUFFIX (put_section) (s, i,
- layout->kernel_size,
- section_addresses,
- strtab,
- image_target);
+ layout->kernel_size = SUFFIX (put_section) (s, i, layout->kernel_size,
sdata,
+ image_target);
#ifdef MKIMAGE_ELF32
if (image_target->elf_target == EM_ARM)
@@ -1855,8 +1841,8 @@ SUFFIX (locate_sections) (Elf_Ehdr *e, const char
*kernel_path,
layout->kernel_size = ALIGN_UP (layout->kernel_size, 16);
- tramp = arm_get_trampoline_size (e, sections, section_entsize,
- num_sections, image_target);
+ tramp = arm_get_trampoline_size (e, sdata->sections,
sdata->section_entsize,
+ sdata->num_sections, image_target);
layout->tramp_off = layout->kernel_size;
layout->kernel_size += ALIGN_UP (tramp, 16);
@@ -1867,15 +1853,16 @@ SUFFIX (locate_sections) (Elf_Ehdr *e, const char
*kernel_path,
layout->end = layout->kernel_size;
/* .bss */
- 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);
+ for (i = 0, s = sdata->sections;
+ i < sdata->num_sections;
+ i++, s = (Elf_Shdr *) ((char *) s + sdata->section_entsize))
+ {
+ if (SUFFIX (is_bss_section) (s, image_target))
+ layout->end = SUFFIX (put_section) (s, i, layout->end, sdata,
image_target);
+
+ /* This is here just to save us another pass through the loop... */
+ sdata->vaddresses[i] = sdata->addresses[i] + image_target->vaddr_offset;
+ }
layout->end = ALIGN_UP (layout->end + image_target->vaddr_offset,
image_target->section_align) -
image_target->vaddr_offset;
@@ -1886,8 +1873,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 *
@@ -1897,18 +1882,12 @@ SUFFIX (grub_mkimage_load_image) (const char
*kernel_path,
const struct grub_install_image_target_desc
*image_target)
{
char *kernel_img, *out_img;
- const char *strtab;
+ struct section_metadata sdata = { 0, };
Elf_Ehdr *e;
- Elf_Shdr *sections;
- Elf_Addr *section_addresses;
- Elf_Addr *section_vaddresses;
int i;
Elf_Shdr *s;
- Elf_Half num_sections;
Elf_Off section_offset;
- Elf_Half section_entsize;
grub_size_t kernel_size;
- Elf_Shdr *symtab_section = 0;
grub_memset (layout, 0, sizeof (*layout));
@@ -1923,48 +1902,45 @@ SUFFIX (grub_mkimage_load_image) (const char
*kernel_path,
grub_util_error ("invalid ELF header");
section_offset = grub_target_to_host (e->e_shoff);
- section_entsize = grub_target_to_host16 (e->e_shentsize);
- num_sections = grub_target_to_host16 (e->e_shnum);
+ sdata.section_entsize = grub_target_to_host16 (e->e_shentsize);
+ sdata.num_sections = grub_target_to_host16 (e->e_shnum);
- if (kernel_size < section_offset + (grub_uint32_t) section_entsize *
num_sections)
+ if (kernel_size < section_offset
+ + (grub_uint32_t) sdata.section_entsize *
sdata.num_sections)
grub_util_error (_("premature end of file %s"), kernel_path);
- sections = (Elf_Shdr *) (kernel_img + section_offset);
+ sdata.sections = (Elf_Shdr *) (kernel_img + section_offset);
/* Relocate sections then symbols in the virtual address space. */
- s = (Elf_Shdr *) ((char *) sections
- + grub_host_to_target16 (e->e_shstrndx) *
section_entsize);
- strtab = (char *) e + grub_host_to_target_addr (s->sh_offset);
+ s = (Elf_Shdr *) ((char *) sdata.sections
+ + grub_host_to_target16 (e->e_shstrndx) *
sdata.section_entsize);
+ sdata.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);
+ sdata.addresses = xmalloc (sizeof (*sdata.addresses) * sdata.num_sections);
+ memset (sdata.addresses, 0, sizeof (*sdata.addresses) * sdata.num_sections);
+ sdata.vaddresses = xmalloc (sizeof (*sdata.vaddresses) * sdata.num_sections);
+ memset (sdata.vaddresses, 0, sizeof (*sdata.addresses) * sdata.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, &sdata, layout, image_target);
if (!is_relocatable (image_target))
{
Elf_Addr current_address = layout->kernel_size;
- for (i = 0, s = sections;
- i < num_sections;
- i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
+ for (i = 0, s = sdata.sections;
+ i < sdata.num_sections;
+ i++, s = (Elf_Shdr *) ((char *) s + sdata.section_entsize))
if (grub_target_to_host32 (s->sh_type) == SHT_NOBITS)
{
Elf_Word sec_align = grub_host_to_target_addr (s->sh_addralign);
- const char *name = strtab + grub_host_to_target32 (s->sh_name);
+ const char *name = sdata.strtab + grub_host_to_target32
(s->sh_name);
if (sec_align)
current_address = ALIGN_UP (current_address
+ image_target->vaddr_offset,
sec_align)
- image_target->vaddr_offset;
-
+
grub_util_info ("locating the section %s at 0x%"
GRUB_HOST_PRIxLONG_LONG,
name, (unsigned long long) current_address);
@@ -1972,7 +1948,7 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path,
current_address = grub_host_to_target_addr (s->sh_addr)
- image_target->link_addr;
- section_vaddresses[i] = current_address
+ sdata.vaddresses[i] = current_address
+ image_target->vaddr_offset;
current_address += grub_host_to_target_addr (s->sh_size);
}
@@ -1993,16 +1969,16 @@ SUFFIX (grub_mkimage_load_image) (const char
*kernel_path,
if (is_relocatable (image_target))
{
- symtab_section = NULL;
- for (i = 0, s = sections;
- i < num_sections;
- i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
+ sdata.symtab = NULL;
+ for (i = 0, s = sdata.sections;
+ i < sdata.num_sections;
+ i++, s = (Elf_Shdr *) ((char *) s + sdata.section_entsize))
if (s->sh_type == grub_host_to_target32 (SHT_SYMTAB))
{
- symtab_section = s;
+ sdata.symtab = s;
break;
}
- if (! symtab_section)
+ if (! sdata.symtab)
grub_util_error ("%s", _("no symbol table"));
#ifdef MKIMAGE_ELF64
if (image_target->elf_target == EM_IA_64)
@@ -2017,7 +1993,7 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path,
layout->kernel_size += ALIGN_UP (tramp, 16);
layout->ia64jmp_off = layout->kernel_size;
- layout->ia64jmpnum = SUFFIX (count_funcs) (e, symtab_section,
+ layout->ia64jmpnum = SUFFIX (count_funcs) (e, sdata.symtab,
image_target);
layout->kernel_size += 16 * layout->ia64jmpnum;
@@ -2048,31 +2024,19 @@ SUFFIX (grub_mkimage_load_image) (const char
*kernel_path,
if (is_relocatable (image_target))
{
- layout->start_address = SUFFIX (relocate_symbols) (e, sections,
symtab_section,
- section_vaddresses, section_entsize,
- num_sections,
- (char *) out_img +
layout->ia64jmp_off,
- layout->ia64jmp_off
- + image_target->vaddr_offset,
- layout->bss_start,
- layout->end,
- image_target);
+ layout->start_address = SUFFIX (relocate_symbols) (e, &sdata,
+ (char *) out_img + layout->ia64jmp_off,
+ layout->ia64jmp_off +
image_target->vaddr_offset,
+ layout->bss_start, layout->end, image_target);
+
if (layout->start_address == (Elf_Addr) -1)
grub_util_error ("start symbol is not defined");
/* Resolve addresses in the virtual address space. */
- SUFFIX (relocate_addresses) (e, sections, section_addresses,
- section_entsize,
- num_sections, strtab,
- out_img, layout->tramp_off,
- layout->got_off,
- image_target);
+ SUFFIX (relocate_addresses) (e, &sdata, out_img, layout->tramp_off,
+ layout->got_off, image_target);
- make_reloc_section (e, layout,
- section_vaddresses, sections,
- section_entsize, num_sections,
- strtab,
- image_target);
+ make_reloc_section (e, layout, &sdata, image_target);
if (image_target->id != IMAGE_EFI)
{
out_img = xrealloc (out_img, layout->kernel_size + total_module_size
@@ -2084,9 +2048,9 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path,
}
}
- for (i = 0, s = sections;
- i < num_sections;
- i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
+ for (i = 0, s = sdata.sections;
+ i < sdata.num_sections;
+ i++, s = (Elf_Shdr *) ((char *) s + sdata.section_entsize))
if (SUFFIX (is_data_section) (s, image_target)
/* Explicitly initialize BSS
when producing PE32 to avoid a bug in EFI implementations.
@@ -2097,17 +2061,17 @@ SUFFIX (grub_mkimage_load_image) (const char
*kernel_path,
|| SUFFIX (is_text_section) (s, image_target))
{
if (grub_target_to_host32 (s->sh_type) == SHT_NOBITS)
- memset (out_img + section_addresses[i], 0,
+ memset (out_img + sdata.addresses[i], 0,
grub_host_to_target_addr (s->sh_size));
else
- memcpy (out_img + section_addresses[i],
+ memcpy (out_img + sdata.addresses[i],
kernel_img + grub_host_to_target_addr (s->sh_offset),
grub_host_to_target_addr (s->sh_size));
}
free (kernel_img);
- free (section_vaddresses);
- free (section_addresses);
+ free (sdata.vaddresses);
+ free (sdata.addresses);
return out_img;
}
--
2.15.0
- Re: [PATCH 1/2] mkimage: avoid copying relocations for sections that won't be copied., Peter Jones, 2018/02/15
- Re: [PATCH 1/2] mkimage: avoid copying relocations for sections that won't be copied., Vladimir 'phcoder' Serbinenko, 2018/02/15
- Re: [PATCH 1/2] mkimage: avoid copying relocations for sections that won't be copied., Daniel Kiper, 2018/02/20
- [PATCH v2 1/3] mkimage: refactor a bunch of section data into a struct.,
Peter Jones <=
- [PATCH v2 3/3] .mod files: Strip annobin annotations and .eh_frame, and their relocations, Peter Jones, 2018/02/20
- Re: [PATCH v2 3/3] .mod files: Strip annobin annotations and .eh_frame, and their relocations, Daniel Kiper, 2018/02/21
- [PATCH v2 2/3] mkimage: avoid copying relocations for sections that won't be copied., Peter Jones, 2018/02/20
- Re: [PATCH v2 2/3] mkimage: avoid copying relocations for sections that won't be copied., Daniel Kiper, 2018/02/21
- Re: [PATCH v2 1/3] mkimage: refactor a bunch of section data into a struct., Daniel Kiper, 2018/02/21
- Re: [PATCH v2 1/3] mkimage: refactor a bunch of section data into a struct., Peter Jones, 2018/02/21
- [PATCH v3 1/7] aout.h: Fix missing include., Peter Jones, 2018/02/21
- [PATCH v3 7/7] .mod files: Strip annobin annotations and .eh_frame, and their relocations, Peter Jones, 2018/02/21
- Re: [PATCH v3 7/7] .mod files: Strip annobin annotations and .eh_frame, and their relocations, Daniel Kiper, 2018/02/23
- Re: [PATCH v3 7/7] .mod files: Strip annobin annotations and .eh_frame, and their relocations, Daniel Kiper, 2018/02/23