]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libelf: Fix elf_begin.c build on 32bit arches.
authorMark Wielaard <mark@klomp.org>
Tue, 14 Nov 2023 20:34:50 +0000 (21:34 +0100)
committerMark Wielaard <mark@klomp.org>
Tue, 14 Nov 2023 20:34:50 +0000 (21:34 +0100)
commitf84f1cd7e296bf223cb45b5469978d4bea82cec0
tree9dff5eb685b57579a6a787eebeb6f8d8a236f11c
parentf1a381fb050650a9c15e15d0102967df3f0a6a03
libelf: Fix elf_begin.c build on 32bit arches.

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>
libelf/elf_begin.c