linux-um archives
 help / color / mirror / Atom feed
* [PATCH] um: Avoid longjmp/setjmp symbol clashes with libpthread.a
@ 2017-05-23 21:08 Florian Fainelli
  2017-05-23 23:03 ` Florian Fainelli
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Florian Fainelli @ 2017-05-23 21:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: Florian Fainelli, Jeff Dike, Richard Weinberger, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin,
	maintainer:X86 ARCHITECTURE 32-BIT AND 64-BIT,
	open list:USER-MODE LINUX, , open list:USER-MODE LINUX

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")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 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(-)

diff --git a/arch/um/Makefile b/arch/um/Makefile
index 0ca46ededfc7..6ca4f66085c1 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -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
 
diff --git a/arch/x86/um/setjmp_32.S b/arch/x86/um/setjmp_32.S
index b766792c9933..16ccb6492e16 100644
--- a/arch/x86/um/setjmp_32.S
+++ b/arch/x86/um/setjmp_32.S
@@ -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
diff --git a/arch/x86/um/setjmp_64.S b/arch/x86/um/setjmp_64.S
index 45f547b4043e..eeb39352897a 100644
--- a/arch/x86/um/setjmp_64.S
+++ b/arch/x86/um/setjmp_64.S
@@ -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
-- 
2.12.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] um: Avoid longjmp/setjmp symbol clashes with libpthread.a
  2017-05-23 21:08 [PATCH] um: Avoid longjmp/setjmp symbol clashes with libpthread.a Florian Fainelli
@ 2017-05-23 23:03 ` Florian Fainelli
  2017-05-24 11:22 ` kbuild test robot
  2017-05-24 16:21 ` kbuild test robot
  2 siblings, 0 replies; 4+ messages in thread
From: Florian Fainelli @ 2017-05-23 23:03 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jeff Dike, Richard Weinberger, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:USER-MODE LINUX (UML), open list:USER-MODE LINUX (UML)

On 05/23/2017 02:08 PM, Florian Fainelli wrote:
> 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")
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---

> -	.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....

-- 
Florian


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] um: Avoid longjmp/setjmp symbol clashes with libpthread.a
  2017-05-23 21:08 [PATCH] um: Avoid longjmp/setjmp symbol clashes with libpthread.a Florian Fainelli
  2017-05-23 23:03 ` Florian Fainelli
@ 2017-05-24 11:22 ` kbuild test robot
  2017-05-24 16:21 ` kbuild test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2017-05-24 11:22 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: kbuild-all, linux-kernel, Florian Fainelli, Jeff Dike,
	Richard Weinberger, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:USER-MODE LINUX (UML), open list:USER-MODE LINUX (UML)

[-- Attachment #1: Type: text/plain, Size: 2412 bytes --]

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 <jdike@addtoit.com>
:::::: CC: Linus Torvalds <torvalds@woody.linux-foundation.org>

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

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 7762 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] um: Avoid longjmp/setjmp symbol clashes with libpthread.a
  2017-05-23 21:08 [PATCH] um: Avoid longjmp/setjmp symbol clashes with libpthread.a Florian Fainelli
  2017-05-23 23:03 ` Florian Fainelli
  2017-05-24 11:22 ` kbuild test robot
@ 2017-05-24 16:21 ` kbuild test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2017-05-24 16:21 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: kbuild-all, linux-kernel, Florian Fainelli, Jeff Dike,
	Richard Weinberger, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:USER-MODE LINUX (UML), open list:USER-MODE LINUX (UML)

[-- Attachment #1: Type: text/plain, Size: 1466 bytes --]

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

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 4135 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-05-24 16:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-23 21:08 [PATCH] um: Avoid longjmp/setjmp symbol clashes with libpthread.a Florian Fainelli
2017-05-23 23:03 ` Florian Fainelli
2017-05-24 11:22 ` kbuild test robot
2017-05-24 16:21 ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox