This is an archive of the discontinued LLVM Phabricator instance.

lld: elf: Fix sections with explict addresses in regions
ClosedPublic

Authored by yodaldevoid on Apr 15 2019, 6:54 PM.

Details

Summary

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.

Diff Detail

Repository
rL LLVM

Event Timeline

yodaldevoid created this revision.Apr 15 2019, 6:54 PM
ruiu accepted this revision.Apr 16 2019, 2:24 AM

LGTM

This change seems correct, although it is a bit tricky and perhaps unnecessary to move . backwards in many linker scripts.

lld/ELF/LinkerScript.cpp
769 ↗(On Diff #195286)

Add () to group & operator for those who don't remember which has a higher predence, & or &&.

This revision is now accepted and ready to land.Apr 16 2019, 2:24 AM
yodaldevoid marked an inline comment as done.Apr 16 2019, 8:16 AM

I have addressed the comment regarding the grouping of operators.

I agree that it is not often that the dot needs to be moved backwards, but if I had not run into this in the wild I would not have looked to fix this issue. GCC's linker handles this fine, for what it's worth.

ruiu added a comment.Apr 17 2019, 12:51 AM

LGTM, please commit.

My last comment was not to you but to generally mention that this is a bit tricky case, which is true, but we need to support that anyway.

Thank you for doing this.

I myself do not have commit access. If someone who does could commit this it would be appreciated.

ruiu added a comment.Apr 17 2019, 7:31 PM

Committed as r358638.

This revision was automatically updated to reflect the committed changes.
grimar added a subscriber: grimar.Apr 18 2019, 5:13 AM
grimar added inline comments.
lld/trunk/test/ELF/linkerscript/out-of-order-section-in-region.s
12

When the test has a large script, we usually make it as a *.test not as *.s.
I did that conversion in rL358659.