From patchwork Mon Dec 16 23:12:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13910665 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 462391D9A51 for ; Mon, 16 Dec 2024 23:13:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734390808; cv=none; b=eYsDNNoN51ilLWfSOPRJxUTDhe/uavWq7G3lT9azZwni6qd9U82p5sEg8f90jbwYCW4CnVixoRe85SpfRdMCltT0bLI78GOoeogtt5rwLAfCtXtORVTnq1yiuUaBg0JPJJUiJ4mlR08NFK90nwZW81o+EohHRp5VdnbalPQSyDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734390808; c=relaxed/simple; bh=IChtsS2vcC0zzlF9qX93bNksLgkX24amcVZg/Whalhg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l7BKB1+SUCXDvGYAh4W2cqhH3EoxokLdVjl0mLIosvWFAu7lJDMLA7fpKxLEVC1UIYh8mFi2xXtyXs+NQ4IBTQuUUpDeH8QQ/W6cKC8BV7h3tX+wh54GlrdM07KBVWy3s7Ht2xOsMBdWk1RCSeZZDBF3PQqeg+kMIzDBWLnZSJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=yZAoAsop; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="yZAoAsop" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-21636268e43so57166205ad.2 for ; Mon, 16 Dec 2024 15:13:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1734390806; x=1734995606; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=KtErM1Ve2hYinmhWDXFCRPsbxJ5zQtoWuxH4M5kRJWs=; b=yZAoAsophac381RvX87Kck32TSlUlWV8JTdi3EX3V5YXYxVXDjkP7p6vPUNyuDq4Xr 529+cX/SbJt2Ii2IDF1caXgca/HvpJNI2iruBG6knFVretP1XZo1TpDzXQcymEjUCg14 UUc49ZaWhw7g4R0AOIHaHKpj+6Y1FRNHa1OQ1Ndx0cPZnZyAHnN8BCj1M36nZSss9y2P 34qPTTUdE0xoQC97QPGrqu0Kw9vd0IYO3m+ZODjxzv5eTr1DAk2BcLQj+iOQJOC5lZOd qCH3ew77HSs5zNZUWYSPMCsZ3hLXXvZ40aYqxxuRZRbb/JjVQ8QvawX6F1mrD1YYs4Dn bDeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734390806; x=1734995606; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KtErM1Ve2hYinmhWDXFCRPsbxJ5zQtoWuxH4M5kRJWs=; b=Zkr1PQjhlQu42SkTfkAy4lERY19veeRh4DGzd+WDSw3TLh2SzpdeeOl+tjI/SmZ3lb g6BM66a0FP5bw/iLkYdTMvFdJi2AHXxy+AcTOhY0lpOwn4FK9SBbCxrQTatq/5LqB9OF Xq9MNNciAfBm8od1M8YKO6/UCcuYlQmR8HdKyXkuuWGyFLljDUReKUgYrTvOtqjnj/Jk 1FleqszooVJeelFvfe3xtbojZweCKs0072EG2WOLIXPuowBo1Fklq5bRR3Gv6CwPRVBO k+CEonoEE/McuLALmhsJfTMcKch0xjN85A0FfRiOWNguAjtjGcpm4J6fLiiie/TItoP4 nYdg== X-Forwarded-Encrypted: i=1; AJvYcCXNyL8K/lzAbiz8icqVZLcEzo1GI0GusFUVLKXclOpBrXNQ2bAnEeYCgO+fdV6TRjfwLjawZRn/nnSSRUgZYw+n+N1Lons=@vger.kernel.org X-Gm-Message-State: AOJu0YwO2mpbdveodgyjClh3yMDiy2tLy9z7XiAv1AfJ/2bgbznlUNjL CPqp5OCOf00EtRWamRtkLrlSXyi8FZgjD9Mfa5DYi38TQa2qQcxufHzuolPLTvw= X-Gm-Gg: ASbGncu3J5nJG2xas7IIPJG4wQXrCI6humfyTNWwN0LigVocYgCtgnIWGTAZXmiv9up Pozd0CsYmgH5tKp/OaipzWy9SPjjCY0HyIDYIdWeXhRDlHBM6RqNSAU0iNLCncS2AIpf+4OfFCZ of+pva3HHUs/UJ3YWfo5v0FDF+T5wLP3/nXghR7M1X8PUm4ve0fjDcQgZ4RBXYVgFhe0nW9cMgG yhymmKpf0RAzQB7L+0IT62GslctA3LmBUeZDfuvjlri9y+LNrU6GYcXlj8HV//X5TjLpmAX X-Google-Smtp-Source: AGHT+IG7d1EVk09Gyn4kffMe9mhj+HK2qa0XP67wFBNzKqGiDe300RSugOZB/wYYtlbfPKTuuRzmLQ== X-Received: by 2002:a17:902:ecc8:b0:215:7421:262 with SMTP id d9443c01a7336-218929820a5mr216451045ad.12.1734390806556; Mon, 16 Dec 2024 15:13:26 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1dcc47bsm48333255ad.63.2024.12.16.15.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 15:13:25 -0800 (PST) From: Charlie Jenkins Date: Mon, 16 Dec 2024 15:12:51 -0800 Subject: [PATCH 1/2] kbuild: Check version of objdump Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-perf_fix_riscv_obj_reading-v1-1-b75962660a9b@rivosinc.com> References: <20241216-perf_fix_riscv_obj_reading-v1-0-b75962660a9b@rivosinc.com> In-Reply-To: <20241216-perf_fix_riscv_obj_reading-v1-0-b75962660a9b@rivosinc.com> To: Masahiro Yamada , Paul Walmsley , Palmer Dabbelt , Albert Ou , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , =?utf-8?q?Micka=C3=ABl_Sala=C3=BC?= =?utf-8?q?n?= , =?utf-8?q?G=C3=BCnther_Noack?= , Nelson Chu Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-riscv@lists.infradead.org, llvm@lists.linux.dev, linux-perf-users@vger.kernel.org, linux-security-module@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3835; i=charlie@rivosinc.com; h=from:subject:message-id; bh=IChtsS2vcC0zzlF9qX93bNksLgkX24amcVZg/Whalhg=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ3rCFsFFrwPjpm/neppcomk8U6ZceR7/mol1y5/FNwstL W2dMm1JRykLgxgHg6yYIgvPtQbm1jv6ZUdFyybAzGFlAhnCwMUpABO5ycPwv/bu6wu/imrKdDZq bjKZHBWWnnRkz7PCvC/pV51nvTyxJ5Hhn+mD3V2n+P5EHHj17tnntVdUz5lVzn/yf6butml/19y Lb+cEAA== X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 Similar to ld-version, add a way to check the version of objdump. This should most of the time end up being the binutils version or the llvm version. Signed-off-by: Charlie Jenkins --- init/Kconfig | 10 +++++++ scripts/Kconfig.include | 6 ++++ scripts/objdump-version.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index a20e6efd3f0fbdd7f0df2448854cc30734a0ee4f..0b5d36f939e1de89c12ebdd61e4815015314d4f1 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -60,6 +60,16 @@ config LLD_VERSION default $(ld-version) if LD_IS_LLD default 0 +config OBJDUMP_IS_GNU + def_bool $(success,test "$(objdump-name)" = objdump) + +config OBJDUMP_IS_LLVM + def_bool $(success,test "$(objdump-name)" = llvm-objdump) + +config OBJDUMP_VERSION + int + default $(objdump-version) + config RUSTC_VERSION int default $(rustc-version) diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include index 33193ca6e8030e659d6b321acaea1acd42c387a4..cb3e2d2564fea8cce780adb3be672c9596b7ccf2 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -58,6 +58,12 @@ $(error-if,$(success,test -z "$(ld-info)"),Sorry$(comma) this linker is not supp ld-name := $(shell,set -- $(ld-info) && echo $1) ld-version := $(shell,set -- $(ld-info) && echo $2) +# Get the objdump name, version, and error out if it is not supported. +objdump-info := $(shell,$(srctree)/scripts/objdump-version.sh $(OBJDUMP)) +$(error-if,$(success,test -z "$(objdump-info)"),Sorry$(comma) this objdump is not supported.) +objdump-name := $(shell,set -- $(objdump-info) && echo $1) +objdump-version := $(shell,set -- $(objdump-info) && echo $2) + # machine bit flags # $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise. # $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise. diff --git a/scripts/objdump-version.sh b/scripts/objdump-version.sh new file mode 100755 index 0000000000000000000000000000000000000000..fa24f8dc2d3c42fd1195fceb3c96b27f7127db25 --- /dev/null +++ b/scripts/objdump-version.sh @@ -0,0 +1,69 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Print the objdump name and its version in a 5 or 6-digit form. +# Also, perform the minimum version check. + +set -e + +# Convert the version string x.y.z to a canonical 5 or 6-digit form. +get_canonical_version() +{ + IFS=. + set -- $1 + + # If the 2nd or 3rd field is missing, fill it with a zero. + # + # The 4th field, if present, is ignored. + # This occurs in development snapshots as in 2.35.1.20201116 + echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0})) +} + +orig_args="$@" + +# Get the first line of the --version output. +IFS=' +' +set -- $(LC_ALL=C "$@" --version) + +# Split the line on spaces. +IFS=' ' +set -- $1 + +min_tool_version=$(dirname $0)/min-tool-version.sh + +if [ "$1" = GNU -a "$2" = objdump ]; then + shift $(($# - 1)) + version=$1 + min_version=$($min_tool_version binutils) + disp_name="GNU objdump" +else + while [ $# -gt 1 -a "$1" != "LLVM" ]; do + shift + done + + if [ "$1" = LLVM ]; then + version=$3 + min_version=$($min_tool_version llvm) + disp_name="llvm-objdump" + else + echo "$orig_args: unknown objdump" >&2 + exit 1 + fi +fi + +version=${version%%[!0-9.]*} + +cversion=$(get_canonical_version $version) +min_cversion=$(get_canonical_version $min_version) + +if [ "$cversion" -lt "$min_cversion" ]; then + echo >&2 "***" + echo >&2 "*** objdump is too old." + echo >&2 "*** Your $disp_name version: $version" + echo >&2 "*** Minimum $disp_name version: $min_version" + echo >&2 "***" + exit 1 +fi + +echo objdump $cversion From patchwork Mon Dec 16 23:12:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13910666 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA3FD1DA109 for ; Mon, 16 Dec 2024 23:13:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734390812; cv=none; b=uzBnDfarLw4MTXcjtCyl5pSSb4iDCQakSi4eAWNFcd0s82CFIPuCKz92AyT04Ixx1CI2HmVb/9VVewGXUXJuy2kQz4rTCxnjWZ41vkeWNVb/5Z0cKSD92PLbcP01+gxF2smPIfX7SuC2hJ0r3kPFlaVAvXuWujyu5gZQFYGzkNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734390812; c=relaxed/simple; bh=k4Sj7dM5EROtRyKRIxtv+8o9o4DaFse9qSyIbzlZ98Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Fv0AUwd/v2dBYheA7U709HkktLxWU+VO7w5lKeW2Fi+CtI4iRQLkTjk5IBiLtN3ijvBP0ynRKxIthRmUR+A7TAWCfrDwDywmogLbnXZ/aeyVxBPrhtN9mjdJXoI+jEmsYtMiYvEkHQv6qXsVAbsBYBhmR6dtUoc9vWCIoYVqcl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=rLzNy+Zo; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="rLzNy+Zo" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-216728b1836so33244245ad.0 for ; Mon, 16 Dec 2024 15:13:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1734390809; x=1734995609; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=sm+gy0vg6ADpwKtQUne3ds2s3sgHguLz0qdVVhDqizo=; b=rLzNy+ZoD62XrVBG36DyvneX+0xpq7HIHUzxZgHPmXBc9QEUE5T62rTbzpje8A9xcz n/NzfEDKmuP3+oXVhcadC8LYl74usW5a8YoL2U4UhvDPN4gFnfv8Eim9I4SfJplAQGgX 6iTdSPXU7hLhW6VrjxXpl571KVK7PRLaEa1rTcJIGdJNU32cMQAskfTyef9AKRH7SHwV T8uye/SUoIQZI405B38FMIYd7XH6DTqQnQGWy+AnMOrNYbaCWTkNeNutwJdunKlHOpxR lWz1XL79M5qJnS4WSp8by4kzqYq+B7yzWyXH2Pq4m1fsN5jHcsSv3Tx2b6jhpwPLM4Ou MtCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734390809; x=1734995609; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sm+gy0vg6ADpwKtQUne3ds2s3sgHguLz0qdVVhDqizo=; b=fac0Y5MpDeei3GCbN5Y3cmD4bWwEUgY/FNH1LQ2fyNceuIFklfs8uXEJTjLza5i1Kd HmtcE7j3lBKVm2DUSUdJiJVEjVMFHDFlNfFGq/eHoaehcX8SEi5/3dGLpOWk0GRPaGhq lCbAIotxlkBN948IQ8hlUDBGZ4qZduFQCDBEUNN3SY39DUSEwlhRBMJkR9fsyCJPZ4Fd m9Fwn60mjIFtkCKj8gw5a5YGLuL1H2hG9c2AGu0JRcDYdF6U3Co3Chv4HYwt4s4boupj mjoZZQHuCDqe3oVjC+cE5zWfF84irvaJ20M5MVv5K09nTbUpSgutmU5h8OJrP12msI1W p4Kg== X-Forwarded-Encrypted: i=1; AJvYcCWFaX1pbiaTqwlmOjJvQuAj9Mw63VFhg5tCPXsIRkmDE/RJehV5dj6gfJZZYwtSq0bBIN9XDbKrJsIZnns8ykK2djKc9rg=@vger.kernel.org X-Gm-Message-State: AOJu0YxuXpQ9m+Ke14u2lboqHNmW08ePN21lXlWxV9WiN0hAxQWR0nxU hdZP5dkXFPRX7+UhNWhyZZxaWcwStlRiJzT2ZefkG/1LXEP6I9CkX+ySbZmiXb0= X-Gm-Gg: ASbGncu1RxOhw84/TwsGMtiRj8EhfVQY+23DvevfYI9GAARaieiZq1qfxgoz17un48V 4H0w08sU5CEdL788LJPtOKLlj7VFfPIgO3sBrBLvZvu3DntS7g7FK3jjslKWL3s3VWP7DMCqhZH HqLXn9r2wXmFu2S7EkgXpZ3yCE/zThOYvvLKjNxGEMFeaezjFlwdf6msNFtIpoiJfUfSqAgtmC6 tLElFeJVi8sQcfqpRBikmuvJ+aLAx+HsJklisKY/x4E4uhWOSB07rqudUyCzEU8cQdZvHrz X-Google-Smtp-Source: AGHT+IEUS1KQ0ef501yi9KQdApUOJap2Q7VLgsPuhiCn2hfgEw7VxTtRPysE5A5XxEfaj3jPqra1Kw== X-Received: by 2002:a17:902:ecd1:b0:216:3eaf:3781 with SMTP id d9443c01a7336-21892a58734mr187815855ad.43.1734390808967; Mon, 16 Dec 2024 15:13:28 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1dcc47bsm48333255ad.63.2024.12.16.15.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 15:13:28 -0800 (PST) From: Charlie Jenkins Date: Mon, 16 Dec 2024 15:12:52 -0800 Subject: [PATCH 2/2] tools: perf: tests: Fix code reading for riscv Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-perf_fix_riscv_obj_reading-v1-2-b75962660a9b@rivosinc.com> References: <20241216-perf_fix_riscv_obj_reading-v1-0-b75962660a9b@rivosinc.com> In-Reply-To: <20241216-perf_fix_riscv_obj_reading-v1-0-b75962660a9b@rivosinc.com> To: Masahiro Yamada , Paul Walmsley , Palmer Dabbelt , Albert Ou , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , =?utf-8?q?Micka=C3=ABl_Sala=C3=BC?= =?utf-8?q?n?= , =?utf-8?q?G=C3=BCnther_Noack?= , Nelson Chu Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-riscv@lists.infradead.org, llvm@lists.linux.dev, linux-perf-users@vger.kernel.org, linux-security-module@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2802; i=charlie@rivosinc.com; h=from:subject:message-id; bh=k4Sj7dM5EROtRyKRIxtv+8o9o4DaFse9qSyIbzlZ98Q=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ3rCFsHN62Zdecfs+JNP2uLlep5+jx3vdkTV/r39gW3+i RnX8+22dZSyMIhxMMiKKbLwXGtgbr2jX3ZUtGwCzBxWJpAhDFycAjCR+wmMDF+2JGUuPhm4eJ+U wobqzxGrOt5EMjWvrZGL5XpxZAfXtzWMDFOnT7tTaS962CctyFjKfIG1dduJX4UMnUpCpZ6iYvz KnAA= X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 After binutils commit e43d876 which was first included in binutils 2.41, riscv no longer supports dumping in the middle of instructions. Increase the objdump window by 2-bytes to ensure that any instruction that sits on the boundary of the specified stop-address is not cut in half. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 5 +++++ tools/perf/tests/code-reading.c | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index d4a7ca0388c071b536df59c0eb11d55f9080c7cd..f164047471267936bc62389b7d7d9a7cbdca8f97 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -229,6 +229,11 @@ config GCC_SUPPORTS_DYNAMIC_FTRACE def_bool CC_IS_GCC depends on $(cc-option,-fpatchable-function-entry=8) +config RISCV_OBJDUMP_SUPPORTS_SPLIT_INSTRUCTION + # Some versions of objdump do not support dumping partial instructions + def_bool y + depends on !(OBJDUMP_IS_GNU && OBJDUMP_VERSION > 24100) + config HAVE_SHADOW_CALL_STACK def_bool $(cc-option,-fsanitize=shadow-call-stack) # https://github.com/riscv-non-isa/riscv-elf-psabi-doc/commit/a484e843e6eeb51f0cb7b8819e50da6d2444d769 diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index 27c82cfb7e7de42284bf5af9cf7594a3a963052e..605f4a8e1dbc00d8a572503f45053c2f30ad19e3 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -183,9 +184,23 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf, const char *fmt; FILE *f; int ret; + u64 stop_address = addr + len; + + if (IS_ENABLED(__riscv) && !IS_ENABLED(CONFIG_RISCV_OBJDUMP_SUPPORTS_SPLIT_INSTRUCTION)) { + /* + * On some versions of riscv objdump, dumping in the middle of + * instructions is not supported. riscv instructions are aligned along + * 2-byte intervals and can be either 2-bytes or 4-bytes. This makes it + * possible that the stop-address lands in the middle of a 4-byte + * instruction. Increase the stop_address by two to ensure an + * instruction is not cut in half, but leave the len as-is so only the + * expected number of bytes are collected. + */ + stop_address += 2; + } fmt = "%s -z -d --start-address=0x%"PRIx64" --stop-address=0x%"PRIx64" %s"; - ret = snprintf(cmd, sizeof(cmd), fmt, test_objdump_path, addr, addr + len, + ret = snprintf(cmd, sizeof(cmd), fmt, test_objdump_path, addr, stop_address, filename); if (ret <= 0 || (size_t)ret >= sizeof(cmd)) return -1;