uml: Backport upstream fix to build against static libpthread
[openwrt/staging/noltari.git] / target / linux / uml / patches-4.4 / 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 diff --git a/arch/um/Makefile b/arch/um/Makefile
37 index 0ca46ededfc7..6ca4f66085c1 100644
38 --- a/arch/um/Makefile
39 +++ b/arch/um/Makefile
40 @@ -59,10 +59,14 @@ KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/um
41 # Same things for in6addr_loopback and mktime - found in libc. For these two we
42 # only get link-time error, luckily.
43 #
44 +# -Dlongjmp=kernel_longjmp prevents anything from referencing the libpthread.a
45 +# embedded copy of longjmp, same thing for setjmp.
46 +#
47 # These apply to USER_CFLAGS to.
48
49 KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
50 $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \
51 + -Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
52 -Din6addr_loopback=kernel_in6addr_loopback \
53 -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
54
55 diff --git a/arch/x86/um/setjmp_32.S b/arch/x86/um/setjmp_32.S
56 index b766792c9933..39053192918d 100644
57 --- a/arch/x86/um/setjmp_32.S
58 +++ b/arch/x86/um/setjmp_32.S
59 @@ -16,9 +16,9 @@
60
61 .text
62 .align 4
63 - .globl setjmp
64 - .type setjmp, @function
65 -setjmp:
66 + .globl kernel_setjmp
67 + .type kernel_setjmp, @function
68 +kernel_setjmp:
69 #ifdef _REGPARM
70 movl %eax,%edx
71 #else
72 @@ -35,13 +35,13 @@ setjmp:
73 movl %ecx,20(%edx) # Return address
74 ret
75
76 - .size setjmp,.-setjmp
77 + .size kernel_setjmp,.-kernel_setjmp
78
79 .text
80 .align 4
81 - .globl longjmp
82 - .type longjmp, @function
83 -longjmp:
84 + .globl kernel_longjmp
85 + .type kernel_longjmp, @function
86 +kernel_longjmp:
87 #ifdef _REGPARM
88 xchgl %eax,%edx
89 #else
90 @@ -55,4 +55,4 @@ longjmp:
91 movl 16(%edx),%edi
92 jmp *20(%edx)
93
94 - .size longjmp,.-longjmp
95 + .size kernel_longjmp,.-kernel_longjmp
96 diff --git a/arch/x86/um/setjmp_64.S b/arch/x86/um/setjmp_64.S
97 index 45f547b4043e..c56942e1a38c 100644
98 --- a/arch/x86/um/setjmp_64.S
99 +++ b/arch/x86/um/setjmp_64.S
100 @@ -18,9 +18,9 @@
101
102 .text
103 .align 4
104 - .globl setjmp
105 - .type setjmp, @function
106 -setjmp:
107 + .globl kernel_setjmp
108 + .type kernel_setjmp, @function
109 +kernel_setjmp:
110 pop %rsi # Return address, and adjust the stack
111 xorl %eax,%eax # Return value
112 movq %rbx,(%rdi)
113 @@ -34,13 +34,13 @@ setjmp:
114 movq %rsi,56(%rdi) # Return address
115 ret
116
117 - .size setjmp,.-setjmp
118 + .size kernel_setjmp,.-kernel_setjmp
119
120 .text
121 .align 4
122 - .globl longjmp
123 - .type longjmp, @function
124 -longjmp:
125 + .globl kernel_longjmp
126 + .type kernel_longjmp, @function
127 +kernel_longjmp:
128 movl %esi,%eax # Return value (int)
129 movq (%rdi),%rbx
130 movq 8(%rdi),%rsp
131 @@ -51,4 +51,4 @@ longjmp:
132 movq 48(%rdi),%r15
133 jmp *56(%rdi)
134
135 - .size longjmp,.-longjmp
136 + .size kernel_longjmp,.-kernel_longjmp
137 --
138 2.13.0
139