Skip to content

Commit

Permalink
rimage: add support for relocatable objects
Browse files Browse the repository at this point in the history
Relocatable ELF objects don't contain segments, update rimage to
prevent it from aborting in such cases.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
  • Loading branch information
lyakh authored and lgirdwood committed Apr 16, 2024
1 parent ed33af4 commit 30b9470
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions tools/rimage/src/elf_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ static int elf_header_read(struct elf_file *elf)
if (elf->header.ehsize < sizeof(Elf32_Ehdr))
return elf_error(elf, "Invalid file header size.", EINVAL);

if (elf->header.phoff >= elf->file_size)
return elf_error(elf, "Invalid program header file offset.", EINVAL);

if (elf->header.phentsize < sizeof(Elf32_Phdr))
return elf_error(elf, "Invalid program header size.", EINVAL);

if (elf->header.phoff + elf->header.phnum * sizeof(Elf32_Phdr) > elf->file_size)
return elf_error(elf, "Invalid number of program header entries.", EINVAL);

if (elf->header.shoff >= elf->file_size)
return elf_error(elf, "Invalid section header file offset.", EINVAL);

Expand Down Expand Up @@ -250,6 +241,12 @@ static int elf_program_headers_read(struct elf_file *elf)
int i, ret;
size_t offset, count;

if (!elf->header.phnum) {
elf->programs = NULL;
elf->programs_count = 0;
return 0;
}

elf->programs = calloc(elf->header.phnum, sizeof(Elf32_Phdr));
if (!elf->programs)
return elf_error(elf, "Cannot allocate program array.", ENOMEM);
Expand Down

0 comments on commit 30b9470

Please sign in to comment.