From patchwork Tue Jun 19 19:26:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 139240 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5598780lji; Tue, 19 Jun 2018 12:28:08 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKyr1N5iVaw+zDIhEjw2C9R3O2iFQVcCf2DCW5tS9NzufJ7+JwOvs0+njSc5Og9x94H5jNg X-Received: by 2002:a62:1747:: with SMTP id 68-v6mr19229082pfx.69.1529436488784; Tue, 19 Jun 2018 12:28:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529436488; cv=none; d=google.com; s=arc-20160816; b=cg88lvHYJpmwPgtIAiWHLFkCLINBUJkfZli3iOXpTui46BymjIXE6hmULfrW3p0rRu IZUVJRn4cV4UZf9p3kAdUO04Hjd56XTlJTIBLughDuIfdYhlyf+1QatedXo+QyDbp9MS I6nPNST1mWI4exhjqKQlhdjS1owrmo76ExBPEt7dieNhRyd21JC9vGBl7f64Hm7Sn7yR Ry7bMnlUelm1azVKlvigjIPpzuLlTrmR6bq2WZn75v/ST6HSx0DfWuDfsBirlyqb5aJn 4KtyXSuslumr+rz5P+Z7pYr6/KzzaFHJN3zr8Rc/7fEtfDvUgEBNq18Uj9AoEVb0OtMz NGMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=vXkMZMdtqXwQabFANthjvHFgEKPyu0gVz46zl6OeIVE=; b=K+pvKoU/9m7CFwwzv0QC8tdHUUaS6PndI4pHntUQo3KWFXdCOy09f3/vAaqdgHLmvB mZ+5hV/UWU9X2BrFUI1hgXvFcAzdA/EBl0t9HTOs6sm3tH5npAFpWCo+Nbo8yJe8zP7Q 0KUVPH+bzsi+sn25f1J3K710ZoprMVabHD2V0CBi3KjWCOpO1GTPRo6CcaWhcdISogFl VWTPMWdNSt+/7kjXpHDIL/jI4gKijEwh8sChkAwnV9mUqGSyWpYgwN0IuPBt2YmJGb8u OlW7evWzVFq4pw7HtsRm741vA4bz1IO9Swltwg+kqWAP1i8OxWLVB2suhuq1Qk1Mp5gb sJzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="i7GNC/TH"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9-v6si389459pgt.16.2018.06.19.12.28.08; Tue, 19 Jun 2018 12:28:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="i7GNC/TH"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030488AbeFST2G (ORCPT + 30 others); Tue, 19 Jun 2018 15:28:06 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:46563 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967238AbeFST1s (ORCPT ); Tue, 19 Jun 2018 15:27:48 -0400 Received: by mail-wr0-f193.google.com with SMTP id v13-v6so768577wrp.13 for ; Tue, 19 Jun 2018 12:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vXkMZMdtqXwQabFANthjvHFgEKPyu0gVz46zl6OeIVE=; b=i7GNC/THtkqIFgVKnHdxUVIbmlKJIQy7v3p4BwEj1erCZvwTmWIa+/hKBzYZjD56Xu vMlyj27HMPXKIPMNFtnWvldICGi16v2J1M9Azc3oD69HaghjPgbPIKjvcmISiImH0rnq ++UP/h6sU4C+UubeUp2yZaTEL9W4nKhSquTcU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vXkMZMdtqXwQabFANthjvHFgEKPyu0gVz46zl6OeIVE=; b=gQ3r1qy/ea1v5/P2TWVwN42LifKdBtnh8cyySSQPeJ3DSRKWktlmrkS1SBqYMTmYmT U9azr7hNee4hsBJNhrEL34ybrumJaf3IqCxSC/+t/faES/PlrW4MFrdp9UeN4ypeUX94 E6M/XFEN2/ta60IHgXtF3mMBxTXa7vXypcBfv+6LYXvrqltssfPqXPVUvqtBe0rECmhP 87Pgt6Iez9xM42SUJNNM/i6F+HpxhKZ63SUDyny3wPEDt2IOuoov4fDxMcWyu9O5Rm21 sOP4zHRL9g1PpNGZSTbuYnX1rNggSFQd8hK3wPkS9i6TPdKxhhNM94j7r/lZxqYgXbRk 4cug== X-Gm-Message-State: APt69E0axfwloUWAtuBFhrctDww70tmVw6XzJ6jebJy+ot+USEx7QhS3 xoyn3l6KWEUG+lZl3PFC9f+VJg== X-Received: by 2002:adf:88ca:: with SMTP id g10-v6mr14060672wrg.62.1529436467570; Tue, 19 Jun 2018 12:27:47 -0700 (PDT) Received: from dogfood.home ([2a01:cb1d:112:6f00:a06d:5653:4fd5:13a]) by smtp.gmail.com with ESMTPSA id c53-v6sm982601wrg.12.2018.06.19.12.27.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jun 2018 12:27:46 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux@armlinux.org.uk, linux@roeck-us.net, mark.rutland@arm.com, arnd@arndb.de, linux-kernel@vger.kernel.org, Ard Biesheuvel Subject: [PATCH 2/2] ARM: assembler: prevent ADR from setting the Thumb bit twice Date: Tue, 19 Jun 2018 21:26:33 +0200 Message-Id: <20180619192633.21846-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180619192633.21846-1-ard.biesheuvel@linaro.org> References: <20180619192633.21846-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To work around recent issues where ADR references to Thumb function symbols may or may not have the Thumb bit set already when they are resolved by GAS, reference the symbol indirectly via a local symbol typed as 'function', and emit the reference in a way that prevents the assembler from resolving it directly. Instead, it will be fixed up by the linker, which behaves consistently and according to spec when it comes to relocations of symbols with function annotation targetting wide ADR instructions. Signed-off-by: Ard Biesheuvel --- arch/arm/include/asm/assembler.h | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index 6ae42ad29518..ee2d4eb26318 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -195,13 +195,33 @@ .irp c,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo .macro badr\c, rd, sym #ifdef CONFIG_THUMB2_KERNEL - adr\c \rd, \sym + 1 + __badr \c, \rd, \sym #else adr\c \rd, \sym #endif .endm .endr + /* + * GAS's behavior with respect to setting the Thumb bit on addresses + * of locally defined symbols taken using adr instructions is + * inconsistent, and so we are better off letting the linker handle + * it instead. So emit the reference as a relocation, and force a + * wide encoding so that we can support both forward and backward + * references, and avoid the R_ARM_THM_PC8 relocation that operates + * on the narrow encoding, which is documented as not taking the + * Thumb bit into account. (IHI 0044E ELF for the ARM Architecture) + * + * Note that this needs to be a separate macro or \@ does not work + * correctly. + */ + .macro __badr, c, rd, sym + .set .Lsym\@, \sym + .type .Lsym\@, %function + .reloc ., R_ARM_THM_ALU_PREL_11_0, .Lsym\@ + adr\c\().w \rd, . + .endm + /* * Get current thread_info. */