Skip to contentSkip to conversation

ARM: entry: add .ltorg directive to keep literals in range

PATCH In review Ard Biesheuvel 3 participants 5 messages May 30, 2022 – Jun 8, 2022 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: entry: add .ltorg directive to keep literals in range

LKP reports a build issue on Clang, related to a literal load of __current issued through the ldr_va macro. This turns out to be due to the fact that group relocations are disabled when CONFIG_COMPILE_TEST=y, which means that the ldr_va macro resolves to a pair of LDR instructions, the first one being a literal load issued too far from its literal pool.

Due to the introduction of a couple of new uses of this macro in commit 508074607c7b95b2 ("ARM: 9195/1: entry: avoid explicit literal loads"), the literal pools end up getting rearranged in a way that causes the literal for __current to go out of range. Let's fix this up by putting a .ltorg directive in a suitable place in the code.

Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
Fixes 508074607c7b95b2 ("ARM: 9195/1: entry: avoid explicit literal loads")
---
 arch/arm/kernel/entry-common.S | 1 +
 1 file changed, 1 insertion(+)
arch/arm/kernel/entry-common.S +1 -0
index 7aa3ded4af92..6a447ac67d80 100644
@@ -298,14 +298,15 @@ local_restart:
 9001:
 	sub	lr, saved_pc, #4
 	str	lr, [sp, #S_PC]
 	get_thread_info tsk
 	b	ret_fast_syscall
 #endif
 ENDPROC(vector_swi)
+	.ltorg
 
 	/*
 	 * This is the really slow path.  We're going to be doing
 	 * context switches, and waiting for our parent to respond.
 	 */
 __sys_trace:
 	add	r0, sp, #S_OFF
Signature · 7 lines
2.30.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Tested-by on v1 1/1
#1 lore raw
Quoted 6 lines · Ard Biesheuvel

LKP reports a build issue on Clang, related to a literal load of __current issued through the ldr_va macro. This turns out to be due to the fact that group relocations are disabled when CONFIG_COMPILE_TEST=y, which means that the ldr_va macro resolves to a pair of LDR instructions, the first one being a literal load issued too far from its literal pool.

For the record, I do see a similar failure with GNU as, not sure if it is worth calling that out in the commit message or not:

arch/arm/kernel/entry-common.S: Assembler messages:
arch/arm/kernel/entry-common.S:149: Error: invalid literal constant: pool needs to be closer

Quoted 6 lines

Due to the introduction of a couple of new uses of this macro in commit 508074607c7b95b2 ("ARM: 9195/1: entry: avoid explicit literal loads"), the literal pools end up getting rearranged in a way that causes the literal for __current to go out of range. Let's fix this up by putting a .ltorg directive in a suitable place in the code.

Quoted 6 lines
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
Fixes 508074607c7b95b2 ("ARM: 9195/1: entry: avoid explicit literal loads")

With the problematic configuration, I no longer see issues with either clang or GCC:

Quoted 27 lines
---
 arch/arm/kernel/entry-common.S | 1 +
 1 file changed, 1 insertion(+)
arch/arm/kernel/entry-common.S +1 -0
index 7aa3ded4af92..6a447ac67d80 100644
@@ -298,14 +298,15 @@ local_restart:
 9001:
 	sub	lr, saved_pc, #4
 	str	lr, [sp, #S_PC]
 	get_thread_info tsk
 	b	ret_fast_syscall
 #endif
 ENDPROC(vector_swi)
+	.ltorg
 
 	/*
 	 * This is the really slow path.  We're going to be doing
 	 * context switches, and waiting for our parent to respond.
 	 */
 __sys_trace:
 	add	r0, sp, #S_OFF
Signature · 1 line
2.30.2

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#2 lore raw
Quoted 9 lines · Nathan Chancellor
Quoted 6 lines · Ard Biesheuvel

LKP reports a build issue on Clang, related to a literal load of __current issued through the ldr_va macro. This turns out to be due to the fact that group relocations are disabled when CONFIG_COMPILE_TEST=y, which means that the ldr_va macro resolves to a pair of LDR instructions, the first one being a literal load issued too far from its literal pool.

Quoted 6 lines

For the record, I do see a similar failure with GNU as, not sure if it is worth calling that out in the commit message or not:

arch/arm/kernel/entry-common.S: Assembler messages:
arch/arm/kernel/entry-common.S:149: Error: invalid literal constant: pool needs to be closer

Correct, the underlying issue is not specific to Clang. I did notice, though, that the Clang assembler does not deduplicate literal pool entries like GAS does, which might make Clang more susceptible than GCC/binutils.

In any case, the fix is not Clang-specific.

Quoted 13 lines
Quoted 6 lines

Due to the introduction of a couple of new uses of this macro in commit 508074607c7b95b2 ("ARM: 9195/1: entry: avoid explicit literal loads"), the literal pools end up getting rearranged in a way that causes the literal for __current to go out of range. Let's fix this up by putting a .ltorg directive in a suitable place in the code.

Quoted 6 lines
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
Fixes 508074607c7b95b2 ("ARM: 9195/1: entry: avoid explicit literal loads")
Quoted 5 lines

With the problematic configuration, I no longer see issues with either clang or GCC:

Thanks.

Quoted 18 lines
Quoted 18 lines
---
 arch/arm/kernel/entry-common.S | 1 +
 1 file changed, 1 insertion(+)
arch/arm/kernel/entry-common.S +1 -0
index 7aa3ded4af92..6a447ac67d80 100644
@@ -298,14 +298,15 @@ local_restart:
 9001:
      sub     lr, saved_pc, #4
      str     lr, [sp, #S_PC]
      get_thread_info tsk
      b       ret_fast_syscall
 #endif
 ENDPROC(vector_swi)
+     .ltorg
 
Quoted 9 lines
Quoted 9 lines
arch/arm/kernel/entry-common.S +0 -1
      /*
       * This is the really slow path.  We're going to be doing
       * context switches, and waiting for our parent to respond.
       */
 __sys_trace:
      add     r0, sp, #S_OFF
--

2.30.2

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw
Quoted 14 lines · Ard Biesheuvel
Quoted 12 lines · Nathan Chancellor
Quoted 6 lines · Ard Biesheuvel

LKP reports a build issue on Clang, related to a literal load of __current issued through the ldr_va macro. This turns out to be due to the fact that group relocations are disabled when CONFIG_COMPILE_TEST=y, which means that the ldr_va macro resolves to a pair of LDR instructions, the first one being a literal load issued too far from its literal pool.

For the record, I do see a similar failure with GNU as, not sure if it is worth calling that out in the commit message or not:

Quoted 8 lines
Quoted 3 lines

arch/arm/kernel/entry-common.S: Assembler messages:
arch/arm/kernel/entry-common.S:149: Error: invalid literal constant: pool needs to be closer

Correct, the underlying issue is not specific to Clang. I did notice, though, that the Clang assembler does not deduplicate literal pool entries like GAS does, which might make Clang more susceptible than GCC/binutils.

Thanks for the report; just circling back on this, but this should be resolved in ToT (clang-15):
https://github.com/llvm/llvm-project/issues/55816

Quoted 2 lines

In any case, the fix is not Clang-specific.

Signature · 7 lines
Thanks,
~Nick Desaulniers

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#4 lore raw
Quoted 20 lines · Nick Desaulniers
Quoted 18 lines · Ard Biesheuvel
Quoted 15 lines · Nathan Chancellor
Quoted 6 lines · Ard Biesheuvel

LKP reports a build issue on Clang, related to a literal load of __current issued through the ldr_va macro. This turns out to be due to the fact that group relocations are disabled when CONFIG_COMPILE_TEST=y, which means that the ldr_va macro resolves to a pair of LDR instructions, the first one being a literal load issued too far from its literal pool.

For the record, I do see a similar failure with GNU as, not sure if it is worth calling that out in the commit message or not:

arch/arm/kernel/entry-common.S: Assembler messages:
arch/arm/kernel/entry-common.S:149: Error: invalid literal constant: pool needs to be closer

Quoted 9 lines
Quoted 4 lines

Correct, the underlying issue is not specific to Clang. I did notice, though, that the Clang assembler does not deduplicate literal pool entries like GAS does, which might make Clang more susceptible than GCC/binutils.

Thanks for the report; just circling back on this, but this should be resolved in ToT (clang-15):
https://github.com/llvm/llvm-project/issues/55816

Wow, that was quick!

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel