Skip to content

Commit 9a00318

Browse files
Dave MartinRussell King
authored andcommitted
ARM: 6963/1: Thumb-2: Relax relocation requirements for non-function symbols
The "Thumb bit" of a symbol is only really meaningful for function symbols (STT_FUNC). However, sometimes a branch is relocated against a non-function symbol; for example, PC-relative branches to anonymous assembler local symbols are typically fixed up against the start-of-section symbol, which is not a function symbol. Some inline assembler generates references of this type, such as fixup code generated by macros in <asm/uaccess.h>. The existing relocation code for R_ARM_THM_CALL/R_ARM_THM_JUMP24 interprets this case as an error, because the target symbol appears to be an ARM symbol; but this is really not the case, since the target symbol is just a base in these cases. The addend defines the precise offset to the target location, but since the addend is encoded in a non-interworking Thumb branch instruction, there is no explicit Thumb bit in the addend. Because these instructions never interwork, the implied Thumb bit in the addend is 1, and the destination is Thumb by definition. This patch removes the extraneous Thumb bit check for non-function symbols, enabling modules containing the affected relocation types to be loaded. No modification to the actual relocation code is required, since this code does not take bit[0] of the location->destination offset into account in any case. Function symbols are always checked for interworking conflicts, as before. Signed-off-by: Dave Martin <dave.martin@linaro.org> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 343fda5 commit 9a00318

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎arch/arm/kernel/module.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,17 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
193193
offset -= 0x02000000;
194194
offset += sym->st_value - loc;
195195

196-
/* only Thumb addresses allowed (no interworking) */
197-
if (!(offset & 1) ||
196+
/*
197+
* For function symbols, only Thumb addresses are
198+
* allowed (no interworking).
199+
*
200+
* For non-function symbols, the destination
201+
* has no specific ARM/Thumb disposition, so
202+
* the branch is resolved under the assumption
203+
* that interworking is not required.
204+
*/
205+
if ((ELF32_ST_TYPE(sym->st_info) == STT_FUNC &&
206+
!(offset & 1)) ||
198207
offset <= (s32)0xff000000 ||
199208
offset >= (s32)0x01000000) {
200209
pr_err("%s: section %u reloc %u sym '%s': relocation %u out of range (%#lx -> %#x)\n",

0 commit comments

Comments
 (0)