Bug 11509 - Strange evaluation of symbol containing register
Summary: Strange evaluation of symbol containing register
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-16 21:04 UTC by Theorizer
Modified: 2010-04-24 17:19 UTC (History)
1 user (show)

See Also:
Host:
Target: i386/x86-64
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Theorizer 2010-04-16 21:04:27 UTC
Assume the source below:

        .intel_syntax noprefix

.eqv param, ebp-4

        mov     eax, [param]
        mov     eax, [param]

On this source 'as' (2.19, 2.20) assembles the following:
   0:   8b 45 fc                mov    eax,DWORD PTR [ebp-0x4]
   3:   b8 fc ff ff ff          mov    eax,0xfffffffc

'as' 2.18 however assembles this here:
   0:   8b 01                   mov    eax,DWORD PTR [ecx]
   2:   8b 01                   mov    eax,DWORD PTR [ecx]

if you change the symbol definition line to

.eqv param, ebp

then the assembled code is already the same for both mov instructions (with any
'as' versions):

   0:   8b 45 00                mov    eax,DWORD PTR [ebp+0x0]
   3:   8b 45 00                mov    eax,DWORD PTR [ebp+0x0]

As I see it does not matter whether you apply .eqv, .equ, .equiv, or =. The
result is always the same.
Comment 1 H.J. Lu 2010-04-19 14:37:19 UTC
I don't think we should support ".eqv param, ebp-4"
since it is evaluated and fully resolved at the first
use. We got ".eqv param, -4" starting from the
second use.
Comment 2 H.J. Lu 2010-04-20 21:17:07 UTC
This test failed:

[hjl@gnu-6 pr11509]$ cat 1.s
.intel_syntax noprefix

.eqv param, ebp-4
[hjl@gnu-6 pr11509]$ ./as --32 -o 1.o 1.s
1.s: Assembler messages:
1.s:3: Error: can't make global register symbol `param'
[hjl@gnu-6 pr11509]$ 

I think it is a bad idea to use ".eqv param, ebp-4".
Comment 3 Sourceware Commits 2010-04-21 18:10:19 UTC
Subject: Bug 11509

CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2010-04-21 18:09:53

Modified files:
	gas            : ChangeLog read.c 
	gas/config     : tc-i386-intel.c tc-i386.c 
	gas/testsuite  : ChangeLog 
	gas/testsuite/gas/i386: equ.d equ.s 

Log message:
	Properly handle ".equ symbol, reg + NUM" in x86 Intel syntax.
	
	gas/
	
	2010-04-21  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR gas/11509
	* config/tc-i386-intel.c (i386_intel_simplify_register): New.
	(i386_intel_simplify): Use i386_is_register and
	i386_intel_simplify_register. Set X_md for O_register and
	check X_md for O_constant.
	(i386_intel_operand): Use i386_is_register.
	
	* config/tc-i386.c (i386_is_register): New.
	(x86_cons): Initialize the X_md field.  Use i386_is_register.
	(parse_register): Use i386_is_register.
	(tc_x86_parse_to_dw2regnum): Likewise.
	
	gas/testsuite/
	
	2010-04-21  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR gas/11509
	* gas/i386/equ.s: Add tests for ".equ symbol, reg + NUM".
	* gas/i386/equ.d: Updated.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.4136&r2=1.4137
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/read.c.diff?cvsroot=src&r1=1.162&r2=1.163
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-i386-intel.c.diff?cvsroot=src&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-i386.c.diff?cvsroot=src&r1=1.431&r2=1.432
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1657&r2=1.1658
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/equ.d.diff?cvsroot=src&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/equ.s.diff?cvsroot=src&r1=1.4&r2=1.5

Comment 4 H.J. Lu 2010-04-21 18:26:50 UTC
Fixed.
Comment 5 Theorizer 2010-04-24 17:19:10 UTC
Thanks that you convinced yourself that it is a bug and fixed it :-). I tested
your patch with 2.20.51.20100424 and it is working fine. Thanks again.