From nobody Wed Dec 17 15:07:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB903C77B75 for ; Tue, 18 Apr 2023 21:28:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232838AbjDRV2R (ORCPT ); Tue, 18 Apr 2023 17:28:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232707AbjDRV2N (ORCPT ); Tue, 18 Apr 2023 17:28:13 -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 B83E0AD3D for ; Tue, 18 Apr 2023 14:28:00 -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 551FC63951 for ; Tue, 18 Apr 2023 21:28:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80055C4339E; Tue, 18 Apr 2023 21:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681853279; bh=QLb9CZEh4jbifWcfcjQ/raJsyLVWkp1Ug+utfGGdmOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AAFVT7Th4uWYQ5gVAbR35YJeC/EuGSNAl/6RaCsICHji5Ezk2jCGofZBnr4atJJpy UOompHmTAw/0dhGQ9f6EdBAstltpwdxCpBvvuBQLchl4MbBH6FnZHGX0Te6SzUBEW7 qNL/MXS66dNDLAX0L8Vzd4Xl7qvwfMKolvby59iGOvnyWuHwMtD3fNGN2J2AnoAHAC Jo7PRS/UJkvi59h3ZV1yedBmCN9m00imhM6P76KbnrUyfSY2ykwdbffmvGhBXYnvK7 3rAoqOZAMxAYP++eGZNZpEApbXxOsspLX3MBqWyxoVXeh5SCCN0wKco4CcvMcI/uBB L1uti4KL0mHgA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes , Nick Desaulniers Subject: [PATCH v3 1/8] objtool: Limit unreachable warnings to once per function Date: Tue, 18 Apr 2023 14:27:47 -0700 Message-Id: <9d38f881bfc34e031c74e4e90064ccb3e49f599a.1681853186.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Miroslav Benes --- tools/objtool/check.c | 5 +++-- tools/objtool/include/objtool/elf.h | 1 + tools/objtool/include/objtool/warn.h | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 5b600bbf2389..a00931342c7e 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4514,6 +4514,7 @@ static int validate_sls(struct objtool_file *file) static int validate_reachable_instructions(struct objtool_file *file) { struct instruction *insn; + int warnings =3D 0; =20 if (file->ignore_unreachables) return 0; @@ -4523,10 +4524,10 @@ static int validate_reachable_instructions(struct o= bjtool_file *file) continue; =20 WARN_INSN(insn, "unreachable instruction"); - return 1; + warnings++; } =20 - return 0; + return warnings; } =20 int check(struct objtool_file *file) diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index e1ca588eb69d..78e2d0fc21ca 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/o= bjtool/warn.h index b1c920dc9516..f195deab456e 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -55,7 +55,12 @@ static inline char *offstr(struct section *sec, unsigned= long offset) =20 #define WARN_INSN(insn, format, ...) \ ({ \ - WARN_FUNC(format, insn->sec, insn->offset, ##__VA_ARGS__); \ + struct instruction *_insn =3D (insn); \ + if (!_insn->sym || !_insn->sym->warned) \ + WARN_FUNC(format, _insn->sec, _insn->offset, \ + ##__VA_ARGS__); \ + if (_insn->sym) \ + _insn->sym->warned =3D 1; \ }) =20 #define BT_FUNC(format, insn, ...) \ --=20 2.39.2 From nobody Wed Dec 17 15:07:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2402BC77B75 for ; Tue, 18 Apr 2023 21:28:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229978AbjDRV2U (ORCPT ); Tue, 18 Apr 2023 17:28:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232818AbjDRV2P (ORCPT ); Tue, 18 Apr 2023 17:28:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CA5EAD0F for ; Tue, 18 Apr 2023 14:28:01 -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 A2BBC63945 for ; Tue, 18 Apr 2023 21:28:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9872C433A4; Tue, 18 Apr 2023 21:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681853280; bh=mkUcunGwZcbLDMBJzfgmVtTvYRmD88J1hdWzV9cPHn4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f8rTKQmVKoRowFB1Jq7qGx9DQ9/NsrY/BoSFNs1K1A9O4YYLn7ohcGN8TuFihLB+g TaTb3hO0eTLP2LBZvrGkcwkmN0GGyV89ICl3jyL6BZAkLOk+fC1e3+BtI55vftBGSr 2ZP6o0Gczg/JnPUuXVViIT/qYPw63CdFJz5ZfXzV6f0sWnquxWV87W1dkvtUi7bWZ5 42Ag6eY86awyKJWJIx8O9cRunf8u7jg1ZYxIr5cEXK8S+ks09CXhFV1uXCdIkMOZkT M0jP+AOkdATyQNedY3gsvuduYfPV8yxjkXaZVRk2YyBjlFz6dyad/n+fGrNI9Yon46 OD6yD/yFptwww== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes , Nick Desaulniers Subject: [PATCH v3 2/8] objtool: Add verbose option for disassembling affected functions Date: Tue, 18 Apr 2023 14:27:48 -0700 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Miroslav Benes --- 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/Docume= ntation/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 follow= ing rules: Objtool warnings ---------------- =20 +NOTE: When requesting help with an objtool warning, please recreate with +OBJTOOL_VERBOSE=3D1 (e.g., "make OBJTOOL_VERBOSE=3D1") 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. =20 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[] =3D { 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"), =20 OPT_END(), }; @@ -118,6 +119,10 @@ int cmd_parse_options(int argc, const char **argv, con= st char * const usage[]) parse_options(envc, envv, check_options, env_usage, 0); } =20 + env =3D getenv("OBJTOOL_VERBOSE"); + if (env && !strcmp(env, "1")) + opts.verbose =3D true; + argc =3D parse_options(argc, argv, check_options, usage, 0); if (argc !=3D 1) usage_with_options(usage, check_options); diff --git a/tools/objtool/check.c b/tools/objtool/check.c index a00931342c7e..c63e0867daca 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4530,6 +4530,81 @@ static int validate_reachable_instructions(struct ob= jtool_file *file) return warnings; } =20 +/* '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 =3D getenv("CROSS_COMPILE"); + + objdump_str =3D "%sobjdump -wdr %s | gawk -M -v _funcs=3D'%s' '" + "BEGIN { split(_funcs, funcs); }" + "/^$/ { func_match =3D 0; }" + "/<.*>:/ { " + "f =3D gensub(/.*<(.*)>:/, \"\\\\1\", 1);" + "for (i in funcs) {" + "if (funcs[i] =3D=3D f) {" + "func_match =3D 1;" + "base =3D strtonum(\"0x\" $1);" + "break;" + "}" + "}" + "}" + "{" + "if (func_match) {" + "addr =3D strtonum(\"0x\" $1);" + "printf(\"%%04x \", addr - base);" + "print;" + "}" + "}' 1>&2"; + + /* fake snprintf() to calculate the size */ + size =3D snprintf(NULL, 0, objdump_str, cross_compile, objname, funcs) + = 1; + if (size <=3D 0) { + WARN("objdump string size calculation failed"); + return -1; + } + + cmd =3D malloc(size); + + /* real snprintf() */ + snprintf(cmd, size, objdump_str, cross_compile, objname, funcs); + ret =3D 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 =3D NULL, *tmp; + + for_each_sym(file, sym) { + if (sym->warned) { + if (!funcs) { + funcs =3D malloc(strlen(sym->name) + 1); + strcpy(funcs, sym->name); + } else { + tmp =3D malloc(strlen(funcs) + strlen(sym->name) + 2); + sprintf(tmp, "%s %s", funcs, sym->name); + free(funcs); + funcs =3D tmp; + } + } + } + + if (funcs) + disas_funcs(funcs); + + return 0; +} + int check(struct objtool_file *file) { int ret, warnings =3D 0; @@ -4674,6 +4749,8 @@ int check(struct objtool_file *file) warnings +=3D ret; } =20 + if (opts.verbose) + disas_warned_funcs(file); =20 if (opts.stats) { printf("nr_insns_visited: %ld\n", nr_insns_visited); diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/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; }; =20 extern struct opts opts; --=20 2.39.2 From nobody Wed Dec 17 15:07:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8566C6FD18 for ; Tue, 18 Apr 2023 21:28:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232985AbjDRV20 (ORCPT ); Tue, 18 Apr 2023 17:28:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232753AbjDRV2P (ORCPT ); Tue, 18 Apr 2023 17:28:15 -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 91B62BBB1 for ; Tue, 18 Apr 2023 14:28:01 -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 09E606395A for ; Tue, 18 Apr 2023 21:28:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E4AEC433A0; Tue, 18 Apr 2023 21:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681853280; bh=pBU1V3n8RoeNydoWkCOq7gRDOLCsSaGVqI+g1UM+LHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mG5cYVFRVoVveup0sM4ym0gMevTAZG6FJHEsWSU21tEm7ayDCeF9gOXAR0VM8DZjr 5C14MITk1NDLNM/Ax3aI8n6SmbQHnNTz1tpR3JqM/fVwKUB5JEcWwScT9AQ9zO/zY0 V1TwpLTdaU5F9enIOoKlMdTbPwx1rbwpyKYZOWDlCS0imSE3fdi0Dsd401W/kkHwol 0izRQKppbnRm2/maVb9w6Cr3xQ6XBvQctEelTOU8j+IePma+pdIBNa2pHnB7euNPQ4 PWK8kIF7YPEiIyvdoRk7E6utFwNxEuncCeijR6PmxWB9a0R0jyyTsNqY526UEUvwUz 0HAzKEFGPD6WA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes , Nick Desaulniers Subject: [PATCH v3 3/8] objtool: Include backtrace in verbose mode Date: Tue, 18 Apr 2023 14:27:49 -0700 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Include backtrace in verbose mode. This makes it easy to gather all the information needed for diagnosing objtool warnings. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- 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/Docume= ntation/objtool.txt index 4d6c5acde7a3..5a69c207a10e 100644 --- a/tools/objtool/Documentation/objtool.txt +++ b/tools/objtool/Documentation/objtool.txt @@ -246,8 +246,8 @@ Objtool warnings =20 NOTE: When requesting help with an objtool warning, please recreate with OBJTOOL_VERBOSE=3D1 (e.g., "make OBJTOOL_VERBOSE=3D1") 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. =20 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 c63e0867daca..aa083296af1e 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3657,8 +3657,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, =20 ret =3D validate_branch(file, func, alt->insn, state); if (ret) { - if (opts.backtrace) - BT_FUNC("(alt)", insn); + BT_INSN(insn, "(alt)"); return ret; } } @@ -3703,8 +3702,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, ret =3D validate_branch(file, func, insn->jump_dest, state); if (ret) { - if (opts.backtrace) - BT_FUNC("(branch)", insn); + BT_INSN(insn, "(branch)"); return ret; } } @@ -3802,8 +3800,8 @@ static int validate_unwind_hint(struct objtool_file *= file, { if (insn->hint && !insn->visited && !insn->ignore) { int ret =3D validate_branch(file, insn_func(insn), insn, *state); - if (ret && opts.backtrace) - BT_FUNC("<=3D=3D=3D (hint)", insn); + if (ret) + BT_INSN(insn, "<=3D=3D=3D (hint)"); return ret; } =20 @@ -3861,8 +3859,7 @@ static int validate_unret(struct objtool_file *file, = struct instruction *insn) =20 ret =3D validate_unret(file, alt->insn); if (ret) { - if (opts.backtrace) - BT_FUNC("(alt)", insn); + BT_INSN(insn, "(alt)"); return ret; } } @@ -3888,10 +3885,8 @@ static int validate_unret(struct objtool_file *file,= struct instruction *insn) } ret =3D validate_unret(file, insn->jump_dest); if (ret) { - if (opts.backtrace) { - BT_FUNC("(branch%s)", insn, - insn->type =3D=3D INSN_JUMP_CONDITIONAL ? "-cond" : ""); - } + BT_INSN(insn, "(branch%s)", + insn->type =3D=3D INSN_JUMP_CONDITIONAL ? "-cond" : ""); return ret; } =20 @@ -3913,8 +3908,7 @@ static int validate_unret(struct objtool_file *file, = struct instruction *insn) =20 ret =3D validate_unret(file, dest); if (ret) { - if (opts.backtrace) - BT_FUNC("(call)", insn); + BT_INSN(insn, "(call)"); return ret; } /* @@ -4216,8 +4210,8 @@ static int validate_symbol(struct objtool_file *file,= struct section *sec, state->uaccess =3D sym->uaccess_safe; =20 ret =3D validate_branch(file, insn_func(insn), insn, *state); - if (ret && opts.backtrace) - BT_FUNC("<=3D=3D=3D (sym)", insn); + if (ret) + BT_INSN(insn, "<=3D=3D=3D (sym)"); return ret; } =20 diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index f195deab456e..ac04d3fe4dd9 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -63,12 +63,14 @@ static inline char *offstr(struct section *sec, unsigne= d long offset) _insn->sym->warned =3D 1; \ }) =20 -#define BT_FUNC(format, insn, ...) \ -({ \ - struct instruction *_insn =3D (insn); \ - char *_str =3D 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 =3D (insn); \ + char *_str =3D offstr(_insn->sec, _insn->offset); \ + WARN(" %s: " format, _str, ##__VA_ARGS__); \ + free(_str); \ + } \ }) =20 #define WARN_ELF(format, ...) \ --=20 2.39.2 From nobody Wed Dec 17 15:07:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2677AC77B76 for ; Tue, 18 Apr 2023 21:28:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232855AbjDRV2X (ORCPT ); Tue, 18 Apr 2023 17:28:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232814AbjDRV2P (ORCPT ); Tue, 18 Apr 2023 17:28:15 -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 8FD14BBAA for ; Tue, 18 Apr 2023 14:28:01 -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 008CD6394F for ; Tue, 18 Apr 2023 21:28:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96148C433D2; Tue, 18 Apr 2023 21:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681853280; bh=d8JeZbsO9FoCUm7Dn+I8dcmej5dQ111QeGOLzKzYoxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hQOxdvbFmQbJ8Ey4p9LJ+o8btkCtcDjirAQFXJUP9kU7/jj5rHE7x6YNHb2wuzse/ wZzM5lnhebXXYVROnDVsWNniHyqHAtA65tiRFNLYvSyCWQLFPaESkwG1Dm098ottzm pthA0dTvkLcmyvE93Mz+Y/BoY7whAsZNwvxg6VTWG8nQe/RXJyrlRXaTR3ttw9l7jd sHRNLAw2FR5jzW8oKGwhO/ojHNkRN150MZr4s9boNzIR/YcaGjlZKkvfunlh5Gdmnt pxhY3aZSbLQ3fxejuQqc/7BG6oKjhWQ50+mV+aN1M5BVvdFNSDVKBeyL0Hbr6rQQuQ Tha6MYOjdzuCQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes , Nick Desaulniers Subject: [PATCH v3 4/8] objtool: Detect missing __noreturn annotations Date: Tue, 18 Apr 2023 14:27:50 -0700 Message-Id: <6e2b93d8c65eaed6c4166a358269dc0ef01f890c.1681853186.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Miroslav Benes --- 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/Docume= ntation/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. =20 +3. file.o: warning: objtool: foo+0x48c: bar() is missing a __noreturn anno= tation + + 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. =20 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 aa083296af1e..dd10128ab013 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4507,7 +4507,8 @@ static int validate_sls(struct objtool_file *file) =20 static int validate_reachable_instructions(struct objtool_file *file) { - struct instruction *insn; + struct instruction *insn, *prev_insn; + struct symbol *call_dest; int warnings =3D 0; =20 if (file->ignore_unreachables) @@ -4517,6 +4518,17 @@ static int validate_reachable_instructions(struct ob= jtool_file *file) if (insn->visited || ignore_unreachable_insn(file, insn)) continue; =20 + prev_insn =3D prev_insn_same_sec(file, insn); + if (prev_insn && prev_insn->dead_end) { + call_dest =3D 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++; } --=20 2.39.2 From nobody Wed Dec 17 15:07:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF0CCC6FD18 for ; Tue, 18 Apr 2023 21:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233001AbjDRV2m (ORCPT ); Tue, 18 Apr 2023 17:28:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232997AbjDRV2e (ORCPT ); Tue, 18 Apr 2023 17:28:34 -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 278F31026E for ; Tue, 18 Apr 2023 14:28:12 -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 B6D6D612AE for ; Tue, 18 Apr 2023 21:28:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE361C4339B; Tue, 18 Apr 2023 21:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681853281; bh=ij85bIvlI0ug5hahPrm5CUQ/Uj6pydt9FfFsLuqiE1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RwW7odxeNgHigkMNNMw1f88aayUFzwCqtCcmWcCvr+ZBqnoaEexntOjXcgZD2PLf8 VWilc8PbrS+97sWQ5yTo1qLWnrcjD3AKumLAPGjRsydINKg01qS5oUyqjxJiuTPLYN XMKEPDsMDzZTLXtgmKHfktMroK7xaAtrSOuBEYwUTkDVRhu5ln+OfoeGoCe94YIzVq ycgik4QUrMA6gXCr/X/8UvIQrw25D4gYdd1uThwXmtl+iNXz1j9VJ9dg7Mjj8yDIoi Xozdhxx3k2/QJqQS+tgYJUqEiR6LJdHueN3e0ZV5KlyYIVpvyzjbiVgzfFmkm+K33H pqKiNjWgQgZNQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes , Nick Desaulniers Subject: [PATCH v3 5/8] objtool: Ignore exc_double_fault() __noreturn warnings Date: Tue, 18 Apr 2023 14:27:51 -0700 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Miroslav Benes --- 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 dd10128ab013..1cace399d32a 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4505,6 +4505,35 @@ static int validate_sls(struct objtool_file *file) return warnings; } =20 +static bool ignore_noreturn_call(struct instruction *insn) +{ + struct symbol *call_dest =3D insn_call_dest(insn); + + /* + * FIXME: hack, we need a real noreturn solution + * + * 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: + * + * - have compiler communicate __noreturn functions somehow + * - 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 + */ + if (!strcmp(call_dest->name, "exc_double_fault")) { + /* prevent further unreachable warnings for the caller */ + insn->sym->warned =3D 1; + return true; + } + + return false; +} + static int validate_reachable_instructions(struct objtool_file *file) { struct instruction *insn, *prev_insn; @@ -4521,7 +4550,7 @@ static int validate_reachable_instructions(struct obj= tool_file *file) prev_insn =3D prev_insn_same_sec(file, insn); if (prev_insn && prev_insn->dead_end) { call_dest =3D 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++; --=20 2.39.2 From nobody Wed Dec 17 15:07:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D880C6FD18 for ; Tue, 18 Apr 2023 21:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233008AbjDRV2o (ORCPT ); Tue, 18 Apr 2023 17:28:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232978AbjDRV2e (ORCPT ); Tue, 18 Apr 2023 17:28:34 -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 D031CAD3D for ; Tue, 18 Apr 2023 14:28:13 -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 1A2D863964 for ; Tue, 18 Apr 2023 21:28:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5146EC433EF; Tue, 18 Apr 2023 21:28:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681853281; bh=WeuYulFAOo3QWy7DY6IxPDrEghLxpSGlZTD112qJl50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sSNHEHguFD6YyAWfQ1wYp/ylJAjG5fiTRuh7fOWDkzNzkgh+Q3fh5sLhjuQLjvCTH Re3o6PhjPw1ZMz9QD99L8IcERE5fmgEt4d3mEH/yuSU2XzkgMdcj6bUYo6127sa98e YfWiPt4fGvcxYvxqyMwTuuoH4XAhnjc0iQnIoAGvIfYtgwT97yAiM+hB2Fa5NaABk4 c8Rz69VKES3JUape+FBypFBHjWURpa8Bx30tL1FCoFMmKvhhG3uM1SdXbLyhkUdtck oLB1TUFK0fWzWv7V/fgP8IS5c7EOEt18JEzcaKoIUp2WOrJDA+a0xmQu8uvmeA+Dlq OWvmcRvRCmAXw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes , Nick Desaulniers Subject: [PATCH v3 6/8] objtool: Remove superfluous global_noreturns entries Date: Tue, 18 Apr 2023 14:27:52 -0700 Message-Id: <2725d7f2ccc2361c6903de9ebaa2b5bb304f7ac2.1681853186.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" lbug_with_loc() no longer exists, and resume_play_dead() is static (objtool only checks globals and weaks). Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- tools/objtool/check.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 1cace399d32a..2047a6d5339b 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -217,7 +217,6 @@ static bool __dead_end_function(struct objtool_file *fi= le, struct symbol *func, "kthread_complete_and_exit", "kthread_exit", "kunit_try_catch_throw", - "lbug_with_loc", "machine_real_restart", "make_task_dead", "mpt_halt_firmware", @@ -225,7 +224,6 @@ static bool __dead_end_function(struct objtool_file *fi= le, struct symbol *func, "panic", "panic_smp_self_stop", "rest_init", - "resume_play_dead", "rewind_stack_and_make_dead", "sev_es_terminate", "snp_abort", --=20 2.39.2 From nobody Wed Dec 17 15:07:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A263C77B75 for ; Tue, 18 Apr 2023 21:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232986AbjDRV2l (ORCPT ); Tue, 18 Apr 2023 17:28:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232996AbjDRV2e (ORCPT ); Tue, 18 Apr 2023 17:28:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 270FFC671 for ; Tue, 18 Apr 2023 14:28:12 -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 172B96393D for ; Tue, 18 Apr 2023 21:28:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A98FCC433A1; Tue, 18 Apr 2023 21:28:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681853281; bh=rKNOJA2iFxFHQD00gPxbX9WeLPWBE9JGs0wdA5OiRv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c0blbe4lLqfHHadAtOQFMEbIpw6pqLcijlz7BFygBypbTqIXXrbuq+bnKXo2qQOBu NULyMH4LXCIdMoKckY0Yr3CwAt3oS6pyE/2aJnwD2NwZHBFsAKwEMBGJInOdBwf3lC QX8TAaHzTIS1uGJ+DJHBuWCMZrryJYd9PLT8qK4Z+//BZSiSJG7y/o/Q5tf6sRg4m8 DlbxA992QxOtLr9oD9r+tS5cCJcI+batN2VA+4n9ZspK1y4iZ/xAaO5kKpZp+4iXxd UTqRKHX/qAq8KrnFuqhjgFUPbc0Oq7pl3Ky20SgdthWPVxxSBowFQxl14CXSxakaNZ NXx5512m9DnWQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes , Nick Desaulniers Subject: [PATCH v3 7/8] tools/lib/subcmd: Replace NORETURN usage with __noreturn Date: Tue, 18 Apr 2023 14:27:53 -0700 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" NORETURN is redundant with __noreturn, just use the latter. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- tools/lib/subcmd/parse-options.h | 8 ++------ tools/lib/subcmd/subcmd-util.h | 5 ++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/tools/lib/subcmd/parse-options.h b/tools/lib/subcmd/parse-opti= ons.h index 41b9b942504d..8e9147358a28 100644 --- a/tools/lib/subcmd/parse-options.h +++ b/tools/lib/subcmd/parse-options.h @@ -6,10 +6,6 @@ #include #include =20 -#ifndef NORETURN -#define NORETURN __attribute__((__noreturn__)) -#endif - enum parse_opt_type { /* special types */ OPTION_END, @@ -183,9 +179,9 @@ extern int parse_options_subcommand(int argc, const cha= r **argv, const char *const subcommands[], const char *usagestr[], int flags); =20 -extern NORETURN void usage_with_options(const char * const *usagestr, +extern __noreturn void usage_with_options(const char * const *usagestr, const struct option *options); -extern NORETURN __attribute__((format(printf,3,4))) +extern __noreturn __attribute__((format(printf,3,4))) void usage_with_options_msg(const char * const *usagestr, const struct option *options, const char *fmt, ...); diff --git a/tools/lib/subcmd/subcmd-util.h b/tools/lib/subcmd/subcmd-util.h index b2aec04fce8f..dfac76e35ac7 100644 --- a/tools/lib/subcmd/subcmd-util.h +++ b/tools/lib/subcmd/subcmd-util.h @@ -5,8 +5,7 @@ #include #include #include - -#define NORETURN __attribute__((__noreturn__)) +#include =20 static inline void report(const char *prefix, const char *err, va_list par= ams) { @@ -15,7 +14,7 @@ static inline void report(const char *prefix, const char = *err, va_list params) fprintf(stderr, " %s%s\n", prefix, msg); } =20 -static NORETURN inline void die(const char *err, ...) +static __noreturn inline void die(const char *err, ...) { va_list params; =20 --=20 2.39.2 From nobody Wed Dec 17 15:07:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20966C77B7C for ; Tue, 18 Apr 2023 21:28:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233013AbjDRV2t (ORCPT ); Tue, 18 Apr 2023 17:28:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232999AbjDRV2e (ORCPT ); Tue, 18 Apr 2023 17:28:34 -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 D0C12CC0B for ; Tue, 18 Apr 2023 14:28:13 -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 D12D96395F for ; Tue, 18 Apr 2023 21:28:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1075AC4339E; Tue, 18 Apr 2023 21:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681853282; bh=ntG9ViCrjPSzd67qUu5eqOdkFLpY/tylKZuYgUZ9cSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pk0raLmseMDt9vaVephe1yLCLi62LKnBpUmBkCmZlO4/Sn3u7b5Ln3Zq5YmxpVl+4 /t87PR/8MhAMcKqkGZLxm4l1AzGlZAYMNnGoWU97LqXABy7V+oyb7fV2BX5mefj5v9 ZgONh0VS3+sWtvi9PqpNzfztuVF2fvJhT93yBfdsF6NUXBndZ4JFT2xAQj9F9lsBcD Ofa4D3QKqOVN02bDfDOTunZixBiISy78Mo4Lczhwm6GMndgpBvRj/QQviAUl1ckPXc fEoFqkIPx6TAG28sjHwumFEAsFUNVPf8iv/Ywge5y5uV0EGzIkDfuyalEG+UYb/MOf e2KbhGMX43y9Q== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes , Nick Desaulniers Subject: [PATCH v3 8/8] objtool: Move noreturn function list to separate file Date: Tue, 18 Apr 2023 14:27:54 -0700 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This makes it a little cleaner and easier to maintain. Suggested-by: Peter Zijlstra Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- tools/objtool/Documentation/objtool.txt | 5 ++- tools/objtool/check.c | 44 ++---------------------- tools/objtool/noreturns.h | 45 +++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 44 deletions(-) create mode 100644 tools/objtool/noreturns.h diff --git a/tools/objtool/Documentation/objtool.txt b/tools/objtool/Docume= ntation/objtool.txt index 2cd1fa16ed08..00f0a7e385ec 100644 --- a/tools/objtool/Documentation/objtool.txt +++ b/tools/objtool/Documentation/objtool.txt @@ -306,9 +306,8 @@ the objtool maintainers. 3. file.o: warning: objtool: foo+0x48c: bar() is missing a __noreturn anno= tation =20 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. + __noreturn annotation. NOTE: In addition to annotating the function + with __noreturn, please also add it to tools/objtool/noreturns.h. =20 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 2047a6d5339b..69794c25f857 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -192,49 +192,11 @@ static bool __dead_end_function(struct objtool_file *= file, struct symbol *func, struct instruction *insn; bool empty =3D true; =20 - /* - * Unfortunately these have to be hard coded because the noreturn - * attribute isn't provided in ELF data. Keep 'em sorted. - */ +#define NORETURN(func) __stringify(func), static const char * const global_noreturns[] =3D { - "__invalid_creds", - "__module_put_and_kthread_exit", - "__reiserfs_panic", - "__stack_chk_fail", - "__ubsan_handle_builtin_unreachable", - "arch_call_rest_init", - "arch_cpu_idle_dead", - "btrfs_assertfail", - "cpu_bringup_and_idle", - "cpu_startup_entry", - "do_exit", - "do_group_exit", - "do_task_dead", - "ex_handler_msr_mce", - "fortify_panic", - "hlt_play_dead", - "hv_ghcb_terminate", - "kthread_complete_and_exit", - "kthread_exit", - "kunit_try_catch_throw", - "machine_real_restart", - "make_task_dead", - "mpt_halt_firmware", - "nmi_panic_self_stop", - "panic", - "panic_smp_self_stop", - "rest_init", - "rewind_stack_and_make_dead", - "sev_es_terminate", - "snp_abort", - "start_kernel", - "stop_this_cpu", - "usercopy_abort", - "x86_64_start_kernel", - "x86_64_start_reservations", - "xen_cpu_bringup_again", - "xen_start_kernel", +#include "noreturns.h" }; +#undef NORETURN =20 if (!func) return false; diff --git a/tools/objtool/noreturns.h b/tools/objtool/noreturns.h new file mode 100644 index 000000000000..cede6068ddf6 --- /dev/null +++ b/tools/objtool/noreturns.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * This is a (sorted!) list of all known __noreturn functions in the kerne= l. + * It's needed for objtool to properly reverse-engineer the control flow g= raph. + * + * Yes, this is unfortunate. A better solution is in the works. + */ +NORETURN(__invalid_creds) +NORETURN(__module_put_and_kthread_exit) +NORETURN(__reiserfs_panic) +NORETURN(__stack_chk_fail) +NORETURN(__ubsan_handle_builtin_unreachable) +NORETURN(arch_call_rest_init) +NORETURN(arch_cpu_idle_dead) +NORETURN(btrfs_assertfail) +NORETURN(cpu_bringup_and_idle) +NORETURN(cpu_startup_entry) +NORETURN(do_exit) +NORETURN(do_group_exit) +NORETURN(do_task_dead) +NORETURN(ex_handler_msr_mce) +NORETURN(fortify_panic) +NORETURN(hlt_play_dead) +NORETURN(hv_ghcb_terminate) +NORETURN(kthread_complete_and_exit) +NORETURN(kthread_exit) +NORETURN(kunit_try_catch_throw) +NORETURN(machine_real_restart) +NORETURN(make_task_dead) +NORETURN(mpt_halt_firmware) +NORETURN(nmi_panic_self_stop) +NORETURN(panic) +NORETURN(panic_smp_self_stop) +NORETURN(rest_init) +NORETURN(rewind_stack_and_make_dead) +NORETURN(sev_es_terminate) +NORETURN(snp_abort) +NORETURN(start_kernel) +NORETURN(stop_this_cpu) +NORETURN(usercopy_abort) +NORETURN(x86_64_start_kernel) +NORETURN(x86_64_start_reservations) +NORETURN(xen_cpu_bringup_again) +NORETURN(xen_start_kernel) --=20 2.39.2