<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Steve,<div><br></div><div>For the labeltest.s I get:</div><div><br></div><div><font face="Courier">% llvm-mc -triple x86_64-apple-darwin10 -filetype=obj -o x86_labeltest.o labeltest.s</font></div><div><br></div><div><div>First with just -v that produces disassembly (without verbose operands):</div><div><font face="Courier">% otool -tv x86_labeltest.o <br>x86_labeltest.o:<br>(__TEXT,__text) section<br>foo:<br>0000000000000000<span class="Apple-tab-span" style="white-space: pre;"> </span>nop<br>bar:<br>0000000000000001<span class="Apple-tab-span" style="white-space: pre;"> </span>nop<br>0000000000000002<span class="Apple-tab-span" style="white-space: pre;"> </span>jmp<span class="Apple-tab-span" style="white-space: pre;"> </span>0x7<br>0000000000000007<span class="Apple-tab-span" style="white-space: pre;"> </span>jmp<span class="Apple-tab-span" style="white-space: pre;"> </span>0x1<br>0000000000000009<span class="Apple-tab-span" style="white-space: pre;"> </span>jmp<span class="Apple-tab-span" style="white-space: pre;"> </span>0xe<br>000000000000000e<span class="Apple-tab-span" style="white-space: pre;"> </span>nop<br>baz:<br>000000000000000f<span class="Apple-tab-span" style="white-space: pre;"> </span>nop</font></div></div><div><br></div><div><br></div><div>And second with -V that produces “verbose operands”:</div><div><br></div><div><font face="Courier">% otool -tV x86_labeltest.o <br>x86_labeltest.o:<br>(__TEXT,__text) section<br>foo:<br>0000000000000000<span class="Apple-tab-span" style="white-space:pre"> </span>nop<br>bar:<br>0000000000000001<span class="Apple-tab-span" style="white-space:pre"> </span>nop<br>0000000000000002<span class="Apple-tab-span" style="white-space:pre"> </span>jmp<span class="Apple-tab-span" style="white-space:pre"> </span>bar<br>0000000000000007<span class="Apple-tab-span" style="white-space:pre"> </span>jmp<span class="Apple-tab-span" style="white-space:pre"> </span>bar<br>0000000000000009<span class="Apple-tab-span" style="white-space:pre"> </span>jmp<span class="Apple-tab-span" style="white-space:pre"> </span>baz<br>000000000000000e<span class="Apple-tab-span" style="white-space:pre"> </span>nop<br>baz:<br>000000000000000f<span class="Apple-tab-span" style="white-space:pre"> </span>nop</font></div><div><br></div><div>And third adding -j that prints the opcode bytes:</div><div><font face="Courier">% otool -tVj x86_labeltest.o <br>x86_labeltest.o:<br>(__TEXT,__text) section<br>foo:<br>0000000000000000<span class="Apple-tab-span" style="white-space:pre"> </span>90 <span class="Apple-tab-span" style="white-space:pre"> </span>nop<br>bar:<br>0000000000000001<span class="Apple-tab-span" style="white-space:pre"> </span>90 <span class="Apple-tab-span" style="white-space:pre"> </span>nop<br>0000000000000002<span class="Apple-tab-span" style="white-space:pre"> </span>e900000000 <span class="Apple-tab-span" style="white-space:pre"> </span>jmp<span class="Apple-tab-span" style="white-space:pre"> </span>bar<br>0000000000000007<span class="Apple-tab-span" style="white-space:pre"> </span>ebf8 <span class="Apple-tab-span" style="white-space:pre"> </span>jmp<span class="Apple-tab-span" style="white-space:pre"> </span>bar<br>0000000000000009<span class="Apple-tab-span" style="white-space:pre"> </span>e900000000 <span class="Apple-tab-span" style="white-space:pre"> </span>jmp<span class="Apple-tab-span" style="white-space:pre"> </span>baz<br>000000000000000e<span class="Apple-tab-span" style="white-space:pre"> </span>90 <span class="Apple-tab-span" style="white-space:pre"> </span>nop<br>baz:<br>000000000000000f<span class="Apple-tab-span" style="white-space:pre"> </span>90 <span class="Apple-tab-span" style="white-space:pre"> </span>nop</font></div><div><br></div><div>For me, operands of -3, -5 and 1 are of little use. If I think the target is assembled wrong I want to see where it thinks it is going (the hex address in the object file) and the opcode bytes so I can hand decode what is going on (more important in things like arm that don’t have simple displacements).</div><div><br></div><div>Also if I’m printing symbolic operands like “bar” I don’t want to see the address of bar or the displacement in that case. Basically I want to see as close to real assembly code as possible.</div><div><br></div><div>Also note for Mach-O, we work hard to not have symbols at the same address and not using symbols that are not assembly temporary names. We use things like 1f, 2b or L21 because we break sections into “atoms” at the symbol addresses by default (when the assembly has the directive .subsections_via_symbols which produces the flag in the header SUBSECTIONS_VIA_SYMBOLS).</div><div><br></div><div>Kev</div><div><br></div><div>P.S. We also display raw text bytes with just -t and no -v or -V which is useful when debugging very broken objects:</div><div><br></div><div><font face="Courier">% otool -t x86_labeltest.o <br>x86_labeltest.o:<br>(__TEXT,__text) section<br>0000000000000000 90 90 e9 00 00 00 00 eb f8 e9 00 00 00 00 90 90</font></div><div><br></div><div><br></div><div><div><div>On Aug 26, 2014, at 12:43 PM, Steve King <<a href="mailto:steve@metrokings.com">steve@metrokings.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi Kev,<br>I'm glad to hear llvm-objdump is getting attention. I'm unclear on<br>how much output specialization one could (or should) do for ELF vs.<br>Mach-O. If you're game, let's compare an example:<br><br>$ cat labeltest.s<br>.text<br>foo:<br> nop<br>bar:<br>bum:<br> nop<br> jmp bar<br> jmp bum<br> jmp baz<br> nop<br>baz:<br> nop<br><br>Assembling for x86 and llvm-objdump'ing, i get<br><br>$ llvm-mc -arch=x86 -filetype=obj labeltest.s -o x86_labeltest.o<br>$ llvm-objdump -d x86_labeltest.o<br><br>x86_labeltest.o: file format ELF32-i386<br><br>Disassembly of section .text:<br>foo:<br> 0: 90 nop<br><br>bum:<br> 1: 90 nop<br> 2: eb fd jmp -3<br> 4: eb fb jmp -5<br> 6: eb 01 jmp 1<br> 8: 90 nop<br><br>baz:<br> 9: 90 nop<br><br>I get the dump above with or without -symbolize.<br><br>My personal golden reference, GNU objdump, does this:<br><br>$ objdump -dw x86_labeltest.o<br><br>x86_labeltest.o: file format elf32-i386<br><br><br>Disassembly of section .text:<br><br>00000000 <foo>:<br> 0: 90 nop<br><br>00000001 <bar>:<br> 1: 90 nop<br> 2: eb fd jmp 1 <bar><br> 4: eb fb jmp 1 <bar><br> 6: eb 01 jmp 9 <baz><br> 8: 90 nop<br><br>00000009 <baz>:<br> 9: 90 nop<br><br>What does otool produce?<br><br><br>On Tue, Aug 26, 2014 at 11:16 AM, Kevin Enderby <<a href="mailto:enderby@apple.com">enderby@apple.com</a>> wrote:<br><blockquote type="cite">For branch targets my preference is to print the target’s address (not the displacement of the branch), and preferably in hex.<br></blockquote><br>I like this too.<br><br><blockquote type="cite">I don’t think having multiple addresses for a target is a real problem with the exception of the address 0 (which is often an unrelocated no addend value). So the trick is to not print the symbol name in the object with the address of zero in those cases<br></blockquote><br>Right, relocations are a special case.<br></blockquote><br></div><div>The trick here is with otool(1) and -V we will “guess” at operands symbolic value. That is even if there is no relocation entry and we have a target address that matches a symbol table value we will use that. And special case the zero value to try to print zero and not the symbol with the zero address the best we can. I can dig out the logic I came up with that if you want it.</div><br></div></body></html>