GAS 2.19.51.20090519 incorrectly assembles |.intel_syntax noprefix | jmp $+2 | nop as |00000000 <.text>: | 0: e9 02 00 00 00 jmp 7 <.text+0x7> | 1: DISP32 $ | 5: 90 nop | 6: 90 nop | 7: 90 nop GAS 2.19.51.20090414 is correct: |00000000 <.text>: | 0: eb 00 jmp 2 <.text+0x2> | 2: 90 nop | 3: 90 nop
What does "jmp $+2" mean? It seems invalid to me.
"jmp $+2" jumps to the next instruction after itself (this form of "jmp" is 2 bytes long), i.e. essentially it is a no-op. It was often used in the past on x86 to provide delays after I/O instructions. Now, these older programs cannot be assembled with GAS. Notice that it is Intel syntax, it is valid.
Is "jmp $+2" a documented syntax? The normal way is "jmp .+2".
It's a usual syntax for x86 assemblers ( e.g. MASM http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ , NASM http://www.nasm.us/doc/nasmdoc3.html#section-3.5 ). It seems it was not documented in GAS, not for x86, at least. The "jmp .+2" thing is AT&T syntax |.att_syntax | jmp .+2 | nop This still works.
Subject: Bug 10198 CVSROOT: /cvs/src Module name: src Changes by: hjl@sourceware.org 2009-06-01 16:31:00 Modified files: gas : ChangeLog gas/config : tc-i386-intel.c gas/testsuite : ChangeLog gas/testsuite/gas/i386: jump.d jump.s jump16.d jump16.s Log message: gas/ 2009-06-01 H.J. Lu <hongjiu.lu@intel.com> PR gas/10198 * config/tc-i386-intel.c (i386_intel_operand): Check '$' as '.'. gas/testsuite/ 2009-06-01 H.J. Lu <hongjiu.lu@intel.com> PR gas/10198 * gas/i386/jump.s: Add test for "jmp $+2". * gas/i386/jump16.s: Likewise. * gas/i386/jump.d: Updated. * gas/i386/jump16.d: Likewise. Patches: http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.3818&r2=1.3819 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/config/tc-i386-intel.c.diff?cvsroot=src&r1=1.2&r2=1.3 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1488&r2=1.1489 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/jump.d.diff?cvsroot=src&r1=1.5&r2=1.6 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/jump.s.diff?cvsroot=src&r1=1.2&r2=1.3 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/jump16.d.diff?cvsroot=src&r1=1.4&r2=1.5 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/jump16.s.diff?cvsroot=src&r1=1.2&r2=1.3
Fixed.