000-um-Avoid-longjmp-setjmp-symbol-clashes-with-libpthre.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. From f44f1e7da7c8e3f4575d5d61c4df978496903fcc Mon Sep 17 00:00:00 2001
  2. From: Florian Fainelli <[email protected]>
  3. Date: Tue, 23 May 2017 17:32:31 -0700
  4. Subject: [PATCH] um: Avoid longjmp/setjmp symbol clashes with libpthread.a
  5. [ Upstream commit f44f1e7da7c8e3f4575d5d61c4df978496903fcc ]
  6. Building a statically linked UML kernel on a Centos 6.9 host resulted in
  7. the following linking failure (GCC 4.4, glibc-2.12):
  8. /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libpthread.a(libpthread.o):
  9. In function `siglongjmp':
  10. (.text+0x8490): multiple definition of `longjmp'
  11. 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:
  12. first defined here
  13. /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libpthread.a(libpthread.o):
  14. In function `sem_open':
  15. (.text+0x77cd): warning: the use of `mktemp' is dangerous, better use
  16. `mkstemp'
  17. collect2: ld returned 1 exit status
  18. make[4]: *** [vmlinux] Error 1
  19. Adopt a solution similar to the one done for vmap where we define
  20. longjmp/setjmp to be kernel_longjmp/setjmp. In the process, make sure we
  21. do rename the functions in arch/x86/um/setjmp_*.S accordingly.
  22. Fixes: a7df4716d195 ("um: link with -lpthread")
  23. Signed-off-by: Florian Fainelli <[email protected]>
  24. Signed-off-by: Richard Weinberger <[email protected]>
  25. ---
  26. arch/um/Makefile | 4 ++++
  27. arch/x86/um/setjmp_32.S | 16 ++++++++--------
  28. arch/x86/um/setjmp_64.S | 16 ++++++++--------
  29. 3 files changed, 20 insertions(+), 16 deletions(-)
  30. --- a/arch/um/Makefile
  31. +++ b/arch/um/Makefile
  32. @@ -59,10 +59,14 @@ KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_D
  33. # Same things for in6addr_loopback and mktime - found in libc. For these two we
  34. # only get link-time error, luckily.
  35. #
  36. +# -Dlongjmp=kernel_longjmp prevents anything from referencing the libpthread.a
  37. +# embedded copy of longjmp, same thing for setjmp.
  38. +#
  39. # These apply to USER_CFLAGS to.
  40. KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
  41. $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \
  42. + -Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
  43. -Din6addr_loopback=kernel_in6addr_loopback \
  44. -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
  45. --- a/arch/x86/um/setjmp_32.S
  46. +++ b/arch/x86/um/setjmp_32.S
  47. @@ -16,9 +16,9 @@
  48. .text
  49. .align 4
  50. - .globl setjmp
  51. - .type setjmp, @function
  52. -setjmp:
  53. + .globl kernel_setjmp
  54. + .type kernel_setjmp, @function
  55. +kernel_setjmp:
  56. #ifdef _REGPARM
  57. movl %eax,%edx
  58. #else
  59. @@ -35,13 +35,13 @@ setjmp:
  60. movl %ecx,20(%edx) # Return address
  61. ret
  62. - .size setjmp,.-setjmp
  63. + .size kernel_setjmp,.-kernel_setjmp
  64. .text
  65. .align 4
  66. - .globl longjmp
  67. - .type longjmp, @function
  68. -longjmp:
  69. + .globl kernel_longjmp
  70. + .type kernel_longjmp, @function
  71. +kernel_longjmp:
  72. #ifdef _REGPARM
  73. xchgl %eax,%edx
  74. #else
  75. @@ -55,4 +55,4 @@ longjmp:
  76. movl 16(%edx),%edi
  77. jmp *20(%edx)
  78. - .size longjmp,.-longjmp
  79. + .size kernel_longjmp,.-kernel_longjmp
  80. --- a/arch/x86/um/setjmp_64.S
  81. +++ b/arch/x86/um/setjmp_64.S
  82. @@ -18,9 +18,9 @@
  83. .text
  84. .align 4
  85. - .globl setjmp
  86. - .type setjmp, @function
  87. -setjmp:
  88. + .globl kernel_setjmp
  89. + .type kernel_setjmp, @function
  90. +kernel_setjmp:
  91. pop %rsi # Return address, and adjust the stack
  92. xorl %eax,%eax # Return value
  93. movq %rbx,(%rdi)
  94. @@ -34,13 +34,13 @@ setjmp:
  95. movq %rsi,56(%rdi) # Return address
  96. ret
  97. - .size setjmp,.-setjmp
  98. + .size kernel_setjmp,.-kernel_setjmp
  99. .text
  100. .align 4
  101. - .globl longjmp
  102. - .type longjmp, @function
  103. -longjmp:
  104. + .globl kernel_longjmp
  105. + .type kernel_longjmp, @function
  106. +kernel_longjmp:
  107. movl %esi,%eax # Return value (int)
  108. movq (%rdi),%rbx
  109. movq 8(%rdi),%rsp
  110. @@ -51,4 +51,4 @@ longjmp:
  111. movq 48(%rdi),%r15
  112. jmp *56(%rdi)
  113. - .size longjmp,.-longjmp
  114. + .size kernel_longjmp,.-kernel_longjmp