Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp308681ybg; Wed, 3 Jun 2020 01:07:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHuQh4LO1on6l5hRt7O5o/vfM12g8eLBJZV0icLD0NWpYlPW3LefAwPnLrSAkPoKdlayKq X-Received: by 2002:a17:906:a88:: with SMTP id y8mr27195847ejf.68.1591171663601; Wed, 03 Jun 2020 01:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591171663; cv=none; d=google.com; s=arc-20160816; b=t5z+ynrCmccEV5eSIrBzYrqPBLvg5HxEplAHAzXLX+GajReXmWgbvWpgfChdgJp+4G bV2BFq5zYulfhyC/IzSCxNFFVuhH2Kh13hHLi0BZ3SwhZEysWfIEeuIv6sK68kZka8xt JbbfwoOc0I8h8/2vn8oTx8vrZcrlpUzvYOYugOLA+x0QMa4xcQOLaxRewrHFg4xYZIPh VIRgiMhYgc6C0eEc5E377yN/5RzMO7tb8yX2XLEVcGa7TFU7tnbX8/l3k32cRWqyR7i3 7lTrycNaL+qseD3uzz48uO9koX7R1rQQUaDJguao8uLDL1ywvrwFr+Lbd6jmQG5sB3db 3Irw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=rkEkw5QqPkETs3jN0pum2lLGzixVLfiVa01AvyrcEcA=; b=mwZEdFj4Oao+C50z6ThWEjdEvViiXsc0H++Lj3E/+4txxUCnvD4zWbwjFduEoevUCe lIAewVfCcVh7pTDG6ED442A4dMifvdaxdiFKSmKzf0Y/0WiVA87CbRHOBzY86gx8EYTj F4QGd791Tdesn6YeXpGr53y+0W/jmsFOi9Sshb2J7LDGk6Vz/2VqJ3V/vF8eTRMkZeJ9 2pk0dtNKj+joDhj8LF/7hsnZqXx7siVVjDPpTBkZNfhYV74pJg6d3acWMQNMuPCVect4 RLi2kmn4Ko34uO3IG9ljo/75uVuQxL/D0OlF+OwlqtIkF9aSW3dR6W3U+87wLwHEy7zP aOQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i12si726405ejc.462.2020.06.03.01.07.19; Wed, 03 Jun 2020 01:07:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726151AbgFCIEp (ORCPT + 99 others); Wed, 3 Jun 2020 04:04:45 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:61013 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725275AbgFCIEp (ORCPT ); Wed, 3 Jun 2020 04:04:45 -0400 X-Originating-IP: 90.112.45.105 Received: from debian.home (lfbn-gre-1-325-105.w90-112.abo.wanadoo.fr [90.112.45.105]) (Authenticated sender: alex@ghiti.fr) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 18F37240005; Wed, 3 Jun 2020 08:04:39 +0000 (UTC) From: Alexandre Ghiti To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra , Zong Li , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org Cc: Alexandre Ghiti , Anup Patel Subject: [PATCH v4 4/4] riscv: Check relocations at compile time Date: Wed, 3 Jun 2020 04:00:10 -0400 Message-Id: <20200603080010.13366-5-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200603080010.13366-1-alex@ghiti.fr> References: <20200603080010.13366-1-alex@ghiti.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Relocating kernel at runtime is done very early in the boot process, so it is not convenient to check for relocations there and react in case a relocation was not expected. There exists a script in scripts/ that extracts the relocations from vmlinux that is then used at postlink to check the relocations. Signed-off-by: Alexandre Ghiti Reviewed-by: Anup Patel --- arch/riscv/Makefile.postlink | 36 ++++++++++++++++++++++++++++++++ arch/riscv/tools/relocs_check.sh | 26 +++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 arch/riscv/Makefile.postlink create mode 100755 arch/riscv/tools/relocs_check.sh diff --git a/arch/riscv/Makefile.postlink b/arch/riscv/Makefile.postlink new file mode 100644 index 000000000000..bf2b2bca1845 --- /dev/null +++ b/arch/riscv/Makefile.postlink @@ -0,0 +1,36 @@ +# SPDX-License-Identifier: GPL-2.0 +# =========================================================================== +# Post-link riscv pass +# =========================================================================== +# +# Check that vmlinux relocations look sane + +PHONY := __archpost +__archpost: + +-include include/config/auto.conf +include scripts/Kbuild.include + +quiet_cmd_relocs_check = CHKREL $@ +cmd_relocs_check = \ + $(CONFIG_SHELL) $(srctree)/arch/riscv/tools/relocs_check.sh "$(OBJDUMP)" "$(NM)" "$@" + +# `@true` prevents complaint when there is nothing to be done + +vmlinux: FORCE + @true +ifdef CONFIG_RELOCATABLE + $(call if_changed,relocs_check) +endif + +%.ko: FORCE + @true + +clean: + @true + +PHONY += FORCE clean + +FORCE: + +.PHONY: $(PHONY) diff --git a/arch/riscv/tools/relocs_check.sh b/arch/riscv/tools/relocs_check.sh new file mode 100755 index 000000000000..baeb2e7b2290 --- /dev/null +++ b/arch/riscv/tools/relocs_check.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Based on powerpc relocs_check.sh + +# This script checks the relocations of a vmlinux for "suspicious" +# relocations. + +if [ $# -lt 3 ]; then + echo "$0 [path to objdump] [path to nm] [path to vmlinux]" 1>&2 + exit 1 +fi + +bad_relocs=$( +${srctree}/scripts/relocs_check.sh "$@" | + # These relocations are okay + # R_RISCV_RELATIVE + grep -F -w -v 'R_RISCV_RELATIVE' +) + +if [ -z "$bad_relocs" ]; then + exit 0 +fi + +num_bad=$(echo "$bad_relocs" | wc -l) +echo "WARNING: $num_bad bad relocations" +echo "$bad_relocs" -- 2.20.1