[PATCH] D39096: [ELF] - Generalize finding output section by name.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 25 15:31:38 PDT 2017


ruiu added inline comments.


================
Comment at: ELF/LinkerScript.cpp:107
+  OutputSection *Sec = NameToOutputSection.lookup(Name);
+  if (!Sec || Sec->Location.empty())
+    return nullptr;
----------------
grimar wrote:
> ruiu wrote:
> > What does `Location.empty()` mean?
> It is the same as check in `LinkerScript::createOutputSection`.
> 
> When we parse scripts, sometimes we have forward references to sections,
> like in following script (from addr-zero.s):
> ```
> SECTIONS { foo = ADDR(.text) - ABSOLUTE(ADDR(.text)); };
> ```
> 
> In that case script parser calls `getOrCreateOutputSection` to declare output section early,
> then `Factory.addInputSec` calls `createOutputSection` to define it and sets `Location`.
> 
> This function returns sections only if it was already defined (processed by factory).
> 
That's too subtle. I couldn't understand it without your explanation, and you won't be able to understand that too if you come back to this code a few years later.

Also, why don't you want to return a forward reference?


https://reviews.llvm.org/D39096





More information about the llvm-commits mailing list