<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=iso-8859-1">
<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;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@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]-->
</head>
<body lang="DE" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-GB">Hello everyone,<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 have an issue with some code that I jit/load as position independent code. I have a feeling that it is not possible to solve the issue but I wanted to give it a try.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:gray">#include</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#A31515"><stdio.h></span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">int</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> magicValue = 123;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">int</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> magicValue2 = 321;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">volatile</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">int</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> *pValue = &magicValue;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">void</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> printMagicValue()<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> printf(</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#A31515">"Planschi...\n"</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> printf(</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#A31515">"The magic value is %i 0x%p && 0x%p\n"</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">,
magicValue, &magicValue, pValue);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">void</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> setMagicValue(</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">int</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:gray">value</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> magicValue =
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:gray">value</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:Consolas;color:black">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:black">This is the code which I will load as PIC, for the JTMB I use the following settings:<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">JTMB</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:teal">-></span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">setRelocationModel(llvm::Reloc::</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:darkslategray">PIC_</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">JTMB</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:teal">-></span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">setCodeModel(llvm::CodeModel::</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:darkslategray">Small</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:black">The code will be loaded into a shared memory. Two process will execute the memory from there, calling “printMagicValue”, “setMagicValue(120)” and “printMagicValue” again. Only the first process will
JIT the code, every other process will access it from the shared memory.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:black">The first Process will say:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Planschi...<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">The magic value is 123 0x00000270BB090038 && 0x00000270BB090038<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Planschi...<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">The magic value is 120 0x00000270BB090038 && 0x00000270BB090038<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">The second Process will say:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Planschi...<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">The magic value is 120 0x00000237A5DE0038 && 0x00000270BB090038<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Planschi...<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">The magic value is 120 0x00000237A5DE0038 && 0x00000270BB090038<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">The values will be read correctly! Hurray! But my problem is, that the pointer ‘pValue’ was written with an absolute value and not with a PIC conform value. The second process will now print the address from the first
process. I hoped, that – since the code is PIC – that also the pointers are written PIC like. I think I understand why this is not the case, but can I somehow change this behaviour without calculating the offset myself? My overall goal is to share the entire
code between two processes.<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 hope my question is somewhat understandable and I hope even more, that there is a solution to this…<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">Thank you for any help in advance and kind greetings<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Björn<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, Takeshi Fukushima. Junichi Tajika
</body>
</html>