<div dir="ltr">This is what I meant by llvm-objdump improvements.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 27, 2019 at 7:32 AM bd1976 llvm <<a href="mailto:bd1976llvm@gmail.com">bd1976llvm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Seiya,</div><div dir="ltr"><br></div><div>If you want a project that is not trival; but, doable in a summer; will be be a great leaning opportunity, and will be very useful to developers. Then I would suggest improving the disassembly of object files on x86_64. I can't count the number of times this has caused confusion.</div><div><br></div><div><p style="margin:0px;padding:0px;color:rgb(51,51,51);font-family:sans-serif;font-size:14px">Consider the following assembly:</p><div class="gmail-m_3161361939041082982gmail-code gmail-m_3161361939041082982gmail-panel" style="margin:9px 0px;padding:0px;border:1px solid rgb(204,204,204);background:rgb(245,245,245);font-size:12px;line-height:1.33333;font-family:monospace;border-radius:3px;color:rgb(51,51,51)"><div class="gmail-m_3161361939041082982gmail-codeContent gmail-m_3161361939041082982gmail-panelContent" style="margin:0px;padding:9px 12px"><pre class="gmail-m_3161361939041082982gmail-code-java" style="margin-top:0px;margin-bottom:0px;padding:0px;max-height:30em;overflow:auto;white-space:pre-wrap"> nop
nop
.globl sym1
sym1:
ret
.section .text2,<span class="gmail-m_3161361939041082982gmail-code-quote" style="color:rgb(0,145,0)">"ax"</span>,@progbits
jmp .text
jmp .text+1
jmp .text+6
jmp sym1
.globl sym2
sym2:
jmp .text2
jmp .text2+1
jmp .text2+20
jmp sym2
jmp sym2@plt
</pre></div></div><p style="margin:10px 0px 0px;padding:0px;color:rgb(51,51,51);font-family:sans-serif;font-size:14px">When assembled and then disassembled you will see output something like:</p><div class="gmail-m_3161361939041082982gmail-code gmail-m_3161361939041082982gmail-panel" style="margin:9px 0px;padding:0px;border:1px solid rgb(204,204,204);background:rgb(245,245,245);font-size:12px;line-height:1.33333;font-family:monospace;border-radius:3px;color:rgb(51,51,51)"><div class="gmail-m_3161361939041082982gmail-codeContent gmail-m_3161361939041082982gmail-panelContent" style="margin:0px;padding:9px 12px"><pre class="gmail-m_3161361939041082982gmail-code-java" style="margin-top:0px;margin-bottom:0px;padding:0px;max-height:30em;overflow:auto;white-space:pre-wrap">Disassembly of section .text:
0x00000000: 90 nop
0x00000001: 90 nop
sym1:
0x00000002: C3 ret
Disassembly of section .text2:
0x00000000: E9 00 00 00 00 jmp .text+0xFFFFFFFFFFFFFFFC (0000000000000005h)
0x00000005: E9 00 00 00 00 jmp .text+0xFFFFFFFFFFFFFFFD (000000000000000Ah)
0x0000000A: E9 00 00 00 00 jmp sym1 (000000000000000Fh)
0x0000000F: E9 00 00 00 00 jmp sym2 (0000000000000014h)
sym2:
0x00000014: EB EA jmp 0000000000000000h
0x00000016: EB E9 jmp 0000000000000001h
0x00000018: EB FA jmp sym2 (0000000000000014h)
0x0000001A: EB F8 jmp sym2 (0000000000000014h)
0x0000001C: E9 00 00 00 00 jmp sym2 (0000000000000021h)
</pre></div></div><p style="margin:10px 0px 0px;padding:0px;color:rgb(51,51,51);font-family:sans-serif;font-size:14px">This is pretty confusing. What is wanted is output more like this:</p><div class="gmail-m_3161361939041082982gmail-code gmail-m_3161361939041082982gmail-panel" style="margin:9px 0px;padding:0px;border:1px solid rgb(204,204,204);background:rgb(245,245,245);font-size:12px;line-height:1.33333;font-family:monospace;border-radius:3px;color:rgb(51,51,51)"><div class="gmail-m_3161361939041082982gmail-codeContent gmail-m_3161361939041082982gmail-panelContent" style="margin:0px;padding:9px 12px"><pre class="gmail-m_3161361939041082982gmail-code-java" style="margin-top:0px;margin-bottom:0px;padding:0px;max-height:30em;overflow:auto;white-space:pre-wrap">Disassembly of section .text[0]:
0x00000000: 90 nop
0x00000001: 90 nop
sym1:
0x00000002: C3 ret
Disassembly of section .text2[1]:
0x00000000: E9 ?? ?? ?? ?? jmp .text[0] + 0x0
0x00000005: E9 ?? ?? ?? ?? jmp .text[0] + 0x1
0x0000000A: E9 ?? ?? ?? ?? jmp .text[0] + 0x6 (sym1 + 0x4)
0x0000000F: E9 ?? ?? ?? ?? jmp sym1 + 0x0
sym2:
0x00000014: EB EA jmp .text2[0] + 0x0
0x00000016: EB E9 jmp .text2[0] + 0x1
0x00000018: EB FA jmp .text2[0] + 0x14 (sym2 + 0x0)
0x0000001A: EB F8 jmp .text2[0] + 0x14 (sym2 + 0x0)
0x0000001C: E9 ?? ?? ?? ?? jmp sym2 (via GOT)</pre></div></div></div><div><br></div><div><font face="arial, helvetica, sans-serif">Please forgive me for using the output of our internal tools to illustrate the point (I prepared this internally and don't have much time to write this email so I just copied and pasted). If you try this with LLVM's binary tools or GNU's you will see similar results.</font></div><div><br></div><div><p style="margin:10px 0px 0px;padding:0px;color:rgb(51,51,51);font-family:sans-serif;font-size:14px">Concrete suggestions for improvements:</p><ul class="gmail-m_3161361939041082982gmail-alternate" type="square" style="margin:10px 0px 0px;color:rgb(51,51,51);font-family:sans-serif;font-size:14px"><li>section relative targets augmented with symbol information</li><li>?? to indicate Relocation patches</li><li>targets of PC relative jumps computed correctly</li><li>sections names augmented with their indices (section name are ambiguous)</li><li>branches via PLT indicated with added comments</li></ul><p style="margin:10px 0px 0px;padding:0px;color:rgb(51,51,51);font-family:sans-serif;font-size:14px">This is not trivial to accomplish. Specifically, computing the target of branches will either require more integration between the binary tools and the dissembler; or, possibly the binary tools could create a fake layout and then patch up the instructions so that they disassemble "correctly".</p><p style="margin:10px 0px 0px;padding:0px;color:rgb(51,51,51);font-family:sans-serif;font-size:14px">If you manage to get that done; then I would suggest going further and trying to enhance the disassembly by adding color coding/outlining/ASCII art to the output to show things like loops, if statements, basic blocks. As inspiration see "rich disassembly" in this presentation by apple: <a href="http://devimages.apple.com/llvm/videos/LLVMMCinPractice.m4v" target="_blank">http://devimages.apple.com/llvm/videos/LLVMMCinPractice.m4v</a>.</p></div><div><br></div></div></div>
</blockquote></div>