Page MenuHomePhabricator

[ELF] Fix incorrect physical address on self-referencing AT command
ClosedPublic

Authored by erickreyes on Dec 19 2017, 10:40 AM.

Details

Reviewers
ruiu
rafael
Group Reviewers
lld
Summary

When a section placement (AT) command references the section itself, the physical address of the section in the ELF header was calculated incorrectly due to alignment happening right after the location pointer's value was captured.

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

erickreyes created this revision.Dec 19 2017, 10:40 AM
ruiu added a comment.Dec 26 2017, 1:18 AM

This looks good, but I wonder in what situation you want to define a self-referencing LMA. (I just want to understand the problem better.)

erickreyes added a comment.EditedJan 2 2018, 12:39 PM
In D41403#964012, @ruiu wrote:

This looks good, but I wonder in what situation you want to define a self-referencing LMA. (I just want to understand the problem better.)

I ran into this problem when trying to link the Linux kernel with lld. There are a lot of sections defined like this in arm64:

.rodata : AT(ADDR(.rodata) - 0)

Since the linker script is generated, I guess there are situations where an offset is applied to the section address (zero in this case).

ruiu accepted this revision.Jan 9 2018, 5:34 PM

LGTM

This revision is now accepted and ready to land.Jan 9 2018, 5:34 PM

Replaced the patch with Rafael's version, which avoids computing section alignment twice

Do you have commit access?