http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49094
Summary: ARM aligned(1) attribute is sometimes dropped Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: will_le...@trimble.com Created attachment 24313 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24313 simple test case to demonstrate problem GCC 4.6.0 sometimes produces unaligned accesses for structures with __attribute__((aligned(1),packed)). GCC 4.4.1 seems fine. See the attached "tst.c" file. GCC 4.6.0 will access an unaligned ip->ip_dst with "ldr" instead of several "ldrb" instructions. The file can be compiled and examined with: arm-none-eabi-gcc -c -g -Os tst.c arm-none-eabi-objdump -S tst.o ********* GCC 4.6.0 produces: Disassembly of section .text: 00000000 <test_alignment>: { struct ip *ip = (struct ip *)m; struct in_addr pkt_dst; pkt_dst = ip->ip_dst ; if( pkt_dst.s_addr == 0 ) return 1; 0: e5900007 ldr r0, [r0, #7] else return 0; } 4: e2700001 rsbs r0, r0, #1 8: 33a00000 movcc r0, #0 c: e12fff1e bx lr ********* GCC 4.4.1 produces: Disassembly of section .text: 00000000 <test_alignment>: } __attribute__ ((aligned(1), packed)); struct ip *ip_fw_fwd_addr; int test_alignment( char *m ) { 0: e5d02008 ldrb r2, [r0, #8] 4: e5d03007 ldrb r3, [r0, #7] 8: e5d01009 ldrb r1, [r0, #9] c: e1833402 orr r3, r3, r2, lsl #8 10: e5d0200a ldrb r2, [r0, #10] 14: e1833801 orr r3, r3, r1, lsl #16 18: e1932c02 orrs r2, r3, r2, lsl #24 pkt_dst = ip->ip_dst ; if( pkt_dst.s_addr == 0 ) return 1; else return 0; } 1c: 13a00000 movne r0, #0 ; 0x0 20: 03a00001 moveq r0, #1 ; 0x1 24: e12fff1e bx lr