This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/25380] New: application segmentation fault when compiled with "-O2", but not with "-O1"
- From: "hugh dot daschbach at emulex dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 Dec 2005 01:36:54 -0000
- Subject: [Bug c/25380] New: application segmentation fault when compiled with "-O2", but not with "-O1"
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
ppc64 segmentation fault on function return that returns the value of another
function.
Segmentation fault occurs when application is compiled with "-O2", but not when
compiled with "-O1". *.i files identical, so included is a small test program,
rather than the .i file. Apply following as a patch. Test with "make test".
diff -urpN null/libwrapped.c ppc-test/libwrapped.c
--- null/libwrapped.c 1969-12-31 16:00:00.000000000 -0800
+++ ppc-test/libwrapped.c 2005-12-12 10:22:02.000000000 -0800
@@ -0,0 +1,11 @@
+#include "proto.h"
+
+unsigned long fn(void)
+{
+ return 0;
+}
+
+unsigned long wrapped(void)
+{
+ return fn();
+}
diff -urpN null/main.c ppc-test/main.c
--- null/main.c 1969-12-31 16:00:00.000000000 -0800
+++ ppc-test/main.c 2005-12-12 12:11:37.000000000 -0800
@@ -0,0 +1,9 @@
+#include <stdio.h>
+#include "proto.h"
+
+int main(int argc, char **argv)
+{
+ printf("unwrapped: %ld\n", fn());
+ printf("wrapped: %ld\n", wrapped());
+ return 0;
+}
diff -urpN null/Makefile ppc-test/Makefile
--- null/Makefile 1969-12-31 16:00:00.000000000 -0800
+++ ppc-test/Makefile 2005-12-12 12:27:25.000000000 -0800
@@ -0,0 +1,21 @@
+# -*- makefile -*-
+
+CFLAGS = -m64 -Wall -g -O2
+
+main: main.o libwrapped.so
+ $(CC) $(CFLAGS) -o main main.o -L. -lwrapped
+
+libwrapped.o: libwrapped.c proto.h
+ $(CC) $(CFLAGS) -c -o libwrapped.o libwrapped.c
+
+libwrapped.so: libwrapped.o
+ ld -g -m elf64ppc -G -h libwrapped.so -o libwrapped.so libwrapped.o
+
+main.o: main.c proto.h
+ $(CC) $(CFLAGS) -c -o main.o main.c
+
+clean:
+ rm -f *.o *.so main
+
+test: main
+ LD_LIBRARY_PATH=. ./main
diff -urpN null/proto.h ppc-test/proto.h
--- null/proto.h 1969-12-31 16:00:00.000000000 -0800
+++ ppc-test/proto.h 2005-12-09 13:58:10.000000000 -0800
@@ -0,0 +1,3 @@
+extern unsigned long fn(void);
+extern unsigned long wrapped(void);
+
--
Summary: application segmentation fault when compiled with "-O2",
but not with "-O1"
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: hugh dot daschbach at emulex dot com
GCC build triplet: powerpc64-unknown-linux-gnu
GCC host triplet: powerpc64-unknown-linux-gnu
GCC target triplet: powerpc64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25380