#579327 binutils: .intel_syntax misassembles a forward-referenced .equ as a data reference

Package:
binutils
Source:
binutils
Description:
GNU assembler, linker and binary utilities
Submitter:
Josh Triplett
Date:
2010-05-03 17:03:57 UTC
Severity:
normal
#579327#3
Date:
2010-04-27 01:55:34 UTC
From:
To:
This bug already reported upstream as
http://sourceware.org/bugzilla/show_bug.cgi?id=11544 ; I'll mark it as
forwarded as soon as I have a bug number.


The following three-line text case assembles incorrectly:

..intel_syntax noprefix
    mov ax, AN_EQU
..equ AN_EQU, 5

Compiled with "gcc -c test.S"

Disassembled with "objdump -M intel -d test.o":

   0:   66 8b 04 25 05 00 00    mov    ax,WORD PTR ds:0x5
   7:   00

For some reason, this assembled as a memory dereference of ds:0x5.  Somehow, gas
knew enough to substitute the value 5, but didn't know to treat it as an immediate.

If I move the equate before the instruction, it assembles correctly:

..intel_syntax noprefix
..equ AN_EQU, 5
    mov ax, AN_EQU

   0:   66 b8 05 00             mov    ax,0x5

If I substitute a literal 5 in the instruction, it assembles correctly:

..intel_syntax noprefix
    mov ax, 5

   0:   66 b8 05 00             mov    ax,0x5

And if I use AT&T syntax, it assembles correctly:

..att_syntax
    mov $AN_EQU, %ax
..equ AN_EQU, 5

   0:   66 b8 05 00             mov    ax,0x5


I originally observed this bug in in 16-bit assembly with .code16, but I
can also reproduce it in 64-bit assembly.

- Josh Triplett