From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by listman.redhat.com (Postfix) with ESMTP id BD52D3EBEC for ; Wed, 3 Jul 2002 10:17:03 -0400 (EDT) Received: (from mail@localhost) by int-mx1.corp.redhat.com (8.11.6/8.11.6) id g63EH2N14123 for axp-list@listman.redhat.com; Wed, 3 Jul 2002 10:17:02 -0400 Received: from mx1.redhat.com (mx1.redhat.com [172.16.48.31]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with SMTP id g63EH2a14115 for ; Wed, 3 Jul 2002 10:17:02 -0400 Received: from mail.scs.ch (mail.scs.ch [212.254.229.5]) by mx1.redhat.com (8.11.6/8.11.6) with SMTP id g63E72919410 for ; Wed, 3 Jul 2002 10:07:03 -0400 Received: from SCHLEPPDOWN (schleppdown.scs.ch [172.19.1.17]) by mail.scs.ch (8.11.6/8.11.6) with SMTP id g63EGtm05379 for ; Wed, 3 Jul 2002 16:16:55 +0200 From: "Martin Frey" To: Subject: Compiler Bug in 7.1 Date: Wed, 3 Jul 2002 16:16:42 +0200 Message-ID: <005a01c2229c$48ad1360$110113ac@americas.cpqcorp.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_005B_01C222AD.0C35E360" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0.1 Precedence: bulk Reply-To: axp-list@redhat.com X-Reply-To: List-Help: List-Post: List-Subscribe: , List-Id: Linux and Red Hat on Alpha processors List-Unsubscribe: , List-Archive: This is a multi-part message in MIME format. ------=_NextPart_000_005B_01C222AD.0C35E360 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, when compiling the attached program I hit a bug in the compiler as shipped in Redhat 7.1 (gcc-2.96-87). Can someone with a Redhat 7.2 installation compile it and send me the assembler output? If the bug is also in 7.2 I will try to submit a bug report. You need to compile it towards a kernel tree that is configured for SMP and EV6 CPUs. With ommiting the -mcpu=ev6 compiler option the problem disappears. What happens: when calling an inline function (bogus_inline in the example) the inlining of the function fails. At the begin of the function the argument calculated inside the inline gets computed half through and stored on the stack [ 80($30) ]. The first instance of the inline functions used the half computed argument from the stack while the second instance computes all over correctly and used the correct result. Details are in the comments in the C code. Regards, Martin -- Supercomputing Systems AG email: frey@scs.ch Martin Frey web: http://www.scs.ch/~frey/ Technoparkstrasse 1 phone: +41 1 445 16 00 CH-8005 Zuerich fax: +41 1 445 16 10 ------=_NextPart_000_005B_01C222AD.0C35E360 Content-Type: application/octet-stream; name="gccbug.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gccbug.c" /* compile with gcc -D__KERNEL__ -D__SMP__ -Wall -Wstrict-prototypes -O2 \ -fomit-frame-pointer -fno-strict-aliasing -pipe -mno-fp-regs -ffixed-8 \ -mcpu=ev6 -Wa,-mev6 -I/usr/src/linux-2.4.3-12/include -o gccbug.S -S gccbug.c */ #include #include #include struct foo; struct bar { atomic_t atom; struct inode *ip; }; void external_function(struct vm_area_struct *vma, struct inode *vp, struct bar *bar, struct foo *foo); struct inode *second_external_function(unsigned long var_a, unsigned long var_b, int c); void function_with_wrong_args(unsigned long var_a, unsigned long var_b, int wrong_flag, int var_d); static inline void bogus_inline(unsigned long var_a, unsigned long var_b, int flag, int var_d) { /* the bug occurs only with the pairs 11:3 and 8:3. These combination can be calculated with a s4addq or s8addq. Changing e.g. the 11:3 to 10:3 avoids the bug. */ function_with_wrong_args(var_a, var_b, flag ? 11: 3, var_d); } void bugy_function(struct foo *foo, unsigned long var_a, unsigned long var_b, int var_c) { struct address_space *mapping = NULL; struct bar *bar= NULL; struct inode *vp = NULL; vp = second_external_function(var_b, var_a, 0); mapping = vp->i_mapping; bar = vp->u.generic_ip; if(S_ISDIR(vp->i_mode)) goto almost_end; retry: if (atomic_read(&bar->atom)) { struct vm_area_struct *vma; spin_lock(&mapping->i_shared_lock); vma = mapping->i_mmap_shared; while (vma) { if (var_c) external_function(vma, vp, bar, foo); vma = vma->vm_next_share; } vma = mapping->i_mmap; while (vma) { external_function(vma, vp, bar, foo); vma = vma->vm_next_share; } spin_unlock(&mapping->i_shared_lock); } /* this call ends up buggy. The var_c gets computed in the inline function as cmpult $31, $13, $1 and stored on the stack with stl $1, 80($30) and the arguments gets then reloaded with ldl $18, 80($30) */ bogus_inline(var_a, var_b, var_c, 0); if (var_c) goto retry; goto end; almost_end: /* here we got the right computation of var_c in the inline function: cmpult $31,$13,$18 s8addq $18,3,$18 */ bogus_inline(var_a, var_b, var_c, 0); end: } ------=_NextPart_000_005B_01C222AD.0C35E360 Content-Type: application/octet-stream; name="gccbug.S" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gccbug.S" .file 1 "gccbug.c" .set noat .set noreorder .arch ev6 .text .align 4 .globl bugy_function .ent bugy_function bugy_function: .frame $30,96,$26,0 .mask 0x400fe00,-96 ldgp $29,0($27) $bugy_function..ng: lda $30,-96($30) stq $18,72($30) mov $31,$18 stq $15,56($30) mov $16,$15 ldq $16,72($30) stq $11,24($30) stq $12,32($30) stq $13,40($30) mov $19,$13 stq $14,48($30) stq $26,0($30) stq $9,8($30) stq $10,16($30) .prologue 1 stq $17,64($30) jsr $26,second_external_function ldgp $29,0($26) ldah $2,1 mov $0,$12 lda $2,-4096($2) ldl $1,80($12) ldq $14,288($12) ldq $11,480($12) and $1,$2,$1 zapnot $1,15,$1 lda $1,-16384($1) beq $1,$L782 // here we do the first half of the computation // and store it on the stack. cmpult $31,$13,$1 stl $1,80($30) $L783: ldl $1,0($11) beq $1,$L784 lda $10,96($14) 1: ldl_l $1,0($10) blbs $1,2f or $1,1,$1 stl_c $1,0($10) beq $1,2f mb .subsection 2 2: ldl $1,0($10) blbs $1,2b br 1b .previous ldq $9,88($14) beq $9,$L800 .align 4 $L787: mov $9,$16 mov $12,$17 mov $11,$18 mov $15,$19 beq $13,$L788 jsr $26,external_function ldgp $29,0($26) $L788: ldq $9,72($9) bne $9,$L787 $L800: ldq $9,80($14) beq $9,$L801 .align 4 $L792: mov $9,$16 mov $12,$17 mov $11,$18 mov $15,$19 jsr $26,external_function ldgp $29,0($26) ldq $9,72($9) bne $9,$L792 $L801: mb stl $31,0($10) $L784: // here we fetch the first half of the computation // and use it. The s8addq instruction is missing! ldl $18,80($30) ldq $16,64($30) mov $31,$19 ldq $17,72($30) jsr $26,function_with_wrong_args ldgp $29,0($26) beq $13,$L797 br $31,$L783 .align 4 $L782: ldq $16,64($30) ldq $17,72($30) // here we do the whole computation as it should // be: cmpult + s8addq! cmpult $31,$13,$18 mov $31,$19 s8addq $18,3,$18 jsr $26,function_with_wrong_args ldgp $29,0($26) $L797: ldq $26,0($30) ldq $9,8($30) ldq $10,16($30) ldq $11,24($30) ldq $12,32($30) ldq $13,40($30) ldq $14,48($30) ldq $15,56($30) lda $30,96($30) ret $31,($26),1 .end bugy_function .ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-87)" ------=_NextPart_000_005B_01C222AD.0C35E360--