[LLVMdev] [lld] Undefined symbols postprocessing

Shankar Easwaran shankare at codeaurora.org
Mon Feb 23 11:33:12 PST 2015


On 2/20/2015 12:59 AM, Denis Protivensky wrote:
> Joerg:
> How do you then make sure to not export redundant symbols? Consider
> _GLOBAL_OFFSET_TABLE_ -- if the only user is in a dead function, it
> should not be in the symbol table. Same for __tls_get_addr.
> I agree that dead code elimination needs additional consideration, but my problem is that lld pollutes the symbol table inserting symbols unconditionally. I'd want to find a solution to this problem first as it generates even more redundant symbols right now.
>
> Rui:
> 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 func and if there's a reference to __imp_func, 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.
>
> 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.
>
> 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.)
> Looks like your trick won't work for me, because the virtual library you add is parsed in the Resolver::resolve() method where I don't have enough knowledge whether to add specific symbols or not. My problem is that I can only do it in the relocation pass (or some other pass if needed), which goes after symbol resolution.
Not sure why you want to call the Resolver again, wouldnt this API 
suffice ? You can have a new API in the symbol table class called from 
the resolver, with the list of undefined symbols.

Shankar Easwaran

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by the Linux Foundation




More information about the llvm-dev mailing list