Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp3492994ybg; Sun, 7 Jun 2020 01:09:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn8RPPGwcu67TStuBUEGFGe8nOMYxQF56SSBgaEaHT8b1fedZCoW2joQGxMWVFrEXeBZ12 X-Received: by 2002:a50:fb14:: with SMTP id d20mr16838789edq.209.1591517354639; Sun, 07 Jun 2020 01:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591517354; cv=none; d=google.com; s=arc-20160816; b=vXKtZOyvykppf8murNRSRn0ioDBm/6Z5mxi2alb9MAlZa+3dQKdrPUi4bJ/8l1DNUl LIOTUWpTR4X91NufVgHggcpUL+vvUtUT+pLjPmr8FPhj7UeIgxyCs+l4kmyfD1PN5UlG tKPG0aWRbsIkIVW4C2NEq/0Al21QejjijO2ISqmSjfiSv5Sm01v9WLWnyMo2wGQfW79A Ieb8rL0k+bSpgR7uctHZwqWpA/1/zmuoiGA8V14c9c/5kElC568f9Pw7SDH1deuWCWlN nlKetxG/LXlryfczAOiYXkEZL2z7xlz/t5V8U2NXsTV/snHWv89jWPx09qQCBkaNrQL0 2vmw== 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=rRew2Z860TH5hdGLHngGsUsVmOvpsyWHUhOknXiiYrogATNtbei5q71+rEpLYfX1n5 RVf/VYlp+m4Olv0kmBE4j+2IrmhGDjBhCY4Gy0t1TQFMedJ+f9dWE4rL+wkSW6ELRmcD epw061WzcgIrSOlYlPN9ouYKYsKIQdyaRev+J0UHwVN5jLwZuo07PKtHcFPdZIB0KZzk j4T2jK842lAhnCIxYXeJPuRT5WiBN1DooeffIMWHiH0r5yvx161AAkdSm4pAxP4gJgav wE+5dQmC+PxOIcWxoDdw/+ArL2JKm7XbjKChSHr7oqkJCFevMRAShko2Ouc25gXIfZ3T xPxA== 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 t12si6996607eji.88.2020.06.07.01.08.51; Sun, 07 Jun 2020 01:09:14 -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 S1726475AbgFGIET (ORCPT + 99 others); Sun, 7 Jun 2020 04:04:19 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:28807 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726192AbgFGIET (ORCPT ); Sun, 7 Jun 2020 04:04:19 -0400 X-Originating-IP: 90.112.45.105 Received: from localhost.localdomain (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 8C217240003; Sun, 7 Jun 2020 08:04:12 +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 v5 4/4] riscv: Check relocations at compile time Date: Sun, 7 Jun 2020 03:59:49 -0400 Message-Id: <20200607075949.665-5-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200607075949.665-1-alex@ghiti.fr> References: <20200607075949.665-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