<div dir="ltr">Hi Russell,<div><br></div><div>Thanks for looking in to this.</div><div><br></div><div>The root cause of this problem is in libObject - ELF and MachO objects both set the Exported flag on their symbols correctly, but COFF currently does not. The Right Thing to do here would be to fix libObject, but nobody has found time for that yet. In the mean time the workaround you've discovered works just fine.</div><div><br></div><div>- Lang.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 31, 2016 at 6:48 PM, Russell Wallace via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Addendum: this still fails:<div><br></div><div><div>      auto ExprSymbol = J.findSymbol("putchard");</div></div><div><br></div><div> As yet, I have no idea why - that symbol even seemed to be exported:</div><div><br></div><div><div>extern "C"</div><div>double putchard(double X) {</div><div>  putchar((char)X);</div><div>  return 0;</div><div>}</div></div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 1, 2016 at 2:42 AM, Russell Wallace <span dir="ltr"><<a href="mailto:russell.wallace@gmail.com" target="_blank">russell.wallace@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">To try to find out why it was crashing, I followed the trail of function calls:<div><br></div><div><div>C:\llvm\examples\Kaleidoscope\Orc\initial\toy.cpp</div><div><br></div><div>      auto ExprSymbol = J.findUnmangledSymbol("__anon_expr");</div><div><br></div><div>  JITSymbol findUnmangledSymbol(const std::string Name) {</div><div>    return findSymbol(mangle(Name));</div><div>  }</div><div><br></div><div>  JITSymbol findSymbol(const std::string &Name) {</div><div>    return CompileLayer.findSymbol(Name, true);</div><div>  }</div><div><br></div><div>  CompileLayerT CompileLayer;</div><div>  typedef IRCompileLayer<ObjLayerT> CompileLayerT;</div><div><br></div><div>C:\llvm\include\llvm\ExecutionEngine\Orc\IRCompileLayer.h</div><div><br></div><div>template <typename BaseLayerT> class IRCompileLayer {</div><div><br></div><div>  JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {</div><div>    return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);</div><div>  }</div><div><br></div><div>C:\llvm\examples\Kaleidoscope\Orc\initial\toy.cpp</div><div><br></div><div>  typedef ObjectLinkingLayer<> ObjLayerT;</div><div><br></div><div>C:\llvm\include\llvm\ExecutionEngine\Orc\ObjectLinkingLayer.h</div><div><br></div><div>  JITSymbol findSymbol(StringRef Name, bool ExportedSymbolsOnly) {</div><div>    for (auto I = LinkedObjSetList.begin(), E = LinkedObjSetList.end(); I != E;</div><div>         ++I)</div><div>      if (auto Symbol = findSymbolIn(I, Name, ExportedSymbolsOnly))</div><div>        return Symbol;</div><div><br></div><div>  JITSymbol findSymbolIn(ObjSetHandleT H, StringRef Name,</div><div>                         bool ExportedSymbolsOnly) {</div><div>    if (auto Sym = (*H)->getSymbol(Name)) {</div></div><div><div>C:\llvm\examples\Kaleidoscope\Orc\initial\toy.cpp</div><div><br></div><div>      auto ExprSymbol = J.findUnmangledSymbol("__anon_expr");</div><div><br></div><div>  JITSymbol findUnmangledSymbol(const std::string Name) {</div><div>    return findSymbol(mangle(Name));</div><div>  }</div><div><br></div><div>  JITSymbol findSymbol(const std::string &Name) {</div><div>    return CompileLayer.findSymbol(Name, true);</div><div>  }</div><div><br></div><div>  CompileLayerT CompileLayer;</div><div>  typedef IRCompileLayer<ObjLayerT> CompileLayerT;</div><div><br></div><div>C:\llvm\include\llvm\ExecutionEngine\Orc\IRCompileLayer.h</div><div><br></div><div>template <typename BaseLayerT> class IRCompileLayer {</div><div><br></div><div>  JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {</div><div>    return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);</div><div>  }</div><div><br></div><div>C:\llvm\examples\Kaleidoscope\Orc\initial\toy.cpp</div><div><br></div><div>  typedef ObjectLinkingLayer<> ObjLayerT;</div><div><br></div><div>C:\llvm\include\llvm\ExecutionEngine\Orc\ObjectLinkingLayer.h</div><div><br></div><div>  JITSymbol findSymbol(StringRef Name, bool ExportedSymbolsOnly) {</div><div>    for (auto I = LinkedObjSetList.begin(), E = LinkedObjSetList.end(); I != E;</div><div>         ++I)</div><div>      if (auto Symbol = findSymbolIn(I, Name, ExportedSymbolsOnly))</div><div>        return Symbol;</div><div><br></div><div>  JITSymbol findSymbolIn(ObjSetHandleT H, StringRef Name,</div><div>                         bool ExportedSymbolsOnly) {</div><div>    if (auto Sym = (*H)->getSymbol(Name)) {</div></div><div><div>      if (Sym.isExported() || !ExportedSymbolsOnly) {</div></div><div><br></div><div>and after putting in some debugging code, it turns out this is it - the client wants exported symbols only, but the expression is not exported. This is the easiest change to fix the problem:</div><div><br></div><div><div>  JITSymbol findSymbol(const std::string &Name) {</div><div>    return CompileLayer.findSymbol(Name, false);</div><div>  }</div></div><div><br></div><div> but is it the right one? Or should the symbol be exported instead?</div></div>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>