From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28542 invoked by alias); 10 Nov 2014 14:56:33 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 28489 invoked by uid 48); 10 Nov 2014 14:56:25 -0000 From: "Sergey.Belyashov at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/63808] New: [arm] Invalid register saving in FIQ handler causes register corruption Date: Mon, 10 Nov 2014 14:56:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 4.8.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: Sergey.Belyashov at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-11/txt/msg00727.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63808 Bug ID: 63808 Summary: [arm] Invalid register saving in FIQ handler causes register corruption Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: Sergey.Belyashov at gmail dot com I have found strange bug which causes USR-mode register damage after FIQ processing. Fiq handler stores R8 to the stack and loads it to USR-mode registers at return instruction: fiq: sub lr, lr, #4 stmfd sp!, {r0, r1, r2, r3, r4, r5, r6, r7, r8, lr} .... ldmfd sp!, {r0, r1, r2, r3, r4, r5, r6, r7, r8, pc}^ To reproduce use this code: unsigned char a[8][5]; int func1(unsigned port); unsigned func2(unsigned,void*); __attribute__((optimize("Os"),interrupt("FIQ"))) void fiq(void) { static unsigned char b[8]; unsigned char *p = a[0]; for(int i = 0; i < 8; ++i) { unsigned s = func1(i + 0x10000); func2(s, &b[i]); do { if (s & 1) ++*p; ++p; s >>= 1; } while (s != 0x01); } } Compile it using: $ arm-none-eabi-gcc -c -S -std=c99 test_fiq.c I try to create dummy FIQ handler with one instruction, which clobbes R8: __asm__ volatile ("bl 0x12345" : : : "r8"); But compiler creates valid entry/exit code (ignoring R8 in save/restore). $ arm-none-eabi-gcc -v Using built-in specs. COLLECT_GCC=arm-none-eabi-gcc COLLECT_LTO_WRAPPER=/usr/bin/../lib/gcc/arm-none-eabi/4.8.4/lto-wrapper Target: arm-none-eabi Configured with: /build/buildd/gcc-arm-none-eabi-4.8.4.2014q3/src/gcc/configure --target=arm-none-eabi --prefix=/build/buildd/gcc-arm-none-eabi-4.8.4.2014q3/install-native --libexecdir=/build/buildd/gcc-arm-none-eabi-4.8.4.2014q3/install-native/lib --infodir=/build/buildd/gcc-arm-none-eabi-4.8.4.2014q3/install-native/share/doc/gcc-arm-none-eabi/info --mandir=/build/buildd/gcc-arm-none-eabi-4.8.4.2014q3/install-native/share/doc/gcc-arm-none-eabi/man --htmldir=/build/buildd/gcc-arm-none-eabi-4.8.4.2014q3/install-native/share/doc/gcc-arm-none-eabi/html --pdfdir=/build/buildd/gcc-arm-none-eabi-4.8.4.2014q3/install-native/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/build/buildd/gcc-arm-none-eabi-4.8.4.2014q3/install-native/arm-none-eabi --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Tools for ARM Embedded Processors' --with-multilib-list=armv6-m,armv7-m,armv7e-m,armv7-r Thread model: single gcc version 4.8.4 20140725 (release) [ARM/embedded-4_8-branch revision 213147] (GNU Tools for ARM Embedded Processors)