<div dir="ltr">If you can write what you want to output in C with asm statements, clang can show you what the IR should look like.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 2, 2018 at 7:35 AM, Kenneth Adam Miller via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Program counter - EIP, RIP for x86/64. I need to obtain it and pass it as an argument to the function that calculates an ordinal from it.<br><br>I think that there must be some way to use the bitcode language to place byte values at a designated offset. Or use the command line to specify the section and offset for the data.</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 1, 2018 at 6:00 PM, Brenda So <span dir="ltr"><<a href="mailto:sogun3@gmail.com" target="_blank">sogun3@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Kenneth,<div><br></div><div>Can you elaborate what you mean by instruction pointer value? Like the actual instruction with opcode and operands? With the sample code that I showed you, the instrucrtion pointer in the innermost for loop will have access to the following functions:</div><div><br></div><div><a href="http://llvm.org/doxygen/classllvm_1_1Instruction.html" target="_blank">http://llvm.org/doxygen/classl<wbr>lvm_1_1Instruction.html</a> <br></div><div><br></div><div>Alternatively, you can use the dump() operation to dump the instructions out. </div><div><br></div><div>Unfortunately I don't know how to address your second question. That's stretching my knowledge in LLVM.</div><span class="m_7119993990174305231HOEnZb"><font color="#888888"><div><br></div><div>Brenda</div><div><br></div></font></span></div><div class="m_7119993990174305231HOEnZb"><div class="m_7119993990174305231h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 1, 2018 at 11:32 AM, Kenneth Adam Miller <span dir="ltr"><<a href="mailto:kennethadammiller@gmail.com" target="_blank">kennethadammiller@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thank you so much!<br><br>What about discovering the instruction pointer value?<div>Also, does anybody know how to embed an artifact as a resource in a binary? I'd like to have two text sections, and have one copied in from another binary.</div></div><div class="m_7119993990174305231m_-3351729360773504208HOEnZb"><div class="m_7119993990174305231m_-3351729360773504208h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 1, 2018 at 2:15 PM, Brenda So <span dir="ltr"><<a href="mailto:sogun3@gmail.com" target="_blank">sogun3@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><div dir="ltr"><div dir="ltr"><div><div><div>Hi,<br><br></div>You can write it as if you are writing an optimization pass: <a href="http://llvm.org/docs/ProgrammersManual.html" target="_blank">http://llvm.org/docs/Programme<wbr>rsManual.html</a><br><br></div>It
sounds like your highest level is a module, hence you should write a
module pass. There is example code on LLVM Programmer's Manual on how to
do a function pass:<br><br><pre><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">Function</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">*</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">targetFunc</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">=</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">...;</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-k">class</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-nc">OurFunctionPass</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">:</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-k">public</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">FunctionPass</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">{</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-k">public</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">:</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">OurFunctionPass</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">()</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">:</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">callCounter</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">(</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-mi">0</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">)</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">{</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">}</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-k">virtual</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">runOnFunction</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">(</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">Function</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">&</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">F</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">)</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">{</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-k">for</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">(</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">BasicBlock</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">&</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-nl">B</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">:</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">F</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">)</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">{</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-k">for</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">(</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">Instruction</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">&</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-nl">I</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">:</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">B</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">)</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">{</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-k">if</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">(</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-k">auto</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">*</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">CallInst</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">=</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">dyn_cast</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o"><</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">CallInst</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">></span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">(</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">&</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">I</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">))</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">{</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-c1">// We know we've encountered a call instruction, so we</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-c1">// need to determine if it's a call to the</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-c1">// function pointed to by m_func or not.</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-k">if</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">(</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">CallInst</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">-></span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">getCalledFunction</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">()</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">==</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">targetFunc</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">)</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">++</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">callCounter</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">;</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">}</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">}</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">}</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">}</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-k">private</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-o">:</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-kt">unsigned</span> <span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-n">callCounter</span><span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">;</span>
<span class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928m_7474471231330051592gmail-m_8144030881301047945gmail-p">};</span></pre>Making the
FunctionPass a Module pass should be pretty easy with the linked guide.
(instead of inheriting from Function Pass you can inherit frmo module
pass) Afterwards, you can build your new pass against your LLVM source
code and run it using the opt functionality. <br><br></div><div>Hope I didn't misunderstood your question -- if you have anymore let me know!<br></div><div><br></div><div>Brenda<br></div><div><br><br></div></div><div class="gmail_extra"><br></div><br></div></span><div class="gmail_extra"><br><div class="gmail_quote"><span>On Sun, Apr 1, 2018 at 1:48 PM, Kenneth Adam Miller via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_7119993990174305231m_-3351729360773504208m_-6889923263702135928h5"><div dir="ltr">Hello,<div><br></div><div><br></div><div>I hope you are all doing well and thanks in advance. I need to program a transformation of a set of llvm bitcode to have some various techniques woven in. In particular, I need to resolve a given computed target address to one of several in the same way that the function of a dynamic library is resolved, but I need this resolution to happen in the binary target of my choice where I tell it to. It's basically exactly the same facility as when you compile a group of files as a shared library target. The only difference is, I need this to happen under my control, according to function targets that I can choose and for an argument value that I can also choose as an ordinal to look them up. </div><div><br></div><div>I think that I may need to write a compiler pass where this occurs but part of the problem is 1) I don't know how to make such a thing occur at the bitcode level, 2) and the oridinal is calculated from the instruction pointer. <br><br>Can anybody help? Is there a library or function call for calculating lookup tables from a given set of targets given an ordinal? Is there a way to obtain the instruction pointer in llvm bitcode?</div></div>
<br></div></div><span>______________________________<wbr>_________________<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></span></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>