<font size=2 face="sans-serif">Hello Lang,</font>
<br>
<br><font size=2 face="sans-serif">thanks for your answer! With small steps
I'm coming to my goal.</font>
<br>
<br><font size=2 face="sans-serif">But I don't know what to do with "NotifyObjectLoaded".
So I overloaded the function and can now access the sections. Soo... I
allocate memory in my sharedmemory for the sections and use mapSectionAddress
to change the addresses. But how do I copy the memory in the finalizeMemory
method? I don't have access to the section anymore!</font>
<br><font size=2 face="sans-serif">Plus, is there a way to reallocate global
variables too, which aren't declared as extern - give them another memory
location? I see these values with "symbols" in "NotifyObjectLoaded",
but I don't have an address for them.</font>
<br><font size=2 face="sans-serif">And... can I load .obj files, which
Visual Studio had generated?</font>
<br>
<br><font size=2 face="sans-serif">Kind regards</font>
<br><font size=2 face="sans-serif">Björn</font>
<br>
<br>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">From:      
 </font><font size=1 face="sans-serif">Lang Hames <lhames@gmail.com></font>
<br><font size=1 color=#5f5f5f face="sans-serif">To:      
 </font><font size=1 face="sans-serif">bjoern.gaier@horiba.com,
Clang Dev <cfe-dev@lists.llvm.org>, LLVM Developers Mailing List
<llvm-dev@lists.llvm.org></font>
<br><font size=1 color=#5f5f5f face="sans-serif">Date:      
 </font><font size=1 face="sans-serif">07.05.2017 04:37</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Subject:    
   </font><font size=1 face="sans-serif">Re: [cfe-dev]
