Skip to contentSkip to conversation

um: Avoid longjmp/setjmp symbol clashes with libpthread.a

PATCH Superseded Florian Fainelli 2 participants 4 messages May 23, 2017 – May 24, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 um: Avoid longjmp/setjmp symbol clashes with libpthread.a

Building a statically linked UML kernel on a Centos 6.9 host resulted in the following linking failure (GCC 4.4, glibc-2.12):

/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libpthread.a(libpthread.o):
In function `siglongjmp':
(.text+0x8490): multiple definition of `longjmp' 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:
first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libpthread.a(libpthread.o):
In function `sem_open':
(.text+0x77cd): warning: the use of `mktemp' is dangerous, better use
`mkstemp'
collect2: ld returned 1 exit status
make[4]: *** [vmlinux] Error 1

Adopt a solution similar to the one done for vmap where we define longjmp/setjmp to be kernel_longjmp/setjmp. In the process, make sure we do rename the functions in arch/x86/um/setjmp_*.S accordingly.

Fixes a7df4716d195 ("um: link with -lpthread")
---
 arch/um/Makefile        |  4 ++++
 arch/x86/um/setjmp_32.S | 16 ++++++++--------
 arch/x86/um/setjmp_64.S | 16 ++++++++--------
 3 files changed, 20 insertions(+), 16 deletions(-)
arch/um/Makefile +4 -0
index 0ca46ededfc7..6ca4f66085c1 100644
@@ -59,10 +59,14 @@ KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/um
 # Same things for in6addr_loopback and mktime - found in libc. For these two we
 # only get link-time error, luckily.
 #
+# -Dlongjmp=kernel_longjmp prevents anything from referencing the libpthread.a
+# embedded copy of longjmp, same thing for setjmp.
+#
 # These apply to USER_CFLAGS to.
 
 KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
 	$(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap	\
+	-Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
 	-Din6addr_loopback=kernel_in6addr_loopback \
 	-Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
 
arch/x86/um/setjmp_32.S +8 -8
index b766792c9933..16ccb6492e16 100644
@@ -16,9 +16,9 @@
 
 	.text
 	.align 4
-	.globl setjmp
-	.type setjmp, @function
-setjmp:
+	.globl kernel_setjmp
+	.type kernel_setjmp, @function
+kernel_setjmp:
 #ifdef _REGPARM
 	movl %eax,%edx
 #else
@@ -35,13 +35,13 @@ setjmp:
 	movl %ecx,20(%edx)		# Return address
 	ret
 
-	.size setjmp,.-setjmp
+	.size kernel_setjmp,.-kernel_setjmp
 
 	.text
 	.align 4
-	.globl longjmp
-	.type longjmp, @function
-longjmp:
+	.globl kernel_jongjmp
+	.type kernel_jongjmp, @function
+kernel_jongjmp:
 #ifdef _REGPARM
 	xchgl %eax,%edx
 #else
@@ -55,4 +55,4 @@ longjmp:
 	movl 16(%edx),%edi
 	jmp *20(%edx)
 
-	.size longjmp,.-longjmp
+	.size kernel_jongjmp,.-kernel_jongjmp
arch/x86/um/setjmp_64.S +8 -8
index 45f547b4043e..eeb39352897a 100644
@@ -18,9 +18,9 @@
 
 	.text
 	.align 4
-	.globl setjmp
-	.type setjmp, @function
-setjmp:
+	.globl kernel_setjmp
+	.type kernel_setjmp, @function
+kernel_setjmp:
 	pop  %rsi			# Return address, and adjust the stack
 	xorl %eax,%eax			# Return value
 	movq %rbx,(%rdi)
@@ -34,13 +34,13 @@ setjmp:
 	movq %rsi,56(%rdi)		# Return address
 	ret
 
-	.size setjmp,.-setjmp
+	.size kernel_setjmp,.-kernel_setjmp
 
 	.text
 	.align 4
-	.globl longjmp
-	.type longjmp, @function
-longjmp:
+	.globl kernel_jongjmp
+	.type kernel_jongjmp, @function
+kernel_jongjmp:
 	movl %esi,%eax			# Return value (int)
 	movq (%rdi),%rbx
 	movq 8(%rdi),%rsp
@@ -51,4 +51,4 @@ longjmp:
 	movq 48(%rdi),%r15
 	jmp *56(%rdi)
 
-	.size longjmp,.-longjmp
+	.size kernel_jongjmp,.-kernel_jongjmp
Signature · 1 line
2.12.2
#1 lore raw
Quoted 23 lines · Florian Fainelli

Building a statically linked UML kernel on a Centos 6.9 host resulted in the following linking failure (GCC 4.4, glibc-2.12):

/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libpthread.a(libpthread.o):
In function `siglongjmp':
(.text+0x8490): multiple definition of `longjmp' 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:
first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libpthread.a(libpthread.o):
In function `sem_open':
(.text+0x77cd): warning: the use of `mktemp' is dangerous, better use
`mkstemp'
collect2: ld returned 1 exit status
make[4]: *** [vmlinux] Error 1

