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