public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/53016] New: memcpy optimization can cause unaligned access on ARM
@ 2012-04-17  7:08 jquesnelle at gmail dot com
  2012-04-17  8:15 ` [Bug target/53016] " mikpe at it dot uu.se
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jquesnelle at gmail dot com @ 2012-04-17  7:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53016

             Bug #: 53016
           Summary: memcpy optimization can cause unaligned access on ARM
    Classification: Unclassified
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jquesnelle@gmail.com


Created attachment 27174
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27174
reproduction files

The built-in memcpy that -O2 substitutes in seems to cause an unaligned memory
access on ARMv5TE when structs are stacked in a certain way. I originally
discovered this when a release build of native code for inclusion in an Android
program caused a SIGBUS. Attached is a simple test case that replicates this on
Android. There is no main() function but it should be trivial to substitute in
(sorry, I don't have access to a regular ARM Linux box). It appears to involve
over-aggressive use of ldm/stm (possibly ignoring padding?). 

Works fine (-O0):
memcpy((void*)&parent.children[2],(const void*)child3,size);
  24:    4b0a          ldr    r3, [pc, #40]    
  26:    447b          add    r3, pc
  28:    1c19          adds    r1, r3, #0
  2a:    3138          adds    r1, #56
  2c:    4b09          ldr    r3, [pc, #36]    
  2e:    447b          add    r3, pc
  30:    681b          ldr    r3, [r3, #0]
  32:    9a03          ldr    r2, [sp, #12]
  34:    1c08          adds    r0, r1, #0
  36:    1c11          adds    r1, r2, #0
  38:    1c1a          adds    r2, r3, #0
  3a:    f7ff fffe     bl    0 <memcpy>

Gives SIGBUS (-O2):
memcpy((void*)&parent.children[2],(const void*)child3,size);
   2:    4b07          ldr    r3, [pc, #28]
   4:    4907          ldr    r1, [pc, #28]    
   6:    447b          add    r3, pc
   8:    681a          ldr    r2, [r3, #0]
   a:    4479          add    r1, pc
   c:    3138          adds    r1, #56
   e:    1c0b          adds    r3, r1, #0
  10:    323c          adds    r2, #60
  12:    ca31          ldmia    r2!, {r0, r4, r5} <--- Unaligned access
  14:    c331          stmia    r3!, {r0, r4, r5}
  16:    ca13          ldmia    r2!, {r0, r1, r4}
  18:    c313          stmia    r3!, {r0, r1, r4}
  1a:    6812          ldr    r2, [r2, #0]
  1c:    601a          str    r2, [r3, #0]

I have confirmed this both on a TI OMAP 3530 (BeagleBoard) and Samsung Exynos
3110 (Samsung Epic 4G). I'm not sure if this is the same as bug #47754.


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

end of thread, other threads:[~2012-04-18 14:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-17  7:08 [Bug c/53016] New: memcpy optimization can cause unaligned access on ARM jquesnelle at gmail dot com
2012-04-17  8:15 ` [Bug target/53016] " mikpe at it dot uu.se
2012-04-17  8:20 ` mikpe at it dot uu.se
2012-04-17 14:38 ` rearnsha at gcc dot gnu.org
2012-04-17 16:35 ` jquesnelle at gmail dot com
2012-04-17 16:58 ` mikpe at it dot uu.se
2012-04-17 17:09 ` jquesnelle at gmail dot com
2012-04-17 17:31 ` mikpe at it dot uu.se
2012-04-18 14:29 ` rearnsha at gcc dot gnu.org

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).