Kaleidoscope on Windows - bug maybe found?

To try to find out why it was crashing, I followed the trail of function calls:

C:\llvm\examples\Kaleidoscope\Orc\initial\toy.cpp

auto ExprSymbol = J.findUnmangledSymbol("__anon_expr");

JITSymbol findUnmangledSymbol(const std::string Name) {
return findSymbol(mangle(Name));
}

JITSymbol findSymbol(const std::string &Name) {
return CompileLayer.findSymbol(Name, true);
}

CompileLayerT CompileLayer;
typedef IRCompileLayer CompileLayerT;

C:\llvm\include\llvm\ExecutionEngine\Orc\IRCompileLayer.h

template class IRCompileLayer {

JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
}

C:\llvm\examples\Kaleidoscope\Orc\initial\toy.cpp

typedef ObjectLinkingLayer<> ObjLayerT;

C:\llvm\include\llvm\ExecutionEngine\Orc\ObjectLinkingLayer.h

JITSymbol findSymbol(StringRef Name, bool ExportedSymbolsOnly) {
for (auto I = LinkedObjSetList.begin(), E = LinkedObjSetList.end(); I != E;
++I)
if (auto Symbol = findSymbolIn(I, Name, ExportedSymbolsOnly))
return Symbol;

JITSymbol findSymbolIn(ObjSetHandleT H, StringRef Name,
bool ExportedSymbolsOnly) {
if (auto Sym = (*H)->getSymbol(Name)) {

C:\llvm\examples\Kaleidoscope\Orc\initial\toy.cpp

auto ExprSymbol = J.findUnmangledSymbol("__anon_expr");

JITSymbol findUnmangledSymbol(const std::string Name) {
return findSymbol(mangle(Name));
}

JITSymbol findSymbol(const std::string &Name) {
return CompileLayer.findSymbol(Name, true);
}

CompileLayerT CompileLayer;
typedef IRCompileLayer CompileLayerT;

C:\llvm\include\llvm\ExecutionEngine\Orc\IRCompileLayer.h

template class IRCompileLayer {

JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
}

C:\llvm\examples\Kaleidoscope\Orc\initial\toy.cpp

typedef ObjectLinkingLayer<> ObjLayerT;

C:\llvm\include\llvm\ExecutionEngine\Orc\ObjectLinkingLayer.h

JITSymbol findSymbol(StringRef Name, bool ExportedSymbolsOnly) {
for (auto I = LinkedObjSetList.begin(), E = LinkedObjSetList.end(); I != E;
++I)
if (auto Symbol = findSymbolIn(I, Name, ExportedSymbolsOnly))
return Symbol;

JITSymbol findSymbolIn(ObjSetHandleT H, StringRef Name,
bool ExportedSymbolsOnly) {
if (auto Sym = (*H)->getSymbol(Name)) {

if (Sym.isExported() || !ExportedSymbolsOnly) {

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:

JITSymbol findSymbol(const std::string &Name) {
return CompileLayer.findSymbol(Name, false);
}

but is it the right one? Or should the symbol be exported instead?

Addendum: this still fails:

auto ExprSymbol = J.findSymbol(“putchard”);

As yet, I have no idea why - that symbol even seemed to be exported:

extern “C”
double putchard(double X) {
putchar((char)X);
return 0;
}

Hi Russell,

Thanks for looking in to this.

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.

  • Lang.