<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:-webkit-standard;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p.gmail-m-2595300190310052765msolistparagraph, li.gmail-m-2595300190310052765msolistparagraph, div.gmail-m-2595300190310052765msolistparagraph
        {mso-style-name:gmail-m_-2595300190310052765msolistparagraph;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:387802570;
        mso-list-template-ids:-1792114880;}
@list l0:level1
        {mso-level-start-at:2;
        mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1
        {mso-list-id:668951310;
        mso-list-template-ids:-1210409016;}
@list l1:level1
        {mso-level-start-at:2;
        mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l2
        {mso-list-id:799303291;
        mso-list-template-ids:-1981759634;}
@list l3
        {mso-list-id:1532690606;
        mso-list-template-ids:2101139776;}
@list l3:level1
        {mso-level-start-at:2;
        mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l3:level2
        {mso-level-start-at:2;
        mso-level-tab-stop:72.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l4
        {mso-list-id:1996176763;
        mso-list-template-ids:-858107724;}
@list l4:level1
        {mso-level-start-at:3;
        mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hello Lang and Praveen – and everyone else,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">To 1.)<br>
When I tried using “<span style="font-size:9.5pt;font-family:Consolas;color:blue">int</span><span style="font-size:9.5pt;font-family:Consolas;color:black"> (*function)() = (</span><span style="font-size:9.5pt;font-family:Consolas;color:blue">int</span><span style="font-size:9.5pt;font-family:Consolas;color:black">(*)())jit</span><span style="font-size:9.5pt;font-family:Consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:Consolas;color:black">lookup(</span><span style="font-size:9.5pt;font-family:Consolas;color:#A31515">"helloOrc"</span><span style="font-size:9.5pt;font-family:Consolas;color:black">);</span><span style="color:black">”
 the function was not found again – from your and Praveens answer I thought this would work.<br>
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’?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">To 2.)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">However, your suggestion is really interesting Lang – I want to try this.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">To 3.)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">Thank you for sharing the code, that also helped!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">Thank you so far!  This answered a lot of my questions!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">Kind greetings<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">Björn<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>From:</b> Lang Hames <lhames@gmail.com> <br>
<b>Sent:</b> Montag, 16. September 2019 23:41<br>
<b>To:</b> Gaier, Bjoern <Bjoern.Gaier@horiba.com><br>
<b>Subject:</b> Re: [llvm-dev] Questions after completed Kaleidoscope Chapter 1<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Hi Bjoern,<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"> <span style="font-family:"-webkit-standard",serif;color:black"> </span><o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"-webkit-standard",serif;color:black">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.<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-family:"-webkit-standard",serif;color:black"> <o:p></o:p></span></p>
<ol start="1" type="1">
<li class="gmail-m-2595300190310052765msolistparagraph" style="color:black;mso-list:l2 level1 lfo1">
<span style="font-family:"-webkit-standard",serif">What is the use of “</span><span style="font-family:Consolas">MangleAndInterner</span><span style="font-family:"-webkit-standard",serif">”?<br>
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</span><span style="font-family:Consolas">“?helloOrc@@YAHXZ</span><span style="font-family:"-webkit-standard",serif">”
 with the lookup method – that worked.<o:p></o:p></span></li></ol>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:"-webkit-standard",serif;color:black">Now I tried “</span><span style="font-family:Consolas;color:black">int helloOrc()</span><span style="font-family:"-webkit-standard",serif;color:black">”
 and it failed/did not found the function. Then I tried</span><span style="font-family:Consolas;color:black">“?helloOrc@@YAHXZ</span><span style="font-family:"-webkit-standard",serif;color:black">” again but removed the use of the “</span><span style="font-family:Consolas;color:black">MangleAndInterner</span><span style="font-family:"-webkit-standard",serif;color:black">”
 instance – that worked again.<br>
<br>
What is that instance used for?<o:p></o:p></span></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<ol start="2" type="1">
<li class="gmail-m-2595300190310052765msolistparagraph" style="mso-list:l1 level1 lfo2">
JIT session error<o:p></o:p></li></ol>
<p class="gmail-m-2595300190310052765msolistparagraph">When I first run the JIT, the message “<span style="font-family:Consolas">JIT session error: Symbols not found: { __security_check_cookie, __security_cookie }</span>” was printed into the console.
<o:p></o:p></p>
<ol start="2" type="1">
<ol start="1" type="1">
<li class="gmail-m-2595300190310052765msolistparagraph" style="mso-list:l0 level2 lfo3">
Origin<br>
Is that message coming from "<span style="font-family:Consolas">DynamicLibrarySearchGenerator</span>”?<o:p></o:p></li></ol>
</ol>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<ol start="2" type="1">
<ol start="2" type="1">
<li class="gmail-m-2595300190310052765msolistparagraph" style="mso-list:l3 level2 lfo4">
Redirect<br>
Can I somehow redirect this message to a string or something, or silence it? I want to keep my console output clean.<o:p></o:p></li></ol>
</ol>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">This is usually a pretty serious error. Is the tutorial code still working despite displaying this?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">If these values are genuinely referenced but not used then I would be inclined to add them as null absolute symbols:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">JITEvaluatedSymbol NullSymbolDef(0x0, JITSymbolFlags::Exported);</span><o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">if (auto Err = JD.define(absoluteSymbols({{ES.intern("__security_check_cookie"), NullSymbolDef},</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">                                           ES.intern("__security_cookie"), NullSymbolDef})))</span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">  return Err;</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<ol start="3" type="1">
<li class="gmail-m-2595300190310052765msolistparagraph" style="mso-list:l4 level1 lfo5">
Generator function<o:p></o:p></li></ol>
<p class="gmail-m-2595300190310052765msolistparagraph">Why does the generator function looks like this: “<span style="font-family:Consolas">SymbolNameSet(JITDylib &Parent, const SymbolNameSet &Names)”?</span><br>
<br>
I understood, that the “<span style="font-family:Consolas">Parent</span>” will be the value from “<span style="font-family:Consolas">ES.getMainJITDylib()</span>” while “<span style="font-family:Consolas">Names</span>” will have the names that should be resolved.
 I saw an implementation for the Generator function that kinda looked like that:<br>
<span style="font-family:Consolas">{</span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:Consolas">      orc::SymbolNameSet Added;</span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:Consolas">      orc::SymbolMap     NewSymbols;</span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:Consolas"> </span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:Consolas">      for(auto &Name : Names)
</span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:Consolas">      {</span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:Consolas">            Added.insert(Name);</span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:Consolas">            NewSymbols[Name] = //Something</span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:Consolas">      }</span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:Consolas"> </span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:Consolas">      Parent.define(absoluteSymbols(std::move(NewSymbols)));</span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:Consolas">      return Added;</span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"><span style="font-family:Consolas">}</span><o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph"> <o:p></o:p></p>
<p class="gmail-m-2595300190310052765msolistparagraph">I understood that “<span style="font-family:Consolas">SymbolMap NewSymbols</span>” will store a pair of name and the address to resolve – but why do I tell the JITDylib about this?<br>
And why do I also keep a map of the symbols I added and have to return them? (<span style="font-family:Consolas">SymbolNameSet Added</span>)<o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal">The lookup algorithm pseudocode within a JITDylib looks like:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">void lookup(Query &Q, SymbolNameSet Unresolved) {</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">  lookupWithoutFallback(Q, Unresolved);</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">  if (!Unresolved.empty() && Generator) {</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">    auto NewDefs = Generator(*this, Unresolved);</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">    lookupWithoutFallback(Q, NewDefs);</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">  }</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">}</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Hope this helps!<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> -- Lang.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I hope my questions are not too stupid and that someone can help me with that!<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Thank you a lot x3<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Kind greetings<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Björn<o:p></o:p></p>
</div>
<p class="MsoNormal">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
<o:p></o:p></p>
</div>
<p class="MsoNormal">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</div>
</div>
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
</body>
</html>