JIT doens't resolve address - Resolve obj-Addresses?</font>
<br>
<hr noshade>
<br>
<br>
<br><font size=3>Hi Bjoern,</font>
<br>
<br><font size=3>CCing cfg-dev (since that's where the conversation started)
and llvm-dev (since it's relevant there).</font>
<br>
<br><font size=3>Do you know if there is a way to obtain the fully resolved
obj-code? I wanted to load the functions into a shared memory, but how?
The only thing I receive is a function pointer, but I don't know how large
the function 'behind' is. Even a call to _msize (windows) does only resolve
in a crash. </font>
<br>
<br><font size=3>You can access the fully-resolved object code on a per-section
basis (there is no easy way to do it per-function) by using a custom memory
manager, rather than SectionMemoryManager.</font>
<br>
<br><font size=3>There are two ways to go about this:</font>
<br>
<br><font size=3>(1) The easy way (only valid for shared-memory on the
same machine) is to allocate the sections directly out of shared memory
(by overriding allocateCodeSection/allocateDataSection).</font>
<br>
<br><font size=3>(2) The hard way (which is general enough to allow you
to copy the relocated bytes to remote machines) is three part:</font>
<br><font size=3>(a) Allocate the sections locally (e.g. using malloc,
or inheriting from SectionMemoryManager and capturing the allocation details)</font>
<br><font size=3>(b) Override the notifyObjectLoaded method to allocate
the final memory locations, then call RTDyldMemoryManager::mapSectionAddress
to map each local allocation to its corresponding final address</font>
<br><font size=3>(c) Override finalizeMemory to copy the relocated bytes
to their final addresses</font>
<br>
<br><font size=3>Hope this helps.</font>
<br>
<br><font size=3>Cheers,</font>
<br><font size=3>Lang.</font>
<br>
<br>
<br>
<br>
<br><font size=3>On Tue, May 2, 2017 at 10:47 PM, <</font><a href=mailto:bjoern.gaier@horiba.com target=_blank><font size=3 color=blue><u>bjoern.gaier@horiba.com</u></font></a><font size=3>>
wrote:</font>
<br><font size=2 face="sans-serif">Hello Lang,</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
your answer explained a lot to me, thank you for that. Do you know if there
is a way to obtain the fully resolved obj-code? I wanted to load the functions
into a shared memory, but how? The only thing I receive is a function pointer,
but I don't know how large the function 'behind' is. Even a call to _msize
(windows) does only resolve in a crash.</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
Kind regards</font><font size=3> </font><font size=2 face="sans-serif"><br>
Björn</font><font size=3> <br>
<br>
<br>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
From:        </font><font size=1 face="sans-serif">Lang
Hames <</font><a href=mailto:lhames@gmail.com target=_blank><font size=1 color=blue face="sans-serif"><u>lhames@gmail.com</u></font></a><font size=1 face="sans-serif">></font><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
To:        </font><a href=mailto:bjoern.gaier@horiba.com target=_blank><font size=1 color=blue face="sans-serif"><u>bjoern.gaier@horiba.com</u></font></a><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
Cc:        </font><a href=mailto:willdtz@gmail.com target=_blank><font size=1 color=blue face="sans-serif"><u>willdtz@gmail.com</u></font></a><font size=1 face="sans-serif">,
Clang Dev <</font><a href="mailto:cfe-dev@lists.llvm.org" target=_blank><font size=1 color=blue face="sans-serif"><u>cfe-dev@lists.llvm.org</u></font></a><font size=1 face="sans-serif">></font><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
Date:        </font><font size=1 face="sans-serif">01.05.2017
20:15</font><font size=3> </font><font size=1 color=#5f5f5f face="sans-serif"><br>
Subject:        </font><font size=1 face="sans-serif">Re:
[cfe-dev] JIT doens't resolve address - Resolve obj-Addresses?</font><font size=3>
<br>
</font>
<hr noshade>
<br><font size=3><br>
<br>
<br>
Hi Björn, <br>
<br>
I tried using your code and now it works! I'm happy and surprised! <br>
<br>
Oh - I missed that Will's code had fixed your issue. That's great. :) <br>
<br>
Do you know if there is a way to directly load .obj-Files and resolve the
references with own addresses? Like when somebody used printf in the generated
obj-File, but I replace the address with my own printf?  <br>
<br>
You can load precompiled object files by calling addObjectSet on the ObjectLayer.
<br>
<br>
All external symbol references are resolved by the JITSymbolResolver that
is created by createLambdaResolver. In your example the resolution process
is two-step: First the JIT searches its own function definitions to see
if there is a function called "printf" defined there (this is
what the call to CompileLayer.findSymbol does): <br>
</font><tt><font size=3><br>
[&](const std::string &Name)  {</font></tt><font size=3> </font><tt><font size=3><br>
  printf("FLUSH :0\n");</font></tt><font size=3> </font><tt><font size=3><br>
  if (auto Sym = CompileLayer.findSymbol(Name, false))</font></tt><font size=3>
</font><tt><font size=3><br>
    return Sym;</font></tt><font size=3> </font><tt><font size=3><br>
  return JITSymbol(nullptr);</font></tt><font size=3> </font><tt><font size=3><br>
}</font></tt><font size=3> <br>
<br>
Then, if it doesn't find a definition there, it falls back to searching
in the current process (this is what RTDyldMemoryManager::getSymbolAddressInProcess
does): <br>
</font><tt><font size=3><br>
[](const std::string &S)  { </font></tt><font size=3> </font><tt><font size=3><br>
  printf("PLUSH :0\n"); </font></tt><font size=3> </font><tt><font size=3><br>
  if (auto SymAddr = </font></tt><font size=3> </font><tt><font size=3><br>
        RTDyldMemoryManager::getSymbolAddressInProcess(S)) </font></tt><font size=3>
</font><tt><font size=3><br>
    return JITSymbol(SymAddr, JITSymbolFlags::Exported); </font></tt><font size=3>
</font><tt><font size=3><br>
  return JITSymbol(nullptr); </font></tt><font size=3> </font><tt><font size=3><br>
}</font></tt><font size=3> <br>
<br>
If, for example, you wanted to redirect calls to printf to your own custom
version (while resolving all other externals by the normal process) you
could change the second lambda like so: <br>
</font><tt><font size=3><br>
[](const std::string &S)  { </font></tt><font size=3> </font><tt><font size=3><br>
  printf("PLUSH :0\n");</font></tt><font size=3> </font><tt><font size=3><br>
  if (S == mangleName("printf"))</font></tt><font size=3>
</font><tt><font size=3><br>
    return JITSymbol((JITSymbolAddress)&myCustomPrintf,</font></tt><font size=3>
</font><tt><font size=3><br>
                     JITSymbolFlags::Exported);</font></tt><font size=3>
</font><tt><font size=3><br>
  if (auto SymAddr = </font></tt><font size=3> </font><tt><font size=3><br>
        RTDyldMemoryManager::getSymbolAddressInProcess(S)) </font></tt><font size=3>
</font><tt><font size=3><br>
    return JITSymbol(SymAddr, JITSymbolFlags::Exported); </font></tt><font size=3>
</font><tt><font size=3><br>
  return JITSymbol(nullptr); </font></tt><font size=3> </font><tt><font size=3><br>
}</font></tt><font size=3> <br>
<br>
(You'll just have to pull the mangling logic from findSymbol out into its
own "mangleName" function for this). <br>
<br>
Hope this helps. <br>
<br>
Cheers, <br>
Lang. <br>
<br>
<br>
On Sun, Apr 23, 2017 at 11:08 PM, <</font><a href=mailto:bjoern.gaier@horiba.com target=_blank><font size=3 color=blue><u>bjoern.gaier@horiba.com</u></font></a><font size=3>>
wrote: </font><font size=2 face="sans-serif"><br>
Hello Mr. Dietz,</font><font size=3> </font><font size=2 face="sans-serif"><br>
<br>
I tried using your code and now it works! I'm happy and surprised! I will
now compare the codes and try to spot the main difference! Thanks for your
help!</font><font size=3> </font><font size=2 face="sans-serif"><br>
Do you know if there is a way to directly load .obj-Files and resolve the
references with own addresses? Like when somebody used printf in the generated
obj-File, but I replace the address with my own printf?</font><font size=3>
</font><font size=2 face="sans-serif"><br>
<br>
Kind regards</font><font size=3> </font><font size=2 face="sans-serif"><br>
Björn</font><font size=3> <br>
<br>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
<br>
From:        </font><font size=1 face="sans-serif">Will
Dietz <</font><a href=mailto:willdtz@gmail.com target=_blank><font size=1 color=blue face="sans-serif"><u>willdtz@gmail.com</u></font></a><font size=1 face="sans-serif">></font><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
To:        </font><a href=mailto:bjoern.gaier@horiba.com target=_blank><font size=1 color=blue face="sans-serif"><u>bjoern.gaier@horiba.com</u></font></a><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
Cc:        </font><font size=1 face="sans-serif">Lang
Hames <</font><a href=mailto:lhames@gmail.com target=_blank><font size=1 color=blue face="sans-serif"><u>lhames@gmail.com</u></font></a><font size=1 face="sans-serif">>,
Clang Dev <</font><a href="mailto:cfe-dev@lists.llvm.org" target=_blank><font size=1 color=blue face="sans-serif"><u>cfe-dev@lists.llvm.org</u></font></a><font size=1 face="sans-serif">></font><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
Date:        </font><font size=1 face="sans-serif">21.04.2017
21:50</font><font size=3> </font><font size=1 color=#5f5f5f face="sans-serif"><br>
Subject:        </font><font size=1 face="sans-serif">Re:
[cfe-dev] JIT doens't resolve address</font><font size=3> </font><font size=1 color=#5f5f5f face="sans-serif"><br>
Sent by:        </font><a href=mailto:w@wdtz.org target=_blank><font size=1 color=blue face="sans-serif"><u>w@wdtz.org</u></font></a><font size=3>
<br>
</font>
<hr noshade><font size=3><br>
<br>
<br>
Hmm, I tried using your code (copy+pasted and then mass-dumped headers
to fix includes), and it seems to work fine for me: </font><font size=3 color=blue><u><br>
<br>
</u></font><a href="https://gist.github.com/dtzWill/df84b64a73001532e3fcfe73a2cffbb9#file-test-log" target=_blank><font size=3 color=blue><u>https://gist.github.com/dtzWill/df84b64a73001532e3fcfe73a2cffbb9#file-test-log</u></font></a><font size=3>
<br>
<br>
Do you get different results when using your LLVM? If not, can you identify
the differences between your code and what I constructed from your snippets?
<br>
<br>
I noticed "PAUSE", are you on Windows? I'm not sure what the
functionality/status of the JIT on Windows is, perhaps someone else can
comment on that. <br>
<br>
~Will <br>
<br>
On Fri, Apr 21, 2017 at 1:03 AM, via cfe-dev <</font><a href="mailto:cfe-dev@lists.llvm.org" target=_blank><font size=3 color=blue><u>cfe-dev@lists.llvm.org</u></font></a><font size=3>>
wrote: </font><font size=2 face="sans-serif"><br>
Hello Lang,</font><font size=3> </font><font size=2 face="sans-serif"><br>
<br>
the Code for my jit_main is a normal printf-HelloWorld program. I opended
the file with notepad and found the following:</font><font size=3> </font>
<table width=100% style="border-collapse:collapse;">
<tr valign=top height=8>
<td width=100% style="border-style:solid solid solid solid;border-color:#000000;border-width:1px 1px 1px 1px;padding:1px 1px;"><font size=2 face="sans-serif">;
Function Attrs: noinline norecurse uwtable</font><font size=3> </font><font size=2 face="sans-serif"><br>
define i32 @main() #0 {</font><font size=3> </font><font size=2 face="sans-serif"><br>
entry:</font><font size=3> </font><font size=2 face="sans-serif"><br>
  %retval = alloca i32, align 4</font><font size=3> </font><font size=2 face="sans-serif"><br>
  store i32 0, i32* %retval, align 4</font><font size=3> </font><font size=2 face="sans-serif"><br>
  %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35
x i8], [35 x i8]* @"\01??_C@_0CD@CMJEAMCD@Planschbeckilein?5sagt?5Halloilein@",
i32 0, i32 0))</font><font size=3> </font><font size=2 face="sans-serif"><br>
  %call1 = call i32 @system(i8* getelementptr inbounds ([6 x i8],
[6 x i8]* @"\01??_C@_05DIAHPDGL@PAUSE?$AA@", i32 0, i32 0))</font><font size=3>
</font><font size=2 face="sans-serif"><br>
  ret i32 0</font><font size=3> </font><font size=2 face="sans-serif"><br>
}</font></table>
<br><font size=3><br>
</font><font size=2 face="sans-serif"><br>
<br>
<br>
So... there is a main... Anyway! The code for the main is this one:</font><font size=3>
</font>
<table width=100% style="border-collapse:collapse;">
<tr valign=top height=8>
<td width=100% style="border-style:solid solid solid solid;border-color:#000000;border-width:1px 1px 1px 1px;padding:1px 1px;"><font size=1 color=#808080>#include</font><font size=1>
</font><font size=1 color=#a11f12><stdio.h></font><font size=3> </font><font size=1 color=#808080><br>
#include</font><font size=1> </font><font size=1 color=#a11f12><stdlib.h></font><font size=3>
</font><font size=1 color=blue><br>
<br>
int</font><font size=1> main()</font><font size=3> </font><font size=1><br>
{</font><font size=3> </font><font size=1><br>
        printf(</font><font size=1 color=#a11f12>"Planschbeckilein
sagt Halloilein!\n"</font><font size=1>);</font><font size=3> </font><font size=1><br>
        system(</font><font size=1 color=#a11f12>"PAUSE"</font><font size=1>);</font><font size=3>
</font><font size=1><br>
<br>
        </font><font size=1 color=blue>return</font><font size=1>
0;</font><font size=3> </font><font size=1><br>
}</font></table>
<br><font size=3><br>
</font><font size=2 face="sans-serif"><br>
<br>
<br>
Kind regards</font><font size=3> </font><font size=2 face="sans-serif"><br>
Björn</font><font size=3> <br>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
<br>
<br>
From:        </font><font size=1 face="sans-serif">Lang
Hames <</font><a href=mailto:lhames@gmail.com target=_blank><font size=1 color=blue face="sans-serif"><u>lhames@gmail.com</u></font></a><font size=1 face="sans-serif">></font><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
To:        </font><a href=mailto:bjoern.gaier@horiba.com target=_blank><font size=1 color=blue face="sans-serif"><u>bjoern.gaier@horiba.com</u></font></a><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
Cc:        </font><font size=1 face="sans-serif">Clang
Dev <</font><a href="mailto:cfe-dev@lists.llvm.org" target=_blank><font size=1 color=blue face="sans-serif"><u>cfe-dev@lists.llvm.org</u></font></a><font size=1 face="sans-serif">></font><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
Date:        </font><font size=1 face="sans-serif">20.04.2017
22:54</font><font size=3> </font><font size=1 color=#5f5f5f face="sans-serif"><br>
Subject:        </font><font size=1 face="sans-serif">Re:
[cfe-dev] JIT doens't resolve address</font><font size=3> <br>
</font>
<hr noshade><font size=3><br>
<br>
<br>
<br>
Hi Bjoern, <br>
<br>
Sorry - I just noticed that the address for your "main" function
has come back as '0'. In this case the answer is even simpler: The JIT
never found the function at all, and so definitely didn't have any external
symbols to resolve, so it never called the resolver. <br>
<br>
A failure to find main has three likely causes: <br>
<br>
(1) jit_main.ll does not define main, <br>
(2) jit_main.ll defines main with private/internal linkage (the JIT can't
see private/internal symbols in general) <br>
(3) jit_main.ll defines main with external linkage, but a system mangling
is applied (e.g. on MacOSX 'main' is mangled to '_main'). The mangler
code in your findSymbol function *should* correct for this, but this
may fail if the default data layout for your TargetMachine varies from
the Module's DataLayout. <br>
<br>
Can you share the contents of your jit_main.ll Module? <br>
<br>
Cheers, <br>
Lang. <br>
    <br>
<br>
On Thu, Apr 20, 2017 at 1:35 PM, Lang Hames <</font><a href=mailto:lhames@gmail.com target=_blank><font size=3 color=blue><u>lhames@gmail.com</u></font></a><font size=3>>
wrote: <br>
HI Bjoern, <br>
<br>
There are two kinds of symbol lookup in the JIT: <br>
<br>
(1) You want to find a symbol defined JIT'd code. This is what "findSymbol"
on the JIT class does. <br>
<br>
(2) The JIT wants to fix up a module that contains references to symbols
defined elsewhere (either in your program, or in other JIT'd code). This
is the SymbolResolver's job. <br>
<br>
So assuming your main function in main.ll is trivial, e.g. </font><tt><font size=3><br>
<br>
int main() {</font></tt><font size=3> </font><tt><font size=3><br>
  return 0;</font></tt><font size=3> </font><tt><font size=3><br>
}</font></tt><font size=3> <br>
<br>
then your findSymbol call will return the address of the JIT'd main without
ever needing to look anything up in the resolver. <br>
<br>
If, on the other hand, your main function contains an external reference,
e.g. </font><tt><font size=3><br>
<br>
int main() {</font></tt><font size=3> </font><tt><font size=3><br>
  printf("Hello, World!"); // Reference to externally defined
function printf.</font></tt><font size=3> </font><tt><font size=3><br>
  return 0;</font></tt><font size=3> </font><tt><font size=3><br>
}</font></tt><font size=3> <br>
<br>
Then you'll receive a call back on your resolver looking for the address
of printf. <br>
<br>
Hope this helps! <br>
<br>
Cheers, <br>
Lang. <br>
<br>
On Thu, Apr 20, 2017 at 6:43 AM, via cfe-dev <</font><a href="mailto:cfe-dev@lists.llvm.org" target=_blank><font size=3 color=blue><u>cfe-dev@lists.llvm.org</u></font></a><font size=3>>
wrote: </font><font size=2 face="sans-serif"><br>
Hello LLVM-World,</font><font size=3> </font><font size=2 face="sans-serif"><br>
<br>
I was following the "Building a JIT in LLVM"-Tutorial and tried
to load a normal main. My code is the following:</font><font size=3> </font>
<table width=100% style="border-collapse:collapse;">
<tr valign=top height=8>
<td width=100% style="border-style:solid solid solid solid;border-color:#000000;border-width:1px 1px 1px 1px;padding:1px 1px;"><font size=1 color=blue>class</font><font size=1>
</font><font size=1 color=#4181c0>Jitter</font><font size=3> </font><font size=1><br>
{</font><font size=3> </font><font size=1 color=blue><br>
private</font><font size=1>:</font><font size=3> </font><font size=1><br>
  std::</font><font size=1 color=#4181c0>unique_ptr</font><font size=1><</font><font size=1 color=#4181c0>TargetMachine</font><font size=1>>
TM;</font><font size=3> </font><font size=1><br>
  </font><font size=1 color=blue>const</font><font size=1> </font><font size=1 color=#4181c0>DataLayout</font><font size=1>
DL;</font><font size=3> </font><font size=1><br>
  </font><font size=1 color=#4181c0>ObjectLinkingLayer</font><font size=1><>
ObjectLayer;</font><font size=3> </font><font size=1><br>
  </font><font size=1 color=#4181c0>IRCompileLayer</font><font size=1><</font><font size=1 color=blue>decltype</font><font size=1>(ObjectLayer)>
CompileLayer;</font><font size=3> </font><font size=1 color=blue><br>
<br>
public</font><font size=1>:</font><font size=3> </font><font size=1><br>
  </font><font size=1 color=blue>typedef</font><font size=1> </font><font size=1 color=blue>decltype</font><font size=1>(CompileLayer)::</font><font size=1 color=#4181c0>ModuleSetHandleT</font><font size=1>
</font><font size=1 color=#4181c0>ModuleHandle</font><font size=1>;</font><font size=3>
</font><font size=1><br>
<br>
  Jitter() : TM(</font><font size=1 color=#4181c0>EngineBuilder</font><font size=1>().selectTarget()),
DL(TM</font><font size=1 color=#008080>-></font><font size=1>createDataLayout()),</font><font size=3>
</font><font size=1><br>
      CompileLayer(ObjectLayer, </font><font size=1 color=#4181c0>SimpleCompiler</font><font size=1>(</font><font size=1 color=#008080>*</font><font size=1>TM))
<br>
  {printf(</font><font size=1 color=#a11f12>"!"</font><font size=1>);</font><font size=3>
</font><font size=1><br>
        llvm::sys::</font><font size=1 color=#4181c0>DynamicLibrary</font><font size=1>::LoadLibraryPermanently(</font><font size=1 color=blue>nullptr</font><font size=1>);</font><font size=3>
</font><font size=1><br>
  }</font><font size=3> </font><font size=1><br>
<br>
  </font><font size=1 color=#4181c0>TargetMachine</font><font size=1>
&getTargetMachine() { </font><font size=1 color=blue>return</font><font size=1>
</font><font size=1 color=#008080>*</font><font size=1>TM; }</font><font size=3>
</font><font size=1><br>
<br>
  </font><font size=1 color=#4181c0>ModuleHandle</font><font size=1>
addModule(std::</font><font size=1 color=#4181c0>unique_ptr</font><font size=1><</font><font size=1 color=#4181c0>Module</font><font size=1>>
&&</font><font size=1 color=#808080>M</font><font size=1>) {</font><font size=3>
</font><font size=1><br>
  </font><font size=1 color=#008000>// Build our symbol resolver:</font><font size=3>
</font><font size=1><br>
  </font><font size=1 color=#008000>// Lambda 1: Look back into the
JIT itself to find symbols that are part of</font><font size=3> </font><font size=1><br>
  </font><font size=1 color=#008000>//        
  the same "logical dylib".</font><font size=3> </font><font size=1><br>
  </font><font size=1 color=#008000>// Lambda 2: Search for external
symbols in the host process.</font><font size=3> </font><font size=1><br>
  </font><font size=1 color=blue>auto</font><font size=1> Resolver
= createLambdaResolver(</font><font size=3> </font><font size=1><br>
      [&](</font><font size=1 color=blue>const</font><font size=1>
std::</font><font size=1 color=#4181c0>string</font><font size=1> &</font><font size=1 color=#808080>Name</font><font size=1>)
<br>
      {</font><font size=3> </font><font size=1><br>
                printf(</font><font size=1 color=#a11f12>"FLUSH
:0\n"</font><font size=1>);</font><font size=3> </font><font size=1><br>
<br>
        </font><font size=1 color=blue>if</font><font size=1>
(</font><font size=1 color=blue>auto</font><font size=1> Sym = CompileLayer.findSymbol(</font><font size=1 color=#808080>Name</font><font size=1>,
</font><font size=1 color=blue>false</font><font size=1>))</font><font size=3>
</font><font size=1><br>
          </font><font size=1 color=blue>return</font><font size=1>
Sym;</font><font size=3> </font><font size=1><br>
        </font><font size=1 color=blue>return</font><font size=1>
</font><font size=1 color=#4181c0>JITSymbol</font><font size=1>(</font><font size=1 color=blue>nullptr</font><font size=1>);</font><font size=3>
</font><font size=1><br>
      },</font><font size=3> </font><font size=1><br>
      [](</font><font size=1 color=blue>const</font><font size=1>
std::</font><font size=1 color=#4181c0>string</font><font size=1> &</font><font size=1 color=#808080>S</font><font size=1>)
<br>
          {</font><font size=3> </font><font size=1><br>
                  printf(</font><font size=1 color=#a11f12>"PLUSH
:0\n"</font><font size=1>);</font><font size=3> </font><font size=1><br>
<br>
        </font><font size=1 color=blue>if</font><font size=1>
(</font><font size=1 color=blue>auto</font><font size=1> SymAddr =</font><font size=3>
</font><font size=1><br>
              </font><font size=1 color=#4181c0>RTDyldMemoryManager</font><font size=1>::getSymbolAddressInProcess(</font><font size=1 color=#808080>S</font><font size=1>))</font><font size=3>
</font><font size=1><br>
          </font><font size=1 color=blue>return</font><font size=1>
</font><font size=1 color=#4181c0>JITSymbol</font><font size=1>(SymAddr,
</font><font size=1 color=#4181c0>JITSymbolFlags</font><font size=1>::</font><font size=1 color=#37605e>Exported</font><font size=1>);</font><font size=3>
</font><font size=1><br>
        </font><font size=1 color=blue>return</font><font size=1>
</font><font size=1 color=#4181c0>JITSymbol</font><font size=1>(</font><font size=1 color=blue>nullptr</font><font size=1>);</font><font size=3>
</font><font size=1><br>
      });</font><font size=3> </font><font size=1><br>
<br>
  </font><font size=1 color=#008000>// Build a singleton module set
to hold our module.</font><font size=3> </font><font size=1><br>
  std::</font><font size=1 color=#4181c0>vector</font><font size=1><std::</font><font size=1 color=#4181c0>unique_ptr</font><font size=1><</font><font size=1 color=#4181c0>Module</font><font size=1>>>
Ms;</font><font size=3> </font><font size=1><br>
  Ms.push_back(std::move(</font><font size=1 color=#808080>M</font><font size=1>));</font><font size=3>
</font><font size=1><br>
<br>
  </font><font size=1 color=#008000>// Add the set to the JIT with
the resolver we created above and a newly</font><font size=3> </font><font size=1><br>
  </font><font size=1 color=#008000>// created SectionMemoryManager.</font><font size=3>
</font><font size=1><br>
  </font><font size=1 color=blue>return</font><font size=1> CompileLayer.addModuleSet(std::move(Ms),</font><font size=3>
</font><font size=1><br>
                     
             make_unique<</font><font size=1 color=#4181c0>SectionMemoryManager</font><font size=1>>(),</font><font size=3>
</font><font size=1><br>
                     
             std::move(Resolver));</font><font size=3>
</font><font size=1><br>
}</font><font size=3> </font><font size=1 color=#4181c0><br>
<br>
JITSymbol</font><font size=1> findSymbol(</font><font size=1 color=blue>const</font><font size=1>
std::</font><font size=1 color=#4181c0>string</font><font size=1> </font><font size=1 color=#808080>Name</font><font size=1>)
{</font><font size=3> </font><font size=1><br>
  std::</font><font size=1 color=#4181c0>string</font><font size=1>
MangledName;</font><font size=3> </font><font size=1><br>
  </font><font size=1 color=#4181c0>raw_string_ostream</font><font size=1>
MangledNameStream(MangledName);</font><font size=3> </font><font size=1><br>
  </font><font size=1 color=#4181c0>Mangler</font><font size=1>::getNameWithPrefix(MangledNameStream,
</font><font size=1 color=#808080>Name</font><font size=1>, DL);</font><font size=3>
</font><font size=1><br>
  printf(</font><font size=1 color=#a11f12>"Tzearch for: %s\n\n"</font><font size=1>,
MangledNameStream.str());</font><font size=3> </font><font size=1><br>
  </font><font size=1 color=blue>return</font><font size=1> CompileLayer.findSymbol(MangledNameStream.str(),
</font><font size=1 color=blue>false</font><font size=1>);</font><font size=3>
</font><font size=1><br>
}</font><font size=3> </font><font size=1 color=blue><br>
<br>
void</font><font size=1> removeModule(</font><font size=1 color=#4181c0>ModuleHandle</font><font size=1>
</font><font size=1 color=#808080>H</font><font size=1>) {</font><font size=3>
</font><font size=1><br>
  CompileLayer.removeModuleSet(</font><font size=1 color=#808080>H</font><font size=1>);</font><font size=3>
</font><font size=1><br>
}</font><font size=3> </font><font size=1><br>
<br>
};</font></table>
<br><font size=2 face="sans-serif"><br>
<br>
<br>
<br>
<br>
And calling from main with:</font><font size=3> </font>
<table width=100% style="border-collapse:collapse;">
<tr valign=top height=8>
<td width=100% style="border-style:solid solid solid solid;border-color:#000000;border-width:1px 1px 1px 1px;padding:1px 1px;"><font size=1 color=blue>int</font><font size=1>
main()</font><font size=3> </font><font size=1><br>
{</font><font size=3> </font><font size=1><br>
        llvm::InitializeNativeTarget();</font><font size=3>
</font><font size=1><br>
        llvm::InitializeNativeTargetAsmPrinter();</font><font size=3>
</font><font size=1><br>
        llvm::InitializeNativeTargetAsmParser();</font><font size=3>
</font><font size=1><br>
<br>
        llvm::</font><font size=1 color=#4181c0>LLVMContext</font><font size=1>
context;</font><font size=3> </font><font size=1><br>
        llvm::</font><font size=1 color=#4181c0>SMDiagnostic</font><font size=1>
dia;</font><font size=3> </font><font size=1><br>
<br>
        std::</font><font size=1 color=#4181c0>unique_ptr</font><font size=1><llvm::</font><font size=1 color=#4181c0>Module</font><font size=1>>
M = llvm::parseIRFile(</font><font size=1 color=#a11f12>"./jit_main.ll"</font><font size=1>,
dia, context);</font><font size=3> </font><font size=1><br>
        </font><font size=1 color=#4181c0>Jitter</font><font size=1>
jit;</font><font size=3> </font><font size=1><br>
        printf(</font><font size=1 color=#a11f12>"Wuff?"</font><font size=1>);</font><font size=3>
</font><font size=1><br>
        </font><font size=1 color=#4181c0>Jitter</font><font size=1>::</font><font size=1 color=#4181c0>ModuleHandle</font><font size=1>
h = jit.addModule(std::move(M));</font><font size=3> </font><font size=1><br>
        printf(</font><font size=1 color=#a11f12>"KNUFF!\n"</font><font size=1>);</font><font size=3>
</font><font size=1><br>
<br>
        printf(</font><font size=1 color=#a11f12>"Kuchen!
0x%p\n"</font><font size=1>, jit.findSymbol(</font><font size=1 color=#a11f12>"main"</font><font size=1>).getAddress());</font><font size=3>
</font><font size=1><br>
<br>
        system(</font><font size=1 color=#a11f12>"PAUSE"</font><font size=1>);</font><font size=3>
</font><font size=1><br>
        </font><font size=1 color=blue>return</font><font size=1>
0;</font><font size=3> </font><font size=1><br>
}</font></table>
<br><font size=2 face="sans-serif"><br>
<br>
<br>
<br>
The Code runs without a fail, but when the programm tries to resolve "main"
the address is 0. The strange thing: the printf "</font><font size=1 color=#a11f12>FLUSH
:0\n</font><font size=2 face="sans-serif">" and "</font><font size=1 color=#a11f12>PLUSH
:0\n</font><font size=2 face="sans-serif">" are never called, so did
the code never compiled? What I'm doing wrong?</font><font size=3> </font><font size=2 face="sans-serif"><br>
<br>
Kind regards</font><font size=3> </font><font size=2 face="sans-serif"><br>
Björn<br>
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr.
DE 114 165 789<br>
Geschäftsführer: Hiroshi Kawamura, Dr Hiroshi Nakamura, Markus Bode, Heiko
Lampert, Takashi Nagano, Takeshi Fukushima.</font><font size=3> <br>
_______________________________________________<br>
cfe-dev mailing list</font><font size=3 color=blue><u><br>
</u></font><a href="mailto:cfe-dev@lists.llvm.org" target=_blank><font size=3 color=blue><u>cfe-dev@lists.llvm.org</u></font></a><font size=3 color=blue><u><br>
</u></font><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target=_blank><font size=3 color=blue><u>http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</u></font></a><font size=3><br>
<br>
</font><font size=2 face="sans-serif"><br>
<br>
<br>
<br>
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr.
DE 114 165 789<br>
Geschäftsführer: Hiroshi Kawamura, Dr Hiroshi Nakamura, Markus Bode, Heiko
Lampert, Takashi Nagano, Takeshi Fukushima.</font><font size=3> <br>
<br>
_______________________________________________<br>
cfe-dev mailing list</font><font size=3 color=blue><u><br>
</u></font><a href="mailto:cfe-dev@lists.llvm.org" target=_blank><font size=3 color=blue><u>cfe-dev@lists.llvm.org</u></font></a><font size=3 color=blue><u><br>
</u></font><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target=_blank><font size=3 color=blue><u>http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</u></font></a><font size=3><br>
<br>
</font><font size=2 face="sans-serif"><br>
<br>
<br>
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr.
DE 114 165 789<br>
Geschäftsführer: Hiroshi Kawamura, Dr Hiroshi Nakamura, Markus Bode, Heiko
Lampert, Takashi Nagano, Takeshi Fukushima.</font><font size=3> <br>
<br>
</font><font size=2 face="sans-serif"><br>
<br>
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr.
DE 114 165 789<br>
Geschäftsführer: Hiroshi Kawamura, Dr Hiroshi Nakamura, Markus Bode, Heiko
Lampert, Takashi Nagano, Takeshi Fukushima.</font>
<br>
<br>
<br><font size=2 face="sans-serif"><br>
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr.
DE 114 165 789<br>
Geschäftsführer: Hiroshi Kawamura, Dr Hiroshi Nakamura, Markus Bode, Heiko
Lampert, Takashi Nagano, Takeshi Fukushima.</font>