[llvm-dev] Questions after completed Kaleidoscope Chapter 1

Gaier, Bjoern via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 16 23:29:42 PDT 2019


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



From: Lang Hames <lhames at gmail.com>
Sent: Montag, 16. September 2019 23:41
To: Gaier, Bjoern <Bjoern.Gaier at horiba.com>
Subject: Re: [llvm-dev] Questions after completed Kaleidoscope Chapter 1

Hi Bjoern,

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.


  1.  What is the use of “MangleAndInterner”?
I read it is used to mangle the name for the lookup search, but I seem to be not able to use it correctly. In my first attempt I used the mangled name of my function“?helloOrc@@YAHXZ” with the lookup method – that worked.

Now I tried “int helloOrc()” and it failed/did not found the function. Then I tried“?helloOrc@@YAHXZ” again but removed the use of the “MangleAndInterner” instance – that worked again.

What is that instance used for?
As the name suggests, it performs both mangling and interning. In this context "mangling" means linker mangling, not language mangling (e.g. C++ name mangling). The problem it's trying to solve is that some platforms map C names directly to symbol names (e.g. Linux), but others modify the name to avoid clashes with assembly symbol names (e.g. Darwin, where C names have an underscore prefix added). Internally ORC always deals with linker mangled names to match the behavior of the system linker and dynamic loader. The "interning" part is for performance: ORC uniques all its symbols in a string pool to save memory and improve string comparison performance. So MangleAndInterner takes a C symbol name, applies linker mangling, interns the resulting string value in the string pool, and then returns you a SymbolStringPtr to the pool entry.


  1.  JIT session error

When I first run the JIT, the message “JIT session error: Symbols not found: { __security_check_cookie, __security_cookie }” was printed into the console.

     *   Origin
Is that message coming from "DynamicLibrarySearchGenerator”?

No: That would be comping from the JIT linker, RuntimeDyld. Those symbols must have been referenced in the IR, though I'm not familiar with them.


     *   Redirect
Can I somehow redirect this message to a string or something, or silence it? I want to keep my console output clean.

This is usually a pretty serious error. Is the tutorial code still working despite displaying this?

If these values are genuinely referenced but not used then I would be inclined to add them as null absolute symbols:

JITEvaluatedSymbol NullSymbolDef(0x0, JITSymbolFlags::Exported);
if (auto Err = JD.define(absoluteSymbols({{ES.intern("__security_check_cookie"), NullSymbolDef},
                                           ES.intern("__security_cookie"), NullSymbolDef})))
  return Err;



  1.  Generator function

Why does the generator function looks like this: “SymbolNameSet(JITDylib &Parent, const SymbolNameSet &Names)”?

I understood, that the “Parent” will be the value from “ES.getMainJITDylib()” while “Names” will have the names that should be resolved. I saw an implementation for the Generator function that kinda looked like that:
{

      orc::SymbolNameSet Added;

      orc::SymbolMap     NewSymbols;



      for(auto &Name : Names)

      {

            Added.insert(Name);

            NewSymbols[Name] = //Something

      }



      Parent.define(absoluteSymbols(std::move(NewSymbols)));

      return Added;

}



I understood that “SymbolMap NewSymbols” will store a pair of name and the address to resolve – but why do I tell the JITDylib about this?
And why do I also keep a map of the symbols I added and have to return them? (SymbolNameSet Added)
The lookup algorithm pseudocode within a JITDylib looks like:

void lookup(Query &Q, SymbolNameSet Unresolved) {
  lookupWithoutFallback(Q, Unresolved);
  if (!Unresolved.empty() && Generator) {
    auto NewDefs = Generator(*this, Unresolved);
    lookupWithoutFallback(Q, NewDefs);
  }
}

It is written this way to eliminate differences in handling between lazily generated and regular symbol definitions: they both go through the same path, lazy generation just has an extra step.

Hope this helps!

 -- Lang.


I hope my questions are not too stupid and that someone can help me with that!
Thank you a lot x3

Kind greetings
Björn
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
_______________________________________________
LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190917/65dd4179/attachment-0001.html>


More information about the llvm-dev mailing list