Subject: gcc codegen bug? (affects libX11.a)
To: None <port-mac68k@NetBSD.ORG, port-m68k@NetBSD.ORG>
From: Dave Huang <>
List: port-m68k
Date: 04/04/1998 19:37:28
It looks like there's a codegen bug that affects the static version of
libX11 (and probably other things too?) In particular, the
XPolygonRegion that's in the libX11.a in NetBSD/m68k xcomp.tgz crashes. 
I'm seeing the bug in a stock gcc configured as a cross-compiler
w/netbsd-i386 host and netbsd-m68k target. Since the xcomp from the
NetBSD 1.3 release has a bad libX11.a too, I assume it's in the gcc in
the NetBSD tree too. I haven't tried gcc 2.8.1 or egcs.

Here's the portion of lib/X11/PolyReg.c that makes gcc misbehave:

typedef struct _XRegion {
    long size;
    long numRects;
    BOX *rects;
    BOX extents;

XPolygonRegion(Pts, Count, rule)
    int       Count;                 /* number of pts           */
    XPoint     *Pts;		     /* the pts                 */
    int	rule;			     /* winding rule */
    Region region;


	if ((region->extents.x1 != region->extents.x2) &&
	    (region->extents.y1 != region->extents.y2)) {
	    region->numRects = 1;
	    *(region->rects) = region->extents;


When compiled with -O, everything looks good. Here's the body of the
if block (a1 and d7 both contain region):

 5de:   7201            moveq #1,%d1
 5e0:   2341 0004       movel %d1,%a1@(4)
 5e4:   2047            moveal %d7,%a0
 5e6:   2228 000c       movel %a0@(12),%d1
 5ea:   2428 0010       movel %a0@(16),%d2
 5ee:   2268 0008       moveal %a0@(8),%a1
 5f2:   2281            movel %d1,%a1@
 5f4:   2342 0004       movel %d2,%a1@(4)

But when compiled with -O2, gcc comes up with this (a1 and fp@(-1188)
both contain region):

 646:   7e01            moveq #1,%d7
 648:   2347 0004       movel %d7,%a1@(4)
 64c:   226e fb5c       moveal %fp@(-1188),%a1
 650:   2c29 000c       movel %a1@(12),%d6
 654:   2e29 0010       movel %a1@(16),%d7
 658:   226e fb58       moveal %fp@(-1192),%a1  <-- eh??
 65c:   2286            movel %d6,%a1@
 65e:   2347 0004       movel %d7,%a1@(4)

What's this %fp@(-1192) stuff about? It's never initialized, so the
code ends up trying to write to some random memory location, usually
resulting in a SEGV.

Oy, no wonder mozilla crashed... anyways, if anyone's interested,
there's a NetBSD/m68k mozilla binary at

It's statically linked 'cuz I had to cross-link the thing... native ld
seg faulted trying to link the thing. *growl* Native cc seg faulted or
got signal 6 trying to compile some of the files too.

I used fvdl's patches, btw, and set JB_SP_INDEX to 2. (I think that's
right... that's what I got from looking at setjmp.S, at least :)
Linked w/yesterday's lesstif-current.
Name: Dave Huang     |   Mammal, mammal / their names are called /
INet:   |   they raise a paw / the bat, the cat /
FurryMUCK: Dahan     |   dolphin and dog / koala bear and hog -- TMBG