elf: work around a gcc bug in elf_get_dynamic_info
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Mon, 11 Jan 2021 09:04:53 +0000 (09:04 +0000)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Wed, 13 Jan 2021 13:35:00 +0000 (13:35 +0000)
commit86a4d3fa7d1bda3c02cf713cf289d6f893970117
tree337a32e22b4157895cc701d3097acb76a2628103
parent2ef23b520597f4ea1790a669b83e608f24f4cf12
elf: work around a gcc bug in elf_get_dynamic_info

Since commit 2f056e8a5dd4dc0f075413f931e82cede37d1057
"aarch64: define PI_STATIC_AND_HIDDEN",
building glibc with gcc-8 on aarch64 fails with

/BLD/elf/librtld.os: in function `elf_get_dynamic_info':
/SRC/elf/get-dynamic-info.h:70:(.text+0xad8): relocation truncated to
 fit: R_AARCH64_ADR_PREL_PG_HI21 against symbol `_rtld_local' defined
 in .data section in /BLD/elf/librtld.os

This is a gcc bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98618
The bug is fixed on gcc-10 and not yet backported. gcc-9 is affected,
but the issue happens to not trigger in glibc, gcc-8 and older seems
to miscompile rtld.os.

Rewriting the affected code in elf_get_dynamic_info seems to make the
issue go away on <= gcc-9.

The change makes the logic a bit clearer too (by separating the index
computation and array update) and drops an older gcc workaround (since
gcc 4.6 is no longer supported).

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
elf/get-dynamic-info.h