Subject: i386 egcs code generation bug
To: None <current-users@netbsd.org>
From: Sean Doran <smd@ebone.net>
List: current-users
Date: 11/15/1998 05:54:48
When doing a make build, I get an interesting -i386 codegen bug in
/usr/src/lib/csu/common.c:

With:

crasse# gcc -v
Using builtin specs.
gcc version egcs-2.91.58 19981101 (egcs-1.1.1 pre-release)

(all sources supped 19981114 after supscan)

The problem is the N_GETMAGIC declaration in /usr/include/sys/exec_aout.h.

The -current definition is this:

#define N_GETMAGIC(ex) \
    ((((ex).a_midmag)&0xffff0000) ? \
    (ntohl((u_int32_t)(((ex).a_midmag))&0xffff)) : ((ex).a_midmag))

which results in N_GETMAGIC(hdr) to fail just before _FATAL("Bad magic: ld.so");
in /usr/src/lib/csu/common.c; the result is 0xc0860000 as far as I can tell.

With *this* definition:

#define N_GETMAGIC(ex) \
    ((((ex).a_midmag)&0xffff0000) ? \
    (ntohl((u_int32_t) ((ex).a_midmag))&0xffff) : ((ex).a_midmag))

it works.  The difference is that -current puts extra parentheses
around ((ex).a_midmag))&0xffff) .

a context diff on the .s file follows below.

Removing the extra parens on all the CGD-modified N_GET* macros in
sys/exec_aout.h seems to make things happy once again.

	Sean.
- --
*** crt0.s	Sun Nov 15 05:50:08 1998
--- crt0.s.bad	Sun Nov 15 05:48:19 1998
***************
*** 176,187 ****
  	testl $-65536,%edx
  	je L11
  	movl %edx,%eax
  #APP
  	rorw $8, %ax
  	rorl $16, %eax
  	rorw $8, %ax
  #NO_APP
! 	cmpw $267,%ax
  	jne L12
  	jmp L9
  	.align 2,0x90
--- 176,188 ----
  	testl $-65536,%edx
  	je L11
  	movl %edx,%eax
+ 	andl $65535,%eax
  #APP
  	rorw $8, %ax
  	rorl $16, %eax
  	rorw $8, %ax
  #NO_APP
! 	cmpl $267,%eax
  	jne L12
  	jmp L9
  	.align 2,0x90
***************
*** 192,203 ****
  	testl $-65536,%ecx
  	je L15
  	movl %edx,%eax
  #APP
  	rorw $8, %ax
  	rorl $16, %eax
  	rorw $8, %ax
  #NO_APP
! 	cmpw $204,%ax
  	jne L16
  	jmp L9
  	.align 2,0x90
--- 193,205 ----
  	testl $-65536,%ecx
  	je L15
  	movl %edx,%eax
+ 	andl $65535,%eax
  #APP
  	rorw $8, %ax
  	rorl $16, %eax
  	rorw $8, %ax
  #NO_APP
! 	cmpl $204,%eax
  	jne L16
  	jmp L9
  	.align 2,0x90
***************
*** 207,219 ****
  L16:
  	testl $-65536,%ecx
  	je L19
  	movl %edx,%eax
  #APP
  	rorw $8, %ax
  	rorl $16, %eax
  	rorw $8, %ax
  #NO_APP
- 	andl $65535,%eax
  	jmp L20
  	.align 2,0x90
  L19:
--- 209,221 ----
  L16:
  	testl $-65536,%ecx
  	je L19
+ 	andl $65535,%edx
  	movl %edx,%eax
  #APP
  	rorw $8, %ax
  	rorl $16, %eax
  	rorw $8, %ax
  #NO_APP
  	jmp L20
  	.align 2,0x90
  L19:
***************
*** 338,349 ****
  	testl $-65536,%edx
  	je L45
  	movl %edx,%eax
  #APP
  	rorw $8, %ax
  	rorl $16, %eax
  	rorw $8, %ax
  #NO_APP
! 	cmpw $267,%ax
  	je L44
  	jmp L46
  	.align 2,0x90
--- 340,352 ----
  	testl $-65536,%edx
  	je L45
  	movl %edx,%eax
+ 	andl $65535,%eax
  #APP
  	rorw $8, %ax
  	rorl $16, %eax
  	rorw $8, %ax
  #NO_APP
! 	cmpl $267,%eax
  	je L44
  	jmp L46
  	.align 2,0x90
***************
*** 354,365 ****
  	testl $-65536,%ecx
  	je L49
  	movl %edx,%eax
  #APP
  	rorw $8, %ax
  	rorl $16, %eax
  	rorw $8, %ax
  #NO_APP
! 	cmpw $204,%ax
  	je L44
  	jmp L42
  	.align 2,0x90
--- 357,369 ----
  	testl $-65536,%ecx
  	je L49
  	movl %edx,%eax
+ 	andl $65535,%eax
  #APP
  	rorw $8, %ax
  	rorl $16, %eax
  	rorw $8, %ax
  #NO_APP
! 	cmpl $204,%eax
  	je L44
  	jmp L42
  	.align 2,0x90