lld: elf: Fix sections with explict addresses in regions
authorRui Ueyama <ruiu@google.com>
Thu, 18 Apr 2019 02:32:12 +0000 (02:32 +0000)
committerRui Ueyama <ruiu@google.com>
Thu, 18 Apr 2019 02:32:12 +0000 (02:32 +0000)
commit14ef9b30b6833358bc8adceec9231121fe17c1a3
treeb46b96f56ffab41cbbfea4655a819bb612fab007
parent92663376563d69d96399116050b2f7b2ffe9b8d0
lld: elf: Fix sections with explict addresses in regions

Patch by Gabriel Smith.

The address for a section would be evaluated before the region was
switched to. Because of this, the position within the region would not
be updated. After the region is swapped to the dot would be set to the
out of date position within the region, undoing the section address
evaluation.

To fix this, the region is swapped to before the section's address is
evaluated. As part of the fallout of this, expandMemoryRegions needed
to be gated in setDot on the condition that the evaluated address is
less than the dot. This is for the case where sections are not listed
from lowest address to highest address.

Finally, a test for the case where sections are listed "out of order"
was added.

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

llvm-svn: 358638
lld/ELF/LinkerScript.cpp
lld/test/ELF/linkerscript/out-of-order-section-in-region.s [new file with mode: 0644]