From patchwork Wed Apr 12 19:03:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 82648 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp562301vqo; Wed, 12 Apr 2023 12:40:53 -0700 (PDT) X-Google-Smtp-Source: AKy350bxJLnPw3p8/SpNcN5I5dJ3a+Jr/vDsjQkbk90qsSJ05B6Y0d8XStmwqY+QagDUXL/1UxRq X-Received: by 2002:a05:6a20:3392:b0:db:9131:dd7c with SMTP id f18-20020a056a20339200b000db9131dd7cmr7441199pzd.39.1681328453394; Wed, 12 Apr 2023 12:40:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681328453; cv=none; d=google.com; s=arc-20160816; b=WMiWkcJ/hItIs2Gre1iVAJmc0n4cf75DZRhP0trjgul2FWB4oWobWf1EMIXPDo0X3n 6dxkqJjDPW0TFaD9H/cnt75H6GMOkn6v4w8eNXEio+CijnTnHsuWOecNy/piIeR8fUH3 8p8V5z9nSL1o/KqfD+WL7Y6HBG2b8MwxI7lcgioSnvTo19crjOVbPZd+60j3iduy9tMs 3vSo6oFKExQ/CLcQxCL3UPbFyCD3MDahkI4kL/uie2SgRJa2LLJ5LauJfOZAfMfn9zhu tIbaI22SA7Xzf6Q/N8WD5fS+MDyuoNgiOufaNFrDT/e66lWlJOGm7OEIviza2dHr0A2X 0sNg== 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 :dkim-signature; bh=efWCjtcUE4xvsAo1zHAGiD8hgTPm2YAyNz/54vJOJ4M=; b=0FmHxW6ilf9BtXK4utLAdcCaDwyK+54OwoFzeErgMeFVHdxbOhhIXmhUGRzlbAILSI P53TsI3A54QT0g2UDAoBTokAOvYXBLeX1J5mgiLj1H6Lo4n6WNkPDqU6kQhoDhCDQnNh zN+i/ZJp6L1yGH85ZkHwbKLgli1wwuevDHb3a3YoDC+oIkqsCep5sAPXc9FY16/TSwk8 O/2fEl5NgdqX7N9z0HIlOVz9J4O7qnIlmdKsyv2YN2tnkWBpUaOsAE+qpJ3eGl/86O6q XzgwvGgh5BjLfIVzos3GyU7/mzPzO/3Fl/wa+R45O7kGvpUUN9YPzfkQeVKh2e7omMWH 9giQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VIDRrUvh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w26-20020aa7955a000000b0062b90348402si1557606pfq.106.2023.04.12.12.40.38; Wed, 12 Apr 2023 12:40:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VIDRrUvh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbjDLTDv (ORCPT + 99 others); Wed, 12 Apr 2023 15:03:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229491AbjDLTDs (ORCPT ); Wed, 12 Apr 2023 15:03:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7B39E6F for ; Wed, 12 Apr 2023 12:03:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5A49C634D3 for ; Wed, 12 Apr 2023 19:03:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DC60C4339B; Wed, 12 Apr 2023 19:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681326225; bh=dAkEqTLkgIq2vIL65t1W7EqLc3ca55ao4IifwBU07ho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VIDRrUvhwOjhD0Wf0t/If1fqIzu3GuH1BxHN/oPfMgfHOhaeEUq7vZAcPQK1QyZqB OrA7U4S1khWVVCxKFyPXum7dSlqvnBhgUbUamtMej0cYdEnnSUTfdt4zceP+STw3oR CmAiZzEhtdCBi+QELrZ8SItETeZ71Q1EZu5vYjHt9XX8TpemPjQxcIDEcGo+0Ogzj6 0lgL//aRZYDjH1zHS/femqKSKM2wUCA1ntPKMhJLmWtkykHOaRqgXGI0C7WUrLIGdh Iox4rongGMbsUdoN+3QKewQQVHPdI5fNdhIu3XqSVv3f6ofLGLO8zXSG8HiJOGoynm xwnYqwGgC20Zg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH v2 1/9] scripts/objdump-func: Support multiple functions Date: Wed, 12 Apr 2023 12:03:16 -0700 Message-Id: <0bf5f4f5978660985037b24c6db49b114374eb4d.1681325924.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763000664506418083?= X-GMAIL-MSGID: =?utf-8?q?1763000664506418083?= Allow specifying multiple functions on the cmdline. Note this removes the secret EXTRA_ARGS feature. While at it, spread out the awk to make it more readable. Signed-off-by: Josh Poimboeuf --- scripts/objdump-func | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/scripts/objdump-func b/scripts/objdump-func index 4eb463dd9f52..7b15b873d0e2 100755 --- a/scripts/objdump-func +++ b/scripts/objdump-func @@ -3,7 +3,7 @@ # # Disassemble a single function. # -# usage: objdump-func +# usage: objdump-func [ ...] set -o errexit set -o nounset @@ -13,17 +13,33 @@ OBJDUMP="${CROSS_COMPILE:-}objdump" command -v gawk >/dev/null 2>&1 || die "gawk isn't installed" usage() { - echo "usage: objdump-func " >&2 + echo "usage: objdump-func [ ...]" >&2 exit 1 } [[ $# -lt 2 ]] && usage OBJ=$1; shift -FUNC=$1; shift - -# Secret feature to allow adding extra objdump args at the end -EXTRA_ARGS=$@ - -# Note this also matches compiler-added suffixes like ".cold", etc -${OBJDUMP} -wdr $EXTRA_ARGS $OBJ | gawk -M -v f=$FUNC '/^$/ { P=0; } $0 ~ "<" f "(\\..*)?>:" { P=1; O=strtonum("0x" $1); } { if (P) { o=strtonum("0x" $1); printf("%04x ", o-O); print $0; } }' +FUNCS=("$@") + +${OBJDUMP} -wdr $OBJ | gawk -M -v _funcs="${FUNCS[*]}" ' + BEGIN { split(_funcs, funcs); } + /^$/ { func_match=0; } + /<.*>:/ { + f = gensub(/.*<(.*)>:/, "\\1", 1); + for (i in funcs) { + # match compiler-added suffixes like ".cold", etc + if (f ~ "^" funcs[i] "(\\..*)?") { + func_match = 1; + base = strtonum("0x" $1); + break; + } + } + } + { + if (func_match) { + addr = strtonum("0x" $1); + printf("%04x ", addr - base); + print; + } + }' From patchwork Wed Apr 12 19:03:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 82643 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp551086vqo; Wed, 12 Apr 2023 12:17:20 -0700 (PDT) X-Google-Smtp-Source: AKy350YTBPsK69wqtsEZwKuZkRivA1CGmSqtONKhi5lEyJAONXJbzHAMDu9uPofiGiBWNVp63sxU X-Received: by 2002:a17:902:d482:b0:1a6:4c2b:9e7f with SMTP id c2-20020a170902d48200b001a64c2b9e7fmr5440688plg.1.1681327039627; Wed, 12 Apr 2023 12:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681327039; cv=none; d=google.com; s=arc-20160816; b=yf/5DfpvCdWuzEG14TECWWugfumgeH8PpnxSQzT83tCxiuTZHOcOioLmyPx38NDqLW lMXhxFyUkpIcawr0JdNuZRZNKuQ3jyBp/wmKE3eWeJBhdm7PIuTlQroQnCJP14yw58aB XW6pOSI8x+ZortSRxUJ2AqJBg2+/0d3ox2CGetIpqj66V+h98xWZaN0b0xUtvNQ41I8Q zesxiYUKSfES+gis4RIFP/AzSijSLycECU82QE0BrOy2IE5rlOfMiYAKlbyIpZdC3KxX qaR6skDO7wIjLH7JuKI9dsdTKYMLgf666XUXS3otLtQfAFf1L3eFE7JoaEHAlNupxGob CZBQ== 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 :dkim-signature; bh=St7u88AL1UduNoRMQW8Ig21WxS9Q4V0a048ZFTXnkiY=; b=dTVBTVbi7zNeJcXXbk4e5RRzxhdslLjBnOP6zWDEDH//a+kxQ+iqbJHVl/oTkfiG1H HReOkJ9TSYkBiwOZRNMXpDJhpS0eJtHDLeQvibUC7V9a1DDm6Ou4WykEIRblSVMxEtCn s6CeBkp+ywx13LFBORqR/Z3RvvssVg/XKMqTrnzuGSJz8tFwtWDf54v7Fy1Ecfe5fFRk HVZvoSWOXk3fvnKMMEt84DQn7vnvaDikm2JmUBUxRgOC1ZJJ9orIvmHnorMOZuf/MPHb +oG/2c/DYcMjEakuLYWlCo/kZZ87u88ny3GuG4HcDbfCAZiVT2MTcchS/e/Te2XcIyS7 NzlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VJgURYZm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k21-20020a63d115000000b005030a59a818si15599158pgg.402.2023.04.12.12.17.06; Wed, 12 Apr 2023 12:17:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VJgURYZm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230034AbjDLTEN (ORCPT + 99 others); Wed, 12 Apr 2023 15:04:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbjDLTDu (ORCPT ); Wed, 12 Apr 2023 15:03:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31A6EE75 for ; Wed, 12 Apr 2023 12:03:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AD4486386E for ; Wed, 12 Apr 2023 19:03:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2868C4339E; Wed, 12 Apr 2023 19:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681326226; bh=2MYmWN26AulC1KOi8ImzVJToG/EblxS4S4ZwLNvzSQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VJgURYZmbz5Bf05gmRLgRD1ZToyo7nrxC+cvPdpz1xEG+4UkgH9mkwEP6TL2W+D6A 7QTx5pYV2iClS4YJYC5dbEO0yZR3LmSe4PU8yyFXHqmtRyySHIzl3poVBPrREyuquD L7npy1bOjNendeZQLhbO1Z8Xz1NbV2WeM9tRJ/NevO7wNok+WN/Tvh6jOgClB2hAes 4ozs0UqlwVcXJ1zPQtD/kRX1XnUuubrm7yA5AJchnjUdtWT06x3EBcvN8b3+5+4r7X 3QhGBgDCSk5knywEWBHLnRbVyuBR4JhgTk4HpIFxMUUiW+1yuU11MCj7YfQH9cK1qp iW8KYZ7Sexyyg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH v2 2/9] objtool: Add WARN_INSN() Date: Wed, 12 Apr 2023 12:03:17 -0700 Message-Id: <2eaa3155c90fba683d8723599f279c46025b75f3.1681325924.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762999181912360839?= X-GMAIL-MSGID: =?utf-8?q?1762999181912360839?= It's easier to use and also gives easy access to the instruction's containing function, which is useful for printing that function's symbol. It will also be useful in the future for rate-limiting and disassembly of warned functions. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 171 ++++++++++----------------- tools/objtool/include/objtool/warn.h | 5 + tools/objtool/orc_gen.c | 9 +- 3 files changed, 70 insertions(+), 115 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index cae6ac6ff246..e85440db7a5f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1444,7 +1444,7 @@ static void annotate_call_site(struct objtool_file *file, if (opts.mcount && sym->fentry) { if (sibling) - WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset); + WARN_INSN(insn, "tail call to __fentry__ !?!?"); if (opts.mnop) { if (reloc) { reloc->type = R_NONE; @@ -1646,9 +1646,8 @@ static int add_jump_destinations(struct objtool_file *file) continue; } - WARN_FUNC("can't find jump dest instruction at %s+0x%lx", - insn->sec, insn->offset, dest_sec->name, - dest_off); + WARN_INSN(insn, "can't find jump dest instruction at %s+0x%lx", + dest_sec->name, dest_off); return -1; } @@ -1731,13 +1730,12 @@ static int add_call_destinations(struct objtool_file *file) continue; if (!insn_call_dest(insn)) { - WARN_FUNC("unannotated intra-function call", insn->sec, insn->offset); + WARN_INSN(insn, "unannotated intra-function call"); return -1; } if (insn_func(insn) && insn_call_dest(insn)->type != STT_FUNC) { - WARN_FUNC("unsupported call to non-function", - insn->sec, insn->offset); + WARN_INSN(insn, "unsupported call to non-function"); return -1; } @@ -1745,10 +1743,8 @@ static int add_call_destinations(struct objtool_file *file) dest_off = arch_dest_reloc_offset(reloc->addend); dest = find_call_destination(reloc->sym->sec, dest_off); if (!dest) { - WARN_FUNC("can't find call dest symbol at %s+0x%lx", - insn->sec, insn->offset, - reloc->sym->sec->name, - dest_off); + WARN_INSN(insn, "can't find call dest symbol at %s+0x%lx", + reloc->sym->sec->name, dest_off); return -1; } @@ -1808,8 +1804,7 @@ static int handle_group_alt(struct objtool_file *file, } else { if (orig_alt_group->last_insn->offset + orig_alt_group->last_insn->len - orig_alt_group->first_insn->offset != special_alt->orig_len) { - WARN_FUNC("weirdly overlapping alternative! %ld != %d", - orig_insn->sec, orig_insn->offset, + WARN_INSN(orig_insn, "weirdly overlapping alternative! %ld != %d", orig_alt_group->last_insn->offset + orig_alt_group->last_insn->len - orig_alt_group->first_insn->offset, @@ -1878,8 +1873,7 @@ static int handle_group_alt(struct objtool_file *file, if (alt_reloc && arch_pc_relative_reloc(alt_reloc) && !arch_support_alt_relocation(special_alt, insn, alt_reloc)) { - WARN_FUNC("unsupported relocation in alternatives section", - insn->sec, insn->offset); + WARN_INSN(insn, "unsupported relocation in alternatives section"); return -1; } @@ -1893,8 +1887,7 @@ static int handle_group_alt(struct objtool_file *file, if (dest_off == special_alt->new_off + special_alt->new_len) { insn->jump_dest = next_insn_same_sec(file, orig_alt_group->last_insn); if (!insn->jump_dest) { - WARN_FUNC("can't find alternative jump destination", - insn->sec, insn->offset); + WARN_INSN(insn, "can't find alternative jump destination"); return -1; } } @@ -1928,8 +1921,7 @@ static int handle_jump_alt(struct objtool_file *file, if (orig_insn->type != INSN_JUMP_UNCONDITIONAL && orig_insn->type != INSN_NOP) { - WARN_FUNC("unsupported instruction at jump label", - orig_insn->sec, orig_insn->offset); + WARN_INSN(orig_insn, "unsupported instruction at jump label"); return -1; } @@ -2008,8 +2000,7 @@ static int add_special_section_alts(struct objtool_file *file) if (special_alt->group) { if (!special_alt->orig_len) { - WARN_FUNC("empty alternative entry", - orig_insn->sec, orig_insn->offset); + WARN_INSN(orig_insn, "empty alternative entry"); continue; } @@ -2100,8 +2091,7 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn, } if (!prev_offset) { - WARN_FUNC("can't find switch jump table", - insn->sec, insn->offset); + WARN_INSN(insn, "can't find switch jump table"); return -1; } @@ -2305,8 +2295,7 @@ static int read_unwind_hints(struct objtool_file *file) if (sym && sym->bind == STB_GLOBAL) { if (opts.ibt && insn->type != INSN_ENDBR && !insn->noendbr) { - WARN_FUNC("UNWIND_HINT_IRET_REGS without ENDBR", - insn->sec, insn->offset); + WARN_INSN(insn, "UNWIND_HINT_IRET_REGS without ENDBR"); } } } @@ -2320,8 +2309,7 @@ static int read_unwind_hints(struct objtool_file *file) cfi = *(insn->cfi); if (arch_decode_hint_reg(hint->sp_reg, &cfi.cfa.base)) { - WARN_FUNC("unsupported unwind_hint sp base reg %d", - insn->sec, insn->offset, hint->sp_reg); + WARN_INSN(insn, "unsupported unwind_hint sp base reg %d", hint->sp_reg); return -1; } @@ -2384,8 +2372,7 @@ static int read_retpoline_hints(struct objtool_file *file) insn->type != INSN_CALL_DYNAMIC && insn->type != INSN_RETURN && insn->type != INSN_NOP) { - WARN_FUNC("retpoline_safe hint not an indirect jump/call/ret/nop", - insn->sec, insn->offset); + WARN_INSN(insn, "retpoline_safe hint not an indirect jump/call/ret/nop"); return -1; } @@ -2496,8 +2483,7 @@ static int read_intra_function_calls(struct objtool_file *file) } if (insn->type != INSN_CALL) { - WARN_FUNC("intra_function_call not a direct call", - insn->sec, insn->offset); + WARN_INSN(insn, "intra_function_call not a direct call"); return -1; } @@ -2511,8 +2497,7 @@ static int read_intra_function_calls(struct objtool_file *file) dest_off = arch_jump_destination(insn); insn->jump_dest = find_insn(file, insn->sec, dest_off); if (!insn->jump_dest) { - WARN_FUNC("can't find call dest at %s+0x%lx", - insn->sec, insn->offset, + WARN_INSN(insn, "can't find call dest at %s+0x%lx", insn->sec->name, dest_off); return -1; } @@ -2853,7 +2838,7 @@ static int update_cfi_state(struct instruction *insn, /* stack operations don't make sense with an undefined CFA */ if (cfa->base == CFI_UNDEFINED) { if (insn_func(insn)) { - WARN_FUNC("undefined stack state", insn->sec, insn->offset); + WARN_INSN(insn, "undefined stack state"); return -1; } return 0; @@ -3047,8 +3032,7 @@ static int update_cfi_state(struct instruction *insn, } if (op->dest.reg == cfi->cfa.base && !(next_insn && next_insn->hint)) { - WARN_FUNC("unsupported stack register modification", - insn->sec, insn->offset); + WARN_INSN(insn, "unsupported stack register modification"); return -1; } @@ -3058,8 +3042,7 @@ static int update_cfi_state(struct instruction *insn, if (op->dest.reg != CFI_SP || (cfi->drap_reg != CFI_UNDEFINED && cfa->base != CFI_SP) || (cfi->drap_reg == CFI_UNDEFINED && cfa->base != CFI_BP)) { - WARN_FUNC("unsupported stack pointer realignment", - insn->sec, insn->offset); + WARN_INSN(insn, "unsupported stack pointer realignment"); return -1; } @@ -3154,8 +3137,7 @@ static int update_cfi_state(struct instruction *insn, break; default: - WARN_FUNC("unknown stack-related instruction", - insn->sec, insn->offset); + WARN_INSN(insn, "unknown stack-related instruction"); return -1; } @@ -3244,8 +3226,7 @@ static int update_cfi_state(struct instruction *insn, case OP_DEST_MEM: if (op->src.type != OP_SRC_POP && op->src.type != OP_SRC_POPF) { - WARN_FUNC("unknown stack-related memory operation", - insn->sec, insn->offset); + WARN_INSN(insn, "unknown stack-related memory operation"); return -1; } @@ -3257,8 +3238,7 @@ static int update_cfi_state(struct instruction *insn, break; default: - WARN_FUNC("unknown stack-related instruction", - insn->sec, insn->offset); + WARN_INSN(insn, "unknown stack-related instruction"); return -1; } @@ -3297,8 +3277,7 @@ static int propagate_alt_cfi(struct objtool_file *file, struct instruction *insn struct alt_group *orig_group = insn->alt_group->orig_group ?: insn->alt_group; struct instruction *orig = orig_group->first_insn; char *where = offstr(insn->sec, insn->offset); - WARN_FUNC("stack layout conflict in alternatives: %s", - orig->sec, orig->offset, where); + WARN_INSN(orig, "stack layout conflict in alternatives: %s", where); free(where); return -1; } @@ -3325,8 +3304,7 @@ static int handle_insn_ops(struct instruction *insn, if (!state->uaccess_stack) { state->uaccess_stack = 1; } else if (state->uaccess_stack >> 31) { - WARN_FUNC("PUSHF stack exhausted", - insn->sec, insn->offset); + WARN_INSN(insn, "PUSHF stack exhausted"); return 1; } state->uaccess_stack <<= 1; @@ -3358,8 +3336,7 @@ static bool insn_cfi_match(struct instruction *insn, struct cfi_state *cfi2) if (memcmp(&cfi1->cfa, &cfi2->cfa, sizeof(cfi1->cfa))) { - WARN_FUNC("stack state mismatch: cfa1=%d%+d cfa2=%d%+d", - insn->sec, insn->offset, + WARN_INSN(insn, "stack state mismatch: cfa1=%d%+d cfa2=%d%+d", cfi1->cfa.base, cfi1->cfa.offset, cfi2->cfa.base, cfi2->cfa.offset); @@ -3369,8 +3346,7 @@ static bool insn_cfi_match(struct instruction *insn, struct cfi_state *cfi2) sizeof(struct cfi_reg))) continue; - WARN_FUNC("stack state mismatch: reg1[%d]=%d%+d reg2[%d]=%d%+d", - insn->sec, insn->offset, + WARN_INSN(insn, "stack state mismatch: reg1[%d]=%d%+d reg2[%d]=%d%+d", i, cfi1->regs[i].base, cfi1->regs[i].offset, i, cfi2->regs[i].base, cfi2->regs[i].offset); break; @@ -3378,15 +3354,14 @@ static bool insn_cfi_match(struct instruction *insn, struct cfi_state *cfi2) } else if (cfi1->type != cfi2->type) { - WARN_FUNC("stack state mismatch: type1=%d type2=%d", - insn->sec, insn->offset, cfi1->type, cfi2->type); + WARN_INSN(insn, "stack state mismatch: type1=%d type2=%d", + cfi1->type, cfi2->type); } else if (cfi1->drap != cfi2->drap || (cfi1->drap && cfi1->drap_reg != cfi2->drap_reg) || (cfi1->drap && cfi1->drap_offset != cfi2->drap_offset)) { - WARN_FUNC("stack state mismatch: drap1=%d(%d,%d) drap2=%d(%d,%d)", - insn->sec, insn->offset, + WARN_INSN(insn, "stack state mismatch: drap1=%d(%d,%d) drap2=%d(%d,%d)", cfi1->drap, cfi1->drap_reg, cfi1->drap_offset, cfi2->drap, cfi2->drap_reg, cfi2->drap_offset); @@ -3494,20 +3469,17 @@ static int validate_call(struct objtool_file *file, { if (state->noinstr && state->instr <= 0 && !noinstr_call_dest(file, insn, insn_call_dest(insn))) { - WARN_FUNC("call to %s() leaves .noinstr.text section", - insn->sec, insn->offset, call_dest_name(insn)); + WARN_INSN(insn, "call to %s() leaves .noinstr.text section", call_dest_name(insn)); return 1; } if (state->uaccess && !func_uaccess_safe(insn_call_dest(insn))) { - WARN_FUNC("call to %s() with UACCESS enabled", - insn->sec, insn->offset, call_dest_name(insn)); + WARN_INSN(insn, "call to %s() with UACCESS enabled", call_dest_name(insn)); return 1; } if (state->df) { - WARN_FUNC("call to %s() with DF set", - insn->sec, insn->offset, call_dest_name(insn)); + WARN_INSN(insn, "call to %s() with DF set", call_dest_name(insn)); return 1; } @@ -3519,8 +3491,7 @@ static int validate_sibling_call(struct objtool_file *file, struct insn_state *state) { if (insn_func(insn) && has_modified_stack_frame(insn, state)) { - WARN_FUNC("sibling call from callable instruction with modified stack frame", - insn->sec, insn->offset); + WARN_INSN(insn, "sibling call from callable instruction with modified stack frame"); return 1; } @@ -3530,38 +3501,32 @@ static int validate_sibling_call(struct objtool_file *file, static int validate_return(struct symbol *func, struct instruction *insn, struct insn_state *state) { if (state->noinstr && state->instr > 0) { - WARN_FUNC("return with instrumentation enabled", - insn->sec, insn->offset); + WARN_INSN(insn, "return with instrumentation enabled"); return 1; } if (state->uaccess && !func_uaccess_safe(func)) { - WARN_FUNC("return with UACCESS enabled", - insn->sec, insn->offset); + WARN_INSN(insn, "return with UACCESS enabled"); return 1; } if (!state->uaccess && func_uaccess_safe(func)) { - WARN_FUNC("return with UACCESS disabled from a UACCESS-safe function", - insn->sec, insn->offset); + WARN_INSN(insn, "return with UACCESS disabled from a UACCESS-safe function"); return 1; } if (state->df) { - WARN_FUNC("return with DF set", - insn->sec, insn->offset); + WARN_INSN(insn, "return with DF set"); return 1; } if (func && has_modified_stack_frame(insn, state)) { - WARN_FUNC("return with modified stack frame", - insn->sec, insn->offset); + WARN_INSN(insn, "return with modified stack frame"); return 1; } if (state->cfi.bp_scratch) { - WARN_FUNC("BP used as a scratch register", - insn->sec, insn->offset); + WARN_INSN(insn, "BP used as a scratch register"); return 1; } @@ -3633,8 +3598,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, } if (func && insn->ignore) { - WARN_FUNC("BUG: why am I validating an ignored function?", - sec, insn->offset); + WARN_INSN(insn, "BUG: why am I validating an ignored function?"); return 1; } @@ -3667,14 +3631,12 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, } if (!save_insn) { - WARN_FUNC("no corresponding CFI save for CFI restore", - sec, insn->offset); + WARN_INSN(insn, "no corresponding CFI save for CFI restore"); return 1; } if (!save_insn->visited) { - WARN_FUNC("objtool isn't smart enough to handle this CFI save/restore combo", - sec, insn->offset); + WARN_INSN(insn, "objtool isn't smart enough to handle this CFI save/restore combo"); return 1; } @@ -3734,8 +3696,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, if (opts.stackval && func && !is_fentry_call(insn) && !has_valid_stack_frame(&state)) { - WARN_FUNC("call without frame pointer save/setup", - sec, insn->offset); + WARN_INSN(insn, "call without frame pointer save/setup"); return 1; } @@ -3781,15 +3742,14 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, case INSN_CONTEXT_SWITCH: if (func && (!next_insn || !next_insn->hint)) { - WARN_FUNC("unsupported instruction in callable function", - sec, insn->offset); + WARN_INSN(insn, "unsupported instruction in callable function"); return 1; } return 0; case INSN_STAC: if (state.uaccess) { - WARN_FUNC("recursive UACCESS enable", sec, insn->offset); + WARN_INSN(insn, "recursive UACCESS enable"); return 1; } @@ -3798,12 +3758,12 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, case INSN_CLAC: if (!state.uaccess && func) { - WARN_FUNC("redundant UACCESS disable", sec, insn->offset); + WARN_INSN(insn, "redundant UACCESS disable"); return 1; } if (func_uaccess_safe(func) && !state.uaccess_stack) { - WARN_FUNC("UACCESS-safe disables UACCESS", sec, insn->offset); + WARN_INSN(insn, "UACCESS-safe disables UACCESS"); return 1; } @@ -3812,7 +3772,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, case INSN_STD: if (state.df) { - WARN_FUNC("recursive STD", sec, insn->offset); + WARN_INSN(insn, "recursive STD"); return 1; } @@ -3821,7 +3781,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, case INSN_CLD: if (!state.df && func) { - WARN_FUNC("redundant CLD", sec, insn->offset); + WARN_INSN(insn, "redundant CLD"); return 1; } @@ -3929,15 +3889,14 @@ static int validate_unret(struct objtool_file *file, struct instruction *insn) case INSN_CALL_DYNAMIC: case INSN_JUMP_DYNAMIC: case INSN_JUMP_DYNAMIC_CONDITIONAL: - WARN_FUNC("early indirect call", insn->sec, insn->offset); + WARN_INSN(insn, "early indirect call"); return 1; case INSN_JUMP_UNCONDITIONAL: case INSN_JUMP_CONDITIONAL: if (!is_sibling_call(insn)) { if (!insn->jump_dest) { - WARN_FUNC("unresolved jump target after linking?!?", - insn->sec, insn->offset); + WARN_INSN(insn, "unresolved jump target after linking?!?"); return -1; } ret = validate_unret(file, insn->jump_dest); @@ -3978,7 +3937,7 @@ static int validate_unret(struct objtool_file *file, struct instruction *insn) return 0; case INSN_RETURN: - WARN_FUNC("RET before UNTRAIN", insn->sec, insn->offset); + WARN_INSN(insn, "RET before UNTRAIN"); return 1; case INSN_NOP: @@ -3991,7 +3950,7 @@ static int validate_unret(struct objtool_file *file, struct instruction *insn) } if (!next) { - WARN_FUNC("teh end!", insn->sec, insn->offset); + WARN_INSN(insn, "teh end!"); return -1; } insn = next; @@ -4015,7 +3974,7 @@ static int validate_unrets(struct objtool_file *file) ret = validate_unret(file, insn); if (ret < 0) { - WARN_FUNC("Failed UNRET validation", insn->sec, insn->offset); + WARN_INSN(insn, "Failed UNRET validation"); return ret; } warnings += ret; @@ -4043,13 +4002,11 @@ static int validate_retpoline(struct objtool_file *file) if (insn->type == INSN_RETURN) { if (opts.rethunk) { - WARN_FUNC("'naked' return found in RETHUNK build", - insn->sec, insn->offset); + WARN_INSN(insn, "'naked' return found in RETHUNK build"); } else continue; } else { - WARN_FUNC("indirect %s found in RETPOLINE build", - insn->sec, insn->offset, + WARN_INSN(insn, "indirect %s found in RETPOLINE build", insn->type == INSN_JUMP_DYNAMIC ? "jump" : "call"); } @@ -4428,9 +4385,7 @@ static int validate_ibt_insn(struct objtool_file *file, struct instruction *insn if (noendbr_range(file, dest)) continue; - WARN_FUNC("relocation to !ENDBR: %s", - insn->sec, insn->offset, - offstr(dest->sec, dest->offset)); + WARN_INSN(insn, "relocation to !ENDBR: %s", offstr(dest->sec, dest->offset)); warnings++; } @@ -4532,16 +4487,14 @@ static int validate_sls(struct objtool_file *file) switch (insn->type) { case INSN_RETURN: if (!next_insn || next_insn->type != INSN_TRAP) { - WARN_FUNC("missing int3 after ret", - insn->sec, insn->offset); + WARN_INSN(insn, "missing int3 after ret"); warnings++; } break; case INSN_JUMP_DYNAMIC: if (!next_insn || next_insn->type != INSN_TRAP) { - WARN_FUNC("missing int3 after indirect jump", - insn->sec, insn->offset); + WARN_INSN(insn, "missing int3 after indirect jump"); warnings++; } break; @@ -4564,7 +4517,7 @@ static int validate_reachable_instructions(struct objtool_file *file) if (insn->visited || ignore_unreachable_insn(file, insn)) continue; - WARN_FUNC("unreachable instruction", insn->sec, insn->offset); + WARN_INSN(insn, "unreachable instruction"); return 1; } diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/objtool/warn.h index a3e79ae75f2e..b1c920dc9516 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -53,6 +53,11 @@ static inline char *offstr(struct section *sec, unsigned long offset) free(_str); \ }) +#define WARN_INSN(insn, format, ...) \ +({ \ + WARN_FUNC(format, insn->sec, insn->offset, ##__VA_ARGS__); \ +}) + #define BT_FUNC(format, insn, ...) \ ({ \ struct instruction *_insn = (insn); \ diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c index b327f9ccfe73..48efd1e2f00d 100644 --- a/tools/objtool/orc_gen.c +++ b/tools/objtool/orc_gen.c @@ -47,8 +47,7 @@ static int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, orc->type = ORC_TYPE_REGS_PARTIAL; break; default: - WARN_FUNC("unknown unwind hint type %d", - insn->sec, insn->offset, cfi->type); + WARN_INSN(insn, "unknown unwind hint type %d", cfi->type); return -1; } @@ -80,8 +79,7 @@ static int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, orc->sp_reg = ORC_REG_DX; break; default: - WARN_FUNC("unknown CFA base reg %d", - insn->sec, insn->offset, cfi->cfa.base); + WARN_INSN(insn, "unknown CFA base reg %d", cfi->cfa.base); return -1; } @@ -96,8 +94,7 @@ static int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, orc->bp_reg = ORC_REG_BP; break; default: - WARN_FUNC("unknown BP base reg %d", - insn->sec, insn->offset, bp->base); + WARN_INSN(insn, "unknown BP base reg %d", bp->base); return -1; } From patchwork Wed Apr 12 19:03:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 82640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp548232vqo; Wed, 12 Apr 2023 12:11:56 -0700 (PDT) X-Google-Smtp-Source: AKy350YdC75jofKLNJVMbFL7dETJd0pP5t1HpOjzHaawuNue9M1AqmsmG+VjLiLn31g7m7+JsgAv X-Received: by 2002:a05:6a20:b706:b0:d9:f6ee:3b8f with SMTP id fg6-20020a056a20b70600b000d9f6ee3b8fmr3479801pzb.17.1681326715786; Wed, 12 Apr 2023 12:11:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681326715; cv=none; d=google.com; s=arc-20160816; b=xAZsgdZfezOyJZf1Ui76msREq49Fe2avvAPODjXyTGFuYzPY2SSgsGyLNekfDXXM57 KQQZMy9ajCPCdncY1C4Veqz1+NHARQzoUJCsBHxX5wQsVaShzoR/ts/q7ZJVtNb6c42D k7LF+TppmmT94HMQQkUel6+OZb1jBPR3toH9CGJckq/rDdfXuWld6jKSUcFdZJBg55C0 fd52N+kytH/Uzxa0qV3i00Lectdc0c3Z8jEvlIyIweS7x1zFpCXHj9KbLr281tHajsCa OApT8TjPNPQsW5mMSl1kS1XF/fK7qMyavoeUHd0FctPFt/7cUmJm8hWJRwuqWMiD9giE E0Uw== 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 :dkim-signature; bh=k/SHGCZ5QfgNIedwRUZCV0fpgow+nDheJaJwZ/wSJh4=; b=yBgZl2ICyJ/W+t9ODGKdYXHVOjSU9VTftIdU2m5DnTxCQVjmK5egG+5FtXjdAhGvua SGrrHNMKluuGMI6tZUraPafrM92uzXX7TJV7fM0ArLmVKmm6q4UttDc7u2QnsCS0OqQj kg36c1Yxu4rB9xC6TbQiAP9H98OWOW+MN1JYwUnAIirc/DyoeK7FiGGAE4DQDitK2rra InmWsyGIku0Ew7+np8RYuM36IjW2CkAUHCl9QQEoVXtfV0i/DGLXqHykf8PS064yBU6V cfPPQPZAZTdsFTSiDADCFiE/GWzNQs41VX9OoJc3XQH5Pqwzl8Yct9F12uBgD1v9+qoR uIlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QWt5t1kV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i71-20020a63874a000000b0051972e42719si9590160pge.66.2023.04.12.12.11.42; Wed, 12 Apr 2023 12:11:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QWt5t1kV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229974AbjDLTDx (ORCPT + 99 others); Wed, 12 Apr 2023 15:03:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbjDLTDs (ORCPT ); Wed, 12 Apr 2023 15:03:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7693830C8 for ; Wed, 12 Apr 2023 12:03:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 100566386B for ; Wed, 12 Apr 2023 19:03:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44606C433D2; Wed, 12 Apr 2023 19:03:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681326226; bh=os7uY3nMTCWb+jG1PKMR9S3yUK1VjSJJlj7joM5hI9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QWt5t1kVr9C1RDqVU4+9Zo/cjruM2zWe+BLhm+LRCAl1RaCMobV8Gu2Mdwx6cvPcI w1xXBL0pHHtKfsI+8jpBAa5bdj3/ibHeDsx2ZAOGY7RGwZ5vk3LHm6nAWoDfydjvQZ 2Y9zerupDngDJFU2DsoSt6FxRvqq8l+6veIWlRtFHWr644unF8dlcgeuoLwN4mzeTL pV+DDprL7Vu2f6S7jXTdKbqbM9qBFCQh/Krf3Rm2F0qW5jFXVUmdA9jKaz0g63Yld6 HjeK8y+C5X3zDC7yXvlXLWNqJzCXjBlzn2/L/tO5JIL+7WHxSNvTiAgb/x8W3Hg4uX kRceCXII2Gqvw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH v2 3/9] objtool: Limit unreachable warnings to once per function Date: Wed, 12 Apr 2023 12:03:18 -0700 Message-Id: <81ed0b8e5218ac6ecae49af901bf5e0fb3687cef.1681325924.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762998842233519191?= X-GMAIL-MSGID: =?utf-8?q?1762998842233519191?= Unreachable instruction warnings are limited to once per object file. That no longer makes sense for vmlinux validation, which might have more unreachable instructions lurking in other places. Change it to once per function. Note this affects some other (much rarer) non-fatal warnings as well. In general I think one-warning-per-function makes sense, as related warnings can accumulate quickly and we want to eventually get back to failing the build with -Werror anyway. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 5 +++-- tools/objtool/include/objtool/elf.h | 1 + tools/objtool/include/objtool/warn.h | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index e85440db7a5f..de0d0234527d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4509,6 +4509,7 @@ static int validate_sls(struct objtool_file *file) static int validate_reachable_instructions(struct objtool_file *file) { struct instruction *insn; + int warnings = 0; if (file->ignore_unreachables) return 0; @@ -4518,10 +4519,10 @@ static int validate_reachable_instructions(struct objtool_file *file) continue; WARN_INSN(insn, "unreachable instruction"); - return 1; + warnings++; } - return 0; + return warnings; } int check(struct objtool_file *file) diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index ad0024da262b..a668173a5869 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -61,6 +61,7 @@ struct symbol { u8 return_thunk : 1; u8 fentry : 1; u8 profiling_func : 1; + u8 warned : 1; struct list_head pv_target; struct list_head reloc_list; }; diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/objtool/warn.h index b1c920dc9516..4ef9b278e5fd 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -55,7 +55,10 @@ static inline char *offstr(struct section *sec, unsigned long offset) #define WARN_INSN(insn, format, ...) \ ({ \ - WARN_FUNC(format, insn->sec, insn->offset, ##__VA_ARGS__); \ + if (!insn->sym || !insn->sym->warned) \ + WARN_FUNC(format, insn->sec, insn->offset, ##__VA_ARGS__);\ + if (insn->sym) \ + insn->sym->warned = 1; \ }) #define BT_FUNC(format, insn, ...) \ From patchwork Wed Apr 12 19:03:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 82642 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp549252vqo; Wed, 12 Apr 2023 12:14:00 -0700 (PDT) X-Google-Smtp-Source: AKy350bCCHtojdhP+QDtN8SjPfLcXkgAgQ1MBY2Ml424A8M6ErztKl2OkkwkfWTu2a6/1BDA85x9 X-Received: by 2002:a17:90b:3b4c:b0:246:b898:5f54 with SMTP id ot12-20020a17090b3b4c00b00246b8985f54mr10418099pjb.16.1681326839928; Wed, 12 Apr 2023 12:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681326839; cv=none; d=google.com; s=arc-20160816; b=p7P6418Yw4BW2tjqBVmWMBTIyfWPmYUwXMAqzfr5tlDthxF8AS/4jJwHDvfmyqj82g BaARONtl1WHOPnZoGRN/1QYFtp9eVO7Qma7eBeaY7peXFO3vcy825lNOz4C+O6GA4BSm VVp5X1Rkew4q8qBffpY+JL24b3uj7+1VwGB0Q/VAwMuF2aK4OOMqyrf/t9CIcSZdB0jK Kj7+mCuv/E9RZm7H7UWSnt/9sfy1j2VagjmoeCq53HKcWYl2+pBJiUC3onSl+MZ6GomX o2s7BvFwgoWgtS+wV6CM2dNl7vaqE+AI04N/m29nRjrohiOWmRHmgqfnlcBMqdP9hSkk kbpQ== 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 :dkim-signature; bh=16t4cWKSwh/orYuIIb2fPbMmLoAs7nnYoBeAc6VSW1M=; b=PrRFEKotHbVINrghwRFUmWevmfNa2WRtxikxQ7I5DNhu0k2QxB+ebwcfRBPahXwykL +Ea5InkAtdkPcPHXDi/40b1UzLwuygsnW8kwt5eFP/XKRr4ez9kBVQgl8U6s9PWw7bw0 HSRfzKEVuq+v3YcQKLZSffzxZXB4nLmTIh1mSC+xZ0rcI7bozxtsYfEytyQg37rSEQLc XGHPd4QVaTxvvTr9V/9oVewOgXXxxvHhIyDgETvsa62UrYzNPIcXZvmAvjSGLXZumhWY /bmCbE4dV5tSGX8LeDU8gR3eyDavgYxj01QzUDX9whjaWl5o5lxjdqMdef6VDeNzDudX +NjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qLyqRwZ7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k21-20020a63d115000000b005030a59a818si15599158pgg.402.2023.04.12.12.13.46; Wed, 12 Apr 2023 12:13:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qLyqRwZ7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230020AbjDLTD7 (ORCPT + 99 others); Wed, 12 Apr 2023 15:03:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbjDLTDt (ORCPT ); Wed, 12 Apr 2023 15:03:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 634A519AD for ; Wed, 12 Apr 2023 12:03:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F32C763871 for ; Wed, 12 Apr 2023 19:03:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9879AC433A0; Wed, 12 Apr 2023 19:03:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681326226; bh=xaXnGfbC/VMDQDGu1YDrIHmJbcCkfgf/aMjvRsvTeLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qLyqRwZ7Cm9rjuMjVK1mOv2LqbY4qSfm/yt2qOzI90jMhIHqgq3Ne5OXSfZj5MnfC /G9y/FHQz5d2PLw0bF5VWTTAthGhPRPxoBpO+1f1ZzzDnPcLclndGWA2e5eC6nbWU5 tKJ8Jl5bhwLJ2D0jboWiZimpuyS92Mss683UZM8Qz+owmWnqpp9lFOgsckrwPOonmt gLNYTiI2BWey0p+J4oSdLlrU4WZhr/hoY38iDSJmW4vSZCHfap0N0AA+YanzZY4jzV //2ty/m4b9zemQ/58plj+1OcX8fQdafga5hgJcAAOV14c2ktHILY7a8B1nT7ja+n4L kOa8ttD6I5loQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH v2 4/9] objtool: Add symbol iteration helpers Date: Wed, 12 Apr 2023 12:03:19 -0700 Message-Id: <59023e5886ab125aa30702e633be7732b1acaa7e.1681325924.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762998972782785128?= X-GMAIL-MSGID: =?utf-8?q?1762998972782785128?= Add [sec_]for_each_sym() and use them. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 98 ++++++++++++----------------- tools/objtool/elf.c | 2 +- tools/objtool/include/objtool/elf.h | 9 +++ 3 files changed, 51 insertions(+), 58 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index de0d0234527d..d1d47baa252c 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -470,7 +470,7 @@ static int decode_instructions(struct objtool_file *file) // printf("%s: last chunk used: %d\n", sec->name, (int)idx); - list_for_each_entry(func, &sec->symbol_list, list) { + sec_for_each_sym(sec, func) { if (func->type != STT_NOTYPE && func->type != STT_FUNC) continue; @@ -924,7 +924,7 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file) static int create_cfi_sections(struct objtool_file *file) { - struct section *sec, *s; + struct section *sec; struct symbol *sym; unsigned int *loc; int idx; @@ -937,19 +937,14 @@ static int create_cfi_sections(struct objtool_file *file) } idx = 0; - for_each_sec(file, s) { - if (!s->text) + for_each_sym(file, sym) { + if (sym->type != STT_FUNC) continue; - list_for_each_entry(sym, &s->symbol_list, list) { - if (sym->type != STT_FUNC) - continue; - - if (strncmp(sym->name, "__cfi_", 6)) - continue; + if (strncmp(sym->name, "__cfi_", 6)) + continue; - idx++; - } + idx++; } sec = elf_create_section(file->elf, ".cfi_sites", 0, sizeof(unsigned int), idx); @@ -957,28 +952,23 @@ static int create_cfi_sections(struct objtool_file *file) return -1; idx = 0; - for_each_sec(file, s) { - if (!s->text) + for_each_sym(file, sym) { + if (sym->type != STT_FUNC) continue; - list_for_each_entry(sym, &s->symbol_list, list) { - if (sym->type != STT_FUNC) - continue; - - if (strncmp(sym->name, "__cfi_", 6)) - continue; + if (strncmp(sym->name, "__cfi_", 6)) + continue; - loc = (unsigned int *)sec->data->d_buf + idx; - memset(loc, 0, sizeof(unsigned int)); + loc = (unsigned int *)sec->data->d_buf + idx; + memset(loc, 0, sizeof(unsigned int)); - if (elf_add_reloc_to_insn(file->elf, sec, - idx * sizeof(unsigned int), - R_X86_64_PC32, - s, sym->offset)) - return -1; + if (elf_add_reloc_to_insn(file->elf, sec, + idx * sizeof(unsigned int), + R_X86_64_PC32, + sym->sec, sym->offset)) + return -1; - idx++; - } + idx++; } return 0; @@ -2205,23 +2195,20 @@ static int add_func_jump_tables(struct objtool_file *file, */ static int add_jump_table_alts(struct objtool_file *file) { - struct section *sec; struct symbol *func; int ret; if (!file->rodata) return 0; - for_each_sec(file, sec) { - list_for_each_entry(func, &sec->symbol_list, list) { - if (func->type != STT_FUNC) - continue; + for_each_sym(file, func) { + if (func->type != STT_FUNC) + continue; - mark_func_jump_tables(file, func); - ret = add_func_jump_tables(file, func); - if (ret) - return ret; - } + mark_func_jump_tables(file, func); + ret = add_func_jump_tables(file, func); + if (ret) + return ret; } return 0; @@ -2533,30 +2520,27 @@ static bool is_profiling_func(const char *name) static int classify_symbols(struct objtool_file *file) { - struct section *sec; struct symbol *func; - for_each_sec(file, sec) { - list_for_each_entry(func, &sec->symbol_list, list) { - if (func->bind != STB_GLOBAL) - continue; + for_each_sym(file, func) { + if (func->bind != STB_GLOBAL) + continue; - if (!strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR, - strlen(STATIC_CALL_TRAMP_PREFIX_STR))) - func->static_call_tramp = true; + if (!strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR, + strlen(STATIC_CALL_TRAMP_PREFIX_STR))) + func->static_call_tramp = true; - if (arch_is_retpoline(func)) - func->retpoline_thunk = true; + if (arch_is_retpoline(func)) + func->retpoline_thunk = true; - if (arch_is_rethunk(func)) - func->return_thunk = true; + if (arch_is_rethunk(func)) + func->return_thunk = true; - if (arch_ftrace_match(func->name)) - func->fentry = true; + if (arch_ftrace_match(func->name)) + func->fentry = true; - if (is_profiling_func(func->name)) - func->profiling_func = true; - } + if (is_profiling_func(func->name)) + func->profiling_func = true; } return 0; @@ -4222,7 +4206,7 @@ static int validate_section(struct objtool_file *file, struct section *sec) struct symbol *func; int warnings = 0; - list_for_each_entry(func, &sec->symbol_list, list) { + sec_for_each_sym(sec, func) { if (func->type != STT_FUNC) continue; diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 6806ce01d933..500e92979a31 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -474,7 +474,7 @@ static int read_symbols(struct elf *elf) /* Create parent/child links for any cold subfunctions */ list_for_each_entry(sec, &elf->sections, list) { - list_for_each_entry(sym, &sec->symbol_list, list) { + sec_for_each_sym(sec, sym) { char pname[MAX_NAME_LEN + 1]; size_t pnamelen; if (sym->type != STT_FUNC) diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index a668173a5869..78e2d0fc21ca 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -189,4 +189,13 @@ struct symbol *find_func_containing(struct section *sec, unsigned long offset); #define for_each_sec(file, sec) \ list_for_each_entry(sec, &file->elf->sections, list) +#define sec_for_each_sym(sec, sym) \ + list_for_each_entry(sym, &sec->symbol_list, list) + +#define for_each_sym(file, sym) \ + for (struct section *__sec, *__fake = (struct section *)1; \ + __fake; __fake = NULL) \ + for_each_sec(file, __sec) \ + sec_for_each_sym(__sec, sym) + #endif /* _OBJTOOL_ELF_H */ From patchwork Wed Apr 12 19:03:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 82641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp548416vqo; Wed, 12 Apr 2023 12:12:19 -0700 (PDT) X-Google-Smtp-Source: AKy350afbyOeDTW2ivbE+llSrjkpsVPUG44lBHobmveA7qQ34n/HXkToyjkUqGUiyMFcpdY08RXC X-Received: by 2002:a17:902:c711:b0:1a1:b440:377d with SMTP id p17-20020a170902c71100b001a1b440377dmr7314plp.2.1681326739553; Wed, 12 Apr 2023 12:12:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681326739; cv=none; d=google.com; s=arc-20160816; b=GhjgOTt6eDIhtxDQ8TGQfNkJa7cVNXh32rpCjUUK9NJuQXGXqbVR567PMPalY1uXfc 9xnctemHdwEW+X89Zw2tvbh13zmAwEog79pnOK4TeCKbvaCvVHSIk+baIPFR8/wrRob3 lhwEYYxRMPeaBm4MfnZkjqbj9QZWbZcENBFOoeCpUNKs3KUuCUTQFJpSGRJ1HDQGyDLr 9+Udzqn83PpJLE1IeaXIGj98aTo6Z+SoTBpFw7ENU0psIAI5+Hw9a1x+i+QCg8bL8AO4 DXXQbtBsSxnrN4N08JfyOKba+fSS3GR9xuIsnd9YqwjAgxfPNC8L4WMIFRkqJJHPaEJr WeyA== 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 :dkim-signature; bh=6FPkofslGP1xSGUNmOy0OjoRQkzUq/SjVKbTl5AV6Ks=; b=AV+hIca8Epjve0TIqxBKPm0MIi+vZsZOcBs2vb2DrHVB8jJhkp4RotbtDWAGFNk6gA IJyCwjlmh10EDaqt11YyTRM44Xrbe0JDQPTzntg0L/Ap/FgTr4NCprkmjYrf1Du2fjaO 1xbhW4GtCKWdL3RwTXjiVnkwEm63ke8mf7fo3JFE9gcoNmd0sEOG+auQ+d9AH+WU6ze3 8vJezFelj1KxX7KY5j+U7fJU3lLXs5jE5nSelFtYcVPhPR7r9jvymoxMcN7ogqypxau1 Sb0fnhuml7YbCBmRvFJWZR8EPZnl5XGSv63z3n09BzHGZ0rx3QyfuwLc0BlDtfPpWPXv CTfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lFvGhjCA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k21-20020a63d115000000b005030a59a818si15599158pgg.402.2023.04.12.12.12.05; Wed, 12 Apr 2023 12:12:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lFvGhjCA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230085AbjDLTD4 (ORCPT + 99 others); Wed, 12 Apr 2023 15:03:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229819AbjDLTDt (ORCPT ); Wed, 12 Apr 2023 15:03:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 255CA30EE for ; Wed, 12 Apr 2023 12:03:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AF20B63873 for ; Wed, 12 Apr 2023 19:03:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBCB8C4339C; Wed, 12 Apr 2023 19:03:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681326227; bh=Xo5lcU2wwdD++yBcxh/rdhi4q0XegKdBxgS1Acd6DXo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lFvGhjCArhUk17ZwpAZ2Cf1o25V9jEG+7qU4R3iudzxd8iV+aoNl7mhWtmBBZktd/ AKT1KDS2LiTMpz0CvOffjMBVbT7Kx+Raj8v15hky+B/cK1xI23MHJyFY6dDv46xkYz 3pBRG+uEbDqYqMAyq+BpUS10MOcdKbO9k2IE+CJkU4xCe218coEA2FnlIJHDNLwvjs 9lqHEkFygxFoIY5/eN0yTANF3EqJ49ZGqFmsSJiKeP/2TpxLuSeMf2pkjm0a8GO24q VK0n5WcYd/Vkp08wWC3y9dxP0dDhoWZnOz07UuCOk8sbFnfvK8INdOhT7Q8kwUs31m vrp+KhpZ9sIjQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH v2 5/9] objtool: Add verbose option for disassembling affected functions Date: Wed, 12 Apr 2023 12:03:20 -0700 Message-Id: <4cadacc719db1e792c335309056960ca6f71139e.1681325924.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762998867246560599?= X-GMAIL-MSGID: =?utf-8?q?1762998867246560599?= When a warning is associated with a function, add an option to disassemble that function. This makes it easier for reporters to submit the information needed to diagnose objtool warnings. Signed-off-by: Josh Poimboeuf --- tools/objtool/Documentation/objtool.txt | 5 ++ tools/objtool/builtin-check.c | 5 ++ tools/objtool/check.c | 77 +++++++++++++++++++++++++ tools/objtool/include/objtool/builtin.h | 1 + 4 files changed, 88 insertions(+) diff --git a/tools/objtool/Documentation/objtool.txt b/tools/objtool/Documentation/objtool.txt index 8e53fc6735ef..4d6c5acde7a3 100644 --- a/tools/objtool/Documentation/objtool.txt +++ b/tools/objtool/Documentation/objtool.txt @@ -244,6 +244,11 @@ To achieve the validation, objtool enforces the following rules: Objtool warnings ---------------- +NOTE: When requesting help with an objtool warning, please recreate with +OBJTOOL_VERBOSE=1 (e.g., "make OBJTOOL_VERBOSE=1") and send the full +output, including any disassembly below the warning, to the objtool +maintainers. + For asm files, if you're getting an error which doesn't make sense, first make sure that the affected code follows the above rules. diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 7c175198d09f..5e21cfb7661d 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -93,6 +93,7 @@ static const struct option check_options[] = { OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable instruction' warnings"), OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section addresses in warnings"), OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"), + OPT_BOOLEAN('v', "verbose", &opts.verbose, "verbose warnings"), OPT_END(), }; @@ -118,6 +119,10 @@ int cmd_parse_options(int argc, const char **argv, const char * const usage[]) parse_options(envc, envv, check_options, env_usage, 0); } + env = getenv("OBJTOOL_VERBOSE"); + if (env && !strcmp(env, "1")) + opts.verbose = true; + argc = parse_options(argc, argv, check_options, usage, 0); if (argc != 1) usage_with_options(usage, check_options); diff --git a/tools/objtool/check.c b/tools/objtool/check.c index d1d47baa252c..bc9dd69c9a45 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4509,6 +4509,81 @@ static int validate_reachable_instructions(struct objtool_file *file) return warnings; } +/* 'funcs' is a space-separated list of function names */ +static int disas_funcs(const char *funcs) +{ + const char *objdump_str, *cross_compile; + int size, ret; + char *cmd; + + cross_compile = getenv("CROSS_COMPILE"); + + objdump_str = "%sobjdump -wdr %s | gawk -M -v _funcs='%s' '" + "BEGIN { split(_funcs, funcs); }" + "/^$/ { func_match = 0; }" + "/<.*>:/ { " + "f = gensub(/.*<(.*)>:/, \"\\\\1\", 1);" + "for (i in funcs) {" + "if (funcs[i] == f) {" + "func_match = 1;" + "base = strtonum(\"0x\" $1);" + "break;" + "}" + "}" + "}" + "{" + "if (func_match) {" + "addr = strtonum(\"0x\" $1);" + "printf(\"%%04x \", addr - base);" + "print;" + "}" + "}' 1>&2"; + + /* fake snprintf() to calculate the size */ + size = snprintf(NULL, 0, objdump_str, cross_compile, objname, funcs) + 1; + if (size <= 0) { + WARN("objdump string size calculation failed"); + return -1; + } + + cmd = malloc(size); + + /* real snprintf() */ + snprintf(cmd, size, objdump_str, cross_compile, objname, funcs); + ret = system(cmd); + if (ret) { + WARN("disassembly failed: %d", ret); + return -1; + } + + return 0; +} + +static int disas_warned_funcs(struct objtool_file *file) +{ + struct symbol *sym; + char *funcs = NULL, *tmp; + + for_each_sym(file, sym) { + if (sym->warned) { + if (!funcs) { + funcs = malloc(strlen(sym->name) + 1); + strcpy(funcs, sym->name); + } else { + tmp = malloc(strlen(funcs) + strlen(sym->name) + 2); + sprintf(tmp, "%s %s", funcs, sym->name); + free(funcs); + funcs = tmp; + } + } + } + + if (funcs) + disas_funcs(funcs); + + return 0; +} + int check(struct objtool_file *file) { int ret, warnings = 0; @@ -4646,6 +4721,8 @@ int check(struct objtool_file *file) warnings += ret; } + if (opts.verbose) + disas_warned_funcs(file); if (opts.stats) { printf("nr_insns_visited: %ld\n", nr_insns_visited); diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/include/objtool/builtin.h index 2a108e648b7a..fcca6662c8b4 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -37,6 +37,7 @@ struct opts { bool no_unreachable; bool sec_address; bool stats; + bool verbose; }; extern struct opts opts; From patchwork Wed Apr 12 19:03:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 82649 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp564608vqo; Wed, 12 Apr 2023 12:46:12 -0700 (PDT) X-Google-Smtp-Source: AKy350ZV974t7zLf28tKjJLiEmX4DTMqs7ldpGQPAJYAX0ma6LTum8El3AsprpvUfersQJB22t0n X-Received: by 2002:a17:902:6a85:b0:1a5:1bb4:ad8b with SMTP id n5-20020a1709026a8500b001a51bb4ad8bmr3517298plk.17.1681328771971; Wed, 12 Apr 2023 12:46:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681328771; cv=none; d=google.com; s=arc-20160816; b=OJZ2LN2Pp5T4bIDkbUdMv5p4VURG3iZkbyeHXbkwflsMFrBzNt94gX4Mtxm40Khlzk VSf7QTMN+cA7amdTttrup9O3AEWL/g9G/9jz6xYUYd4dePDvb5t1nXFv94E3LAkT2jbQ jjCIn7sIaO39PdC7BxEXQrMuojJRa71FeCOPElsMlkucqNkkcjv90PTUTO1VWnZW0mmd g15bkiHVtfYhcTIHMvwJ1+8u/HwTQcHOhSFEU1SZFjO868NwNt+q+gSw2YY/JIuGzhXu RZsT1LOxZodUrl1aOXrjnPwsrBMV79d92zmirZN2GbvHt+zvs83h9eNXy3OAyGt7fj0D Cy7g== 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 :dkim-signature; bh=oFXAdgl27wyf6qAINaorVsXnJnV6Gd/J7677AZuXdH4=; b=vS3GT0+Y9kdMy/34oz0gi53DYIYO9HtWDipOEE8CQdQ2Gww2f6SNDH4nGn9lbzgBvQ qhYHrqt9V5DVtf77/ip1K5BJJBupWFGZCT82q/hNJQ9lGWTqJFisDDEpIUaje9vmEBOl 2fuUiONB04TkBfpNnlb5rFXzEge/+K7iVw9ORjaBsgKTdxczIm49OCkq5aRNqEEFmvjW PEU4oM/eSGR++6oFLHdyOzJwjDpTKtOmg6AJ+/z/oEN8zrmQpe4bXKbD02dE2S3qCFnh I5wwoa3dsiPDQsOvogcrW/L1zX5UHRsiwwLmWR1XEkg6P2DT63SDFo0lHNJEHDEXQu3S 4Z7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aStfXEpT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a170902e88400b0019cdd3e2aecsi18755414plg.312.2023.04.12.12.45.58; Wed, 12 Apr 2023 12:46:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aStfXEpT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229775AbjDLTEG (ORCPT + 99 others); Wed, 12 Apr 2023 15:04:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229841AbjDLTDt (ORCPT ); Wed, 12 Apr 2023 15:03:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B96CBE6F for ; Wed, 12 Apr 2023 12:03:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 11EAC6387F for ; Wed, 12 Apr 2023 19:03:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AD80C433EF; Wed, 12 Apr 2023 19:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681326227; bh=ALLHXWLy6y39aAaEiGHQFmrawumL94Hfe6ZlVC/BQUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aStfXEpTrgz7R5gGwQpVWCMa1e/aFwS0LM8H2J0mdNSdYpbXavmcZtOxgVFbFpU8s vLQT4p9dMG2o903/IMeW3fY17wQh51/QR8X4zc512DYPheoP4Wqtar8Ah7KDTJetKS rqv2mdZJV3/PfYwz2anB86tac0IFJzJZAvgBX6QfpZK+43o/yOe2oIwGtArCUgcYdX jgAgQhD1Lub4/h32jSgH+q6JPUr+KVy8gnFYY/VMPuYYQPSZDZUXnA9hzXqEMKIadw NhMT7HmI7X84gsO9hiuIcRTvn1NAcOFfRqGqsENcQP3Qor9n5rdeJiujmGh3xeqvWC 6h4subfi9ayvw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH v2 6/9] objtool: Include backtrace in verbose mode Date: Wed, 12 Apr 2023 12:03:21 -0700 Message-Id: <6a11522b7d2fdb713ec80a89fe8cb199ddb511b6.1681325924.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763000998214338116?= X-GMAIL-MSGID: =?utf-8?q?1763000998214338116?= Include backtrace in verbose mode. This makes it easy to gather all the information needed for diagnosing objtool warnings. Signed-off-by: Josh Poimboeuf --- tools/objtool/Documentation/objtool.txt | 4 ++-- tools/objtool/check.c | 26 ++++++++++--------------- tools/objtool/include/objtool/warn.h | 14 +++++++------ 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/tools/objtool/Documentation/objtool.txt b/tools/objtool/Documentation/objtool.txt index 4d6c5acde7a3..5a69c207a10e 100644 --- a/tools/objtool/Documentation/objtool.txt +++ b/tools/objtool/Documentation/objtool.txt @@ -246,8 +246,8 @@ Objtool warnings NOTE: When requesting help with an objtool warning, please recreate with OBJTOOL_VERBOSE=1 (e.g., "make OBJTOOL_VERBOSE=1") and send the full -output, including any disassembly below the warning, to the objtool -maintainers. +output, including any disassembly or backtrace below the warning, to the +objtool maintainers. For asm files, if you're getting an error which doesn't make sense, first make sure that the affected code follows the above rules. diff --git a/tools/objtool/check.c b/tools/objtool/check.c index bc9dd69c9a45..b9e5e0e9c1ee 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3654,8 +3654,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, ret = validate_branch(file, func, alt->insn, state); if (ret) { - if (opts.backtrace) - BT_FUNC("(alt)", insn); + BT_INSN(insn, "(alt)"); return ret; } } @@ -3700,8 +3699,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, ret = validate_branch(file, func, insn->jump_dest, state); if (ret) { - if (opts.backtrace) - BT_FUNC("(branch)", insn); + BT_INSN(insn, "(branch)"); return ret; } } @@ -3799,8 +3797,8 @@ static int validate_unwind_hint(struct objtool_file *file, { if (insn->hint && !insn->visited && !insn->ignore) { int ret = validate_branch(file, insn_func(insn), insn, *state); - if (ret && opts.backtrace) - BT_FUNC("<=== (hint)", insn); + if (ret) + BT_INSN(insn, "<=== (hint)"); return ret; } @@ -3858,8 +3856,7 @@ static int validate_unret(struct objtool_file *file, struct instruction *insn) ret = validate_unret(file, alt->insn); if (ret) { - if (opts.backtrace) - BT_FUNC("(alt)", insn); + BT_INSN(insn, "(alt)"); return ret; } } @@ -3885,10 +3882,8 @@ static int validate_unret(struct objtool_file *file, struct instruction *insn) } ret = validate_unret(file, insn->jump_dest); if (ret) { - if (opts.backtrace) { - BT_FUNC("(branch%s)", insn, - insn->type == INSN_JUMP_CONDITIONAL ? "-cond" : ""); - } + BT_INSN(insn, "(branch%s)", + insn->type == INSN_JUMP_CONDITIONAL ? "-cond" : ""); return ret; } @@ -3910,8 +3905,7 @@ static int validate_unret(struct objtool_file *file, struct instruction *insn) ret = validate_unret(file, dest); if (ret) { - if (opts.backtrace) - BT_FUNC("(call)", insn); + BT_INSN(insn, "(call)"); return ret; } /* @@ -4195,8 +4189,8 @@ static int validate_symbol(struct objtool_file *file, struct section *sec, state->uaccess = sym->uaccess_safe; ret = validate_branch(file, insn_func(insn), insn, *state); - if (ret && opts.backtrace) - BT_FUNC("<=== (sym)", insn); + if (ret) + BT_INSN(insn, "<=== (sym)"); return ret; } diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/objtool/warn.h index 4ef9b278e5fd..856ea8bc10d7 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -61,12 +61,14 @@ static inline char *offstr(struct section *sec, unsigned long offset) insn->sym->warned = 1; \ }) -#define BT_FUNC(format, insn, ...) \ -({ \ - struct instruction *_insn = (insn); \ - char *_str = offstr(_insn->sec, _insn->offset); \ - WARN(" %s: " format, _str, ##__VA_ARGS__); \ - free(_str); \ +#define BT_INSN(insn, format, ...) \ +({ \ + if (opts.verbose || opts.backtrace) { \ + struct instruction *_insn = (insn); \ + char *_str = offstr(_insn->sec, _insn->offset); \ + WARN(" %s: " format, _str, ##__VA_ARGS__); \ + free(_str); \ + } \ }) #define WARN_ELF(format, ...) \ From patchwork Wed Apr 12 19:03:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 82646 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp561144vqo; Wed, 12 Apr 2023 12:38:15 -0700 (PDT) X-Google-Smtp-Source: AKy350YlskyXoV0ZhUQBOBmqC3PX4ucQWcNUj+1Jxq/nlr0xyd3drRe0TvpaFSeSPctJz0JFgCxI X-Received: by 2002:a17:902:ecc4:b0:1a1:b238:d1a5 with SMTP id a4-20020a170902ecc400b001a1b238d1a5mr108351plh.4.1681328295192; Wed, 12 Apr 2023 12:38:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681328295; cv=none; d=google.com; s=arc-20160816; b=OaUjT2YuFiq4jBeArKn2gp+tX7JYqJeaALzZQ0/SIdOzY5cessTZcTnDlnScY754Hu 5cNdi0R4WB9bO/CD7SrarYGBsDNNKI5ZW9N5E6BcAkqv7kXyyRNHYZ3hcGWepqu5BtNZ HiRZ7YfBq7CP13cD7pLP2MJ/gk8BwzOdf6chrIsb+vUMVykzfqgVijoeKN2KYQ3DFtBf obrOMPMGQOYwx4NkYz+6Ia1CSw1BwlQEBixVq2Bh8bYa7Vu+KlMyCXxne9r3w3tzLAJF DQVsgRuJHNtsaaUh0M451MvZcsgDt6OE3HhTzJUBHOtxKFOFyeTlcPgTOddDi5pIgL2P +xYw== 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 :dkim-signature; bh=hxl2VmCL9sh5XwsCS8sXx6VmYYFqfG3c2Y9tSXblm18=; b=W7TrGjLoaDYUnz6ZL1OGIKHzd3hyddkLm/oVDHIA4gKsMv7eZAB1vDLQaakrl9YlE0 ZPsOsA5yJ+xfswgeCuPTRyK/aOBdeW2mS32WiWb647PeUp3fsPSBaKfDyMS0NQ4iUAeu rqqxc+gsXP+2JWpQ9MhmmQg271jmKEusjdTu9/5jPCVo1H01xO1wD33QTgk/TBTDxXpE tUQn3uK2S6vYz2uP5A8d+kgeIR9otOiUC39kBsSWSvXd4YUWWX00L+usCtBGBK4iNGzB 8KY1qBrtRFCRSBtCRSw6AGdQBNGjyPcgzr+at2ZBusj/9wi0jaqldTFUuBhPe/FSpNUt uMdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QTa6Mq9H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g2-20020a170902934200b001a05d8436d8si16096982plp.475.2023.04.12.12.38.00; Wed, 12 Apr 2023 12:38:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QTa6Mq9H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbjDLTED (ORCPT + 99 others); Wed, 12 Apr 2023 15:04:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbjDLTDt (ORCPT ); Wed, 12 Apr 2023 15:03:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75616E69 for ; Wed, 12 Apr 2023 12:03:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 04D7263879 for ; Wed, 12 Apr 2023 19:03:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DA5AC4339E; Wed, 12 Apr 2023 19:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681326227; bh=ZbdbfriA0hOhgUPH3GEXbKxjxz1wYETUQssT8P5Kvmk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QTa6Mq9HtuH6HEOc6xiuWAnaIPbHGzYHuN2rthxwa9ieVHkamL+uFKhhJXoh2tZrg FBHVARFe/1m1NhUwTrVGYYbz0bcFUkbLZVF3C56YvsNjpCXRZWehFOrodfpfWWHa6P Rn33Y0PoL38yPxatStxYNMnLpCQfI3Zds/9YaNH8vXb5Xw/1LtEMJUfMbbig473iWF xrqYOO8S66mFYjZw8P//3mGEQzQ+upg8x9aQThS2bBoiwryJNxYWQ5tnem/swE4WlG 1X5cE576yBV6X3CcCDidtBre0k+O24vhjlvswqMTAAKo2SbLgTY891phXTAg6yPuVK aCDqC0zZ8idAg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH v2 7/9] objtool: Remove superfluous dead_end_function() check Date: Wed, 12 Apr 2023 12:03:22 -0700 Message-Id: <5d603a301e9a8b1036b61503385907e154867ace.1681325924.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763000498483239977?= X-GMAIL-MSGID: =?utf-8?q?1763000498483239977?= annotate_call_site() already sets 'insn->dead_end' for calls to dead end functions. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index b9e5e0e9c1ee..5e7d3c62fb9d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4081,8 +4081,7 @@ static bool ignore_unreachable_insn(struct objtool_file *file, struct instructio * It may also insert a UD2 after calling a __noreturn function. */ prev_insn = prev_insn_same_sec(file, insn); - if ((prev_insn->dead_end || - dead_end_function(file, insn_call_dest(prev_insn))) && + if (prev_insn->dead_end && (insn->type == INSN_BUG || (insn->type == INSN_JUMP_UNCONDITIONAL && insn->jump_dest && insn->jump_dest->type == INSN_BUG))) From patchwork Wed Apr 12 19:03:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 82650 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp564789vqo; Wed, 12 Apr 2023 12:46:33 -0700 (PDT) X-Google-Smtp-Source: AKy350bqlA+6fLUBTjuMBOYQczSfGWJA2lWUuOYxx8Gu+zxFQlCKGRw84YfvP1jp3ttqud1o2Y2h X-Received: by 2002:a17:902:ea12:b0:1a3:c8bc:6a41 with SMTP id s18-20020a170902ea1200b001a3c8bc6a41mr26544plg.21.1681328793132; Wed, 12 Apr 2023 12:46:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681328793; cv=none; d=google.com; s=arc-20160816; b=0p4ERi3fsMTxlFKMmhT68svzrnHtizD5oHHHl9rxr/kVxeUkdiyW5wsyT0UKby5iRj ebtD4DQGEnOmPnEdG1xIvQQQsxYMy1CHVOPbWnD/RsrAVweoYs/bXBWrCe7ty7kw8G3R 00ZIdCkjIcRC6Pafwbo4GT2RraXxdDFMsV98zoKfY3AcHvXIZ0dXoL8nxHKR+7YqxjWV PvUG+/pfaRchJM5Cg5y+09fxXdpnE4NEtB9WeHuus/lZpTCTrULRrm4K6hsP0w2BVBwL NbkZQ1GfcM629xt/OZwwvvyNLgO2p7atOJOc4H/1+YHmauz2CA1IF//Viy1134t4+bgn Tskg== 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 :dkim-signature; bh=DqmXPTZzw/m90QjwpgswduutR05Fn57tRycXsQ8xd9s=; b=LWXqrYKrJ3ffvNj/DLfJOoq8toYud4dIzAF37ZKJnNnnMyV+Yjme4ZqHOG3W82si30 6ZgqVMBGDeiIvfu3AGO5vuGtrogBZlafTslqefVmnjSZ6pI9G0CzLASDyyOZuGvxPB/o wRdQzIHfbES0mY9SBjwtupfqS03xvGmH4o6yir0g3jjsI1lIHGwwYwqelmcGE9wAq4+o WX5P3mofKfDKMdQZqjaK3JHram3imykk19MwRPO4MYazetxKvcdPNtKVr39K6zbex4tU PjX9mzLyJnKPXBBVD9afFARQML8brB6s30Z/kWBGtJjQO6uivdz124dEUSGFIV+hpwTZ NL0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UudiDOuj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a170902c64100b001a64476e1eesi7337982pls.185.2023.04.12.12.46.14; Wed, 12 Apr 2023 12:46:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UudiDOuj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229877AbjDLTEJ (ORCPT + 99 others); Wed, 12 Apr 2023 15:04:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229904AbjDLTDu (ORCPT ); Wed, 12 Apr 2023 15:03:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DEC040F9 for ; Wed, 12 Apr 2023 12:03:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BBED66120A for ; Wed, 12 Apr 2023 19:03:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F105FC433D2; Wed, 12 Apr 2023 19:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681326228; bh=vyrH7fWmcqWjltl/LdT1BsNQ9591BQaxXbDWTsC3pYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UudiDOujlu3FC9gXbLoKD/o9qBM5vOmRVcq9RCfnH2a+m7zindDoVG0SirE95XWlP ffko4mKUAo/3phlkK9kJu7UDtNghhhf2IlLadhhKjqWD1C/RqDLnciHusi6+DtfynJ Bk8eZh04yv+8fUCVHlMGD01c1FS8YHuN3tNDp/50xZlMpMlvijlzImNgca7M0Mkri2 NchUqg8Kz0peoSFTWP1jBx1x86gKSmf+2cEKmPoMlQCE3UgLotOj7d3EjB0g6tj1GZ ZRSglLWvn9f/vwjWnk6qo3LfEpb2n4tJI4UYLIFHcpU9qATq+M5FSXkw5tqmKkX3AN q3B6E/dQaZSnw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH v2 8/9] objtool: Detect missing __noreturn annotations Date: Wed, 12 Apr 2023 12:03:23 -0700 Message-Id: <0f630a0eb4585ab4114e4eecaa6f166a1fd81d49.1681325924.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763001020933561463?= X-GMAIL-MSGID: =?utf-8?q?1763001020933561463?= Most "unreachable instruction" warnings these days seem to actually be the result of a missing __noreturn annotation. Add an explicit check for that. Signed-off-by: Josh Poimboeuf --- tools/objtool/Documentation/objtool.txt | 6 ++++++ tools/objtool/check.c | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/objtool/Documentation/objtool.txt b/tools/objtool/Documentation/objtool.txt index 5a69c207a10e..2cd1fa16ed08 100644 --- a/tools/objtool/Documentation/objtool.txt +++ b/tools/objtool/Documentation/objtool.txt @@ -303,6 +303,12 @@ the objtool maintainers. If it's not actually in a callable function (e.g. kernel entry code), change ENDPROC to END. +3. file.o: warning: objtool: foo+0x48c: bar() is missing a __noreturn annotation + + The call from foo() to bar() doesn't return, but bar() is missing the + __noreturn annotation. NOTE: In addition to adding the __noreturn + annotation, the function name also needs to be added to + 'global_noreturns' in tools/objtool/check.c. 4. file.o: warning: objtool: func(): can't find starting instruction or diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 5e7d3c62fb9d..60f2d649f19f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4485,7 +4485,8 @@ static int validate_sls(struct objtool_file *file) static int validate_reachable_instructions(struct objtool_file *file) { - struct instruction *insn; + struct instruction *insn, *prev_insn; + struct symbol *call_dest; int warnings = 0; if (file->ignore_unreachables) @@ -4495,6 +4496,17 @@ static int validate_reachable_instructions(struct objtool_file *file) if (insn->visited || ignore_unreachable_insn(file, insn)) continue; + prev_insn = prev_insn_same_sec(file, insn); + if (prev_insn && prev_insn->dead_end) { + call_dest = insn_call_dest(prev_insn); + if (call_dest) { + WARN_INSN(insn, "%s() is missing a __noreturn annotation", + call_dest->name); + warnings++; + continue; + } + } + WARN_INSN(insn, "unreachable instruction"); warnings++; } From patchwork Wed Apr 12 19:03:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 82651 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp564812vqo; Wed, 12 Apr 2023 12:46:35 -0700 (PDT) X-Google-Smtp-Source: AKy350bshae1YWCefm8lcCsCwFLHJrbJgvjY33hAHxxUVax0VhhQxu4qN5jYlCowoegQFGNJziSN X-Received: by 2002:a17:90a:bc8d:b0:22c:6d7c:c521 with SMTP id x13-20020a17090abc8d00b0022c6d7cc521mr3600169pjr.45.1681328795296; Wed, 12 Apr 2023 12:46:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681328795; cv=none; d=google.com; s=arc-20160816; b=GwGq7tRXQFzUqRO+naywS/EEAqvrIouNcD72CwNNHOEO9vWS6huhQ8UEewkG17B8Xt g2fFEJU9TW5nqeh3c1v59A2Uj6nwu4rL0pqsD9PdA+6PJFAkUuRvZGRCfRmXJkoyC9H1 cyDTGP0WveTlaa/nHHmyX3b+AYoZ4agmxLN3TK2fY9t78RLNTwyhY/0EYwxKkOSuQKyK yAPZs2qNqfXi7a1/j9aTIqqrweLWbIaV28lGJT7jw378B5gCH6V6gKJBiOEtb7ZOkEO9 jMAQk27LxVvt+Y/T822EMBZAjJOB3NTE848cHxN5VEMl0UYkPlgh8BOM8wKezxhEaWlN PUeA== 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 :dkim-signature; bh=G0gSiAK9snB1UybVtdSz/1ts4LhS3+3pgXIONcTdHao=; b=bMBOkEGZUJ/HoEJ//DvY4uWRvYa05ohu3jqsXxgrZMIvtsUeRwdJr72OL4FIENLPPP GWp+HLb1CEgRqhw8fA9SxxHiehK3XxVnbLnI1uONxBCjgEJmt4brfweW9wMqJfTHS5SP PMqKs4xhX3naLMmPqNJVOkvGQlCEbAIOJnmzvlfWOuws+B6HnguiQnWTSXPMAtIyXTKy 0a5/fRKiw/S3HS6rFArdsz08K16JXmU+C37Gb0JgV9NjZH8Uvtd9FYwGg6N5xJTPp//A +NWnXnmJhHtXRE3tL0ils/QtVlsJtHkR1QKG+W9A6MKYnGSu90+0LhOXZthiIN5ZMvYx dgOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TGnrh85+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a17090a409300b002467a036c62si2534871pjg.45.2023.04.12.12.46.17; Wed, 12 Apr 2023 12:46:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TGnrh85+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230378AbjDLTEQ (ORCPT + 99 others); Wed, 12 Apr 2023 15:04:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229911AbjDLTDu (ORCPT ); Wed, 12 Apr 2023 15:03:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F7F646B9 for ; Wed, 12 Apr 2023 12:03:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 140EA6387D for ; Wed, 12 Apr 2023 19:03:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F03DC4339B; Wed, 12 Apr 2023 19:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681326228; bh=h9r8KJRiCpRGToEG6UzamCIqwFgA/cCcBPojuYwWHP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TGnrh85+l03ixoIvN+Boa5Wsmn1a2TRrdjOGzj9r1U9roeakZMS3e49+rtkhk8d0S W98FJK8H4zyqtSbS4F8UMeq8rO5A8pPOD+QZX/4VCSONkjab6sUPh04OB2hkBuVJjD F6wUHNNQtG6I1ip+cOQMZwiA5Kb+sdsGeNMQ+wRxiSC6mCVxltBaIRlA3c7WmYuq7m KFNqT6cZgPcDpwp7+epsiajuithymXLOa/1eujZFaqu8zqPNjnXUKoM6GACX+HCXZP IhoLQGnFVilG9RmYQ6RoVhcyT7IXDx17q4WWJVUimXZkd8XqlxPzaiI3EpjF/epPAD gqZDpC/Ct7vog== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH v2 9/9] objtool: Ignore exc_double_fault() __noreturn warnings Date: Wed, 12 Apr 2023 12:03:24 -0700 Message-Id: <683214828d8b2ad732dab1a74e858087519d8c8b.1681325924.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763001022732788456?= X-GMAIL-MSGID: =?utf-8?q?1763001022732788456?= This is a hack, but it works for now. Problem is, exc_double_fault() may or may not return, depending on whether CONFIG_X86_ESPFIX64 is set. But objtool has no visibility to the kernel config. "Fix" it by silencing the exc_double_fault() __noreturn warning. This removes the following warning: vmlinux.o: warning: objtool: xenpv_exc_double_fault+0xd: exc_double_fault() is missing a __noreturn annotation Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 60f2d649f19f..7641e818db7d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4483,6 +4483,35 @@ static int validate_sls(struct objtool_file *file) return warnings; } +static bool ignore_noreturn_call(struct instruction *insn) +{ + struct symbol *call_dest = insn_call_dest(insn); + + /* + * This is a hack, but it works for now. + * + * Problem is, exc_double_fault() may or may not return, depending on + * whether CONFIG_X86_ESPFIX64 is set. But objtool has no visibility + * to the kernel config. + * + * Other potential ways to fix it: + * + * - remove CONFIG_X86_ESPFIX64 + * - read the .config file + * - add a cmdline option + * - create a generic objtool annotation format (vs a bunch of custom + * formats) and annotate it + * - have compiler communicate __noreturn functions somehow + */ + if (!strcmp(call_dest->name, "exc_double_fault")) { + /* prevent further unreachable warnings for the caller */ + insn->sym->warned = 1; + return true; + } + + return false; +} + static int validate_reachable_instructions(struct objtool_file *file) { struct instruction *insn, *prev_insn; @@ -4499,7 +4528,7 @@ static int validate_reachable_instructions(struct objtool_file *file) prev_insn = prev_insn_same_sec(file, insn); if (prev_insn && prev_insn->dead_end) { call_dest = insn_call_dest(prev_insn); - if (call_dest) { + if (call_dest && !ignore_noreturn_call(prev_insn)) { WARN_INSN(insn, "%s() is missing a __noreturn annotation", call_dest->name); warnings++;