1

I've disassembled a function and I'm certain that I know what the function is doing - it's two nested loops that generates multiplication tables. However, there's a section of the assembly that doesn't make sense to me.

   0x0000000000000035 <+53>:    lea    0x0(%rip),%rdi        # 0x3c <main+60>
   0x000000000000003c <+60>:    callq  0x41 <main+65>
   0x0000000000000041 <+65>:    lea    0x0(%rip),%rsi        # 0x48 <main+72>
   0x0000000000000048 <+72>:    mov    %rax,%rdi
   0x000000000000004b <+75>:    callq  0x50 <main+80>
   0x0000000000000050 <+80>:    mov    %rax,%rdx

Are the callq instructions just calling the next instruction, which would have just been called anyway? It also seems like the rdi register is being set to the next instruction but is then overwritten by rax before anything is done with it.

Is this a common pattern of calls that I should be able to recognize?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Tom H
  • 46,766
  • 14
  • 87
  • 128
  • 5
    call next-instruction is a sure sign you're looking at a `.o` that hasn't been linked, so the `call rel32` offsets are just `0` placeholders to be filled in by the linker, according to the symbol relocations. Same for the RIP-relative LEAs. But this looks like GDB disassembly, without the machine code that would make that extra visible; you ran GDB on a `.o`? Use `objdump -drwC -Mintel` to annotate with symbol-relocation info. (The `-Mintel` is optional; you're using AT&T syntax right now.) – Peter Cordes Jan 26 '23 at 16:48
  • See [Understanding RIP relative relocations](https://stackoverflow.com/q/68067522) for an example of what the output should look like. – Peter Cordes Jan 26 '23 at 16:53
  • Thanks for the suggestion. Using the objdump command confirms what I suspected - that these are calls to the IO stream to output the results. I thought that I've disassembled other similar files and seen calls to puts/printf before now, which is what I expected to see here. At least it makes some sense though. The lea calls still don't make sense to me though. – Tom H Jan 26 '23 at 16:59
  • Are the values in the lea calls also placeholders? – Tom H Jan 26 '23 at 17:00
  • 2
    Yes, note the RIP-relative addressing mode, `[RIP + rel32]` – Peter Cordes Jan 26 '23 at 17:03

0 Answers0