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.
Details
Diff Detail
Event Timeline
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.
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.
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 | ||
26 | You added two newlines -- I wanted to make sure that last line ends with "\n" (which didn't). Now it ends with "\n\n". |
Better MemoryRegion existence check
Updates styling
Removes superfluous braces
Removes extra newline
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.
Refactoring has rendered patch irrelevant. Implemented in D32934 for refactored script parser.
Is this guaranteed that MemoryRegion[Name] exists?