Why do I find some never called instructions nopl, nopw after ret or jmp in GCC compiled code?

2

When I compile code with gcc - (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 - I find in the compiled code some unused code lines at the end of some/all functions or after some absolute jmp.

It seems the result is to align the code, but: Why don't use simply some 0s or NOPs?

The unused code lines I find are something such as the following code lines where I inserted <==:

  1. 134d:       eb b7                   jmp    1306 <msb32+0x16>
    134f:       90                      nop    <==
    1350:       b8 ff ff ff ff          mov    $0xffffffff,%eax
    1355:       c3                      retq
    1356:       66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1) <==
    135d:       00 00 00 
    
    0000000000001360 <object_key_compare_serials>:
    1360:       48 8b 07                mov    (%rdi),%rax
    
  2. 12fa:       74 44                   je     1340 <msb32+0x50>
    [...]
    1338:       c3                      retq
    1339:       0f 1f 80 00 00 00 00    nopl   0x0(%rax) <==
    1340:       c1 e7 10                shl    $0x10,%edi
    
gcc
assembly
x86-64
padding
nop
asked on Stack Overflow Jan 5, 2020 by Sir Jo Black • edited Jan 6, 2020 by phuclv

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0