When this testcase, using inline assembly, is compiled with -Os, -O2, or -O3 it
segfaults. -O0 and -O1 allow it to run correctly.
Moving the inline assembly into a separate file and including it in the
compilation allow the program to run correctly at all -O levels.
My results are
gcc -O0 -mcpu=ev67 -D__FAIL rewritten.S test.c -o test && ./test # works
gcc -O1 -mcpu=ev67 -D__FAIL rewritten.S test.c -o test && ./test # works
gcc -Os -mcpu=ev67 -D__FAIL rewritten.S test.c -o test && ./test # segfault
gcc -O2 -mcpu=ev67 -D__FAIL rewritten.S test.c -o test && ./test # segfault
gcc -O3 -mcpu=ev67 -D__FAIL rewritten.S test.c -o test && ./test # segfault
Compiling without -D__FAIL causes the external assembly in rewritten.S to be
used. Without -D__FAIL, the program runs correctly at all -O levels.
--
Summary: Code segfault when compiled with -Os, -O2, or -O3
Product: gcc
Version: 4.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mattst88 at gmail dot com
GCC build triplet: alpha-unknown-linux-gnu
GCC host triplet: alpha-unknown-linux-gnu
GCC target triplet: alpha-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43691