This is an archive of the discontinued LLVM Phabricator instance.

[LLD] Add memory ORIGIN and LENGTH expression support
AbandonedPublic

Authored by raidiun on Feb 9 2017, 10:57 AM.

Details

Reviewers
evgeny777
ruiu
Summary

Adds support for the ORIGIN and MEMORY functions in expression parsing.
ORIGIN produces an absolute address based on the memory section it references.
LENGTH produces the length of the referenced memory section.

Diff Detail

Event Timeline

raidiun created this revision.Feb 9 2017, 10:57 AM
ruiu added inline comments.Feb 9 2017, 11:01 AM
ELF/LinkerScript.cpp
1871

Is this guaranteed that MemoryRegion[Name] exists?

1872

Fix indentation

1876

Ditto

test/ELF/linkerscript/symbol-memoryexpr.s
34

Please add a newline at end.

raidiun updated this revision to Diff 87845.Feb 9 2017, 11:10 AM
raidiun removed a subscriber: llvm-commits.

Fixes indentation and newline.

raidiun marked 3 inline comments as done.Feb 9 2017, 11:14 AM

No, MemoryRegion[Name] is not guaranteed to exist.

Is a call to setError sufficient to generate the error?
Should probably also add a test case for this.

raidiun updated this revision to Diff 87854.Feb 9 2017, 12:04 PM
raidiun added a subscriber: llvm-commits.

Add parse-time checking for existence of MemoryRegion and test case for undefined region.
NB: Error is triggered if MEMORY definitions come after SECTION. Not sure how ld handles this.

raidiun marked an inline comment as done.Feb 9 2017, 12:09 PM
ruiu added inline comments.Feb 9 2017, 1:09 PM
ELF/LinkerScript.cpp
1871

I believe that if a linker script file contains MEMORY commands, they must appear before any SECTIONS commands. Therefore, we can check the existence of MemoryRegions[Name] outside the lambdas. (And raising an error early is better than doing that in the lambdas.)

1873

Why return has braces?

1877

Please format this patch in the LLVM style.

test/ELF/linkerscript/symbol-memoryexpr.s
34

You added two newlines -- I wanted to make sure that last line ends with "\n" (which didn't). Now it ends with "\n\n".

raidiun updated this revision to Diff 87870.Feb 9 2017, 1:50 PM

Better MemoryRegion existence check
Updates styling
Removes superfluous braces
Removes extra newline

ruiu edited edge metadata.Feb 9 2017, 1:57 PM

Almost fine, a few nits.

ELF/LinkerScript.cpp
1871

Do s/ScriptConfig/Opt/g

(Opt is an alias to ScriptConfig in this class.)

OK to use Opt in ifs at 1871 and 1877.
Using Opt in lambdas results in segfault. Presumably instance is gone by the time the lambda expressions are called. Could evaluate outside lambda expressions if preferred.
Similar pattern is used in lambdas for other commands (e.g. line 1868) accessing ScriptBase (LinkerScript.h:314).
ScriptBase->Opt may improve consistency but is currently private.

ruiu accepted this revision.Feb 9 2017, 2:27 PM

LGTM

This revision is now accepted and ready to land.Feb 9 2017, 2:27 PM
raidiun abandoned this revision.May 6 2017, 2:06 AM

Refactoring has rendered patch irrelevant. Implemented in D32934 for refactored script parser.