libelf: Use offsetof to get field of unaligned
authorMark Wielaard <mark@klomp.org>
Tue, 14 Dec 2021 15:12:31 +0000 (16:12 +0100)
committerMark Wielaard <mark@klomp.org>
Thu, 16 Dec 2021 17:10:24 +0000 (18:10 +0100)
commit8303a9cf380a57d035557a157fe0e4d58e2b3090
tree92c9fe40334a6c4f4d4ba72ffb5187b696e0bf05
parentd70b27cd02227d5b533f9da2c811bea08eddabde
libelf: Use offsetof to get field of unaligned

gcc undefined sanitizer flags:

elf_begin.c:230:18: runtime error: member access within misaligned
address 0xf796400a for type 'struct Elf64_Shdr', which requires 4 byte
alignment struct.

We aren't actually accessing the field member of the struct, but are
taking the address of it. Which the compiler can take as a hint that
the address is correctly aligned. But we can do the same by adding
the field offsetof to the base address. Which doesn't trigger a
runtime error.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libelf/ChangeLog
libelf/elf_begin.c