kernel: backport ARM memset fixes for GCC 4.7/4.8
[openwrt.git] / target / linux / generic / patches-3.3 / 002-ARM-7668-1-fix-memset-related-crashes-caused-by-rece.patch
1 From 418df63adac56841ef6b0f1fcf435bc64d4ed177 Mon Sep 17 00:00:00 2001
2 From: Nicolas Pitre <nicolas.pitre@linaro.org>
3 Date: Tue, 12 Mar 2013 13:00:42 +0100
4 Subject: [PATCH] ARM: 7670/1: fix the memset fix
5
6 Commit 455bd4c430b0 ("ARM: 7668/1: fix memset-related crashes caused by
7 recent GCC (4.7.2) optimizations") attempted to fix a compliance issue
8 with the memset return value.  However the memset itself became broken
9 by that patch for misaligned pointers.
10
11 This fixes the above by branching over the entry code from the
12 misaligned fixup code to avoid reloading the original pointer.
13
14 Also, because the function entry alignment is wrong in the Thumb mode
15 compilation, that fixup code is moved to the end.
16
17 While at it, the entry instructions are slightly reworked to help dual
18 issue pipelines.
19
20 Signed-off-by: Nicolas Pitre <nico@linaro.org>
21 Tested-by: Alexander Holler <holler@ahsoftware.de>
22 Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
23 ---
24  arch/arm/lib/memset.S | 33 +++++++++++++--------------------
25  1 file changed, 13 insertions(+), 20 deletions(-)
26
27 diff --git a/arch/arm/lib/memset.S b/arch/arm/lib/memset.S
28 index d912e7397ecc..94b0650ea98f 100644
29 --- a/arch/arm/lib/memset.S
30 +++ b/arch/arm/lib/memset.S
31 @@ -14,31 +14,15 @@
32  
33         .text
34         .align  5
35 -       .word   0
36 -
37 -1:     subs    r2, r2, #4              @ 1 do we have enough
38 -       blt     5f                      @ 1 bytes to align with?
39 -       cmp     r3, #2                  @ 1
40 -       strltb  r1, [ip], #1            @ 1
41 -       strleb  r1, [ip], #1            @ 1
42 -       strb    r1, [ip], #1            @ 1
43 -       add     r2, r2, r3              @ 1 (r2 = r2 - (4 - r3))
44 -/*
45 - * The pointer is now aligned and the length is adjusted.  Try doing the
46 - * memset again.
47 - */
48  
49  ENTRY(memset)
50 -/*
51 - * Preserve the contents of r0 for the return value.
52 - */
53 -       mov     ip, r0
54 -       ands    r3, ip, #3              @ 1 unaligned?
55 -       bne     1b                      @ 1
56 +       ands    r3, r0, #3              @ 1 unaligned?
57 +       mov     ip, r0                  @ preserve r0 as return value
58 +       bne     6f                      @ 1
59  /*
60   * we know that the pointer in ip is aligned to a word boundary.
61   */
62 -       orr     r1, r1, r1, lsl #8
63 +1:     orr     r1, r1, r1, lsl #8
64         orr     r1, r1, r1, lsl #16
65         mov     r3, r1
66         cmp     r2, #16
67 @@ -127,4 +111,13 @@ ENTRY(memset)
68         tst     r2, #1
69         strneb  r1, [ip], #1
70         mov     pc, lr
71 +
72 +6:     subs    r2, r2, #4              @ 1 do we have enough
73 +       blt     5b                      @ 1 bytes to align with?
74 +       cmp     r3, #2                  @ 1
75 +       strltb  r1, [ip], #1            @ 1
76 +       strleb  r1, [ip], #1            @ 1
77 +       strb    r1, [ip], #1            @ 1
78 +       add     r2, r2, r3              @ 1 (r2 = r2 - (4 - r3))
79 +       b       1b
80  ENDPROC(memset)
81 -- 
82 1.8.3.2
83