MIPS: Fix genex.S build with LLVM before 21
Subsystems (2)
PATCH v2 1/1 MIPS: Fix genex.S build with LLVM before 21
Since commit 56651128e2fb ("MIPS: Fix idle VS timer enqueue"), BUILD_SKIPOVER_PROLOGUE uses label differences as the immediates of ORI and PTR_ADDIU. The LLVM integrated assembler accepts such an immediate only from LLVM 21 on, so LLVM=1 builds of every MIPS configuration fail with LLVM 17 to 20 unless LLVM_IAS=0 is set:
<instantiation>:7:11: error: expected an immediate
ori $26, r4k_wait_idle_size - 2
^
<instantiation>:10:14: error: expected an immediate
addiu $26, r4k_wait_exit - r4k_wait_insn + 2
^Wrap both expressions in %lo(). For that operator, LLVM 17 to 20 emit a LO16 fixup instead of rejecting the operand, and resolve it when writing the object, since both expressions are constants by then; no relocation is left. Both values are between 2 and 30, so %lo() does not change them. GNU as and LLVM 21 to 23 emit the same code as before, except on microMIPS, where GNU as now uses the 32-bit ADDIU in the delay slot instead of the 16-bit one. With GCC, the 2 extra bytes replace the 16-bit NOP that padded the end of the prologue, so all symbols keep their addresses; with Clang and LLVM_IAS=0, except_vec_vi and the code after it, up to nmi_handler, move by 4 bytes.
---
v2: only the stable tags change; the code and the rest of the changelog are those of v1 [v1]. The tags now start at 6.6.x and name the two prerequisites Maciej suggested [review] plus b713f27e32d8.
What each stable series has today, and what it will get with the tags:
series 56651128e2fb b713f27e32d8 2b6d718c8dbe will get ------ ------------ ------------ ------------ -------------------- 7.3.y yes yes yes this patch 6.18.y yes yes no 2b6d718c8dbe + this 6.12.y no no no all three + this (a) 6.6.y no no no all three + this (a) 6.1.y no no no nothing (b)
(a) On 6.12.118 and 6.6.162 the three cherry-picks and this patch apply cleanly. For malta_defconfig, genex.o builds with GCC 8.1 and 16.2 and with LLVM 13.0.1, 17.0.1 and 21.1.8 (6.6.162: also 11.1.0), and kernels built with GCC 16.2 and LLVM 17.0.1 boot under QEMU. 56651128e2fb needs b713f27e32d8: without it, all the code after r4k_wait in genex.S is placed in .init.text. Both were queued for 6.12 and 6.6 in 2025 and dropped because of the build failure fixed here ([1] below).
(b) 56651128e2fb conflicts in idle.c on 6.1.y and older.
[v1] https://lore.kernel.org/r/[email protected]/
[review] https://lore.kernel.org/r/[email protected]/
The notes of v1, unchanged:
Quoted 41 lines
No MIPS hardware here. Against mips-fixes (v7.4-rc1). All builds use W=1 and kernel.org toolchains.
- genex.o, before and after, with GCC 8.1 to 16.2 and with LLVM 17 to 23, both with the integrated assembler and with LLVM_IAS=0. Configs:
64r6el, 32r6el, 64r2el, 32r2el, eyeq5, eyeq6, malta (little and big endian, MIPS32r1, microMIPS little and big endian), ip22, ip27, loongson3 andcavium_octeon.
- The objects are byte-identical before and after with GCC, with LLVM_IAS=0 and with LLVM 21 to 23. The only exception is the microMIPS ADDIU above. The 4-byte move with LLVM_IAS=0 is harmless:
set_vi_handler()computes the offsets and the length of the vectored handler from symbols before copying it, andejtag_debug_handlerandnmi_handlerare only referenced through their symbols.
- LLVM 17 to 20 now assemble genex.o for all of these configs except microMIPS and Octeon, which the integrated assembler rejects for other reasons. For malta (little and big endian, MIPS32r1), ip22 and ip27, these objects are byte-identical to the LLVM 21 genex.o.
- vmlinux of 64r2el, 32r2el and malta, built with GCC 8.1 and 16.2, LLVM 17, 20, 21 and 23, and LLVM 17 with LLVM_IAS=0. Where both sides build, vmlinux is byte-identical before and after. With LLVM 17 and 20, genex.o was the only object that failed before, and vmlinux links after. No new warnings.
- The malta kernels built with GCC 8.1 and 16.2, LLVM 17, 20 and 23, and LLVM 17 with LLVM_IAS=0 boot under QEMU 6.2 -cpu 24Kf. That CPU usesr4k_wait(), so interrupts go throughskipover_handle_int. Each kernel boots to an init that keeps the CPU going in and out of idle and then reboots; a QEMU trace shows every interrupt that lands in the idle region resuming atr4k_wait_exit. A microMIPS kernel does not boot under QEMU -cpu M14Kc with or without this patch, so the microMIPS change was not run.In the 2025 thread [2], Nathan suggested requiring LLVM 21 for MIPS in
min-tool-version.sh, and Maciej an #error for older Clang. Both would also stop LLVM 17 to 20 builds with LLVM_IAS=0, which work today, and the stable trees would need the same change before56651128e2fbcould go back to them.On 6.18.y, which also allows LLVM 15 and 16, the patch applies after
2b6d718c8dbe, and LLVM 15 and 16 fail and are fixed the same way.
Quoted 6 lines
The
56651128e2fbbackport was dropped from the 6.14, 6.12 and 6.6 stable queues because of this build failure [1], so 6.12.y and 6.6.y still lack that fix.[1] https://lore.kernel.org/r/2025051415-unloader-likely-b0e6@gregkh/
[2] https://lore.kernel.org/r/20250521224450.GA2412476@ax162/
arch/mips/kernel/genex.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/mips/kernel/genex.S +2 -2
@@ -146,10 +146,10 @@ r4k_wait_exit: MFC0 k0, CP0_EPC /* Subtract/add 2 to let the ISA bit propagate through the mask. */ PTR_LA k1, r4k_wait_insn - 2 - ori k0, r4k_wait_idle_size - 2 + ori k0, %lo(r4k_wait_idle_size - 2) /* %lo() for LLVM < 21 */ .set noreorder bne k0, k1, \handler - PTR_ADDIU k0, r4k_wait_exit - r4k_wait_insn + 2 + PTR_ADDIU k0, %lo(r4k_wait_exit - r4k_wait_insn + 2) /* ditto */ .set reorder MTC0 k0, CP0_EPC .set pop
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.34.1
Quoted 25 lines · Tzu-Ching Yang
Since commit
56651128e2fb("MIPS: Fix idle VS timer enqueue"),BUILD_SKIPOVER_PROLOGUEuses label differences as the immediates of ORI andPTR_ADDIU. The LLVM integrated assembler accepts such an immediate only from LLVM 21 on, so LLVM=1 builds of every MIPS configuration fail with LLVM 17 to 20 unless LLVM_IAS=0 is set:<instantiation>:7:11: error: expected an immediate
ori $26,r4k_wait_idle_size- 2^ <instantiation>:10:14: error: expected an immediate addiu $26, r4k_wait_exit - r4k_wait_insn + 2 ^Wrap both expressions in %lo(). For that operator, LLVM 17 to 20 emit a LO16 fixup instead of rejecting the operand, and resolve it when writing the object, since both expressions are constants by then; no relocation is left. Both values are between 2 and 30, so %lo() does not change them. GNU as and LLVM 21 to 23 emit the same code as before, except on microMIPS, where GNU as now uses the 32-bit ADDIU in the delay slot instead of the 16-bit one. With GCC, the 2 extra bytes replace the 16-bit NOP that padded the end of the prologue, so all symbols keep their addresses; with Clang and LLVM_IAS=0,
except_vec_viand the code after it, up tonmi_handler, move by 4 bytes.
Quoted 4 lines
Fixes 56651128e2fb ("MIPS: Fix idle VS timer enqueue")Reported-by kernel test robot <[email protected]>
Thanks for the patch.
Confirming that landed in clang-21.
Quoted 108 lines
Cc [email protected] # 6.6.x: 56651128e2fb: MIPS: Fix idle VS timer enqueueCc [email protected] # 6.6.x: b713f27e32d8: MIPS: Move r4k_wait() to .cpuidle.text sectionCc [email protected] # 6.6.x: 2b6d718c8dbe: MIPS: Fix whitespace damage in r4k_wait from VS timer fixCc [email protected] # 6.6.xSigned-off-by Tzu-Ching Yang <[email protected]>---
v2: only the stable tags change; the code and the rest of the changelog are those of v1 [v1]. The tags now start at 6.6.x and name the two prerequisites Maciej suggested [review] plusb713f27e32d8.What each stable series has today, and what it will get with the tags:
series 56651128e2fb b713f27e32d8 2b6d718c8dbe will get ------ ------------ ------------ ------------ -------------------- 7.3.y yes yes yes this patch 6.18.y yes yes no 2b6d718c8dbe + this 6.12.y no no no all three + this (a) 6.6.y no no no all three + this (a) 6.1.y no no no nothing (b)(a) On 6.12.118 and 6.6.162 the three cherry-picks and this patch apply cleanly. For
malta_defconfig, genex.o builds with GCC 8.1 and 16.2 and with LLVM 13.0.1, 17.0.1 and 21.1.8 (6.6.162: also 11.1.0), and kernels built with GCC 16.2 and LLVM 17.0.1 boot under QEMU.56651128e2fbneedsb713f27e32d8: without it, all the code afterr4k_waitingenex.Sis placed in .init.text. Both were queued for 6.12 and 6.6 in 2025 and dropped because of the build failure fixed here ([1] below).
(b)56651128e2fbconflicts inidle.con 6.1.y and older.[v1] https://lore.kernel.org/r/[email protected]/
[review] https://lore.kernel.org/r/[email protected]/The notes of v1, unchanged:
Quoted 41 lines
No MIPS hardware here. Against mips-fixes (v7.4-rc1). All builds use W=1 and kernel.org toolchains.
- genex.o, before and after, with GCC 8.1 to 16.2 and with LLVM 17 to 23, both with the integrated assembler and with LLVM_IAS=0. Configs:
64r6el, 32r6el, 64r2el, 32r2el, eyeq5, eyeq6, malta (little and big endian, MIPS32r1, microMIPS little and big endian), ip22, ip27, loongson3 andcavium_octeon.
- The objects are byte-identical before and after with GCC, with LLVM_IAS=0 and with LLVM 21 to 23. The only exception is the microMIPS ADDIU above. The 4-byte move with LLVM_IAS=0 is harmless:
set_vi_handler()computes the offsets and the length of the vectored handler from symbols before copying it, andejtag_debug_handlerandnmi_handlerare only referenced through their symbols.
- LLVM 17 to 20 now assemble genex.o for all of these configs except microMIPS and Octeon, which the integrated assembler rejects for other reasons. For malta (little and big endian, MIPS32r1), ip22 and ip27, these objects are byte-identical to the LLVM 21 genex.o.
- vmlinux of 64r2el, 32r2el and malta, built with GCC 8.1 and 16.2, LLVM 17, 20, 21 and 23, and LLVM 17 with LLVM_IAS=0. Where both sides build, vmlinux is byte-identical before and after. With LLVM 17 and 20, genex.o was the only object that failed before, and vmlinux links after. No new warnings.
- The malta kernels built with GCC 8.1 and 16.2, LLVM 17, 20 and 23, and LLVM 17 with LLVM_IAS=0 boot under QEMU 6.2 -cpu 24Kf. That CPU usesr4k_wait(), so interrupts go throughskipover_handle_int. Each kernel boots to an init that keeps the CPU going in and out of idle and then reboots; a QEMU trace shows every interrupt that lands in the idle region resuming atr4k_wait_exit. A microMIPS kernel does not boot under QEMU -cpu M14Kc with or without this patch, so the microMIPS change was not run.In the 2025 thread [2], Nathan suggested requiring LLVM 21 for MIPS in
min-tool-version.sh, and Maciej an #error for older Clang. Both would also stop LLVM 17 to 20 builds with LLVM_IAS=0, which work today, and the stable trees would need the same change before56651128e2fbcould go back to them.On 6.18.y, which also allows LLVM 15 and 16, the patch applies after
2b6d718c8dbe, and LLVM 15 and 16 fail and are fixed the same way.Quoted 6 lines
The
56651128e2fbbackport was dropped from the 6.14, 6.12 and 6.6 stable queues because of this build failure [1], so 6.12.y and 6.6.y still lack that fix.[1] https://lore.kernel.org/r/2025051415-unloader-likely-b0e6@gregkh/
[2] https://lore.kernel.org/r/20250521224450.GA2412476@ax162/arch/mips/kernel/genex.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/mips/kernel/genex.S +2
-2@@ -146,10 +146,10 @@ r4k_wait_exit: MFC0 k0, CP0_EPC /* Subtract/add 2 to let the ISA bit propagate through the mask. */ PTR_LA k1, r4k_wait_insn - 2 - ori k0, r4k_wait_idle_size - 2 + ori k0, %lo(r4k_wait_idle_size - 2) /* %lo() for LLVM < 21 */ .set noreorder bne k0, k1, \handler - PTR_ADDIU k0, r4k_wait_exit - r4k_wait_insn + 2 + PTR_ADDIU k0, %lo(r4k_wait_exit - r4k_wait_insn + 2) /* ditto */ .set reorder MTC0 k0, CP0_EPC .set popbase-commit:
6628e7d4c6b25c8d18f1345e3a20d21829aae7e4--
2.34.1
Signature · 2 lines
Thanks, ~Nick Desaulniers