uml: Add 4.9 kernel patches
[openwrt/openwrt.git] / target / linux / uml / patches-4.9 / 000-um-Avoid-longjmp-setjmp-symbol-clashes-with-libpthre.patch
1 From f44f1e7da7c8e3f4575d5d61c4df978496903fcc Mon Sep 17 00:00:00 2001
2 From: Florian Fainelli <f.fainelli@gmail.com>
3 Date: Tue, 23 May 2017 17:32:31 -0700
4 Subject: [PATCH] um: Avoid longjmp/setjmp symbol clashes with libpthread.a
5
6 [ Upstream commit f44f1e7da7c8e3f4575d5d61c4df978496903fcc ]
7
8 Building a statically linked UML kernel on a Centos 6.9 host resulted in
9 the following linking failure (GCC 4.4, glibc-2.12):
10
11 /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libpthread.a(libpthread.o):
12 In function `siglongjmp':
13 (.text+0x8490): multiple definition of `longjmp'
14 arch/x86/um/built-in.o:/local/users/fainelli/openwrt/trunk/build_dir/target-x86_64_musl/linux-uml/linux-4.4.69/arch/x86/um/setjmp_64.S:44:
15 first defined here
16 /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libpthread.a(libpthread.o):
17 In function `sem_open':
18 (.text+0x77cd): warning: the use of `mktemp' is dangerous, better use
19 `mkstemp'
20 collect2: ld returned 1 exit status
21 make[4]: *** [vmlinux] Error 1
22
23 Adopt a solution similar to the one done for vmap where we define
24 longjmp/setjmp to be kernel_longjmp/setjmp. In the process, make sure we
25 do rename the functions in arch/x86/um/setjmp_*.S accordingly.
26
27 Fixes: a7df4716d195 ("um: link with -lpthread")
28 Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
29 Signed-off-by: Richard Weinberger <richard@nod.at>
30 ---
31 arch/um/Makefile | 4 ++++
32 arch/x86/um/setjmp_32.S | 16 ++++++++--------
33 arch/x86/um/setjmp_64.S | 16 ++++++++--------
34 3 files changed, 20 insertions(+), 16 deletions(-)
35
36 --- a/arch/um/Makefile
37 +++ b/arch/um/Makefile
38 @@ -59,10 +59,14 @@ KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_D
39 # Same things for in6addr_loopback and mktime - found in libc. For these two we
40 # only get link-time error, luckily.
41 #
42 +# -Dlongjmp=kernel_longjmp prevents anything from referencing the libpthread.a
43 +# embedded copy of longjmp, same thing for setjmp.
44 +#
45 # These apply to USER_CFLAGS to.
46
47 KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
48 $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \
49 + -Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
50 -Din6addr_loopback=kernel_in6addr_loopback \
51 -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
52
53 --- a/arch/x86/um/setjmp_32.S
54 +++ b/arch/x86/um/setjmp_32.S
55 @@ -16,9 +16,9 @@
56
57 .text
58 .align 4
59 - .globl setjmp
60 - .type setjmp, @function
61 -setjmp:
62 + .globl kernel_setjmp
63 + .type kernel_setjmp, @function
64 +kernel_setjmp:
65 #ifdef _REGPARM
66 movl %eax,%edx
67 #else
68 @@ -35,13 +35,13 @@ setjmp:
69 movl %ecx,20(%edx) # Return address
70 ret
71
72 - .size setjmp,.-setjmp
73 + .size kernel_setjmp,.-kernel_setjmp
74
75 .text
76 .align 4
77 - .globl longjmp
78 - .type longjmp, @function
79 -longjmp:
80 + .globl kernel_longjmp
81 + .type kernel_longjmp, @function
82 +kernel_longjmp:
83 #ifdef _REGPARM
84 xchgl %eax,%edx
85 #else
86 @@ -55,4 +55,4 @@ longjmp:
87 movl 16(%edx),%edi
88 jmp *20(%edx)
89
90 - .size longjmp,.-longjmp
91 + .size kernel_longjmp,.-kernel_longjmp
92 --- a/arch/x86/um/setjmp_64.S
93 +++ b/arch/x86/um/setjmp_64.S
94 @@ -18,9 +18,9 @@
95
96 .text
97 .align 4
98 - .globl setjmp
99 - .type setjmp, @function
100 -setjmp:
101 + .globl kernel_setjmp
102 + .type kernel_setjmp, @function
103 +kernel_setjmp:
104 pop %rsi # Return address, and adjust the stack
105 xorl %eax,%eax # Return value
106 movq %rbx,(%rdi)
107 @@ -34,13 +34,13 @@ setjmp:
108 movq %rsi,56(%rdi) # Return address
109 ret
110
111 - .size setjmp,.-setjmp
112 + .size kernel_setjmp,.-kernel_setjmp
113
114 .text
115 .align 4
116 - .globl longjmp
117 - .type longjmp, @function
118 -longjmp:
119 + .globl kernel_longjmp
120 + .type kernel_longjmp, @function
121 +kernel_longjmp:
122 movl %esi,%eax # Return value (int)
123 movq (%rdi),%rbx
124 movq 8(%rdi),%rsp
125 @@ -51,4 +51,4 @@ longjmp:
126 movq 48(%rdi),%r15
127 jmp *56(%rdi)
128
129 - .size longjmp,.-longjmp
130 + .size kernel_longjmp,.-kernel_longjmp