<div dir="ltr">Ah, you're right. I tried to copy the existing behavior of the old LLD but I missed that point (and this feature didn't have test). Will fix.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 24, 2015 at 7:39 PM, Peter Collingbourne <span dir="ltr"><<a href="mailto:peter@pcc.me.uk" target="_blank">peter@pcc.me.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Thu, Jun 25, 2015 at 02:21:44AM -0000, Rui Ueyama wrote:<br>
> Author: ruiu<br>
> Date: Wed Jun 24 21:21:44 2015<br>
> New Revision: 240620<br>
><br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D240620-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=RVcHITTvGJEv-iYkDKSbHm31N9MT0c2H1DEf4j9q5BE&s=GKUfSMMacnitADMr0y5DoG_DM5FX7eybr5M0Fb6Ry8c&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=240620&view=rev</a><br>
> Log:<br>
> COFF: Handle undefined symbols starting with __imp_ in a special way.<br>
><br>
> MSVC linker is able to link an object file created from the following code.<br>
> Note that __imp_hello is not defined anywhere.<br>
><br>
>   void hello() { printf("Hello\n"); }<br>
>   extern void (*__imp_hello)();<br>
>   int main() { __imp_hello(); }<br>
><br>
> Function symbols exported from DLLs are automatically mangled by appending<br>
> __imp_ prefix, so they have two names (original one and with the prefix).<br>
> This "feature" seems to simulate that behavior even for non-DLL symbols.<br>
><br>
> This is in my opnion very odd feature. Even MSVC linker warns if you use this.<br>
> I'm adding that anyway for the sake of compatibiltiy.<br>
><br>
> Added:<br>
>     lld/trunk/test/COFF/locally-imported.test<br>
> Modified:<br>
>     lld/trunk/COFF/SymbolTable.cpp<br>
><br>
> Modified: lld/trunk/COFF/SymbolTable.cpp<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_SymbolTable.cpp-3Frev-3D240620-26r1-3D240619-26r2-3D240620-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=RVcHITTvGJEv-iYkDKSbHm31N9MT0c2H1DEf4j9q5BE&s=VArOqRcI7R6e9W02hnSxOb9Mego21XpDo54Ndyxha_A&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=240620&r1=240619&r2=240620&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/COFF/SymbolTable.cpp (original)<br>
> +++ lld/trunk/COFF/SymbolTable.cpp Wed Jun 24 21:21:44 2015<br>
> @@ -70,17 +70,26 @@ bool SymbolTable::reportRemainingUndefin<br>
>      auto *Undef = dyn_cast<Undefined>(Sym->Body);<br>
>      if (!Undef)<br>
>        continue;<br>
> +    StringRef Name = Undef->getName();<br>
>      if (SymbolBody *Alias = Undef->getWeakAlias()) {<br>
>        Sym->Body = Alias->getReplacement();<br>
>        if (!isa<Defined>(Sym->Body)) {<br>
>          // Aliases are yet another symbols pointed by other symbols<br>
>          // that could also remain undefined.<br>
> -        llvm::errs() << "undefined symbol: " << Undef->getName() << "\n";<br>
> +        llvm::errs() << "undefined symbol: " << Name << "\n";<br>
>          Ret = true;<br>
>        }<br>
>        continue;<br>
>      }<br>
> -    llvm::errs() << "undefined symbol: " << Undef->getName() << "\n";<br>
> +    // If we can resolve a symbol by removing __imp_ prefix, do that.<br>
> +    // This odd rule is for compatibility with MSVC linker.<br>
> +    if (Name.startswith("__imp_")) {<br>
> +      if (Defined *Imp = find(Name.substr(strlen("__imp_")))) {<br>
> +        Sym->Body = Imp;<br>
<br>
</div></div>Is it correct to simply strip the prefix? Don't we need to introduce a level<br>
of indirection as if we were creating an import table entry?<br>
<br>
Thanks,<br>
<span class="HOEnZb"><font color="#888888">--<br>
Peter<br>
</font></span></blockquote></div><br></div>