<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body>
    Hi Björn<br>
    <br>
    I made a workaround for this specific issue a long time ago for the
    Projucer C++ JIT Engine. It basically forwards the call to another
    stub that provides enough space to encode a full 64-bit address. The
    patch is based on LLVM 3.9, so I guess it won't work out-of-the-box
    on a recent release, but it may give you enough hints to figure it
    out on your own:<br>
<a class="moz-txt-link-freetext" href="https://github.com/weliveindetail/pj-llvm/commit/97cd336d458ae9c73232d1b539ceefcdb2f5eb0f">https://github.com/weliveindetail/pj-llvm/commit/97cd336d458ae9c73232d1b539ceefcdb2f5eb0f</a><br>
    <br>
    Alternatively, you could consider a memory manager that makes sure
    all calls are within a 32-bit range. For the code you JIT yourself,
    this should be no problem. In case you have to link against an old
    MSVCRT though, this is not possible, because it has a fixed load
    address that's far beyond the 32-bit range from any heap allocation
    you can make for your JITed code. That's been our issue back then
    and so this patch was the last resort.<br>
    <br>
    Please also note: this is for freestanding function only. I didn't
    consider member function calls, etc. (addend is always 0) because it
    was not relevant for the specific issue.<br>
    <br>
    Hope it helps<br>
    Stefan<br>
    <br>
    <div class="moz-cite-prefix">On 21/08/2020 13:22, Gaier, Bjoern via
      llvm-dev wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:OSBPR01MB36086724D6DF1071815A1D02E25B0@OSBPR01MB3608.jpnprd01.prod.outlook.com">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></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]-->
      <div class="WordSection1">
        <p class="MsoNormal"><span lang="EN-GB">I figured out that this
            problem is caused because “planschiValue” has a REL32
            relocation and the addresses between the code and the
            variable overflows 32bit.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-GB">Is there any workaround
            for this kind of issue?<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
        <div>
          <div style="border:none;border-top:solid #E1E1E1
            1.0pt;padding:3.0pt 0cm 0cm 0cm">
            <p class="MsoNormal"><b><span
                  style="mso-fareast-language:DE" lang="EN-US">From:</span></b><span
                style="mso-fareast-language:DE" lang="EN-US"> llvm-dev
                <a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev-bounces@lists.llvm.org"><llvm-dev-bounces@lists.llvm.org></a>
                <b>On Behalf Of </b>Gaier, Bjoern via llvm-dev<br>
                <b>Sent:</b> 20 August 2020 12:15<br>
                <b>To:</b> LLVM Developers Mailing List
                <a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org"><llvm-dev@lists.llvm.org></a>; Lang Hames
                <a class="moz-txt-link-rfc2396E" href="mailto:lhames@gmail.com"><lhames@gmail.com></a><br>
                <b>Subject:</b> [llvm-dev] ORC JIT - Incorrect support
                for COFF files?<o:p></o:p></span></p>
          </div>
        </div>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal"><span lang="EN-GB">Hey LLVM-Mailing-List
            and Lang,<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-GB">I’m still learning how
            to use the ORC JIT but I finally reached the point to JIT
            and execute some code. For this purpose I created a test
            file (TestModule.cpp) and compiled it with Clang, generating
            two different files, one in the LLVM IR format and one in
            the Microsoft COFF format.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
        <p class="MsoNormal"
          style="margin-bottom:12.0pt;text-autospace:none"><span
            lang="EN-GB">The JIT resolves all undefined references,
            including “</span><span
            style="font-size:9.5pt;font-family:Consolas;color:blue"
            lang="EN-GB">extern</span><span
            style="font-size:9.5pt;font-family:Consolas;color:black"
            lang="EN-GB">
          </span><span
            style="font-size:9.5pt;font-family:Consolas;color:blue"
            lang="EN-GB">int</span><span
            style="font-size:9.5pt;font-family:Consolas;color:black"
            lang="EN-GB"> planschiValue;</span><span lang="EN-GB">” and
            “</span><span
            style="font-size:9.5pt;font-family:Consolas;color:blue"
            lang="EN-GB">void</span><span
            style="font-size:9.5pt;font-family:Consolas;color:black"
            lang="EN-GB"> externFunction();</span><span lang="EN-GB">”.
            Using the IR Module I will get the correct address for
            “planschiValue” and the correct value – however this is not
            the case for the object file.<o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            lang="EN-GB">For the object file I get (via printf from the
            module) the address 0x000002295D6B003C while the actual
            address is 0x00007FF71D9959A4.
            <o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            lang="EN-GB"><o:p> </o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            lang="EN-GB">I’m really surprised about this, because the IR
            module works with no problem. I attach the source code, the
            IR file and the resulting object file (including its
            assembly file).<o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            lang="EN-GB"><o:p> </o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            lang="EN-GB">Any ideas what I’m doing wrong?<o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            lang="EN-GB"><o:p> </o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            lang="EN-GB">Thank you for the help in advance and kind
            greetings<o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            lang="EN-GB">Björn<o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            lang="EN-GB"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:DE">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, Junichi Tajika, Ergin Cansiz. <o:p></o:p></span></p>
      </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, Junichi Tajika, Ergin Cansiz.
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="https://flowcrypt.com/pub/stefan.graenitz@gmail.com">https://flowcrypt.com/pub/stefan.graenitz@gmail.com</a></pre>
  </body>
</html>