<div><br></div><div><div dir="auto">Hi </div><div dir="auto"><br></div><div dir="auto">Since it’s midnight in my time zone and I will try to reply to you shortly with mobile but may give you more information tomorrow.</div><div dir="auto"><br></div><div dir="auto">First, thanks for your comments. I may try to google whether such kind of machine IR address exists</div><div dir="auto"><br></div><div dir="auto">Second, to derive a basic blocks binary address. I first use LLVM pass to get the source line number and column number for every instruction inside the block, The I will query the dwarf line mapping table to get the binary address. I use the first instruction’s address as the block’s start address. I found some exceptions. Then I try to found the lowest addresses among all the instructions and set it as the block’s address. however, I found that there are still some exceptions. Thus, I don’t know how to generate a precise binary level control flow graph.</div><div dir="auto"><br></div><div dir="auto">Regards</div><div dir="auto">Muhui</div><br><div class="gmail_quote"><div><<a href="mailto:paul.robinson@sony.com">paul.robinson@sony.com</a>>于2018年6月13日 周三下午11:53写道:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div class="m_5068649046575259726WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I can imagine a machine-IR pass that could construct a CFG shortly before starting the AsmPrinter phase; I am pretty sure there is nothing that would affect
the CFG after that point. I don't know whether such an analysis exists currently. I also don't know whether it would be straightforward to map an LLVM IR CFG to the machine-IR CFG; maybe not, as there are certainly machine-IR passes that do things like splitting
and merging blocks.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Deriving final binary addresses for blocks in the CFG would require that you track or insert labels, and then examine the final binary to determine the addresses
for each of those labels. I am unclear how you would correlate these values with the CFG, however.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">--paulr<u></u><u></u></span></p>
<p class="MsoNormal"><a name="m_5068649046575259726__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<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""> Muhui Jiang [mailto:<a href="mailto:jiangmuhui@gmail.com" target="_blank">jiangmuhui@gmail.com</a>]
<br>
<b>Sent:</b> Wednesday, June 13, 2018 11:12 AM<br>
<b>To:</b> Robinson, Paul<br>
<b>Cc:</b> <a href="http://mayuyu.io" target="_blank">mayuyu.io</a>; llvm-dev</span></p></div></div></div></div></div><div lang="EN-US" link="blue" vlink="purple"><div class="m_5068649046575259726WordSection1"><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""><br>
<b>Subject:</b> Re: [llvm-dev] IR to binary address mapping<u></u><u></u></span></p></div></div></div></div></div><div lang="EN-US" link="blue" vlink="purple"><div class="m_5068649046575259726WordSection1"><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Hi Paul<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks for your comments. Suppose I can generate the control flow graph via LLVM Pass or the default option like '-dot-cfg' with opt. However, the control flow graph is based on llvm IR level. I would like to have a control flow graph based
on binary level. Thus, I want to map the IR to binary address. <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">As far as I know, we used to use the debug information to map the IR to source code and then use the dwarf line mapping table to map to binary address. However, I come across many problems. For example, dwarf mapping table's information
is not complete. Sometimes the line number could even be zero. Besides, one line and column number could map to more than one binary address. Thus, I may need the mapping from IR to binary to give me a control flow graph on binary level. Do you have any comments
or solutions? Many Thanks<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Regards<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Muhui<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">2018-06-13 23:05 GMT+08:00 <<a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.com</a>>:<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">We preserve the source line/column for two reasons. First, so that any compiler diagnostic messages
can point to a source location that caused the diagnostic; second, because debugging information in the final binary wants to be able to map machine instruction addresses back to source locations. There is never any need for the end-user to map machine instruction
addresses back to IR instructions, so we don't maintain any information that could produce such a mapping.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">--paulr</span><u></u><u></u></p>
<p class="MsoNormal"><a name="m_5068649046575259726_m_-1688809287284250986__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span></a><u></u><u></u></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<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""> llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>]
<b>On Behalf Of </b>Muhui Jiang via llvm-dev<br>
<b>Sent:</b> Wednesday, June 13, 2018 3:09 AM<br>
<b>To:</b> <a href="http://mayuyu.io" target="_blank">mayuyu.io</a><br>
<b>Cc:</b> llvm-dev<br>
<b>Subject:</b> Re: [llvm-dev] IR to binary address mapping</span><u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">Hi<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">However, frontend may also do various operations on the source code and one line number and column number could map to more than one binary address. Why LLVM IR cannot?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Regrads<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Muhui<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">2018-06-12 23:18 GMT+08:00
<a href="http://mayuyu.io" target="_blank">mayuyu.io</a> <<a href="mailto:admin@mayuyu.io" target="_blank">admin@mayuyu.io</a>>:<u></u><u></u></p>
<p class="MsoNormal">In theory that’s not exactly possible/accurate. Due to various operations in the Backend like Instruction Legalization, one IR instruction might got emitted into multiple assembly
instruction, for example<br>
<br>
Zhang<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><br>
> <span style="font-family:"MS Gothic"">在</span> 2018<span style="font-family:"MS Gothic"">年</span>6<span style="font-family:"MS Gothic"">月</span>12<span style="font-family:"MS Gothic"">日,</span>22:30<span style="font-family:"MS Gothic"">,</span>Muhui Jiang
via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>
<span style="font-family:"MS Gothic"">写道:</span><br>
> <br>
> Hi<br>
> <br>
> I know that LLVM provide some debug API for us to know the source code information. For example, every IR instruction's source line number and column number.
<br>
> <br>
> However, are there any method to get a mapping from IR instruction to binary address directly. I don't want to use dwarf line mapping table as a bridge. I think the binary is generated by clang and llvm. I think there definitely is some information about
the mapping relationship between LLVM IR and the target binary address. Do anyone has suggestions? Many Thanks<br>
> <br>
> Regards<br>
> Muhui<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">> _______________________________________________<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" target="_blank">
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></p>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div></blockquote></div></div>