From patchwork Tue Jan 17 19:26:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 91714 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp654867qgi; Tue, 17 Jan 2017 11:26:41 -0800 (PST) X-Received: by 10.99.121.69 with SMTP id u66mr47072884pgc.96.1484681201113; Tue, 17 Jan 2017 11:26:41 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y70si25829155plh.229.2017.01.17.11.26.40; Tue, 17 Jan 2017 11:26:41 -0800 (PST) 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 sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751266AbdAQT0e (ORCPT + 25 others); Tue, 17 Jan 2017 14:26:34 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:38588 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751221AbdAQT0b (ORCPT ); Tue, 17 Jan 2017 14:26:31 -0500 Received: by mail-wm0-f41.google.com with SMTP id r144so238679185wme.1 for ; Tue, 17 Jan 2017 11:26:31 -0800 (PST) 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=50KhQCtAYNHKshLc8v9I656KZxFKwtLxgxrPl4ZMuak=; b=J01Ixbc2zrQ5XEc7vMRrrUpgRSVQ94Gam90tgHgezCtRfgtxggLkOcsulWk46u7pRw rlmXB2AR9snGB+9z1xDKnbMZ5I27BKepPQhxBgBTgtBu0the+VrjtMKGs4aqW+OkieJl pPHTYhodfdTPwZk7d8iPOcQc3HFZEJ3t07Vto= 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=50KhQCtAYNHKshLc8v9I656KZxFKwtLxgxrPl4ZMuak=; b=NsX9dKJSSAJtfs03NbZ8F/iMnXq1fY7uGq/WZj2ZbcGHDH3VOt1t473VVZtCn/SAX2 qNsfcXz7CbfWXJwYZkU0fwHNP/NzIl378PHO04ohb/9VQsfj/hmgJ9fqkMQX5VBdhxY8 p+MqJPXc8C2TQ213Qp2gM8hcmgwB4aRFH1X5veF7yAR7QmkEwVuoY5RPxr5FGn2x8aSW Iupk9GzJqZVhrWjcKIqzDwYN6TIfAvNGgO4g0yIIApzrxEwGmAyb3g2HS1PpovnUVPF8 dhF4kLZ0s3RnR7y0GP++MHyYdLkWi60TwUSg2CAeSORQHaqK6x3ooAqbAOHJP8seQLBJ b8TA== X-Gm-Message-State: AIkVDXKlImVojBEatiNeN/bYBWGR4MWaRBc/bdFAGnAtx7OwAqWNeEx4ZY3ZeYZTMxMfTeCo X-Received: by 10.28.64.132 with SMTP id n126mr19187568wma.107.1484681190111; Tue, 17 Jan 2017 11:26:30 -0800 (PST) Received: from localhost.localdomain ([160.167.203.25]) by smtp.gmail.com with ESMTPSA id 197sm39171953wmy.16.2017.01.17.11.26.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Jan 2017 11:26:29 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, mpe@ellerman.id.au, jeyu@redhat.com Cc: rusty@rustcorp.com.au, suzuki.poulose@arm.com, will.deacon@arm.com, akpm@linux-foundation.org, benh@kernel.crashing.org, paulus@samba.org, arnd@arndb.de, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, linuxppc-dev@lists.ozlabs.org, Ard Biesheuvel Subject: [PATCH v4 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols Date: Tue, 17 Jan 2017 19:26:12 +0000 Message-Id: <1484681173-11644-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484681173-11644-1-git-send-email-ard.biesheuvel@linaro.org> References: <1484681173-11644-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. As it turns out, binutils for powerpc does not account for any relocations beyond R_PPC64_RELATIVE ones in the RELACOUNT field of the .dynamic section, which is unfortunate, since we need to do extra work to figure out the size of the relocation array. So with a little help from the linker scripts, grab an end pointer rather than a count, and iterate over the entire section. Signed-off-by: Ard Biesheuvel --- arch/powerpc/kernel/reloc_64.S | 60 ++++++++++++-------- arch/powerpc/kernel/vmlinux.lds.S | 1 + arch/powerpc/relocs_check.sh | 5 +- 3 files changed, 40 insertions(+), 26 deletions(-) -- 2.7.4 diff --git a/arch/powerpc/kernel/reloc_64.S b/arch/powerpc/kernel/reloc_64.S index d88736fbece6..e50f5d778ea2 100644 --- a/arch/powerpc/kernel/reloc_64.S +++ b/arch/powerpc/kernel/reloc_64.S @@ -12,8 +12,8 @@ #include RELA = 7 -RELACOUNT = 0x6ffffff9 R_PPC64_RELATIVE = 22 +R_PPC64_ADDR32 = 1 /* * r3 = desired final address of kernel @@ -29,29 +29,27 @@ _GLOBAL(relocate) add r9,r9,r12 /* r9 has runtime addr of .rela.dyn section */ ld r10,(p_st - 0b)(r12) add r10,r10,r12 /* r10 has runtime addr of _stext */ + ld r8,(p_rela_end - 0b)(r12) + add r8,r8,r12 /* r8 has addr of end of .rela.dyn section */ /* - * Scan the dynamic section for the RELA and RELACOUNT entries. + * Scan the dynamic section for the RELA entry. + * NOTE: the RELACOUNT entry only covers R_PPC64_RELATIVE relocations, + * so we cannot use it here. */ li r7,0 - li r8,0 1: ld r6,0(r11) /* get tag */ cmpdi r6,0 - beq 4f /* end of list */ + beq 3f /* end of list */ cmpdi r6,RELA - bne 2f - ld r7,8(r11) /* get RELA pointer in r7 */ - b 3f -2: addis r6,r6,(-RELACOUNT)@ha - cmpdi r6,RELACOUNT@l - bne 3f - ld r8,8(r11) /* get RELACOUNT value in r8 */ -3: addi r11,r11,16 + beq 2f + addi r11,r11,16 b 1b -4: cmpdi r7,0 /* check we have both RELA and RELACOUNT */ - cmpdi cr1,r8,0 - beq 6f - beq cr1,6f +2: ld r7,8(r11) /* get RELA pointer in r7 */ +3: cmpdi r7,0 /* check we have both RELA and a non-empty */ + cmpd cr1,r8,r9 /* .rela.dyn section */ + beq 7f + beq cr1,7f /* * Work out linktime address of _stext and hence the @@ -63,26 +61,40 @@ _GLOBAL(relocate) subf r7,r7,r9 /* cur_offset */ subf r10,r7,r10 subf r3,r10,r3 /* final_offset */ + b 4f /* * 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) */ +3: addi r9,r9,24 +4: cmpd r9,r8 + beq 7f +5: ld r0,8(9) /* reloc->r_info (type *and* symbol index) */ + ld r6,0(r9) /* reloc->r_offset */ cmpdi r0,R_PPC64_RELATIVE bne 6f - ld r6,0(r9) /* reloc->r_offset */ ld r0,16(r9) /* reloc->r_addend */ add r0,r0,r3 stdx r0,r7,r6 - addi r9,r9,24 - bdnz 5b + b 3b + + /* + * 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 3b + ld r0,16(r9) /* reloc->r_addend */ + stwx r0,r7,r6 + b 3b + +7: blr -6: blr .balign 8 p_dyn: .llong __dynamic_start - 0b p_rela: .llong __rela_dyn_start - 0b +p_rela_end: + .llong __rela_dyn_end - 0b p_st: .llong _stext - 0b - diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S index 7394b770ae1f..654728fc860d 100644 --- a/arch/powerpc/kernel/vmlinux.lds.S +++ b/arch/powerpc/kernel/vmlinux.lds.S @@ -241,6 +241,7 @@ SECTIONS { __rela_dyn_start = .; *(.rela*) + __rela_dyn_end = .; } #endif /* .exit.data is discarded at runtime, not link time, diff --git a/arch/powerpc/relocs_check.sh b/arch/powerpc/relocs_check.sh index ec2d5c835170..f9636b4e4548 100755 --- a/arch/powerpc/relocs_check.sh +++ b/arch/powerpc/relocs_check.sh @@ -30,7 +30,7 @@ bad_relocs=$( # On PPC64: # R_PPC64_RELATIVE, R_PPC64_NONE # R_PPC64_ADDR64 mach_ - # R_PPC64_ADDR64 __crc_ + # R_PPC64_ADDR32 __crc_ # On PPC: # R_PPC_RELATIVE, R_PPC_ADDR16_HI, # R_PPC_ADDR16_HA,R_PPC_ADDR16_LO, @@ -43,7 +43,8 @@ R_PPC_ADDR16_HA R_PPC_RELATIVE R_PPC_NONE' | grep -E -v '\