This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Align the value if needed when computing the expression
ClosedPublic

Authored by phosek on Jul 19 2017, 4:23 PM.

Details

Reviewers
ruiu

Diff Detail

Repository
rL LLVM

Event Timeline

phosek created this revision.Jul 19 2017, 4:23 PM
ruiu edited edge metadata.Jul 19 2017, 8:18 PM

I think what you were looking for is ExprValue::getValue().

In D35651#815595, @ruiu wrote:

I think what you were looking for is ExprValue::getValue().

That's what I tried initially, but I don't think it's correct. The problem is that if I use {A.Sec, A.ForceAbsolute, A.getValue() + B.getValue(), A.Loc}, the section offset (if A.Sec != nullptr) will get applied twice. If I use A.getValue() + B.getValue() the resulting expression will be absolute and not section relative as it should be if A is.

grimar added a subscriber: grimar.Jul 19 2017, 11:02 PM

Testcase ? :)

phosek updated this revision to Diff 107447.Jul 19 2017, 11:43 PM
phosek edited the summary of this revision. (Show Details)
phosek edited the summary of this revision. (Show Details)

Added a test case, which revealed another issue: while trying PROVIDE_HIDDEN(newsym = ALIGN(_end, CONSTANT(MAXPAGESIZE)) + 5);, I noticed it was working fine in our project but not in LLD. Turned the problem is that we also use a linker script which defines PROVIDE_HIDDEN(_end = .). However, when using only input linker script, this breaks because LLD only finalizes the _end value in fixPredefinedSymbols after all symbol assignment commands have been processed, so newsym will get a wrong value. This change still fixes the case when script is being used.

ruiu added a comment.Jul 20 2017, 8:36 AM

The test you added doesn't seem to exercise the code you added. Don't you need something like ALIGN(3, 8) + 10 to test that?

phosek updated this revision to Diff 107596.Jul 20 2017, 3:39 PM
In D35651#816244, @ruiu wrote:

The test you added doesn't seem to exercise the code you added. Don't you need something like ALIGN(3, 8) + 10 to test that?

I have added few more test cases. This one is still useful because it checks that the relative case works with alignment (i.e. it'd break if we used A.getValue() + B.getValue() or A.getValue() - B.getValue()).

ruiu accepted this revision.Jul 20 2017, 3:42 PM

LGTM

This revision is now accepted and ready to land.Jul 20 2017, 3:42 PM
phosek closed this revision.Jul 20 2017, 4:31 PM