0029-MIPS-Fix-build-with-binutils-2.24.51.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. From d339550fcb6a2048b829634612da96b186d97dfe Mon Sep 17 00:00:00 2001
  2. From: Manuel Lauss <manuel.lauss@gmail.com>
  3. Date: Fri, 7 Nov 2014 14:13:54 +0100
  4. Subject: [PATCH] MIPS: Fix build with binutils 2.24.51+
  5. Starting with version 2.24.51.20140728 MIPS binutils complain loudly
  6. about mixing soft-float and hard-float object files, leading to this
  7. build failure since GCC is invoked with "-msoft-float" on MIPS:
  8. {standard input}: Warning: .gnu_attribute 4,3 requires `softfloat'
  9. LD arch/mips/alchemy/common/built-in.o
  10. mipsel-softfloat-linux-gnu-ld: Warning: arch/mips/alchemy/common/built-in.o
  11. uses -msoft-float (set by arch/mips/alchemy/common/prom.o),
  12. arch/mips/alchemy/common/sleeper.o uses -mhard-float
  13. To fix this, we detect if GAS is new enough to support "-msoft-float" command
  14. option, and if it does, we can let GCC pass it to GAS; but then we also need
  15. to sprinkle the files which make use of floating point registers with the
  16. necessary ".set hardfloat" directives.
  17. Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
  18. Cc: Linux-MIPS <linux-mips@linux-mips.org>
  19. Cc: Matthew Fortune <Matthew.Fortune@imgtec.com>
  20. Cc: Markos Chandras <Markos.Chandras@imgtec.com>
  21. Cc: Maciej W. Rozycki <macro@linux-mips.org>
  22. Patchwork: https://patchwork.linux-mips.org/patch/8355/
  23. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  24. ---
  25. arch/mips/Makefile | 9 +++++++++
  26. arch/mips/include/asm/asmmacro-32.h | 6 ++++++
  27. arch/mips/include/asm/asmmacro.h | 7 +++++++
  28. arch/mips/include/asm/fpregdef.h | 14 ++++++++++++++
  29. arch/mips/include/asm/mipsregs.h | 11 ++++++++++-
  30. arch/mips/kernel/branch.c | 2 +-
  31. arch/mips/kernel/genex.S | 1 +
  32. arch/mips/kernel/r2300_fpu.S | 6 ++++++
  33. arch/mips/kernel/r2300_switch.S | 5 +++++
  34. arch/mips/kernel/r4k_fpu.S | 27 +++++++++++++++++++++++++--
  35. arch/mips/kernel/r4k_switch.S | 11 ++++++++++-
  36. arch/mips/kernel/r6000_fpu.S | 5 +++++
  37. arch/mips/math-emu/cp1emu.c | 2 +-
  38. 13 files changed, 100 insertions(+), 6 deletions(-)
  39. diff --git a/arch/mips/Makefile b/arch/mips/Makefile
  40. index 9b8556d..20f6379 100644
  41. --- a/arch/mips/Makefile
  42. +++ b/arch/mips/Makefile
  43. @@ -93,6 +93,15 @@ LDFLAGS_vmlinux += -G 0 -static -n -nostdlib
  44. KBUILD_AFLAGS_MODULE += -mlong-calls
  45. KBUILD_CFLAGS_MODULE += -mlong-calls
  46. +#
  47. +# pass -msoft-float to GAS if it supports it. However on newer binutils
  48. +# (specifically newer than 2.24.51.20140728) we then also need to explicitly
  49. +# set ".set hardfloat" in all files which manipulate floating point registers.
  50. +#
  51. +ifneq ($(call as-option,-Wa$(comma)-msoft-float,),)
  52. + cflags-y += -DGAS_HAS_SET_HARDFLOAT -Wa,-msoft-float
  53. +endif
  54. +
  55. cflags-y += -ffreestanding
  56. #
  57. diff --git a/arch/mips/include/asm/asmmacro-32.h b/arch/mips/include/asm/asmmacro-32.h
  58. index 70e1f17..8038647 100644
  59. --- a/arch/mips/include/asm/asmmacro-32.h
  60. +++ b/arch/mips/include/asm/asmmacro-32.h
  61. @@ -13,6 +13,8 @@
  62. #include <asm/mipsregs.h>
  63. .macro fpu_save_single thread tmp=t0
  64. + .set push
  65. + SET_HARDFLOAT
  66. cfc1 \tmp, fcr31
  67. swc1 $f0, THREAD_FPR0(\thread)
  68. swc1 $f1, THREAD_FPR1(\thread)
  69. @@ -47,9 +49,12 @@
  70. swc1 $f30, THREAD_FPR30(\thread)
  71. swc1 $f31, THREAD_FPR31(\thread)
  72. sw \tmp, THREAD_FCR31(\thread)
  73. + .set pop
  74. .endm
  75. .macro fpu_restore_single thread tmp=t0
  76. + .set push
  77. + SET_HARDFLOAT
  78. lw \tmp, THREAD_FCR31(\thread)
  79. lwc1 $f0, THREAD_FPR0(\thread)
  80. lwc1 $f1, THREAD_FPR1(\thread)
  81. @@ -84,6 +89,7 @@
  82. lwc1 $f30, THREAD_FPR30(\thread)
  83. lwc1 $f31, THREAD_FPR31(\thread)
  84. ctc1 \tmp, fcr31
  85. + .set pop
  86. .endm
  87. .macro cpu_save_nonscratch thread
  88. diff --git a/arch/mips/include/asm/asmmacro.h b/arch/mips/include/asm/asmmacro.h
  89. index 4225e99..d6d5b19 100644
  90. --- a/arch/mips/include/asm/asmmacro.h
  91. +++ b/arch/mips/include/asm/asmmacro.h
  92. @@ -74,6 +74,8 @@
  93. #endif /* CONFIG_MIPS_MT_SMTC */
  94. .macro fpu_save_16even thread tmp=t0
  95. + .set push
  96. + SET_HARDFLOAT
  97. cfc1 \tmp, fcr31
  98. sdc1 $f0, THREAD_FPR0(\thread)
  99. sdc1 $f2, THREAD_FPR2(\thread)
  100. @@ -92,11 +94,13 @@
  101. sdc1 $f28, THREAD_FPR28(\thread)
  102. sdc1 $f30, THREAD_FPR30(\thread)
  103. sw \tmp, THREAD_FCR31(\thread)
  104. + .set pop
  105. .endm
  106. .macro fpu_save_16odd thread
  107. .set push
  108. .set mips64r2
  109. + SET_HARDFLOAT
  110. sdc1 $f1, THREAD_FPR1(\thread)
  111. sdc1 $f3, THREAD_FPR3(\thread)
  112. sdc1 $f5, THREAD_FPR5(\thread)
  113. @@ -127,6 +131,8 @@
  114. .endm
  115. .macro fpu_restore_16even thread tmp=t0
  116. + .set push
  117. + SET_HARDFLOAT
  118. lw \tmp, THREAD_FCR31(\thread)
  119. ldc1 $f0, THREAD_FPR0(\thread)
  120. ldc1 $f2, THREAD_FPR2(\thread)
  121. @@ -150,6 +156,7 @@
  122. .macro fpu_restore_16odd thread
  123. .set push
  124. .set mips64r2
  125. + SET_HARDFLOAT
  126. ldc1 $f1, THREAD_FPR1(\thread)
  127. ldc1 $f3, THREAD_FPR3(\thread)
  128. ldc1 $f5, THREAD_FPR5(\thread)
  129. diff --git a/arch/mips/include/asm/fpregdef.h b/arch/mips/include/asm/fpregdef.h
  130. index 429481f..f184ba0 100644
  131. --- a/arch/mips/include/asm/fpregdef.h
  132. +++ b/arch/mips/include/asm/fpregdef.h
  133. @@ -14,6 +14,20 @@
  134. #include <asm/sgidefs.h>
  135. +/*
  136. + * starting with binutils 2.24.51.20140729, MIPS binutils warn about mixing
  137. + * hardfloat and softfloat object files. The kernel build uses soft-float by
  138. + * default, so we also need to pass -msoft-float along to GAS if it supports it.
  139. + * But this in turn causes assembler errors in files which access hardfloat
  140. + * registers. We detect if GAS supports "-msoft-float" in the Makefile and
  141. + * explicitly put ".set hardfloat" where floating point registers are touched.
  142. + */
  143. +#ifdef GAS_HAS_SET_HARDFLOAT
  144. +#define SET_HARDFLOAT .set hardfloat
  145. +#else
  146. +#define SET_HARDFLOAT
  147. +#endif
  148. +
  149. #if _MIPS_SIM == _MIPS_SIM_ABI32
  150. /*
  151. diff --git a/arch/mips/include/asm/mipsregs.h b/arch/mips/include/asm/mipsregs.h
  152. index bbc3dd4..d68ad1e 100644
  153. --- a/arch/mips/include/asm/mipsregs.h
  154. +++ b/arch/mips/include/asm/mipsregs.h
  155. @@ -1251,7 +1251,7 @@ do { \
  156. /*
  157. * Macros to access the floating point coprocessor control registers
  158. */
  159. -#define read_32bit_cp1_register(source) \
  160. +#define _read_32bit_cp1_register(source, gas_hardfloat) \
  161. ({ \
  162. int __res; \
  163. \
  164. @@ -1261,12 +1261,21 @@ do { \
  165. " # gas fails to assemble cfc1 for some archs, \n" \
  166. " # like Octeon. \n" \
  167. " .set mips1 \n" \
  168. + " "STR(gas_hardfloat)" \n" \
  169. " cfc1 %0,"STR(source)" \n" \
  170. " .set pop \n" \
  171. : "=r" (__res)); \
  172. __res; \
  173. })
  174. +#ifdef GAS_HAS_SET_HARDFLOAT
  175. +#define read_32bit_cp1_register(source) \
  176. + _read_32bit_cp1_register(source, .set hardfloat)
  177. +#else
  178. +#define read_32bit_cp1_register(source) \
  179. + _read_32bit_cp1_register(source, )
  180. +#endif
  181. +
  182. #ifdef HAVE_AS_DSP
  183. #define rddsp(mask) \
  184. ({ \
  185. diff --git a/arch/mips/kernel/branch.c b/arch/mips/kernel/branch.c
  186. index 4d78bf4..aa5dbd3 100644
  187. --- a/arch/mips/kernel/branch.c
  188. +++ b/arch/mips/kernel/branch.c
  189. @@ -366,7 +366,7 @@ int __compute_return_epc_for_insn(struct pt_regs *regs,
  190. case cop1_op:
  191. preempt_disable();
  192. if (is_fpu_owner())
  193. - asm volatile("cfc1\t%0,$31" : "=r" (fcr31));
  194. + fcr31 = read_32bit_cp1_register(CP1_STATUS);
  195. else
  196. fcr31 = current->thread.fpu.fcr31;
  197. preempt_enable();
  198. diff --git a/arch/mips/kernel/genex.S b/arch/mips/kernel/genex.S
  199. index d84f6a5..00b507f 100644
  200. --- a/arch/mips/kernel/genex.S
  201. +++ b/arch/mips/kernel/genex.S
  202. @@ -408,6 +408,7 @@ NESTED(nmi_handler, PT_SIZE, sp)
  203. .set push
  204. /* gas fails to assemble cfc1 for some archs (octeon).*/ \
  205. .set mips1
  206. + SET_HARDFLOAT
  207. cfc1 a1, fcr31
  208. li a2, ~(0x3f << 12)
  209. and a2, a1
  210. diff --git a/arch/mips/kernel/r2300_fpu.S b/arch/mips/kernel/r2300_fpu.S
  211. index f31063d..5ce3b74 100644
  212. --- a/arch/mips/kernel/r2300_fpu.S
  213. +++ b/arch/mips/kernel/r2300_fpu.S
  214. @@ -28,6 +28,8 @@
  215. .set mips1
  216. /* Save floating point context */
  217. LEAF(_save_fp_context)
  218. + .set push
  219. + SET_HARDFLOAT
  220. li v0, 0 # assume success
  221. cfc1 t1,fcr31
  222. EX(swc1 $f0,(SC_FPREGS+0)(a0))
  223. @@ -65,6 +67,7 @@ LEAF(_save_fp_context)
  224. EX(sw t1,(SC_FPC_CSR)(a0))
  225. cfc1 t0,$0 # implementation/version
  226. jr ra
  227. + .set pop
  228. .set nomacro
  229. EX(sw t0,(SC_FPC_EIR)(a0))
  230. .set macro
  231. @@ -80,6 +83,8 @@ LEAF(_save_fp_context)
  232. * stack frame which might have been changed by the user.
  233. */
  234. LEAF(_restore_fp_context)
  235. + .set push
  236. + SET_HARDFLOAT
  237. li v0, 0 # assume success
  238. EX(lw t0,(SC_FPC_CSR)(a0))
  239. EX(lwc1 $f0,(SC_FPREGS+0)(a0))
  240. @@ -116,6 +121,7 @@ LEAF(_restore_fp_context)
  241. EX(lwc1 $f31,(SC_FPREGS+248)(a0))
  242. jr ra
  243. ctc1 t0,fcr31
  244. + .set pop
  245. END(_restore_fp_context)
  246. .set reorder
  247. diff --git a/arch/mips/kernel/r2300_switch.S b/arch/mips/kernel/r2300_switch.S
  248. index 20b7b04..435ea65 100644
  249. --- a/arch/mips/kernel/r2300_switch.S
  250. +++ b/arch/mips/kernel/r2300_switch.S
  251. @@ -120,6 +120,9 @@ LEAF(_restore_fp)
  252. #define FPU_DEFAULT 0x00000000
  253. + .set push
  254. + SET_HARDFLOAT
  255. +
  256. LEAF(_init_fpu)
  257. mfc0 t0, CP0_STATUS
  258. li t1, ST0_CU1
  259. @@ -165,3 +168,5 @@ LEAF(_init_fpu)
  260. mtc1 t0, $f31
  261. jr ra
  262. END(_init_fpu)
  263. +
  264. + .set pop
  265. diff --git a/arch/mips/kernel/r4k_fpu.S b/arch/mips/kernel/r4k_fpu.S
  266. index 73b0ddf..06f8b2a 100644
  267. --- a/arch/mips/kernel/r4k_fpu.S
  268. +++ b/arch/mips/kernel/r4k_fpu.S
  269. @@ -19,8 +19,12 @@
  270. #include <asm/asm-offsets.h>
  271. #include <asm/regdef.h>
  272. +/* preprocessor replaces the fp in ".set fp=64" with $30 otherwise */
  273. +#undef fp
  274. +
  275. .macro EX insn, reg, src
  276. .set push
  277. + SET_HARDFLOAT
  278. .set nomacro
  279. .ex\@: \insn \reg, \src
  280. .set pop
  281. @@ -33,12 +37,17 @@
  282. .set mips3
  283. LEAF(_save_fp_context)
  284. + .set push
  285. + SET_HARDFLOAT
  286. cfc1 t1, fcr31
  287. + .set pop
  288. #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)
  289. .set push
  290. + SET_HARDFLOAT
  291. #ifdef CONFIG_CPU_MIPS32_R2
  292. - .set mips64r2
  293. + .set mips32r2
  294. + .set fp=64
  295. mfc0 t0, CP0_STATUS
  296. sll t0, t0, 5
  297. bgez t0, 1f # skip storing odd if FR=0
  298. @@ -64,6 +73,8 @@ LEAF(_save_fp_context)
  299. 1: .set pop
  300. #endif
  301. + .set push
  302. + SET_HARDFLOAT
  303. /* Store the 16 even double precision registers */
  304. EX sdc1 $f0, SC_FPREGS+0(a0)
  305. EX sdc1 $f2, SC_FPREGS+16(a0)
  306. @@ -84,11 +95,14 @@ LEAF(_save_fp_context)
  307. EX sw t1, SC_FPC_CSR(a0)
  308. jr ra
  309. li v0, 0 # success
  310. + .set pop
  311. END(_save_fp_context)
  312. #ifdef CONFIG_MIPS32_COMPAT
  313. /* Save 32-bit process floating point context */
  314. LEAF(_save_fp_context32)
  315. + .set push
  316. + SET_HARDFLOAT
  317. cfc1 t1, fcr31
  318. mfc0 t0, CP0_STATUS
  319. @@ -134,6 +148,7 @@ LEAF(_save_fp_context32)
  320. EX sw t1, SC32_FPC_CSR(a0)
  321. cfc1 t0, $0 # implementation/version
  322. EX sw t0, SC32_FPC_EIR(a0)
  323. + .set pop
  324. jr ra
  325. li v0, 0 # success
  326. @@ -150,8 +165,10 @@ LEAF(_restore_fp_context)
  327. #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)
  328. .set push
  329. + SET_HARDFLOAT
  330. #ifdef CONFIG_CPU_MIPS32_R2
  331. - .set mips64r2
  332. + .set mips32r2
  333. + .set fp=64
  334. mfc0 t0, CP0_STATUS
  335. sll t0, t0, 5
  336. bgez t0, 1f # skip loading odd if FR=0
  337. @@ -175,6 +192,8 @@ LEAF(_restore_fp_context)
  338. EX ldc1 $f31, SC_FPREGS+248(a0)
  339. 1: .set pop
  340. #endif
  341. + .set push
  342. + SET_HARDFLOAT
  343. EX ldc1 $f0, SC_FPREGS+0(a0)
  344. EX ldc1 $f2, SC_FPREGS+16(a0)
  345. EX ldc1 $f4, SC_FPREGS+32(a0)
  346. @@ -192,6 +211,7 @@ LEAF(_restore_fp_context)
  347. EX ldc1 $f28, SC_FPREGS+224(a0)
  348. EX ldc1 $f30, SC_FPREGS+240(a0)
  349. ctc1 t1, fcr31
  350. + .set pop
  351. jr ra
  352. li v0, 0 # success
  353. END(_restore_fp_context)
  354. @@ -199,6 +219,8 @@ LEAF(_restore_fp_context)
  355. #ifdef CONFIG_MIPS32_COMPAT
  356. LEAF(_restore_fp_context32)
  357. /* Restore an o32 sigcontext. */
  358. + .set push
  359. + SET_HARDFLOAT
  360. EX lw t1, SC32_FPC_CSR(a0)
  361. mfc0 t0, CP0_STATUS
  362. @@ -242,6 +264,7 @@ LEAF(_restore_fp_context32)
  363. ctc1 t1, fcr31
  364. jr ra
  365. li v0, 0 # success
  366. + .set pop
  367. END(_restore_fp_context32)
  368. #endif
  369. diff --git a/arch/mips/kernel/r4k_switch.S b/arch/mips/kernel/r4k_switch.S
  370. index cc78dd9..83b4f05 100644
  371. --- a/arch/mips/kernel/r4k_switch.S
  372. +++ b/arch/mips/kernel/r4k_switch.S
  373. @@ -22,6 +22,9 @@
  374. #include <asm/asmmacro.h>
  375. +/* preprocessor replaces the fp in ".set fp=64" with $30 otherwise */
  376. +#undef fp
  377. +
  378. /*
  379. * Offset to the current process status flags, the first 32 bytes of the
  380. * stack are not used.
  381. @@ -151,6 +154,9 @@ LEAF(_restore_fp)
  382. #define FPU_DEFAULT 0x00000000
  383. + .set push
  384. + SET_HARDFLOAT
  385. +
  386. LEAF(_init_fpu)
  387. #ifdef CONFIG_MIPS_MT_SMTC
  388. /* Rather than manipulate per-VPE Status, set per-TC bit in TCStatus */
  389. @@ -231,7 +237,8 @@ LEAF(_init_fpu)
  390. #ifdef CONFIG_CPU_MIPS32_R2
  391. .set push
  392. - .set mips64r2
  393. + .set mips32r2
  394. + .set fp=64
  395. sll t0, t0, 5 # is Status.FR set?
  396. bgez t0, 1f # no: skip setting upper 32b
  397. @@ -290,3 +297,5 @@ LEAF(_init_fpu)
  398. #endif
  399. jr ra
  400. END(_init_fpu)
  401. +
  402. + .set pop /* SET_HARDFLOAT */
  403. diff --git a/arch/mips/kernel/r6000_fpu.S b/arch/mips/kernel/r6000_fpu.S
  404. index da0fbe4..4707738 100644
  405. --- a/arch/mips/kernel/r6000_fpu.S
  406. +++ b/arch/mips/kernel/r6000_fpu.S
  407. @@ -18,6 +18,9 @@
  408. .set noreorder
  409. .set mips2
  410. + .set push
  411. + SET_HARDFLOAT
  412. +
  413. /* Save floating point context */
  414. LEAF(_save_fp_context)
  415. mfc0 t0,CP0_STATUS
  416. @@ -85,3 +88,5 @@
  417. 1: jr ra
  418. nop
  419. END(_restore_fp_context)
  420. +
  421. + .set pop /* SET_HARDFLOAT */
  422. diff --git a/arch/mips/math-emu/cp1emu.c b/arch/mips/math-emu/cp1emu.c
  423. index 0b4e2e3..c0a0914 100644
  424. --- a/arch/mips/math-emu/cp1emu.c
  425. +++ b/arch/mips/math-emu/cp1emu.c
  426. @@ -817,7 +817,7 @@ static int isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
  427. if (insn.i_format.rs == bc_op) {
  428. preempt_disable();
  429. if (is_fpu_owner())
  430. - asm volatile("cfc1\t%0,$31" : "=r" (fcr31));
  431. + fcr31 = read_32bit_cp1_register(CP1_STATUS);
  432. else
  433. fcr31 = current->thread.fpu.fcr31;
  434. preempt_enable();
  435. --
  436. 2.4.5