[Bug c/31701] New: Program giving segmentation fault with '-O2' optimization.
Ashay dot Jaiswal at kpitcummins dot com
gcc-bugzilla@gcc.gnu.org
Wed Apr 25 13:15:00 GMT 2007
Hello all,
I have successfully built SH4-Linux toolchain based on
(binutils-2.17, gcc-4.2-20061205, glibc-2.5) for Renesas SH target.
I am facing problem while executing the following program.
------------------------------------------------------------------
#include <stdio.h>
extern void func();
typedef struct abc {
char name[16];
}ABC;
main()
{
int i;
ABC buffer[20];
for (i=0; i<20; i++)
buffer[i].name[0] = 't';
if (buffer[10].name[0] == 't')
printf("OK\n");
else
printf("NOT OK\n");
}
-------------------------------------------------------------------------
The above program when compiled with '-O0' optimization executes successfully,
but I am getting segmentation fault error while executing the program compiled
with '-O2' optimization.
Observations:
1. I found differences in the assembly output of the program when compiled
with '-O0' and '-O2' optimization.
It seems stack register get corrupted with '-O2' optimization.
Following code corrupts the stack register
L10:
mov.w .L18,r14
mov.l .L19,r1
add r14,r14
mov r14,r15 <<here it is corrupting the stack register
mov.l @r15+,r14
jmp @r1
nop
.align 1
2. Program executes successfully when compiled with '-O2' and
'-fno-optimize-sibling-calls' options.
3. Same problem is encountered with gcc-4.0.1 and after reverting the
patch PR21265(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21265) the program
executes successfully with '-O2' optimization. But this solution doesn't
work with gcc-4.2-20061205 based toolchain.
Any help on this will be appreciated.
Regards,
Ashay Jaiswal
KPIT Cummins Infosystems Ltd,
Pune (INDIA)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based SH-Linux toolchains for Renesas' SH Series.
The following site also offers free technical support to its users.
Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU SH-Linux tools were released on April 5, 2007.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
Summary: Program giving segmentation fault with '-O2'
optimization.
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Ashay dot Jaiswal at kpitcummins dot com
GCC build triplet: i686-pc-linux
GCC host triplet: sh4-unknown-linux
GCC target triplet: sh4-unknown-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31701
More information about the Gcc-bugs
mailing list