toolchain/gcc: update 5.x to 5.5.0
[oweals/openwrt.git] / toolchain / gcc / patches / 5.5.0 / 931-fix-MIPS-softfloat-build-issue.patch
1 From 2b46f9187b6f994fc450628a7cd97fc703dd23e0 Mon Sep 17 00:00:00 2001
2 From: BangLang Huang <banglang.huang@foxmail.com>
3 Date: Wed, 9 Nov 2016 10:36:49 +0800
4 Subject: [PATCH] fix MIPS softfloat build issue
5
6     This patch is backport from github/libffi #272
7
8 Signed-off-by: BangLang Huang <banglang.huang@foxmail.com>
9 ---
10  libffi/src/mips/n32.S | 17 +++++++++++++++++
11  libffi/src/mips/o32.S | 17 +++++++++++++++++
12  2 files changed, 34 insertions(+)
13
14 --- a/libffi/src/mips/n32.S
15 +++ b/libffi/src/mips/n32.S
16 @@ -107,6 +107,16 @@ loadregs:  
17  
18         REG_L   t6, 3*FFI_SIZEOF_ARG($fp)  # load the flags word into t6.
19  
20 +#ifdef __mips_soft_float
21 +       REG_L   a0, 0*FFI_SIZEOF_ARG(t9)
22 +       REG_L   a1, 1*FFI_SIZEOF_ARG(t9)
23 +       REG_L   a2, 2*FFI_SIZEOF_ARG(t9)
24 +       REG_L   a3, 3*FFI_SIZEOF_ARG(t9)
25 +       REG_L   a4, 4*FFI_SIZEOF_ARG(t9)
26 +       REG_L   a5, 5*FFI_SIZEOF_ARG(t9)
27 +       REG_L   a6, 6*FFI_SIZEOF_ARG(t9)
28 +       REG_L   a7, 7*FFI_SIZEOF_ARG(t9)
29 +#else
30         and     t4, t6, ((1<<FFI_FLAG_BITS)-1)
31         REG_L   a0, 0*FFI_SIZEOF_ARG(t9)
32         beqz    t4, arg1_next
33 @@ -193,6 +203,7 @@ arg7_next:  
34  arg8_doublep:  
35         l.d     $f19, 7*FFI_SIZEOF_ARG(t9)      
36  arg8_next:     
37 +#endif
38  
39  callit:                
40         # Load the function pointer
41 @@ -214,6 +225,7 @@ retint:
42         b       epilogue
43  
44  retfloat:
45 +#ifndef __mips_soft_float
46         bne     t6, FFI_TYPE_FLOAT, retdouble
47         jal     t9
48         REG_L   t4, 4*FFI_SIZEOF_ARG($fp)
49 @@ -272,6 +284,7 @@ retstruct_f_d:      
50         s.s     $f0, 0(t4)
51         s.d     $f2, 8(t4)
52         b       epilogue
53 +#endif
54  
55  retstruct_d_soft:
56         bne     t6, FFI_TYPE_STRUCT_D_SOFT, retstruct_f_soft
57 @@ -429,6 +442,7 @@ ffi_closure_N32:
58         REG_S   a6, A6_OFF2($sp)
59         REG_S   a7, A7_OFF2($sp)
60  
61 +#ifndef __mips_soft_float
62         # Store all possible float/double registers.
63         s.d     $f12, F12_OFF2($sp)
64         s.d     $f13, F13_OFF2($sp)
65 @@ -438,6 +452,7 @@ ffi_closure_N32:
66         s.d     $f17, F17_OFF2($sp)
67         s.d     $f18, F18_OFF2($sp)
68         s.d     $f19, F19_OFF2($sp)
69 +#endif
70  
71         # Call ffi_closure_mips_inner_N32 to do the real work.
72         LA      t9, ffi_closure_mips_inner_N32
73 @@ -458,6 +473,7 @@ cls_retint:
74         b       cls_epilogue
75  
76  cls_retfloat:
77 +#ifndef __mips_soft_float
78         bne     v0, FFI_TYPE_FLOAT, cls_retdouble
79         l.s     $f0, V0_OFF2($sp)
80         b       cls_epilogue
81 @@ -500,6 +516,7 @@ cls_retstruct_f_d:  
82         l.s     $f0, V0_OFF2($sp)
83         l.d     $f2, V1_OFF2($sp)
84         b       cls_epilogue
85 +#endif
86         
87  cls_retstruct_small2:  
88         REG_L   v0, V0_OFF2($sp)
89 --- a/libffi/src/mips/o32.S
90 +++ b/libffi/src/mips/o32.S
91 @@ -82,13 +82,16 @@ sixteen:
92                 
93         ADDU    $sp, 4 * FFI_SIZEOF_ARG         # adjust $sp to new args
94  
95 +#ifndef __mips_soft_float
96         bnez    t0, pass_d                      # make it quick for int
97 +#endif
98         REG_L   a0, 0*FFI_SIZEOF_ARG($sp)       # just go ahead and load the
99         REG_L   a1, 1*FFI_SIZEOF_ARG($sp)       # four regs.
100         REG_L   a2, 2*FFI_SIZEOF_ARG($sp)
101         REG_L   a3, 3*FFI_SIZEOF_ARG($sp)
102         b       call_it
103  
104 +#ifndef __mips_soft_float
105  pass_d:
106         bne     t0, FFI_ARGS_D, pass_f
107         l.d     $f12, 0*FFI_SIZEOF_ARG($sp)     # load $fp regs from args
108 @@ -130,6 +133,7 @@ pass_f_d:           
109   #     bne     t0, FFI_ARGS_F_D, call_it
110         l.s     $f12, 0*FFI_SIZEOF_ARG($sp)     # load $fp regs from args
111         l.d     $f14, 2*FFI_SIZEOF_ARG($sp)     # passing double and float
112 +#endif
113  
114  call_it:       
115         # Load the function pointer
116 @@ -158,14 +162,23 @@ retfloat:
117         bne     t2, FFI_TYPE_FLOAT, retdouble
118         jalr    t9
119         REG_L   t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
120 +#ifndef __mips_soft_float
121         s.s     $f0, 0(t0)
122 +#else
123 +       REG_S v0, 0(t0)
124 +#endif
125         b       epilogue
126  
127  retdouble:     
128         bne     t2, FFI_TYPE_DOUBLE, noretval
129         jalr    t9
130         REG_L   t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
131 +#ifndef __mips_soft_float
132         s.d     $f0, 0(t0)
133 +#else
134 +       REG_S v1, 4(t0)
135 +       REG_S v0, 0(t0)
136 +#endif
137         b       epilogue
138         
139  noretval:      
140 @@ -261,9 +274,11 @@ $LCFI7:
141         li      $13, 1          # FFI_O32
142         bne     $16, $13, 1f    # Skip fp save if FFI_O32_SOFT_FLOAT
143         
144 +#ifndef __mips_soft_float
145         # Store all possible float/double registers.
146         s.d     $f12, FA_0_0_OFF2($fp)
147         s.d     $f14, FA_1_0_OFF2($fp)
148 +#endif
149  1:     
150         # Call ffi_closure_mips_inner_O32 to do the work.
151         la      t9, ffi_closure_mips_inner_O32
152 @@ -281,6 +296,7 @@ $LCFI7:
153         li      $13, 1          # FFI_O32
154         bne     $16, $13, 1f    # Skip fp restore if FFI_O32_SOFT_FLOAT
155  
156 +#ifndef __mips_soft_float
157         li      $9, FFI_TYPE_FLOAT
158         l.s     $f0, V0_OFF2($fp)
159         beq     $8, $9, closure_done
160 @@ -288,6 +304,7 @@ $LCFI7:
161         li      $9, FFI_TYPE_DOUBLE
162         l.d     $f0, V0_OFF2($fp)
163         beq     $8, $9, closure_done
164 +#endif
165  1:     
166         REG_L   $3, V1_OFF2($fp)
167         REG_L   $2, V0_OFF2($fp)