1

When objdump the binary, there usually some NOP paddings like

66 66 2e 0f 1f 84 00 00 00 00 00    data32 nopw %cs:0x0(%rax,%rax,1)

or

0f 1f 84 00 00 00 00 00   nopl   0x0(%rax,%rax,1)

or

66 90                   xchg   %ax,%ax

at the end of each function. What is the purpose of them? And what factors determine their sizes?

user207421
  • 305,947
  • 44
  • 307
  • 483
WindChaser
  • 960
  • 1
  • 10
  • 30
  • 1
    Instruction alignment for functions and jump targets? This has been asked before. – Kerrek SB Mar 31 '15 at 19:52
  • Why functions need alignment? And it seems jump targets (basic block first-instruction address) do not need alignment. – WindChaser Mar 31 '15 at 19:59
  • Jump targets should also be aligned. See [this answer](http://stackoverflow.com/a/24135535/547981). – Jester Mar 31 '15 at 20:01
  • Just take a look at x86_64 Linux machine code, the jump target can start from any address. – WindChaser Mar 31 '15 at 20:23
  • You get better cache performance when the start of a function is cache-line aligned. – markgz Mar 31 '15 at 20:54
  • @WindChaser: Doesn't need to, but often is. As I said, you should find plenty of material on this website. Search around a bit. – Kerrek SB Mar 31 '15 at 20:59
  • Like my L1 icache size is 64, cache-line alignment means we can align by 16,32,or 64; or only 64? Since I see a lot of jump targets or function entry points are aligned to 32 bytes instead of 64 after inserting NOOPs before them. – WindChaser Apr 10 '15 at 21:15
  • https://stackoverflow.com/a/4486485/11287 ...Modern x86 assemblers use the largest possible NOP opcodes..." But I have no idea why the same loop optimized algorithm is used for functions alignment? – Tal Mar 13 '18 at 14:24
  • https://stackoverflow.com/a/7364850/11287 - explains why you still see this "optimization" between functions. – Tal Mar 13 '18 at 14:39

0 Answers0