<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<br><br><div class="gmail_quote">On Mon, Dec 8, 2008 at 2:28 PM, John Criswell <span dir="ltr"><<a href="mailto:criswell@uiuc.edu">criswell@uiuc.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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.<br>
</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><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.<br>
<div class="Ih2E3d"></div></blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> 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.<br>
<div class="Ih2E3d"></div></blockquote><div> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">><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.<br>
</div>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.<br>
<div class="Ih2E3d"><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.<br>
</div>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.<br>
<div class="Ih2E3d"><br>
><br>
>  Thanks in advance.<br>
><br>
>  Best,<br>
>  Keun Soo<br>
><br>
><br>
<br>
</div>_______________________________________________<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><br>
</blockquote></div><br>