From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23261 invoked by alias); 15 Jan 2004 22:31:12 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 23187 invoked by uid 48); 15 Jan 2004 22:31:10 -0000 Date: Thu, 15 Jan 2004 22:31:00 -0000 From: "oneill+gccbugs at cs dot hmc dot edu" To: gcc-bugs@gcc.gnu.org Message-ID: <20040115223101.13704.oneill+gccbugs@cs.hmc.edu> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c/13704] New: Regression: Spurious register saves with setjmp on MIPS (and others?) (crosscompiling) X-Bugzilla-Reason: CC X-SW-Source: 2004-01/txt/msg01810.txt.bz2 List-Id: This bug a regression in 3.2.x and 3.3.x -- it is not in 3.0.x or 3.4 prereleases, but is in 3.2.x and 3.3.x (including 3.3-20040112) -- it would be helpful to see it fixed in the 3.3.x series, since at present it means that 3.3.x cannot be used without patches for some configurations. Consider the following code (setjmp-caller.c), which will be compiled with -mno-abicalls -fno-pic -ffreestanding --- begin file: setjmp-caller.c ------------------ int setjmp(void *); int foo() { setjmp(0); } --- end file: setjmp-caller.c ------------------ With 3.0.4 and 3.4-20040114, we get the following CORRECT assembly output from a cross compiler (built with -nfp), from running: mips-linux-gcc-3.0.4 -mno-abicalls -fno-pic -ffreestanding -S -o setjmp-caller-3.0.4.s setjmp- caller.c mips-linux-gcc-3.4-20040114 -mno-abicalls -fno-pic -ffreestanding -S -o setjmp-caller-3.4 -20040114.s setjmp-caller.c --- begin file: setjmp-caller-3.0.4.s ------------------ .file 1 "setjmp-caller.c" .text .align 2 .globl foo .ent foo .type foo,@function foo: .frame $fp,24,$31 # vars= 0, regs= 2/0, args= 16, extra= 0 .mask 0xc0000000,-4 .fmask 0x00000000,0 subu $sp,$sp,24 sw $31,20($sp) sw $fp,16($sp) move $fp,$sp move $4,$0 jal setjmp move $sp,$fp lw $31,20($sp) lw $fp,16($sp) addu $sp,$sp,24 j $31 .end foo .ident "GCC: (GNU) 3.0.4" --- end file: setjmp-caller-3.0.4.s ------------------ --- begin file: setjmp-caller-3.4-20040114.s ------------------ .file 1 "setjmp-caller.c" .section .mdebug.abi32 .previous .text .align 2 .globl foo .ent foo .type foo, @function foo: .frame $fp,24,$31 # vars= 0, regs= 2/0, args= 16, gp= 0 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .set nomacro addiu $sp,$sp,-24 sw $31,20($sp) sw $fp,16($sp) move $fp,$sp move $4,$0 jal setjmp nop move $sp,$fp lw $31,20($sp) lw $fp,16($sp) addiu $sp,$sp,24 j $31 nop .set macro .set reorder .end foo .ident "GCC: (GNU) 3.4.0 20040114 (experimental)" --- end file: setjmp-caller-3.4-20040114.s ------------------ With the other versions, we get a number of spurious register saves... For example, with 3.3.2, we get: --- begin file: setjmp-caller-3.3.2.s ------------------ .file 1 "setjmp-caller.c" .section .mdebug.abi32 .previous .text .align 2 .globl foo .ent foo .type foo, @function foo: .frame $fp,104,$31 # vars= 0, regs= 10/6, args= 16, extra= 0 .mask 0xc0ff0000,-52 .fmask 0xfff00000,-8 subu $sp,$sp,104 sw $31,52($sp) sw $fp,48($sp) sw $23,44($sp) sw $22,40($sp) sw $21,36($sp) sw $20,32($sp) sw $19,28($sp) sw $18,24($sp) sw $17,20($sp) sw $16,16($sp) s.d $f30,96($sp) s.d $f28,88($sp) s.d $f26,80($sp) s.d $f24,72($sp) s.d $f22,64($sp) s.d $f20,56($sp) move $fp,$sp move $4,$0 jal setjmp move $sp,$fp lw $31,52($sp) lw $fp,48($sp) lw $23,44($sp) lw $22,40($sp) lw $21,36($sp) lw $20,32($sp) lw $19,28($sp) lw $18,24($sp) lw $17,20($sp) lw $16,16($sp) l.d $f30,96($sp) l.d $f28,88($sp) l.d $f26,80($sp) l.d $f24,72($sp) l.d $f22,64($sp) l.d $f20,56($sp) addu $sp,$sp,104 j $31 .end foo .ident "GCC: (GNU) 3.3.2" --- end file: setjmp-caller-3.3.2.s ------------------ Since the cross compiler was configured with --nfp, this is especially bad, it's emiting floating point instructions for a program that doesn't use fp, on a platform that doesn't support it. I wrote the following bandaid for 3.3.2, but I can't say that it's the right fix, it was just a "make it stop!" solution... --- begin file: gcc-3.3.3-setjmp.patch ------------------ --- gcc-3.3.2+cs161/gcc/reload1.c~ 2003-06-06 22:30:09.000000000 -0700 +++ gcc-3.3.2+cs161/gcc/reload1.c 2004-01-13 21:55:37.000000000 -0800 @@ -760,7 +760,7 @@ && GET_MODE (insn) != VOIDmode) PUT_MODE (insn, VOIDmode); - if (GET_CODE (insn) == CALL_INSN + if (0 && GET_CODE (insn) == CALL_INSN && find_reg_note (insn, REG_SETJMP, NULL)) for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) if (! call_used_regs[i]) --- end file: gcc-3.3.3-setjmp.patch ------------------ Best Regards, M.E. O'Neill. P.S. For what it's worth, in case you want to look into this and you want to know how I built the cross compilers, it was as follows Download binutils-2.14.tar.bz2 gcc-core-3.0.4.tar.gz gcc-core-3.2.3.tar.bz2 gcc-core-3.3-20040112.tar.bz2 gcc-core-3.3.2.tar.bz2 gcc-core-3.4-20040114.tar.bz2 And then, in csh: set target = mips-linux set base = `pwd` set prefix = $base/test-gcc mkdir -p $prefix/bin set path = ($path $prefix/bin) tar xjf binutils-2.14.tar.bz2 mkdir binutils-2.14-build cd binutils-2.14-build ../binutils-2.14/configure --nfp --target $target --prefix $prefix make make install foreach vers (3.2.3 3.3.2 3.3-20040112 3.4-20040114) cd $base if (-e gcc-core-$vers.tar.gz) tar xzf gcc-core-$vers.tar.gz if (-e gcc-core-$vers.tar.bz2) tar xjf gcc-core-$vers.tar.bz2 mkdir -p gcc-$vers-build cd gcc-$vers-build ../gcc-$vers/configure --nfp --disable-shared --disable-threads --target $target --prefix $prefix make make install cd $base mv $prefix/bin/mips-linux-gcc{,-$vers} mv $prefix/bin/mips-linux-cpp{,-$vers} rehash mips-linux-gcc-$vers -mno-abicalls -fno-pic -ffreestanding -S -o setjmp-caller-$vers.s setjmp-caller.c end (note that the 3.4-20040114 build will die [hey, it's a snapshot], but it's easy enough to fix by hand) -- Summary: Regression: Spurious register saves with setjmp on MIPS (and others?) (crosscompiling) Product: gcc Version: 3.3.3 Status: UNCONFIRMED Severity: normal Priority: P1 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: oneill+gccbugs at cs dot hmc dot edu CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: mips-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13704