<div dir="ltr"><div>On Wed, Feb 18, 2015 at 1:38 AM, Denis Protivensky <span dir="ltr"><<a href="mailto:dprotivensky@accesssoftek.com" target="_blank">dprotivensky@accesssoftek.com</a>></span> wrote:<br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi everyone,<br>
<br>
In lld, I need to conditionally add symbols (like GLOBAL_OFFSET_TABLE)<br>
during<br>
static linking because they may be used by relocations (R_ARM_TLS_IE32) or<br>
by some other stuff like STT_GNU_IFUNC symbols.<br>
The problem is that now symbols are added in a declarative way by<br>
specifying in ExecutableWriter::addDefaultAtoms() override.<br>
At that stage, there's no way to determine if additional symbols are<br>
required.<br>
But libraries providing optimizations like STT_GNU_IFUNC<br>
(glibc, for example) expect the GOT symbol to be defined, so the linking<br>
process<br>
fails in Resolver::resolve() if the symbol is not found.<br></blockquote><div><br></div><div>I don't know if this is directly applicable to your problem, but for PE/COFF I needed to add symbols conditionally. If you have a function <i>func</i> and if there's a reference to __imp_<i>func</i>, linker needs to create a data containing the address of func as __imp_func content. It's rarely used, so I wanted to create the __imp_ atom only when there's an unresolved reference to that symbol.</div><div><br></div><div>What I did at that moment is to define a (virtual) library file which dynamically creates an atom. The virtual library file is added at end of the input file list, and if the core linker looks it up for a symbol starting __imp_, the library creates an object file containing the symbol on the fly and returns it.</div><div><br></div><div>My experience of doing that is that worked but might have been too tricky. If this trick is directly applicable to your problem, you may want to do that. If not, I'm perhaps okay with your suggestion (although I didn't think about that hard yet.)</div><div><br></div><div>Thanks</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I propose to add the ability to ignore undefined symbols during initial<br>
resolution, and then postprocess only those undefines for the second time<br>
after the pass manager execution.<br>
<br>
Technically, this shouldn't be a problem:<br>
- there will be a new option in the linking context that should signal<br>
that the postprocessing of undefined symbols should be performed.<br>
- if postprocessing option is set, newly added symbols will be collected<br>
in the MergedFile returned by the Resolver, and then only those new symbols<br>
will take part in the resolution process very similar to what<br>
Resolver::resolve() does.<br>
- available implementations will not break and keep working without use of<br>
postprocessing feature.<br>
<br>
So my proposal is to move from the declarative style towards imperative<br>
and more flexible approach. Of course, there's a downside as the code<br>
loses some of its regularity and becomes more volatile, but in the end -<br>
we have tests to cover such things and ensure everything works as expected.<br>
<br>
Any ideas?<br>
<br>
- Denis Protivensky.<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div></div>