public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/25380]  New: application segmentation fault when compiled with "-O2", but not with "-O1"
@ 2005-12-13  1:36 hugh dot daschbach at emulex dot com
  2005-12-13  2:25 ` [Bug c/25380] " hugh dot daschbach at emulex dot com
  2005-12-13  4:28 ` [Bug target/25380] " amodra at bigpond dot net dot au
  0 siblings, 2 replies; 3+ messages in thread
From: hugh dot daschbach at emulex dot com @ 2005-12-13  1:36 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-12-13  4:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-13  1:36 [Bug c/25380] New: application segmentation fault when compiled with "-O2", but not with "-O1" hugh dot daschbach at emulex dot com
2005-12-13  2:25 ` [Bug c/25380] " hugh dot daschbach at emulex dot com
2005-12-13  4:28 ` [Bug target/25380] " amodra at bigpond dot net dot au

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).