From patchwork Mon Feb 28 17:43:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 251 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:41:12 -0000 Delivered-To: patches@linaro.org Received: by 10.224.19.208 with SMTP id c16cs106976qab; Mon, 28 Feb 2011 09:43:22 -0800 (PST) Received: by 10.216.182.71 with SMTP id n49mr1134557wem.105.1298915001950; Mon, 28 Feb 2011 09:43:21 -0800 (PST) Received: from mail-wy0-f178.google.com (mail-wy0-f178.google.com [74.125.82.178]) by mx.google.com with ESMTPS id f28si6964138wej.4.2011.02.28.09.43.21 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 28 Feb 2011 09:43:21 -0800 (PST) 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 wyf28 with SMTP id 28so4549356wyf.37 for ; Mon, 28 Feb 2011 09:43:21 -0800 (PST) Received: by 10.227.195.137 with SMTP id ec9mr5153580wbb.218.1298915001080; Mon, 28 Feb 2011 09:43:21 -0800 (PST) Received: from arm.com (host86-144-161-218.range86-144.btcentralplus.com [86.144.161.218]) by mx.google.com with ESMTPS id x1sm3468947wbh.20.2011.02.28.09.43.19 (version=SSLv3 cipher=OTHER); Mon, 28 Feb 2011 09:43:20 -0800 (PST) Date: Mon, 28 Feb 2011 17:43:09 +0000 From: Dave Martin To: linaro-dev@lists.linaro.org Cc: Nicolas Pitre , patches@linaro.org Subject: [PATCH] ARM: Thumb-2: Work around buggy Thumb-2 short branch relocations in gas Message-ID: <20110228174309.GA19926@arm.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Oops, forgot to CC: ----- Forwarded message from Dave Martin ----- Date: Mon, 28 Feb 2011 17:38:12 +0000 From: Dave Martin To: linux-arm-kernel@lists.infradead.org Cc: Dave Martin Subject: [PATCH] ARM: Thumb-2: Work around buggy Thumb-2 short branch relocations in gas Various binutils versions can resolve Thumb-2 branches to locally-defined, preemptible global symbols as short-range "b.n" branch instructions. This is a problem, because there's no guarantee the final destination of the symbol, or any candidate locations for a trampoline, are within range of the branch. For this reason, the kernel does not support fixing up the R_ARM_THM_JUMP11 (102) relocation in modules at all, and it makes little sense to add support. The symptom is that the kernel fails with an "unsupported relocation" error when loading some modules. Until fixed tools are available, passing -fno-optimize-sibling-calls to gcc should prevent gcc generating code which hits this problem, at the cost of a bit of extra runtime stack usage in some cases. The problem is described in more detail at: https://bugs.launchpad.net/binutils-linaro/+bug/725126 Only Thumb-2 kernels are affected. This patch adds a new CONFIG_THUMB2_AVOID_R_ARM_THM_JUMP11 config option which adds -fno-optimize-sibling-calls to CFLAGS_MODULE when building a Thumb-2 kernel. Signed-off-by: Dave Martin --- arch/arm/Kconfig | 31 +++++++++++++++++++++++++++++++ arch/arm/Makefile | 4 ++++ 2 files changed, 35 insertions(+), 0 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 5cff165..196f6d2 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1371,6 +1371,37 @@ config THUMB2_KERNEL If unsure, say N. +config THUMB2_AVOID_R_ARM_THM_JUMP11 + bool "Work around buggy Thumb-2 short branch relocations in gas" + depends on THUMB2_KERNEL && MODULES + default y + help + Various binutils versions can resolve Thumb-2 branches to + locally-defined, preemptible global symbols as short-range "b.n" + branch instructions. + + This is a problem, because there's no guarantee the final + destination of the symbol, or any candidate locations for a + trampoline, are within range of the branch. For this reason, the + kernel does not support fixing up the R_ARM_THM_JUMP11 (102) + relocation in modules at all, and it makes little sense to add + support. + + The symptom is that the kernel fails with an "unsupported + relocation" error when loading some modules. + + Until fixed tools are available, passing + -fno-optimize-sibling-calls to gcc should prevent gcc generating + code which hits this problem, at the cost of a bit of extra runtime + stack usage in some cases. + + The problem is described in more detail at: + https://bugs.launchpad.net/binutils-linaro/+bug/725126 + + Only Thumb-2 kernels are affected. + + Unless you are sure your tools don't have this problem, say Y. + config ARM_ASM_UNIFIED bool diff --git a/arch/arm/Makefile b/arch/arm/Makefile index c22c1ad..ef5105a 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -105,6 +105,10 @@ AFLAGS_AUTOIT :=$(call as-option,-Wa$(comma)-mimplicit-it=always,-Wa$(comma)-mau AFLAGS_NOWARN :=$(call as-option,-Wa$(comma)-mno-warn-deprecated,-Wa$(comma)-W) CFLAGS_THUMB2 :=-mthumb $(AFLAGS_AUTOIT) $(AFLAGS_NOWARN) AFLAGS_THUMB2 :=$(CFLAGS_THUMB2) -Wa$(comma)-mthumb +# Work around buggy relocation from gas if requested: +ifeq ($(CONFIG_THUMB2_AVOID_R_ARM_THM_JUMP11),y) +CFLAGS_MODULE +=-fno-optimize-sibling-calls +endif endif # Need -Uarm for gcc < 3.x