[ELF] Don't shrink RelrSection
authorFangrui Song <maskray@google.com>
Wed, 4 Sep 2019 16:27:35 +0000 (16:27 +0000)
committerFangrui Song <maskray@google.com>
Wed, 4 Sep 2019 16:27:35 +0000 (16:27 +0000)
commit7afffb54eac8c7aedc8c24f75ccdd70b176a9d9f
treed38b9ec0c00fe264e5dc93663d7ad932fdc20e2a
parent97fd582b91581f0b4cb10c77813f1a284bd69a92
[ELF] Don't shrink RelrSection

Fixes PR43214.

The size of SHT_RELR may oscillate between 2 numbers (see D53003 for a
similar --pack-dyn-relocs=android issue). This can happen if the shrink
of SHT_RELR causes it to take more words to encode relocation offsets
(this can happen with thunks or segments with overlapping p_offset
ranges), and the expansion of SHT_RELR causes it to take fewer words to
encode relocation offsets.

To avoid the issue, add padding 1s to the end of the relocation section
if its size would decrease. Trailing 1s do not decode to more relocations.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D67164

llvm-svn: 370923
lld/ELF/SyntheticSections.cpp
lld/test/ELF/pack-dyn-relocs-relr-loop.s [new file with mode: 0644]