foo: ret .nops 88 jmp foo => 0000000000000000 <foo>: 0: c3 ret 1: eb 56 jmp 59 <foo+0x59> 3: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] e: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 19: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 24: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 2f: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 3a: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 45: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 50: 66 0f 1f 84 00 00 00 00 00 nop WORD PTR [rax+rax*1+0x0] 59: eb a5 jmp 0 <foo> ---------- jmp foo .nops 128 foo: ret => 0000000000000000 <foo-0x85>: 0: e9 80 00 00 00 jmp 85 <foo> 5: eb 7e jmp 85 <foo> 7: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 12: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 1d: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 28: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 33: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 3e: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 49: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 54: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 5f: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 6a: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 75: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nop WORD PTR cs:[rax+rax*1+0x0] 80: 0f 1f 44 00 00 nop DWORD PTR [rax+rax*1+0x0]
Gas limits number of executed NOP paddings to 7 NOPs: [hjl@gnu-cfl-2 tmp]$ cat x.s foo: ret .p2align 7 mov %eax,%eax [hjl@gnu-cfl-2 tmp]$ gcc -c x.s [hjl@gnu-cfl-2 tmp]$ objdump -dw x.o x.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <foo>: 0: c3 retq 1: eb 7d jmp 80 <foo+0x80> 3: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) e: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 19: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 24: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 2f: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 3a: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 45: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 50: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 5b: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 66: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 71: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 7c: 0f 1f 40 00 nopl 0x0(%rax) 80: 89 c0 mov %eax,%eax [hjl@gnu-cfl-2 tmp]$ cat x.s foo: ret .p2align 6 mov %eax,%eax [hjl@gnu-cfl-2 tmp]$ gcc -c x.s [hjl@gnu-cfl-2 tmp]$ objdump -dw x.o x.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <foo>: 0: c3 retq 1: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) c: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 17: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 22: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 2d: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 38: 0f 1f 84 00 00 00 00 00 nopl 0x0(%rax,%rax,1) 40: 89 c0 mov %eax,%eax [hjl@gnu-cfl-2 tmp]$
> Gas limits number of executed NOP paddings to 7 NOPs: Then .nops with a large immediate should be rejected. A smaller immediate for .nops works, e.g. foo: ret .nops 28 jmp foo
(In reply to Fangrui Song from comment #2) > > Gas limits number of executed NOP paddings to 7 NOPs: > > Then .nops with a large immediate should be rejected. > > A smaller immediate for .nops works, e.g. > > foo: > ret > .nops 28 > jmp foo Gas doesn't reject it. It just jumps over nops.