libelf: Fix unaligned d_off offsets for input sections with large alignments
The mkl_memory_patched.o object inside the libmkl_core.a library from
the Intel Math Kernel Library version 2018.2.199 has this section
with an alignment of 4096 and offset of 0xb68:
[ 2] .data PROGBITS
0000000000000000 000b68 011000 00 WA 0 0 4096
Reading this file with libelf and trying to write it back to disk triggers
the following sequence of events:
1) code in elf_getdata.c clamps d_align for this section's data buffer
to the section's offset
2) code in elf32_updatenull.c checks if the alignment is a power of two
and incorrectly returns an error
This commit fixes this corner case by increasing the alignment to the
next power of two after the clamping, so the check passes.
A test that reproduces this bug using strip is also included.
Signed-off-by: Andrei Homescu <ah@immunant.com>