On 32bit architectures gcc produces an error:
elf_begin.c: In function ‘file_read_elf’:
elf_begin.c:495:30: error: cast to pointer from integer of different
size [-Werror=int-to-pointer-cast]
elf->state.elf64.shdr = (Elf64_Shdr *) (ehdr + e_shoff);
^
This is because we are adding an uintptr to an Elf64_Off which
promotes the result to a 64bit value. Fix this by casting the
e_shoff to an ptrdiff_t. This is fine since the mmap of the file
would have failed if it didn't fit in the 32bit address space
and we check that e_shoff fits inside the image.
* libelf/elf_begin.c (file_read_elf): Cast e_shoff to ptrdiff_t
before adding to ehdr.
Suggested-by: Paul Pluzhnikov <ppluzhnikov@google.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
goto free_and_out;
if (scncnt > 0)
- elf->state.elf64.shdr = (Elf64_Shdr *) (ehdr + e_shoff);
+ elf->state.elf64.shdr = (Elf64_Shdr *) (ehdr + (ptrdiff_t) e_shoff);
for (size_t cnt = 0; cnt < scncnt; ++cnt)
{