[PATCH] D37059: [ELF] - LTO: do not optimize away symbols accessed from linkerscript.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 09:42:50 PDT 2017


grimar added inline comments.


================
Comment at: ELF/ScriptParser.cpp:632
       // Empty commands are allowed. Do nothing here.
-    } else if (SymbolAssignment *Assign = readProvideOrAssignment(Tok)) {
+    } else if (SymbolAssignment *Assign = readProvideOrAssignment(Tok, false)) {
       Cmd->Commands.push_back(Assign);
----------------
ruiu wrote:
> Why false?
I need to distinguish assignments inside output section declaration and outside (global).
Because for example we have in one of testcases:

 `ONLY_IF_RO { abc = 1; *(foo) }`

And in that case we should not create `abc` at all.
I decided to handle only global assignments for now, probably it can be enough. 
That is why `false`.


================
Comment at: ELF/ScriptParser.cpp:705-707
+    if (Global && Tok != ".")
+      Script->Opt.ReferencedSymbols.push_back(Tok);
+    return Cmd;
----------------
ruiu wrote:
> This function doesn't seem like the best place to do this. Is readAssignment better, isn't it?
Unfortunaly not, because PROVIDE/HIDDEN/PROVIDE_HIDDEN are using it too.

We should not provide symbol that was not referenced. 
When we add it to Opt.ReferencedSymbols it creates undefined symbol and that works like it was referenced.
(https://github.com/llvm-mirror/lld/blob/master/ELF/LinkerScript.cpp#L148)
What breaks PROVIDE logic.


https://reviews.llvm.org/D37059





More information about the llvm-commits mailing list