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
6 [ Upstream commit f44f1e7da7c8e3f4575d5d61c4df978496903fcc ]
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):
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:
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
20 collect2: ld returned 1 exit status
21 make[4]: *** [vmlinux] Error 1
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.
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>
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(-)
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.
44 +# -Dlongjmp=kernel_longjmp prevents anything from referencing the libpthread.a
45 +# embedded copy of longjmp, same thing for setjmp.
47 # These apply to USER_CFLAGS to.
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
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
64 - .type setjmp, @function
66 + .globl kernel_setjmp
67 + .type kernel_setjmp, @function
72 @@ -35,13 +35,13 @@ setjmp:
73 movl %ecx,20(%edx) # Return address
76 - .size setjmp,.-setjmp
77 + .size kernel_setjmp,.-kernel_setjmp
82 - .type longjmp, @function
84 + .globl kernel_longjmp
85 + .type kernel_longjmp, @function
90 @@ -55,4 +55,4 @@ longjmp:
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
105 - .type setjmp, @function
107 + .globl kernel_setjmp
108 + .type kernel_setjmp, @function
110 pop %rsi # Return address, and adjust the stack
111 xorl %eax,%eax # Return value
113 @@ -34,13 +34,13 @@ setjmp:
114 movq %rsi,56(%rdi) # Return address
117 - .size setjmp,.-setjmp
118 + .size kernel_setjmp,.-kernel_setjmp
123 - .type longjmp, @function
125 + .globl kernel_longjmp
126 + .type kernel_longjmp, @function
128 movl %esi,%eax # Return value (int)
131 @@ -51,4 +51,4 @@ longjmp:
135 - .size longjmp,.-longjmp
136 + .size kernel_longjmp,.-kernel_longjmp