http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47192
Summary: m68k target - gcc uses stack frame after it has been unlinked when compiling with -Os Product: gcc Version: 4.5.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: t...@ls83.eclipse.co.uk Created attachment 22913 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22913 Testcase - Preprocessor output Attached test case produces code which ends with 61 003c 41EE FFFE lea (-2,%fp),%a0 30:gcc-bug.c **** return d; 31:gcc-bug.c **** } 62 .loc 1 32 0 63 0040 242E FFF8 move.l -8(%fp),%d2 64 0044 4E5E unlk %fp 30:gcc-bug.c **** return d; 65 .loc 1 30 0 66 0046 33D0 0000 move.w (%a0),stc.1197 66 0000 67 .loc 1 32 0 68 004c 4E75 rts If an interrupt occurs between the unlk and move.w, the variable pointed to by (a0) is corrupted prior to being copied. Compiling with -O1 keeps the lea and move.w together before the unlk, which is correct. Compiling with -O2 results in a move.w d1,stc.1197 after the unlk (contents of variable already in d1), so gets away with it. gcc output below and .i file attached. Problem also present in 4.5.1. m68k-elf-gcc -v -save-temps -c -g -gdwarf-2 -ffunction-sections -fdata-sections -Os -mcpu=51qe -Wall -Wa,-ahlms=gcc-bug.ls -I. -I/usr/local/gcc-m68k/m68k-elf/include gcc-bug.c Using built-in specs. COLLECT_GCC=m68k-elf-gcc COLLECT_LTO_WRAPPER=/usr/local/gcc-m68k-4.5.2/libexec/gcc/m68k-elf/4.5.2/lto-wrapper Target: m68k-elf Configured with: ../configure --target=m68k-elf --prefix=/usr/local/gcc-m68k-4.5.2 --enable-languages=c --with-newlib --disable-libssp --with-gnu-as --with-gnu-ld Thread model: single gcc version 4.5.2 (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-g' '-gdwarf-2' '-ffunction-sections' '-fdata-sections' '-Os' '-mcpu=51qe' '-Wall' '-I.' '-I/usr/local/gcc-m68k/m68k-elf/include' /usr/local/gcc-m68k-4.5.2/libexec/gcc/m68k-elf/4.5.2/cc1 -E -quiet -v -I. -I/usr/local/gcc-m68k/m68k-elf/include -imultilib m51qe gcc-bug.c -mcpu=51qe -Wall -ffunction-sections -fdata-sections -g -gdwarf-2 -fworking-directory -Os -fpch-preprocess -o gcc-bug.i ignoring nonexistent directory "/usr/local/gcc-m68k-4.5.2/lib/gcc/m68k-elf/4.5.2/../../../../m68k-elf/sys-include" #include "..." search starts here: #include <...> search starts here: . /usr/local/gcc-m68k/m68k-elf/include /usr/local/gcc-m68k-4.5.2/lib/gcc/m68k-elf/4.5.2/include /usr/local/gcc-m68k-4.5.2/lib/gcc/m68k-elf/4.5.2/include-fixed /usr/local/gcc-m68k-4.5.2/lib/gcc/m68k-elf/4.5.2/../../../../m68k-elf/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-g' '-gdwarf-2' '-ffunction-sections' '-fdata-sections' '-Os' '-mcpu=51qe' '-Wall' '-I.' '-I/usr/local/gcc-m68k/m68k-elf/include' /usr/local/gcc-m68k-4.5.2/libexec/gcc/m68k-elf/4.5.2/cc1 -fpreprocessed gcc-bug.i -quiet -dumpbase gcc-bug.c -mcpu=51qe -auxbase gcc-bug -g -gdwarf-2 -Os -Wall -version -ffunction-sections -fdata-sections -o gcc-bug.s GNU C (GCC) version 4.5.2 (m68k-elf) compiled by GNU C version 4.3.2, GMP version 4.2.2, MPFR version 2.3.1, MPC version 0.8.2 GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64520 GNU C (GCC) version 4.5.2 (m68k-elf) compiled by GNU C version 4.3.2, GMP version 4.2.2, MPFR version 2.3.1, MPC version 0.8.2 GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64520 Compiler executable checksum: 2edb184913810d520b23104a9f78d5ce COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-g' '-gdwarf-2' '-ffunction-sections' '-fdata-sections' '-Os' '-mcpu=51qe' '-Wall' '-I.' '-I/usr/local/gcc-m68k/m68k-elf/include' /usr/local/gcc-m68k-4.5.2/lib/gcc/m68k-elf/4.5.2/../../../../m68k-elf/bin/as -v -I. -I/usr/local/gcc-m68k/m68k-elf/include -mcpu=51qe -ahlms=gcc-bug.ls -o gcc-bug.o gcc-bug.s GNU assembler version 2.20 (m68k-elf) using BFD version (GNU Binutils) 2.20 COMPILER_PATH=/usr/local/gcc-m68k-4.5.2/libexec/gcc/m68k-elf/4.5.2/:/usr/local/gcc-m68k-4.5.2/libexec/gcc/m68k-elf/4.5.2/:/usr/local/gcc-m68k-4.5.2/libexec/gcc/m68k-elf/:/usr/local/gcc-m68k-4.5.2/lib/gcc/m68k-elf/4.5.2/:/usr/local/gcc-m68k-4.5.2/lib/gcc/m68k-elf/:/usr/local/gcc-m68k-4.5.2/lib/gcc/m68k-elf/4.5.2/../../../../m68k-elf/bin/ LIBRARY_PATH=/usr/local/gcc-m68k-4.5.2/lib/gcc/m68k-elf/4.5.2/m51qe/:/usr/local/gcc-m68k-4.5.2/lib/gcc/m68k-elf/4.5.2/../../../../m68k-elf/lib/m51qe/:/usr/local/gcc-m68k-4.5.2/lib/gcc/m68k-elf/4.5.2/:/usr/local/gcc-m68k-4.5.2/lib/gcc/m68k-elf/4.5.2/../../../../m68k-elf/lib/ COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-g' '-gdwarf-2' '-ffunction-sections' '-fdata-sections' '-Os' '-mcpu=51qe' '-Wall' '-I.' '-I/usr/local/gcc-m68k/m68k-elf/include'