uclibc-ng: bump version from 1.0.6 to 1.0.8
[openwrt/openwrt.git] / toolchain / uClibc / patches-0.9.33.2 / 614-mips64_fix_setjmp_longjmp.patch
1 commit 70a04a287a2875c82e6822c36e071afba5b63a62
2 Author: Waldemar Brodkorb <wbx@openadk.org>
3 Date: Wed Jan 29 18:58:56 2014 +0100
4
5 libc: mips: Fix setjmp/longjmp for MIPS64 N64 ABI
6
7 When booting a Linux system with qemu-system-mips64 the execution
8 of $(pwd) in the ash shell triggers a segmentation fault. Ash uses
9 setjmp/longjmp for exception handling.
10
11 After looking at the glibc implementation,
12 I found some differences, with this patch tries to resolve.
13 Now the system boots up fine and no segmentation faults occur.
14
15 The global pointer should be restored and the types for the
16 register values should be wide enough.
17
18 See:
19 http://www.cygwin.com/ml/libc-alpha/2003-03/msg00363.html
20
21 Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
22 Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
23
24 --- a/libc/sysdeps/linux/mips/bits/setjmp.h
25 +++ b/libc/sysdeps/linux/mips/bits/setjmp.h
26 @@ -26,13 +26,19 @@
27
28 #include <sgidefs.h>
29
30 +#if _MIPS_SIM == _MIPS_SIM_ABI32
31 +#define ptrsize void *
32 +#else
33 +#define ptrsize long long
34 +#endif
35 +
36 typedef struct
37 {
38 /* Program counter. */
39 - void * __pc;
40 + ptrsize __pc;
41
42 /* Stack pointer. */
43 - void * __sp;
44 + ptrsize __sp;
45
46 /* Callee-saved registers s0 through s7. */
47 #if _MIPS_SIM == _MIPS_SIM_ABI32
48 @@ -42,10 +48,10 @@ typedef struct
49 #endif
50
51 /* The frame pointer. */
52 - void * __fp;
53 + ptrsize __fp;
54
55 /* The global pointer. */
56 - void * __gp;
57 + ptrsize __gp;
58
59 /* Floating point status register. */
60 int __fpc_csr;
61 --- a/libc/sysdeps/linux/mips/setjmp.S
62 +++ b/libc/sysdeps/linux/mips/setjmp.S
63 @@ -53,6 +53,7 @@ __sigsetjmp:
64 PTR_LA t9, __sigsetjmp_aux
65 #if _MIPS_SIM != _MIPS_SIM_ABI32
66 .cpreturn
67 + move a4, gp
68 #endif
69 jr t9
70 #else
71 --- a/libc/sysdeps/linux/mips/setjmp_aux.c
72 +++ b/libc/sysdeps/linux/mips/setjmp_aux.c
73 @@ -31,7 +31,7 @@ extern int __sigjmp_save (sigjmp_buf, in
74
75 int
76 #if _MIPS_SIM == _MIPS_SIM_ABI64
77 -__sigsetjmp_aux (jmp_buf env, int savemask, long sp, long fp)
78 +__sigsetjmp_aux (jmp_buf env, int savemask, long long sp, long long fp, long long gp)
79 #else /* O32 || N32 */
80 __sigsetjmp_aux (jmp_buf env, int savemask, int sp, int fp)
81 #endif /* O32 || N32 */
82 @@ -65,14 +65,14 @@ __sigsetjmp_aux (jmp_buf env, int savema
83 #endif
84
85 /* .. and the stack pointer; */
86 - env[0].__jmpbuf[0].__sp = (void *) sp;
87 + env[0].__jmpbuf[0].__sp = (ptrsize) sp;
88
89 /* .. and the FP; it'll be in s8. */
90 - env[0].__jmpbuf[0].__fp = (void *) fp;
91 + env[0].__jmpbuf[0].__fp = (ptrsize) fp;
92
93 /* .. and the GP; */
94 #if _MIPS_SIM == _MIPS_SIM_ABI64
95 - __asm__ __volatile__ ("sd $gp, %0" : : "m" (env[0].__jmpbuf[0].__gp));
96 + env[0].__jmpbuf[0].__gp = (ptrsize) gp;
97 #else
98 __asm__ __volatile__ ("sw $gp, %0" : : "m" (env[0].__jmpbuf[0].__gp));
99 #endif