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 --- 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.
42 +# -Dlongjmp=kernel_longjmp prevents anything from referencing the libpthread.a
43 +# embedded copy of longjmp, same thing for setjmp.
45 # These apply to USER_CFLAGS to.
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
53 --- a/arch/x86/um/setjmp_32.S
54 +++ b/arch/x86/um/setjmp_32.S
60 - .type setjmp, @function
62 + .globl kernel_setjmp
63 + .type kernel_setjmp, @function
68 @@ -35,13 +35,13 @@ setjmp:
69 movl %ecx,20(%edx) # Return address
72 - .size setjmp,.-setjmp
73 + .size kernel_setjmp,.-kernel_setjmp
78 - .type longjmp, @function
80 + .globl kernel_longjmp
81 + .type kernel_longjmp, @function
86 @@ -55,4 +55,4 @@ longjmp:
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
99 - .type setjmp, @function
101 + .globl kernel_setjmp
102 + .type kernel_setjmp, @function
104 pop %rsi # Return address, and adjust the stack
105 xorl %eax,%eax # Return value
107 @@ -34,13 +34,13 @@ setjmp:
108 movq %rsi,56(%rdi) # Return address
111 - .size setjmp,.-setjmp
112 + .size kernel_setjmp,.-kernel_setjmp
117 - .type longjmp, @function
119 + .globl kernel_longjmp
120 + .type kernel_longjmp, @function
122 movl %esi,%eax # Return value (int)
125 @@ -51,4 +51,4 @@ longjmp:
129 - .size longjmp,.-longjmp
130 + .size kernel_longjmp,.-kernel_longjmp