Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1659034pxj; Wed, 19 May 2021 10:50:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjWY5RkB5KEH7bzA5iZSkU7yAMh1h/k+BAYyAu67SlanUutdHKz8nZhLQE40Kkwu+nS8hz X-Received: by 2002:aa7:c548:: with SMTP id s8mr275002edr.114.1621446600732; Wed, 19 May 2021 10:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621446600; cv=none; d=google.com; s=arc-20160816; b=DYXiXIwkW/cJBBvn5bthzXYeuB0dwKHA5UeA8itV2L/Ed0RFycp97nLRwHFb9TEZaZ p45pHVTajbiQSsndGoPQtuq/s3jey8DN7G86SqJE5bGmHpBOZkO4jxzeR3D4pMWsZG20 y/nVYxMQk1quvNE1H64uBHHWnm/TdOVXBgnGy7jZemJ6wjMzDudE/P7xpGxK1MGR3feV spHJcZ2lB9MnTG/xfQuuCLeT7fE7OVKs/Le4Inl2UYkHxnLf1Su+wh5lh515Vei+ePDj k6qpZaTU2cg7eC8XRt0Xzv3HaEZCTMyKMzYRiClMIiznEQwNQBveDsazubnWD2las5+u XRiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Qsa54KepOrvokMAZn2zADjtxUrrjmAj4LfBFcB3GFl8=; b=1IFdR4GXlpHgoFJm9nqK1SJvKUrd/4BxbXB1+OktmMETkkOHB9/7qq0rzsroMVnMCY QSQ52y2srtIs+TuXRU+RKbsBVwctO+BNmTMRJZJPqQ/P9EPR/jobQCKsw8jk62Tr+B7b r9FpzeBFs/HKUQFAtv5hrbON9xKRNMhsJu+1P/75lZhf92X134Iu51Vw3IGzXff7xmnq 45awR8C5KWGR/LHqnqo6UAmgC6llwkwOIzgME3T6vuCgx+VS/BojZYL+h+tn5DD0gl4p UdQg4bbaFUqBwi0gt2oYUKV7OSgUMIE6JblFlr/PrSlcszZhbufq3DVEEaNxswT7Jnrj yWLw== 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 dh5si1647832edb.241.2021.05.19.10.49.37; Wed, 19 May 2021 10:50:00 -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 S242592AbhERKRk (ORCPT + 99 others); Tue, 18 May 2021 06:17:40 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:45137 "EHLO relay5-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241365AbhERKRi (ORCPT ); Tue, 18 May 2021 06:17:38 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 5D02D1C0005; Tue, 18 May 2021 10:16:16 +0000 (UTC) From: Alexandre Ghiti To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Paul Walmsley , Palmer Dabbelt , Albert Ou , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Alexandre Ghiti , Anup Patel Subject: [PATCH v6 3/3] riscv: Check relocations at compile time Date: Tue, 18 May 2021 12:12:52 +0200 Message-Id: <20210518101252.1484465-4-alex@ghiti.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210518101252.1484465-1-alex@ghiti.fr> References: <20210518101252.1484465-1-alex@ghiti.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.30.2