From patchwork Thu Oct 27 16:27:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 79753 Delivered-To: patch@linaro.org Received: by 10.80.142.83 with SMTP id 19csp740320edx; Thu, 27 Oct 2016 09:27:43 -0700 (PDT) X-Received: by 10.99.227.81 with SMTP id o17mr12996508pgj.69.1477585663089; Thu, 27 Oct 2016 09:27:43 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 80si8697856pfr.161.2016.10.27.09.27.42; Thu, 27 Oct 2016 09:27:43 -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; 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 dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964928AbcJ0Q13 (ORCPT + 27 others); Thu, 27 Oct 2016 12:27:29 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:36384 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S941721AbcJ0Q1Z (ORCPT ); Thu, 27 Oct 2016 12:27:25 -0400 Received: by mail-wm0-f54.google.com with SMTP id b80so44363128wme.1 for ; Thu, 27 Oct 2016 09:27:24 -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=57Vm0C3oqYDjVATlHiSYJTJYOQbSgKm1HBjEEJSOPBE=; b=NomjDZMixKhiLlQodD0bDQRMKyEHCJ9hGVpRjAx1p2xAy2JZ8J/c3T2zEsb53mS5yY eLsGlI6XZF2nhPebHijJ9h/MswQC9RcGErZKSqCwQHYsw8yFSEGZIyc1jU0M9K+pkO3k SaaiIqim2t2QsAZgxmq2oFZWnWQNu62f7YAcU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=57Vm0C3oqYDjVATlHiSYJTJYOQbSgKm1HBjEEJSOPBE=; b=Wr27qFs46GwW6Xe187k3QyG5WvBS8apDiuocqrNanjwajLC2wJi87woATt71mCvW+g CxJzNhqdGoDHt4kKrvwJEzNnpmHincA9h/Z7mFytBjkDXYazSpkCmjHNfxAMXXFSe1S3 INFaJHQj6Q8uA+fvVcqZvMcENJ/MTym2oP851D0B9rEIysh83aJTkl7pTJ1sDpk2szqZ hJDlFd0oEVi8ADq1Z7TLk/KtBN/iTF9i+vCCN6FqUIY2stoY5bBKR2wVQS5Ft29NRvFD 0XcRF5H+e9odE4/OY3unI2HHAa6+jUFLoLLcrJ+p+ufITyEFBnzWnmBB4Zst6i8+FfV4 XFsA== X-Gm-Message-State: ABUngvdl/o+LWNN3HfhTk6YeO3inXurV0hWvwUtjGPuvI8ZEEKZZG61CWu1VOcjMiB0wE4nn X-Received: by 10.28.8.11 with SMTP id 11mr9256481wmi.27.1477585643747; Thu, 27 Oct 2016 09:27:23 -0700 (PDT) Received: from localhost.localdomain ([105.150.227.229]) by smtp.gmail.com with ESMTPSA id a5sm9355809wjv.6.2016.10.27.09.27.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Oct 2016 09:27:22 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, mpe@ellerman.id.au, jeyu@redhat.com Cc: will.deacon@arm.com, rusty@rustcorp.com.au, akpm@linux-foundation.org, benh@kernel.crashing.org, paulus@samba.org, Ard Biesheuvel Subject: [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols Date: Thu, 27 Oct 2016 17:27:10 +0100 Message-Id: <1477585631-18574-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477585631-18574-1-git-send-email-ard.biesheuvel@linaro.org> References: <1477585631-18574-1-git-send-email-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation of modifying the core modversions code to emit the CRCs as 32-bit quantities, ensure that 64-bit PowerPC will be able to deal with this when CONFIG_RELOCATABLE=y, in which case the CRCs will be emitted into the final ELF binary as R_PPC64_ADDR32 relocations. Since 32-bit relocations cannot be used to relocate memory addresses on 64-bit architectures, and since the CRC pseudo-symbol references are emitted as anonymous relocations (i.e., against the NULL symbol in the .dynsym section) with the final value recorded in the addend (*), we can disregard any relocations where the symbol index != 0. * Note that unsatisfied CRC pseudo-symbol references are emitted as R_PPC64_ADDR32 relocations against named symbols that are typed as weak undefined in the .dynsym symbol table. These can simply be ignored (as before), considering that zero CRCs are interpreted as missing, and the module code deals with that accordingly. Signed-off-by: Ard Biesheuvel --- arch/powerpc/kernel/reloc_64.S | 22 ++++++++++++++++---- arch/powerpc/relocs_check.sh | 3 ++- 2 files changed, 20 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/arch/powerpc/kernel/reloc_64.S b/arch/powerpc/kernel/reloc_64.S index d88736fbece6..7927e00be746 100644 --- a/arch/powerpc/kernel/reloc_64.S +++ b/arch/powerpc/kernel/reloc_64.S @@ -14,6 +14,7 @@ RELA = 7 RELACOUNT = 0x6ffffff9 R_PPC64_RELATIVE = 22 +R_PPC64_ADDR32 = 1 /* * r3 = desired final address of kernel @@ -66,10 +67,10 @@ _GLOBAL(relocate) /* * Run through the list of relocations and process the - * R_PPC64_RELATIVE ones. + * R_PPC64_RELATIVE and R_PPC64_ADDR32 ones. */ mtctr r8 -5: ld r0,8(9) /* ELF64_R_TYPE(reloc->r_info) */ +5: ld r0,8(9) /* reloc->r_info (type *and* symbol index) */ cmpdi r0,R_PPC64_RELATIVE bne 6f ld r6,0(r9) /* reloc->r_offset */ @@ -77,9 +78,22 @@ _GLOBAL(relocate) add r0,r0,r3 stdx r0,r7,r6 addi r9,r9,24 - bdnz 5b + b 7f + + /* + * CRCs of exported symbols are emitted as 32-bit relocations against + * the NULL .dynsym entry, with the CRC value recorded in the addend. + */ +6: cmpdi r0,R_PPC64_ADDR32 + bne 7f + ld r6,0(r9) /* reloc->r_offset */ + ld r0,16(r9) /* reloc->r_addend */ + stwx r0,r7,r6 + addi r9,r9,24 + +7: bdnz 5b + blr -6: blr .balign 8 p_dyn: .llong __dynamic_start - 0b diff --git a/arch/powerpc/relocs_check.sh b/arch/powerpc/relocs_check.sh index ec2d5c835170..2f510fbc87da 100755 --- a/arch/powerpc/relocs_check.sh +++ b/arch/powerpc/relocs_check.sh @@ -43,7 +43,8 @@ R_PPC_ADDR16_HA R_PPC_RELATIVE R_PPC_NONE' | grep -E -v '\