From patchwork Tue Mar 24 17:52:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 46274 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 01E7E214B0 for ; Tue, 24 Mar 2015 17:55:05 +0000 (UTC) Received: by wibbs8 with SMTP id bs8sf777201wib.3 for ; Tue, 24 Mar 2015 10:55:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=tL3I6RHSKei2tzXs0aR8dOdf/GY6id3n3Gc6IqcYufA=; b=Eo2CTfUQgFJjrwVbrbX7qamNx2q8yRZyy5hJEY5WmM/WljuqvCGBNAbzWaW6JSz5k0 8hargVsICDErgK5ojN3f2hLu6dc2Le6g3VkqBw+R6tOFRfgAyN4GpQkYoyoql/V6Ggvy DHGLTeRGXNvrBt6h0LD35/oau8fB4FRMz2f7QXu8iTP8ob2V8vlnBq92eehLm+fCagb6 Nl9DmiNQflzopRNuqQqCP16KmrZrrEV2CJY8DR6ogLATwBaU15oJa/GSJhf+u9OEkCZt dDrkvONDBcVCf2OsfayU0bv1BkvPr5cUb1DEIQd7eXDRnDKdB1zpYsLRzaa4QDq5VogF oJzQ== X-Gm-Message-State: ALoCoQlQVlZU31yGHJ8ClM7OGjoUdELK5T8BMLKoBrzLe5QRvTgONbZwKVmXllVxeXeF8orgYNIS X-Received: by 10.152.87.141 with SMTP id ay13mr1152384lab.3.1427219704216; Tue, 24 Mar 2015 10:55:04 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.3.10 with SMTP id 10ls495lay.26.gmail; Tue, 24 Mar 2015 10:55:03 -0700 (PDT) X-Received: by 10.152.19.199 with SMTP id h7mr5016652lae.32.1427219703863; Tue, 24 Mar 2015 10:55:03 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id b8si3589694lbs.16.2015.03.24.10.55.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Mar 2015 10:55:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by labe2 with SMTP id e2so308495lab.3 for ; Tue, 24 Mar 2015 10:55:03 -0700 (PDT) X-Received: by 10.112.218.5 with SMTP id pc5mr5020718lbc.32.1427219703726; Tue, 24 Mar 2015 10:55:03 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.57.201 with SMTP id k9csp1606367lbq; Tue, 24 Mar 2015 10:55:02 -0700 (PDT) X-Received: by 10.70.55.169 with SMTP id t9mr8538418pdp.57.1427219700675; Tue, 24 Mar 2015 10:55:00 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id hj2si6575184pbc.103.2015.03.24.10.54.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Mar 2015 10:55:00 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YaT1B-0002at-Dp; Tue, 24 Mar 2015 17:53:33 +0000 Received: from mail-wi0-f169.google.com ([209.85.212.169]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YaT0k-0002Nq-E4 for linux-arm-kernel@lists.infradead.org; Tue, 24 Mar 2015 17:53:07 +0000 Received: by wibgn9 with SMTP id gn9so4656120wib.1 for ; Tue, 24 Mar 2015 10:52:44 -0700 (PDT) X-Received: by 10.194.201.164 with SMTP id kb4mr10290742wjc.32.1427219564450; Tue, 24 Mar 2015 10:52:44 -0700 (PDT) Received: from ards-macbook-pro.local ([90.174.5.112]) by mx.google.com with ESMTPSA id ge8sm7064903wjc.32.2015.03.24.10.52.42 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Mar 2015 10:52:43 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, nico@linaro.org, linux@arm.linux.org.uk, dave.martin@arm.com, arnd@arndb.de Subject: [PATCH v2 1/4] ARM: force linker to use PIC veneers Date: Tue, 24 Mar 2015 18:52:27 +0100 Message-Id: <1427219550-21636-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1427219550-21636-1-git-send-email-ard.biesheuvel@linaro.org> References: <1427219550-21636-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150324_105306_653035_9A18B886 X-CRM114-Status: GOOD ( 11.70 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.169 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.169 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 When building a very large kernel, it is up to the linker to decide when and where to insert stubs to allow calls to functions that are out of range for the ordinary b/bl instructions. However, since the kernel is built as a position dependent binary, these stubs (aka veneers) may contain absolute addresses, which will break far calls performed with the MMU off. For instance, the call from __enable_mmu() in the .head.text section to __turn_mmu_on() in the .idmap.text section may be turned into something like this: c0008168 <__enable_mmu>: c0008168: f020 0002 bic.w r0, r0, #2 c000816c: f420 5080 bic.w r0, r0, #4096 c0008170: f000 b846 b.w c0008200 <____turn_mmu_on_veneer> [...] c0008200 <____turn_mmu_on_veneer>: c0008200: 4778 bx pc c0008202: 46c0 nop c0008204: e59fc000 ldr ip, [pc] c0008208: e12fff1c bx ip c000820c: c13dfae1 teqgt sp, r1, ror #21 [...] c13dfae0 <__turn_mmu_on>: c13dfae0: 4600 mov r0, r0 [...] After adding --pic-veneer to the LDFLAGS, the veneer is emitted like this instead: c0008200 <____turn_mmu_on_veneer>: c0008200: 4778 bx pc c0008202: 46c0 nop c0008204: e59fc004 ldr ip, [pc, #4] c0008208: e08fc00c add ip, pc, ip c000820c: e12fff1c bx ip c0008210: 013d7d31 teqeq sp, r1, lsr sp c0008214: 00000000 andeq r0, r0, r0 Note that this particular example is best addressed by moving .head.text and .idmap.text closer together, but this issue could potentially affect any code that needs to execute with the MMU off. Acked-by: Nicolas Pitre Signed-off-by: Ard Biesheuvel --- arch/arm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/Makefile b/arch/arm/Makefile index eb7bb511f853..ae5b33527f32 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -13,7 +13,7 @@ # Ensure linker flags are correct LDFLAGS := -LDFLAGS_vmlinux :=-p --no-undefined -X +LDFLAGS_vmlinux :=-p --no-undefined -X --pic-veneer ifeq ($(CONFIG_CPU_ENDIAN_BE8),y) LDFLAGS_vmlinux += --be8 LDFLAGS_MODULE += --be8