elf: fix handling of virtual/physical addresses

Remove the hackish elf_translate_addresses which should not have
existed in the first place, on write always compute the physical
address of a section using elf_translate_virtual_address which
makes it possible to specify any virtual to physical mapping and
fail nicely if there is none.

Change-Id: I4f436945e90280a6fd9430de6c642dbeb8e23d40
This commit is contained in:
Amaury Pouly 2013-08-06 15:46:09 +02:00
parent 48ccea96f2
commit 8b13d2f5f1
4 changed files with 3 additions and 16 deletions

View file

@ -519,8 +519,8 @@ void elf_write_file(struct elf_params_t *params, elf_write_fn_t write,
phdr.p_offset = sec->offset;
else
phdr.p_offset = 0;
phdr.p_paddr = sec->addr;
phdr.p_vaddr = phdr.p_paddr; /* assume identity map ? */
phdr.p_paddr = elf_translate_virtual_address(params, sec->addr);
phdr.p_vaddr = sec->addr; /* assume identity map ? */
phdr.p_memsz = sec->size;
if(sec->type == EST_LOAD)
phdr.p_filesz = phdr.p_memsz;
@ -795,17 +795,6 @@ uint32_t elf_translate_virtual_address(struct elf_params_t *params, uint32_t add
return addr;
}
void elf_translate_addresses(struct elf_params_t *params)
{
struct elf_section_t *sec = params->first_section;
while(sec)
{
sec->addr = elf_translate_virtual_address(params, sec->addr);
sec = sec->next;
}
params->start_addr = elf_translate_virtual_address(params, params->start_addr);
}
bool elf_is_empty(struct elf_params_t *params)
{
return params->first_section == NULL;

View file

@ -101,7 +101,6 @@ void elf_add_load_section(struct elf_params_t *params,
void elf_add_fill_section(struct elf_params_t *params,
uint32_t fill_addr, uint32_t size, uint32_t pattern, const char *name);
uint32_t elf_translate_virtual_address(struct elf_params_t *params, uint32_t addr);
void elf_translate_addresses(struct elf_params_t *params);
void elf_simplify(struct elf_params_t *params);
void elf_sort_by_address(struct elf_params_t *params);
void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, elf_printf_fn_t printf, void *user);

View file

@ -88,7 +88,6 @@ static void load_elf_by_id(struct cmd_file_t *cmd_file, const char *id)
fclose(fd);
if(!src->loaded)
bug("error loading elf file '%s' (id '%s')\n", src->filename, id);
elf_translate_addresses(&src->elf);
}
static void load_bin_by_id(struct cmd_file_t *cmd_file, const char *id)

View file

@ -19,6 +19,7 @@
*
****************************************************************************/
#define _POSIX_C_SOURCE 200809L /* for strdup */
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
@ -405,7 +406,6 @@ static int load_elf(struct sb1_file_t *sb, const char *filename, int act)
fclose(fd);
if(!loaded)
bug("error loading elf file '%s'\n", filename);
elf_translate_addresses(&elf);
elf_sort_by_address(&elf);
struct elf_section_t *esec = elf.first_section;