Bug 25789 - [as] x86: duplicate jmp when .nops and jmp are used together
Summary: [as] x86: duplicate jmp when .nops and jmp are used together
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-06 00:38 UTC by Fangrui Song
Modified: 2020-04-06 19:07 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2020-04-06 00:38:40 UTC
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]
Comment 1 H.J. Lu 2020-04-06 12:12:19 UTC
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]$
Comment 2 Fangrui Song 2020-04-06 19:04:56 UTC
> 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
Comment 3 H.J. Lu 2020-04-06 19:07:36 UTC
(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.