<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=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Malgun Gothic";
        panose-1:0 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"Malgun Gothic";
        panose-1:0 0 0 0 0 0 0 0 0 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:85.05pt 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</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=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> Currently I have a trick to extract the correlation information
of LLVA and ISA. By adding an intrinsic instruction and comparing the emitted
binary with the original one. The location of machine instruction that I am interested
in is calculated relative to the intrinsic instruction. Unless I change the original
instruction with the intrinsic having a same size, this needs many iterations
as much as the number of interested instructions. Even I endure this tedious
repeating tasks, it is not highly accurate because if the target instruction
was not replaced by intrinsic, it may be optimized in code generator. <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> Since it is possible by using intrinsic and it is the compiler
which has both IR and machine code information and generate both of them, I
believe implementing a method giving this information is possible. Thus I try
to implement that but I am out of concept of LLVM back-end. Does anyone who
could explain this?<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> Thanks,<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> Keun Soo <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Keun Soo Yim
[mailto:yim2012@gmail.com] <br>
<b>Sent:</b> Sunday, December 14, 2008 3:16 AM<br>
<b>To:</b> LLVM Developers Mailing List<br>
<b>Subject:</b> Re: [LLVMdev] How to correlate LLVA with native ISA<o:p></o:p></span></p>

</div>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal style='margin-bottom:12.0pt'><br>
 Thank your for reply. <br>
<br>
 The reason why these information are needed is that I am trying to
extract the program signature (e.g., control flow) out side of the binary.
Conventional compiler technique adds extra checking code into the target source
or target IR in an invasive manner. Since code generator combines the added
code with the original one, they don't need to correlate these two information.<br>
<br>
  It is being implemented as an LLVM analysis pass by using <i>MachineFunctionPass</i>.
If it is MachineBasicBlock or MachineInstruction, does it possible to get the
starting address of real basic block and the exact (runtime) address of real
instruction? <br>
<br>
  Unlike the FunctionPass, my MachineFunctionPass gets an error when it is
loaded by opt. The class has constructor, virtfn, runOnMachineFunction,
getPassName, runOnFunction, and getAnalysisUsage methods where body parts of
all methods are empty. Does any have a similar problem?<br>
<br>
Error opening '../../src/Release/lib/SWP.so': ../../src/Release/lib/SWP.so:
undefined symbol: _ZTIN4llvm19MachineFunctionPassE<br>
<br>
(without virtfn() definition)<br>
Error opening '../../src/Release/lib/SWP.so': ../../src/Release/lib/SWP.so:
undefined symbol: _ZN4llvm19MachineFunctionPass6virtfnEv<br>
<br>
 Thanks in advance!<br>
 - Keun Soo<o:p></o:p></p>

<div>

<p class=MsoNormal>On Mon, Dec 8, 2008 at 2:28 PM, John Criswell <<a
href="mailto:criswell@uiuc.edu">criswell@uiuc.edu</a>> wrote:<o:p></o:p></p>

<p class=MsoNormal>Can you tell us what goal you are trying to accomplish that
requires you<br>
to do this?  There might be better ways of doing what you want.<o:p></o:p></p>

<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;
margin-left:4.8pt;margin-right:0in'>

<p class=MsoNormal><br>
The answer to your question probably depends on whether you're trying to<br>
write a pure LLVM analysis/transform, a JIT, or can interpose at the<br>
static code generator.<o:p></o:p></p>

</blockquote>

<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;
margin-left:4.8pt;margin-right:0in'>

<p class=MsoNormal> From working strictly with the LLVM IR, I don't
believe this is<br>
possible.  There is no instruction that can give you the address of an<br>
LLVM instruction.  There are multiple reasons for this: first, it would<br>
allow one to write code that branches into the middle of basic blocks,<br>
making LLVM's analysis passes much more tedious to write.  Second,<br>
instructions may be expanded to multiple machine instructions or<br>
peephole optimized away into 0 instructions during code generation.<br>
<br>
If you're willing to work with the LLVM static code generator or JIT<br>
infrastructure, then things might be different.  The code generator may<br>
have knowledge of the correlation between LLVM IR instructions and<br>
native code instructions; you may be able to enhance it to get the<br>
information you need.<o:p></o:p></p>

</blockquote>

<div>

<p class=MsoNormal><o:p> </o:p></p>

</div>

<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;
margin-left:4.8pt;margin-right:0in'>

<div>

<p class=MsoNormal>><br>
>  Similarly, by implementing an LLVM IR-level pass, is it feasible to<br>
> get the runtime memory address<br>
>  of a LLVM IR-level variable in global area? Assume the data segment<br>
> base address is given.<o:p></o:p></p>

</div>

<p class=MsoNormal>You should be able to find the address of anything that is
link-time<br>
accessible: these include externally visible global variables and<br>
externally visible functions.  The name of a global variable is its<br>
location in physical memory.  Memory allocated by alloca and malloc are<br>
also guaranteed to be "real" memory locations; the value of the
alloca<br>
or malloc is the location within real memory.<br>
<br>
It's not possible, however, to get the address of an SSA virtual<br>
register.  The code generator is free to put these into spill locations<br>
on the stack or into physical machine registers; in fact, the code<br>
generator can put an SSA value into different registers at different<br>
points in the function.<br>
<br>
You can do things like writing a transform that will take selected SSA<br>
registers and change them into alloca'ed or malloc'ed memory (or even<br>
global variables).  It will hurt performance, but it will allow you to<br>
get a pointer to the real memory location in which they're stored.<o:p></o:p></p>

<div>

<p class=MsoNormal><br>
><br>
>  In the LLVM library, there are already some classes starting with<br>
> Machine but I was not able to find<br>
>  any existing methods that would give the above information.<o:p></o:p></p>

</div>

<p class=MsoNormal>These are used for code generation.  Again, you may be
able to do more<br>
fancy things at (static or dynamic) code generation time, but in pure<br>
LLVM IR transforms, your options are somewhat limited.<br>
<br>
-- John T.<o:p></o:p></p>

<div>

<p class=MsoNormal style='margin-bottom:12.0pt'><br>
><br>
>  Thanks in advance.<br>
><br>
>  Best,<br>
>  Keun Soo<br>
><br>
><o:p></o:p></p>

</div>

<p class=MsoNormal>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>    
    <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><o:p></o:p></p>

</blockquote>

</div>

<p class=MsoNormal><o:p> </o:p></p>

</div>

</body>

</html>