Questions after completed Kaleidoscope Chapter 1

Hello there,

I finished Chapter 1 of the Kaleidoscope tutorial for using the Orc JIT API. I played around with some things and ended with some questions.

(adding Lang Hames, Orcish Scientist, for Orc-related queries)

Hi Bjoren,

For question 1:
As you mentioned, it is used to mangle to the symbol name and interning them, So ORC can find them at runtime in one of the JITDylibs. It would be helpful to know what you tried? (please attach code lines).

For question 2:
I guess you might be missing to link libraries that your program depend on, you can do that via setting up your dynamiclibrary search generator or getCurrentProcess symbols. Plus, Why do you want to hide them, it is an error?

For question 3:
Currently, every symbol whether it is added via generator or not, must be defined in a JITDylib. It is more of a design choice, it makes implementation and resolution logic much easier within ORC.

Thanks
Praveen

Hey Praveen – and everyone else,

For 1.)

In my “Main.cpp” file I used

int (function)() = (int()())jit->lookup("?helloOrc@@YAHXZ");

While the lookup looked like that:

uintptr_t lookup(StringRef Name)

{

auto result = this->es.lookup({&this->es.getMainJITDylib()}, this->mangle(Name.str()));

if(result)

{

return result->getAddress();

}

return 0x0;

}

Basically – it is the code from the tutorial, besides I wanted it to return an unintpr_t.
Anyway, if I remove “this->mangle(Name.str())” and use “Name.str()” instead - then it is still working. This is why I wonder, why that call is important.

A call like:
int (function)() = (int()())jit->lookup(“int helloOrc()”);
Never worked.

For 2.)
I solved the problem by exporting the missing symbols, I just wanted to understand if the error is coming from the “DynamicLibrarySearchGenerator” and if I can silence it to keep my console output clean.

For 3.)

I understand that!

Thank you so much for this x3

Kind greetings

Björn

Hi Bjoern,
Only mangling names should not work, in other words you have to mangle the name according to your platform and intern the symbol to the Execution session. ORC plays with interned symbols.

There is an overload of lookup which receives the mangled name and intern it internally in it’s implementation. So either way can work for you!

The Symbol name is the function name - So try just lookup(“helloORC”).

Let me know, if it solves the problem.

Cheers,
Praveen

Hello Lang and Praveen – and everyone else,

To 1.)
When I tried using “int (function)() = (int()())jit->lookup(“helloOrc”);” the function was not found again – from your and Praveens answer I thought this would work.
I don’t mind using the MSVC C++ mangled name, but it as a certain convenience to not have to. Is there a Clang or a LLVM function I can use to mangle from ‘int helloOrc()’ to ‘?helloOrc@@YAHXZ’?

To 2.)

I was using the tutorial from the LLVM website – “__security_check_cookie and __security_cookie” must be defined to work. What I did is: I added “/EXPORT:__security_check_cookie /EXPORT:__security_cookie” to the linker command line of the Visual Studio compiler. Then It worked.

However, your suggestion is really interesting Lang – I want to try this.

To 3.)

Thank you for sharing the code, that also helped!

Thank you so far! This answered a lot of my questions!

Kind greetings

Björn