Subject: bin/3296: 'as' generates incorrect code
To: None <gnats-bugs@gnats.netbsd.org>
From: Urban Boquist <boquist@cs.chalmers.se>
List: netbsd-bugs
Date: 03/06/1997 23:16:21
>Number:         3296
>Category:       bin
>Synopsis:       as cannot handle some forward references
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Mar  6 14:20:01 1997
>Last-Modified:
>Originator:     Urban Boquist
>Organization:
Dept. of CS, Chalmers, Sweden
>Release:        NetBSD-current, March 1997
>Environment:
	Seen on NetBSD/sparc, but should be machine independent
System: NetBSD dogbert.cs.chalmers.se 1.2B NetBSD 1.2B (DOGBERT) #0: Thu Jan 30 20:57:38 MET 1997 root@dogbert.cs.chalmers.se:/usr/src/sys/arch/i386/compile/DOGBERT i386


>Description:
'as' incorrectly handles some forward references, resulting in incorrect
code being output.

>How-To-Repeat:

$ cat simple.s
.word   L2-L1
L1:
.word   L2-L1
L2:

$ as -v -al simple.s
GNU assembler version 1.92.3, NetBSD $Revision: 1.3 $
SPARC GAS  simple.s                     page 1


   1 0000 00000000      .word   L2-L1     <------- Wrong!
   2                    L1:
   3 0004 00000004      .word   L2-L1
   4                    L2:

>Fix:
The problem is that as tries to optimise expressions of the
type 'L-L' (i.e. two identical labels), but fails to check that the
value of the labels are known. The following fix is more or less
verbatim from a more recent GNU as (binutils-2.7).

*** expr.c.orig	Thu Feb 27 00:38:44 1997
--- expr.c	Thu Feb 27 00:38:48 1997
***************
*** 521,526 ****
--- 521,527 ----
  	    || (expressionP->X_subtract_symbol
  		&& expressionP->X_add_symbol
  		&& expressionP->X_subtract_symbol->sy_frag == expressionP->X_add_symbol->sy_frag
+ 		&& SEG_NORMAL (S_GET_SEGMENT (expressionP->X_add_symbol))
  		&& S_GET_VALUE(expressionP->X_subtract_symbol) == S_GET_VALUE(expressionP->X_add_symbol))) {
  	    expressionP->X_subtract_symbol	= NULL;
  	    expressionP->X_add_symbol		= NULL;

>Audit-Trail:
>Unformatted: