From patchwork Thu Jun 16 11:09:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 1970 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 9A49E23F3D for ; Thu, 16 Jun 2011 11:09:56 +0000 (UTC) Received: from mail-vx0-f180.google.com (mail-vx0-f180.google.com [209.85.220.180]) by fiordland.canonical.com (Postfix) with ESMTP id 5A9B7A1848A for ; Thu, 16 Jun 2011 11:09:56 +0000 (UTC) Received: by vxk12 with SMTP id 12so1489833vxk.11 for ; Thu, 16 Jun 2011 04:09:55 -0700 (PDT) Received: by 10.52.162.72 with SMTP id xy8mr1089760vdb.87.1308222595718; Thu, 16 Jun 2011 04:09:55 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs179367vdc; Thu, 16 Jun 2011 04:09:55 -0700 (PDT) Received: by 10.227.208.148 with SMTP id gc20mr726772wbb.95.1308222593922; Thu, 16 Jun 2011 04:09:53 -0700 (PDT) Received: from mail-wy0-f178.google.com (mail-wy0-f178.google.com [74.125.82.178]) by mx.google.com with ESMTPS id p18si132495wbh.114.2011.06.16.04.09.52 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 16 Jun 2011 04:09:52 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.178 is neither permitted nor denied by best guess record for domain of dave.martin@linaro.org) client-ip=74.125.82.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.178 is neither permitted nor denied by best guess record for domain of dave.martin@linaro.org) smtp.mail=dave.martin@linaro.org Received: by wyf22 with SMTP id 22so320201wyf.37 for ; Thu, 16 Jun 2011 04:09:52 -0700 (PDT) Received: by 10.227.5.210 with SMTP id 18mr789793wbw.18.1308222592039; Thu, 16 Jun 2011 04:09:52 -0700 (PDT) Received: from e200948.peterhouse.linaro.org (fw-lnat.cambridge.arm.com [217.140.96.63]) by mx.google.com with ESMTPS id fm14sm48047wbb.58.2011.06.16.04.09.50 (version=SSLv3 cipher=OTHER); Thu, 16 Jun 2011 04:09:51 -0700 (PDT) From: Dave Martin To: patches@arm.linux.org.uk Cc: patches@linaro.org, Dave Martin Subject: [PATCH] ARM: Thumb-2: Relax relocation requirements for non-function symbols Date: Thu, 16 Jun 2011 12:09:37 +0100 Message-Id: <1308222577-19255-1-git-send-email-dave.martin@linaro.org> X-Mailer: git-send-email 1.7.4.1 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 . 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 Acked-by: Catalin Marinas --- KernelVersion: v3.0-rc2 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index fee7c36..016d6a0 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -193,8 +193,17 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, offset -= 0x02000000; offset += sym->st_value - loc; - /* only Thumb addresses allowed (no interworking) */ - if (!(offset & 1) || + /* + * For function symbols, only Thumb addresses are + * allowed (no interworking). + * + * For non-function symbols, the destination + * has no specific ARM/Thumb disposition, so + * the branch is resolved under the assumption + * that interworking is not required. + */ + if ((ELF32_ST_TYPE(sym->st_info) == STT_FUNC && + !(offset & 1)) || offset <= (s32)0xff000000 || offset >= (s32)0x01000000) { pr_err("%s: section %u reloc %u sym '%s': relocation %u out of range (%#lx -> %#x)\n",