Adopt a solution similar to the one done for vmap where we define longjmp/setjmp to be kernel_longjmp/setjmp. In the process, make sure we do rename the functions in arch/x86/um/setjmp_*.S accordingly.

Fixes a7df4716d195 ("um: link with -lpthread")

---

arch/x86/um/setjmp_32.S setjmp: · line 44

Quoted 6 lines
arch/x86/um/setjmp_32.S +3 -3
-	.globl longjmp
-	.type longjmp, @function
-longjmp:
+	.globl kernel_jongjmp
+	.type kernel_jongjmp, @function
+kernel_jongjmp:

Dyslexia at its finest, I will submit a corrected v2, the perils of switching between machines....

Signature · 1 line
Florian
#2 lore raw
In reply to Florian Fainelli
url: https://github.com/0day-ci/linux/commits/Florian-Fainelli/um-Avoid-longjmp-setjmp-symbol-clashes-with-libpthread-a/20170524-154948 config: um-x86_64_defconfig (attached as .config) compiler…

Hi Florian,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.12-rc2 next-20170524]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Florian-Fainelli/um-Avoid-longjmp-setjmp-symbol-clashes-with-libpthread-a/20170524-154948
config: um-x86_64_defconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=um SUBARCH=x86_64

Note: the linux-review/Florian-Fainelli/um-Avoid-longjmp-setjmp-symbol-clashes-with-libpthread-a/20170524-154948 HEAD 09c4f46a9b5f1dacc04d404bc93231fd21c83d78 builds fine.
It only hurts bisectibility.

All error/warnings (new ones prefixed by >>):

arch/um/os-Linux/skas/process.c: In function 'start_idle_thread':

>> arch/um/os-Linux/skas/process.c:579:1: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^

vim +248 arch/um/kernel/trap.c

^1da177e arch/um/kernel/trap_kern.c Linus Torvalds     2005-04-16  242  
^1da177e arch/um/kernel/trap_kern.c Linus Torvalds     2005-04-16  243  	catcher = current->thread.fault_catcher;
^1da177e arch/um/kernel/trap_kern.c Linus Torvalds     2005-04-16  244  	if (!err)
f72c22e4 arch/um/kernel/trap.c      Richard Weinberger 2013-09-23  245  		goto out;
^1da177e arch/um/kernel/trap_kern.c Linus Torvalds     2005-04-16  246  	else if (catcher != NULL) {
^1da177e arch/um/kernel/trap_kern.c Linus Torvalds     2005-04-16  247  		current->thread.fault_addr = (void *) address;
fab95c55 arch/um/kernel/trap.c      Jeff Dike          2007-10-16 @248  		UML_LONGJMP(catcher, 1);
^1da177e arch/um/kernel/trap_kern.c Linus Torvalds     2005-04-16  249  	}
^1da177e arch/um/kernel/trap_kern.c Linus Torvalds     2005-04-16  250  	else if (current->thread.fault_addr != NULL)
^1da177e arch/um/kernel/trap_kern.c Linus Torvalds     2005-04-16  251  		panic("fault_addr set but no fault catcher");

:::::: The code at line 248 was first introduced by commit :::::: fab95c55e3b94e219044dc7a558632d08c198771 uml: get rid of do_longjmp

:::::: TO: Jeff Dike <[email protected]>
:::::: CC: Linus Torvalds <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#3 lore raw
In reply to Florian Fainelli
url: https://github.com/0day-ci/linux/commits/Florian-Fainelli/um-Avoid-longjmp-setjmp-symbol-clashes-with-libpthread-a/20170524-154948 config: um-allnoconfig (attached as .config) compiler: gcc-6…

Hi Florian,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.12-rc2 next-20170524]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Florian-Fainelli/um-Avoid-longjmp-setjmp-symbol-clashes-with-libpthread-a/20170524-154948
config: um-allnoconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=um 

All errors (new ones prefixed by >>):

arch/um/kernel/built-in.o: In function `segv':

>> (.text+0x34bd): undefined reference to `kernel_longjmp'

arch/um/kernel/built-in.o: In function `bus_handler':
(.text+0x38c6): undefined reference to kernel_longjmp' arch/um/os-Linux/built-in.o: In function switch_threads':
(.text+0x4e7d): undefined reference to kernel_longjmp' arch/um/os-Linux/built-in.o: In function start_idle_thread':
(.text+0x4f20): undefined reference to kernel_longjmp' arch/um/os-Linux/built-in.o: In function start_idle_thread':
(.text+0x4f58): undefined reference to kernel_longjmp' arch/um/os-Linux/built-in.o:(.text+0x4fab): more undefined references to kernel_longjmp' follow
collect2: error: ld returned 1 exit status

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation