Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!seismo!vrdxhq!bms-at!stuart From: stuart@bms-at.UUCP Newsgroups: comp.unix.xenix Subject: Re: Lex Message-ID: <377@bms-at.UUCP> Date: Fri, 17-Apr-87 21:32:27 EST Article-I.D.: bms-at.377 Posted: Fri Apr 17 21:32:27 1987 Date-Received: Sat, 18-Apr-87 08:35:13 EST References: <143@sds.UUCP> Organization: Business Management Systems, Inc., Fairfax, VA Lines: 344 Summary: Large model compiler bugs Your problem was not with Lex, Xenix has numerous bugs with large model compiles. For some programs, the only solution is to hand patch the assembly after every compile! Needless to say, I avoid large model like the plague. As an example, here is a trivial program which will not run in large model: The program runs correctly when compiled using the small model. It bombs using the huge model whether optomized or not. To see it fail, extract bug.c, bug.s(optimized), bug.s.u(unoptimized); cc -M2h bug.c a.out # see it run (no buffering) a.out>temp # see it bomb cc -M2 bug.c a.out>temp # see it run (small model) Our kernel version: release=2.1.3 Our development system: release 2.1 -------------CUT HERE----------------- #include char buf[] = "This is a test\n"; main() { register int rcnt, cnt; /* use both si & di */ register char *bp; rcnt = 0; bp = buf; cnt = sizeof buf - 1; do putchar(*bp++); /* use macro, not function */ while (--cnt); return rcnt; /* tie up register */ } -------------CUT HERE-------------------- ; Static Name Aliases ; TITLE bug BUG_TEXT SEGMENT BYTE PUBLIC 'CODE' BUG_TEXT ENDS _DATA SEGMENT WORD PUBLIC 'DATA' _DATA ENDS CONST SEGMENT WORD PUBLIC 'CONST' CONST ENDS _BSS SEGMENT WORD PUBLIC 'BSS' _BSS ENDS DGROUP GROUP CONST, _BSS, _DATA ASSUME CS: BUG_TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP PUBLIC _buf EXTRN __chkstk:FAR EXTRN __AHSHIFT:FAR EXTRN __flsbuf:FAR _DATA SEGMENT EXTRN __iob:BYTE _DATA ENDS _DATA SEGMENT PUBLIC _buf _buf DB 'This is a test', 0aH, 00H _DATA ENDS BUG_TEXT SEGMENT ; Line 6 PUBLIC _main _main PROC FAR push bp mov bp,sp mov ax,14 call FAR PTR __chkstk push di push si ; bp = -4 ; register di = cnt ; register si = rcnt ; Line 9 sub si,si ; Line 10 mov ax,OFFSET DGROUP:_buf mov [bp-4],ax ;bp mov [bp-2],ds ; Line 11 mov di,15 ; Line 12 $D35: ; Line 13 mov ax,16 cwd add ax,OFFSET __iob adc dx,0 mov cl,OFFSET __AHSHIFT shl dx,cl add dx,SEG __iob mov es,dx mov bx,ax dec WORD PTR es:[bx] cmp WORD PTR es:[bx],0 jl $L20001 mov ax,1 cwd add ax,[bp-4] ;bp adc dx,0 shl dx,cl add dx,[bp-2] les bx,[bp-4] ;bp mov [bp-4],ax ;bp mov [bp-2],dx mov al,es:[bx] mov cx,ax mov ax,12 cwd mov bx,cx add ax,OFFSET __iob adc dx,0 mov cl,OFFSET __AHSHIFT shl dx,cl add dx,SEG __iob mov cx,bx mov es,dx mov bx,ax mov ax,1 cwd mov [bp-10],cx lea cx,[bx] mov [bp-14],cx mov [bp-12],bx ; %%%%% bx not segment ! mov es,bx mov bx,cx add ax,es:[bx] adc dx,0 mov cl,OFFSET __AHSHIFT shl dx,cl add dx,es:[bx+2] mov cx,es:[bx] mov es:[bx],ax mov ax,cx mov cx,es:[bx+2] mov es:[bx+2],dx mov dx,cx mov es,dx mov bx,ax mov al,[bp-10] mov es:[bx],al sub ah,ah jmp SHORT $L20002 $L20001: mov ax,12 cwd add ax,OFFSET __iob adc dx,0 mov cl,OFFSET __AHSHIFT shl dx,cl add dx,SEG __iob push dx push ax mov ax,1 cwd add ax,[bp-4] ;bp adc dx,0 shl dx,cl add dx,[bp-2] les bx,[bp-4] ;bp mov [bp-4],ax ;bp mov [bp-2],dx mov al,es:[bx] cbw push ax call FAR PTR __flsbuf add sp,6 $L20002: ; Line 14 dec di je $+5 jmp $D35 ; Line 15 mov ax,si pop si pop di leave ret _main ENDP BUG_TEXT ENDS END ----------CUT HERE----------------- ; Static Name Aliases ; TITLE bug BUG_TEXT SEGMENT BYTE PUBLIC 'CODE' BUG_TEXT ENDS _DATA SEGMENT WORD PUBLIC 'DATA' _DATA ENDS CONST SEGMENT WORD PUBLIC 'CONST' CONST ENDS _BSS SEGMENT WORD PUBLIC 'BSS' _BSS ENDS DGROUP GROUP CONST, _BSS, _DATA ASSUME CS: BUG_TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP PUBLIC _buf EXTRN __chkstk:FAR EXTRN __AHSHIFT:FAR EXTRN __flsbuf:FAR _DATA SEGMENT EXTRN __iob:BYTE _DATA ENDS _DATA SEGMENT PUBLIC _buf _buf DB 'This is a test', 0aH, 00H _DATA ENDS BUG_TEXT SEGMENT ; Line 6 PUBLIC _main _main PROC FAR push bp mov bp,sp mov ax,14 call FAR PTR __chkstk push di push si ; bp = -4 ; register di = cnt ; register si = rcnt ; Line 7 ; Line 8 ; Line 9 mov si,0 ; Line 10 mov ax,OFFSET DGROUP:_buf mov [bp-4],ax ;bp mov [bp-2],ds ; Line 11 mov di,15 ; Line 12 $D35: ; Line 13 mov ax,16 mov dx,0 add ax,OFFSET __iob adc dx,0 mov cl,OFFSET __AHSHIFT shl dx,cl add dx,SEG __iob mov es,dx mov bx,ax dec WORD PTR es:[bx] cmp WORD PTR es:[bx],0 jge $+5 jmp $L20001 mov ax,1 mov dx,0 add ax,[bp-4] ;bp adc dx,0 mov cl,OFFSET __AHSHIFT shl dx,cl add dx,[bp-2] les bx,[bp-4] ;bp mov [bp-4],ax ;bp mov [bp-2],dx mov al,es:[bx] mov cx,ax mov ax,12 mov dx,0 mov bx,cx add ax,OFFSET __iob adc dx,0 mov cl,OFFSET __AHSHIFT shl dx,cl add dx,SEG __iob mov cx,bx mov es,dx mov bx,ax mov ax,1 mov dx,0 mov [bp-10],cx lea cx,[bx] mov [bp-14],cx mov [bp-12],bx ; %%%%% bx not segment ! mov es,[bp-12] mov bx,[bp-14] add ax,es:[bx] adc dx,0 mov cl,OFFSET __AHSHIFT shl dx,cl add dx,es:[bx+2] mov cx,es:[bx] mov es:[bx],ax mov ax,cx mov cx,es:[bx+2] mov es:[bx+2],dx mov dx,cx mov es,dx mov bx,ax mov al,[bp-10] mov es:[bx],al sub ah,ah jmp $L20002 $L20001: mov ax,12 mov dx,0 add ax,OFFSET __iob adc dx,0 mov cl,OFFSET __AHSHIFT shl dx,cl add dx,SEG __iob push dx push ax mov ax,1 mov dx,0 add ax,[bp-4] ;bp adc dx,0 mov cl,OFFSET __AHSHIFT shl dx,cl add dx,[bp-2] les bx,[bp-4] ;bp mov [bp-4],ax ;bp mov [bp-2],dx mov al,es:[bx] cbw push ax call FAR PTR __flsbuf add sp,6 $L20002: ; Line 14 $DC36: dec di je $+5 jmp $D35 $DB37: ; Line 15 mov ax,si jmp $EX31 ; Line 16 $EX31: pop si pop di leave ret _main ENDP BUG_TEXT ENDS END -- Stuart D. Gathman <..!seismo!dgis!bms-at!stuart>