From patchwork Wed Aug 12 08:10:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Rothwell X-Patchwork-Id: 1343563 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BRMvV1Nbfz9sRN for ; Wed, 12 Aug 2020 18:15:18 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=canb.auug.org.au Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=canb.auug.org.au header.i=@canb.auug.org.au header.a=rsa-sha256 header.s=201702 header.b=XYLc3A8/; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4BRMvM5zvYzDqG6 for ; Wed, 12 Aug 2020 18:15:11 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4BRMpb6qFzzDqY1 for ; Wed, 12 Aug 2020 18:11:03 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=canb.auug.org.au Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=canb.auug.org.au header.i=@canb.auug.org.au header.a=rsa-sha256 header.s=201702 header.b=XYLc3A8/; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4BRMpb2FySz9sRN; Wed, 12 Aug 2020 18:11:03 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=canb.auug.org.au; s=201702; t=1597219863; bh=Qel6ITxOawkiv7Wh7P7TYB6H965dFcwKK5qu7Z+2nOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XYLc3A8/ofxBtGWdVMPughrHVmcGH4H9Y9VYN2o4lAJj6b0Gc3lhNmqQrGWf3WH5g ztSwksED28nx8+1VomsgtVukTfurNluyP2hgNYCK5Jb9efhilmW2aZOeBoH89UEgxE j40lQcqr9u3dOev8pw5trG0FJEhrPa+B/FpiBaAlqVqO5qdVxvlLt2ACFqBRlxO+3Z HpI5A5IbMbVp4H5FFb8HuBEU4inD3usl2xNIGfwCJK19jFvg9uR9Di9PViNv3Cqo8A ab8vJsrhL2P5EJsM6CnBceXLXXNE+WN2hSdE0CmubEvUdFyuyzoF7vOvr/1adUa+tz uxlrpwbm7kBcw== From: Stephen Rothwell To: Michael Ellerman Subject: [PATCH 1/2] powerpc: unrel_branch_check.sh: use nm to find symbol value Date: Wed, 12 Aug 2020 18:10:35 +1000 Message-Id: <20200812081036.7969-2-sfr@canb.auug.org.au> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200812081036.7969-1-sfr@canb.auug.org.au> References: <20200812081036.7969-1-sfr@canb.auug.org.au> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linux PowerPC List , Bill Wendling , Nicholas Piggin Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This is considerably faster then parsing the objdump asm output. It will also make the enabling of llvm-objdump a little easier. Cc: Nicholas Piggin Cc: Bill Wendling Signed-off-by: Stephen Rothwell --- arch/powerpc/Makefile.postlink | 2 +- arch/powerpc/tools/unrel_branch_check.sh | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/Makefile.postlink b/arch/powerpc/Makefile.postlink index 2268396ff4bb..a6c77f4d32b2 100644 --- a/arch/powerpc/Makefile.postlink +++ b/arch/powerpc/Makefile.postlink @@ -18,7 +18,7 @@ quiet_cmd_relocs_check = CHKREL $@ ifdef CONFIG_PPC_BOOK3S_64 cmd_relocs_check = \ $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$(NM)" "$@" ; \ - $(BASH) $(srctree)/arch/powerpc/tools/unrel_branch_check.sh "$(OBJDUMP)" "$@" + $(BASH) $(srctree)/arch/powerpc/tools/unrel_branch_check.sh "$(OBJDUMP)" "$(NM)" "$@" else cmd_relocs_check = \ $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$(NM)" "$@" diff --git a/arch/powerpc/tools/unrel_branch_check.sh b/arch/powerpc/tools/unrel_branch_check.sh index 70da90270c78..0369eb2e7e4b 100755 --- a/arch/powerpc/tools/unrel_branch_check.sh +++ b/arch/powerpc/tools/unrel_branch_check.sh @@ -5,18 +5,15 @@ # This script checks the unrelocated code of a vmlinux for "suspicious" # branches to relocated code (head_64.S code). -# Have Kbuild supply the path to objdump so we handle cross compilation. +# Have Kbuild supply the path to objdump and nm so we handle cross compilation. objdump="$1" -vmlinux="$2" +nm="$2" +vmlinux="$3" -#__end_interrupts should be located within the first 64K kstart=0xc000000000000000 -printf -v kend '0x%x' $(( kstart + 0x10000 )) -end_intr=0x$( -$objdump -R -d --start-address="$kstart" --stop-address="$kend" "$vmlinux" 2>/dev/null | -awk '$2 == "<__end_interrupts>:" { print $1 }' -) +end_intr=0x$($nm -p "$vmlinux" | + sed -E -n '/\s+[[:alpha:]]\s+__end_interrupts\s*$/{s///p;q}') if [ "$end_intr" = "0x" ]; then exit 0 fi From patchwork Wed Aug 12 08:10:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Rothwell X-Patchwork-Id: 1343564 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BRMxz5gQtz9sRN for ; Wed, 12 Aug 2020 18:17:27 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=canb.auug.org.au Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=canb.auug.org.au header.i=@canb.auug.org.au header.a=rsa-sha256 header.s=201702 header.b=ntIwH4IC; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4BRMxz3w6XzDqZQ for ; Wed, 12 Aug 2020 18:17:27 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4BRMpg1vPgzDqY3 for ; Wed, 12 Aug 2020 18:11:07 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=canb.auug.org.au Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=canb.auug.org.au header.i=@canb.auug.org.au header.a=rsa-sha256 header.s=201702 header.b=ntIwH4IC; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4BRMpd70KLz9sTS; Wed, 12 Aug 2020 18:11:05 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=canb.auug.org.au; s=201702; t=1597219866; bh=t0RdvnmV/VADsggqs8a68+YNtHOSGzUsZiTI6YJ98JA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ntIwH4IC/Ij7gr93C2G8Rgn8NjwgufZd8SciHE0QkQrRzy9vBxXKA7qC1b7xF59Fg iysrcXMx2R5OD+GlO7PyymCdi3XBaxGUEkdI5y4L7i2EtWq+F2K1iFk8LZgjQ5143u 7nTJ5/kP37a96Cpc7n2NmfcQk99GkCXno35LVnkxZ8kHsKlq+2oAssmRATVUMi57WN bgiC9Xx2vRm0fbhFfg1LXuquEQET4RxuhgnBB1503UcppLiAPFp1cemlZDIdS6h5yV PFgaJkZqf84JoKxxO/Jadnd/bNTIIBI13tDXdvbfw1KAcNL69ZXaQoEyo427kuOtIi 1KCU+S+XWT+qA== From: Stephen Rothwell To: Michael Ellerman Subject: [PATCH 2/2] powerpc: unrel_branch_check.sh: enable the use of llvm-objdump v9, 10 or 11 Date: Wed, 12 Aug 2020 18:10:36 +1000 Message-Id: <20200812081036.7969-3-sfr@canb.auug.org.au> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200812081036.7969-1-sfr@canb.auug.org.au> References: <20200812081036.7969-1-sfr@canb.auug.org.au> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linux PowerPC List , Bill Wendling , Nicholas Piggin Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Currently, using llvm-objtool, this script just silently succeeds without actually do the intended checking. So this updates it to work properly. Firstly, llvm-objdump does not add target symbol names to the end of branches in its asm output, so we have to drop the branch to __start_initialization_multiplatform using its address. Secondly, v9 and 10 specify branch targets as .+, so we convert those to actual addresses. Thirdly, v10 and 11 error out on a vmlinux if given the -R option complaining that it is "not a dynamic object". The -R does not make any difference to the asm output, so remove it. Lastly, v11 produces asm that is very similar to Gnu objtool (at least as far as branches are concerned), so no further changes are necessary to make it work. Cc: Nicholas Piggin Cc: Bill Wendling Signed-off-by: Stephen Rothwell --- arch/powerpc/tools/unrel_branch_check.sh | 34 ++++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/tools/unrel_branch_check.sh b/arch/powerpc/tools/unrel_branch_check.sh index 0369eb2e7e4b..8301efee1e6c 100755 --- a/arch/powerpc/tools/unrel_branch_check.sh +++ b/arch/powerpc/tools/unrel_branch_check.sh @@ -18,12 +18,16 @@ if [ "$end_intr" = "0x" ]; then exit 0 fi -$objdump -R -D --no-show-raw-insn --start-address="$kstart" --stop-address="$end_intr" "$vmlinux" | +# we know that there is a correct branch to +# __start_initialization_multiplatform, so find its address +# so we can exclude it. +sim=0x$($nm -p "$vmlinux" | + sed -E -n '/\s+[[:alpha:]]\s+__start_initialization_multiplatform\s*$/{s///p;q}') + +$objdump -D --no-show-raw-insn --start-address="$kstart" --stop-address="$end_intr" "$vmlinux" | sed -E -n ' # match lines that start with a kernel address /^c[0-9a-f]*:\s*b/ { - # drop a target that we do not care about - /\<__start_initialization_multiplatform>/d # drop branches via ctr or lr /\= 0x2000000 )); then + to=$(( to - 0x4000000 )) + fi + elif (( to >= 0x8000 )); then + to=$(( to - 0x10000 )) + fi + printf -v to '0x%x' $(( "0x$from" + to )) + ;; + *) printf 'Unkown branch format\n' + ;; + esac + if [ "$to" = "$sim" ]; then + continue + fi if (( to > end_intr )); then if $all_good; then printf '%s\n' 'WARNING: Unrelocated relative branches'