<font size=2 face="sans-serif">Hello Stefan,</font>
<br>
<br><font size=2 face="sans-serif">I'm happy someone replied to my problem!
Many thanks! To be honest... I didn't understood much of your mail. I'm
a beginner with the JIT - so I will explain what I've done.</font>
<br>
<br><font size=2 face="sans-serif">To manage the memory and resolve symbols,
I'm using my own Resolver-Class, which overloads the allocation and the
findSymbol functions. I've noticed today, that the "registerEHFrames"
function of my class gets called automatically, with correct values. I'm
remapping my code and the address are still correct. Great! But, what should
I do with it? I pass the values to the original function, but my exception
won't be caught! It's an exception raised inside the JITTED code and should
also catched there.</font>
<br>
<br><font size=2 face="sans-serif">I tried loading the "msvcrt.lib"
as a archive. That was... a bad idea! I get a Exception while loading:</font>
<br><font size=2 face="sans-serif">Assertion failed: ((int64_t)Result <=
INT32_MAX) && "Relocation overflow", file \lib\executionengine\runtimedyld\Targets/RuntimeDyldCOFFX86_64.h,
line 81</font>
<br>
<br><font size=2 face="sans-serif">Research didn't helped me! My code was
compiled with /MD, but it didn't changed. So I'm still stupid D:</font>
<br><font size=2 face="sans-serif">The JITTED code must be loaded to shared
memory later - there aren't libraries, so even if this would work, it wouldn't
help me. I tried compiling my code with sjlj-exceptions. Didn't worked...</font>
<br>
<br><font size=2 face="sans-serif">Is there no hope left?</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">Stefan Gränitz <stefan.graenitz@gmail.com></font>
<br><font size=1 color=#5f5f5f face="sans-serif">To:
</font><font size=1 face="sans-serif">bjoern.gaier@horiba.com,
llvm-dev@lists.llvm.org</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Date:
</font><font size=1 face="sans-serif">27.09.2017 23:09</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Subject:
</font><font size=1 face="sans-serif">Re: [llvm-dev]
Clang/LLVM JIT - When to use "registerEHFrames()"</font>
<br>
<hr noshade>
<br>
<br>
<br><font size=3>Hi Björn<br>
<br>
To first answer your questionin the subject: For x86 registerEHFrames()
is only a stub. For x86_64 registerEHFrames() is implemented properly in
RuntimeDyldCOFFX86_64, calling MemMgr.registerEHFrames() for each EH frame
section. It should be called and work out of the box without your involvement,
but unfortunately it won't solve your issue. All the essential information
is there in the comments, just check the base classes.<br>
<br>
This thread from last year helps with your unresolved symbol:</font><font size=3 color=blue><u><br>
</u></font><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-October/106458.html"><font size=3 color=blue><u>http://lists.llvm.org/pipermail/llvm-dev/2016-October/106458.html</u></font></a><font size=3><br>
<br>
Back then I tried to solve a related issue: SEH exceptions thrown from
code loaded with RuntimeDyld had to be caught in statically compiled code.
It turned out Windows explicitly prohibits this. I got in touch with Microsoft
people and IIRC it's due to security concerns.<br>
<br>
Depending on your specific case, you may want to fall back to </font><font size=2 face="Calibri">vectored
exception handling. In my experience this was a dead end though. If you
need a solution for arbitrary situations, you just can't jump back to a
"safe" place to continue execution. I tried setjump (on each
entry point to the dynamically loaded code) / longjmp (in the vectored
exception handler), but the address was invalidated when I accessed it.
I suspect it's kind of undefined behavior to call longjmp outside a child
frame of the function that called setjmp. Anyway it turned all far too
hacky.</font><font size=3><br>
<br>
If you are willing to do research, compare implementations and behavior
with the MachO and ELF versions. At least one of them works, just not on
Windows ;)<br>
Also check the LLILC project: </font><a href=https://github.com/dotnet/llilc><font size=3 color=blue><u>https://github.com/dotnet/llilc</u></font></a><font size=3>
I heard about some solution that uses trampolines to push exceptions back
to dynamically loaded code and handle them there.<br>
<br>
AND disclaimer: I did not follow recent developments in this area. If there's
news please let me know!<br>
<br>
Cheers & Good Luck!<br>
Stefan</font>
<p><font size=3>Am 25.09.17 um 11:31 schrieb via llvm-dev:</font>
<br><font size=2 face="sans-serif">Hello friendly LLVM-World,</font><font size=3>
<br>
</font><font size=2 face="sans-serif"><br>
because I don't know if I had send my problem to the correct Mailing-List,
I will send my problem to this address too. I'm not subscribed to this
list, so please add my in CC if you response.</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>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
From: </font><font size=1 face="sans-serif">Bjoern
Gaier/HE/HORIBA</font><font size=3> </font><font size=1 color=#5f5f5f face="sans-serif"><br>
To: </font><font size=1 face="sans-serif">Clang
Dev </font><a href="mailto:cfe-dev@lists.llvm.org"><font size=1 color=blue face="sans-serif"><u><cfe-dev@lists.llvm.org></u></font></a><font size=1 face="sans-serif">,
"cfe-dev" </font><a href="mailto:cfe-dev-bounces@lists.llvm.org"><font size=1 color=blue face="sans-serif"><u><cfe-dev-bounces@lists.llvm.org></u></font></a><font size=3>
</font><font size=1 color=#5f5f5f face="sans-serif"><br>
Date: </font><font size=1 face="sans-serif">19.09.2017
08:05</font><font size=3> </font><font size=1 color=#5f5f5f face="sans-serif"><br>
Subject: </font><font size=1 face="sans-serif">Clang/LLVM
JIT - When to use "registerEHFrames()"</font><font size=3> <br>
</font>
<hr noshade><font size=3><br>
</font><font size=2 face="sans-serif"><br>
Hello friendly Clang-World,</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
I was experimenting with Clang and the JIT capabilities of LLVM. Most of
my attempts were successfully but, I still fail miserably at exceptions.
Doing research I found the function "registerEHFrames()" which
should assist me supporting exceptions - but sadly the documentation I
found wasn't helpful.</font><font size=3> </font><font size=2 face="sans-serif"><br>
I looked at into the "notifyObjectLoaded" function and discovered
that there appear some symbol names starting with "$" - I expected
them to be connected to my try and catch block. But what now? As usually,
at this point I have there names, but can't get there address to register
them with the "registerEHFrames()" function. Also the JITTER
still wants an address for "??_7type_info@@6B@" which is the
virtual table of the type_info struct.</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
Confusing! So friendly Clang-World, could you please help? </font><font size=3><br>
</font><font size=2 face="sans-serif"><br>
Not so important - but has the dragon which decorates clang and LLVM a
name?</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> </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><font size=3> <br>
</font>
<br><tt><font size=3>_______________________________________________<br>
LLVM Developers mailing list<br>
</font></tt><a href="mailto:llvm-dev@lists.llvm.org"><tt><font size=3 color=blue><u>llvm-dev@lists.llvm.org</u></font></tt></a><tt><font size=3><br>
</font></tt><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"><tt><font size=3 color=blue><u>http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</u></font></tt></a><tt><font size=3><br>
</font></tt>
<br><tt><font size=3>-- <br>
</font></tt><a href=https://weliveindetail.github.io/blog/><tt><font size=3 color=blue><u>https://weliveindetail.github.io/blog/</u></font></tt></a><tt><font size=3><br>
</font></tt><a href=https://cryptup.org/pub/stefan.graenitz@gmail.com><tt><font size=3 color=blue><u>https://cryptup.org/pub/stefan.graenitz@gmail.com</u></font></tt></a>
<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>