public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: jpoimboe@kernel.org
Cc: chenhuacai@kernel.org, kernel@xen0n.name, x86@kernel.org,
	peterz@infradead.org, loongarch@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 13/16] objtool: Remove annotate_{,un}reachable()
Date: Thu, 28 Nov 2024 10:39:04 +0100	[thread overview]
Message-ID: <20241128094312.235637588@infradead.org> (raw)
In-Reply-To: 20241128093851.469225872@infradead.org

There are no users of annotate_reachable() left.

And the annotate_unreachable() usage in unreachable() is plain wrong;
it will hide dangerous fall-through code-gen.

Remove both.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 include/linux/compiler.h |   27 ---------------------------
 tools/objtool/check.c    |   43 ++-----------------------------------------
 2 files changed, 2 insertions(+), 68 deletions(-)

--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -109,35 +109,9 @@ void ftrace_likely_update(struct ftrace_
 
 /* Unreachable code */
 #ifdef CONFIG_OBJTOOL
-/*
- * These macros help objtool understand GCC code flow for unreachable code.
- * The __COUNTER__ based labels are a hack to make each instance of the macros
- * unique, to convince GCC not to merge duplicate inline asm statements.
- */
-#define __stringify_label(n) #n
-
-#define __annotate_reachable(c) ({					\
-	asm volatile(__stringify_label(c) ":\n\t"			\
-			".pushsection .discard.reachable\n\t"		\
-			".long " __stringify_label(c) "b - .\n\t"	\
-			".popsection\n\t");				\
-})
-#define annotate_reachable() __annotate_reachable(__COUNTER__)
-
-#define __annotate_unreachable(c) ({					\
-	asm volatile(__stringify_label(c) ":\n\t"			\
-		     ".pushsection .discard.unreachable\n\t"		\
-		     ".long " __stringify_label(c) "b - .\n\t"		\
-		     ".popsection\n\t" : : "i" (c));			\
-})
-#define annotate_unreachable() __annotate_unreachable(__COUNTER__)
-
 /* Annotate a C jump table to allow objtool to follow the code flow */
 #define __annotate_jump_table __section(".rodata..c_jump_table,\"a\",@progbits #")
-
 #else /* !CONFIG_OBJTOOL */
-#define annotate_reachable()
-#define annotate_unreachable()
 #define __annotate_jump_table
 #endif /* CONFIG_OBJTOOL */
 
@@ -147,7 +121,6 @@ void ftrace_likely_update(struct ftrace_
  * control elsewhere.
  */
 #define unreachable() do {		\
-	annotate_unreachable();		\
 	barrier_before_unreachable();	\
 	__builtin_unreachable();	\
 } while (0)
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -638,47 +638,8 @@ static int add_dead_ends(struct objtool_
 	uint64_t offset;
 
 	/*
-	 * Check for manually annotated dead ends.
-	 */
-	rsec = find_section_by_name(file->elf, ".rela.discard.unreachable");
-	if (!rsec)
-		goto reachable;
-
-	for_each_reloc(rsec, reloc) {
-		if (reloc->sym->type == STT_SECTION) {
-			offset = reloc_addend(reloc);
-		} else if (reloc->sym->local_label) {
-			offset = reloc->sym->offset;
-		} else {
-			WARN("unexpected relocation symbol type in %s", rsec->name);
-			return -1;
-		}
-
-		insn = find_insn(file, reloc->sym->sec, offset);
-		if (insn)
-			insn = prev_insn_same_sec(file, insn);
-		else if (offset == reloc->sym->sec->sh.sh_size) {
-			insn = find_last_insn(file, reloc->sym->sec);
-			if (!insn) {
-				WARN("can't find unreachable insn at %s+0x%" PRIx64,
-				     reloc->sym->sec->name, offset);
-				return -1;
-			}
-		} else {
-			WARN("can't find unreachable insn at %s+0x%" PRIx64,
-			     reloc->sym->sec->name, offset);
-			return -1;
-		}
-
-		insn->dead_end = true;
-	}
-
-reachable:
-	/*
-	 * These manually annotated reachable checks are needed for GCC 4.4,
-	 * where the Linux unreachable() macro isn't supported.  In that case
-	 * GCC doesn't know the "ud2" is fatal, so it generates code as if it's
-	 * not a dead end.
+	 * UD2 defaults to being a dead-end, allow them to be annotated for
+	 * non-fatal, eg WARN.
 	 */
 	rsec = find_section_by_name(file->elf, ".rela.discard.reachable");
 	if (!rsec)



  parent reply	other threads:[~2024-11-28  9:44 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-28  9:38 [PATCH v2 00/16] objtool: Rewrite annotations Peter Zijlstra
2024-11-28  9:38 ` [PATCH v2 01/16] objtool: Generic annotation infrastructure Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:38 ` [PATCH v2 02/16] objtool: Convert ANNOTATE_NOENDBR to ANNOTATE Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:38 ` [PATCH v2 03/16] objtool: Convert ANNOTATE_RETPOLINE_SAFE " Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:38 ` [PATCH v2 04/16] objtool: Convert instrumentation_{begin,end}() " Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:38 ` [PATCH v2 05/16] objtool: Convert VALIDATE_UNRET_BEGIN " Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:38 ` [PATCH v2 06/16] objtool: Convert ANNOTATE_IGNORE_ALTERNATIVE " Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:38 ` [PATCH v2 07/16] objtool: Convert ANNOTATE_INTRA_FUNCTION_CALL " Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:38 ` [PATCH v2 08/16] objtool: Collapse annotate sequences Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:39 ` [PATCH v2 09/16] objtool: Collect more annotations in objtool.h Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:39 ` [PATCH v2 10/16] unreachable: Unify Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:39 ` [PATCH v2 11/16] x86: Convert unreachable() to BUG() Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-12-16  9:32     ` Peter Zijlstra
2024-12-24  9:47       ` [tip: objtool/core] x86/mm: " tip-bot2 for Peter Zijlstra
2024-11-28  9:39 ` [PATCH v2 12/16] loongarch: Use ASM_REACHABLE Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:39 ` Peter Zijlstra [this message]
2024-12-02 11:15   ` [tip: objtool/core] objtool: Remove annotate_{,un}reachable() tip-bot2 for Peter Zijlstra
2024-11-28  9:39 ` [PATCH v2 14/16] objtool: Convert {.UN}REACHABLE to ANNOTATE Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:39 ` [PATCH v2 15/16] objtool: Fix ANNOTATE_REACHABLE to be a normal annotation Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28  9:39 ` [PATCH v2 16/16] objtool: Warn about unknown annotation types Peter Zijlstra
2024-12-02 11:15   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2024-11-28 18:44 ` [PATCH v2 00/16] objtool: Rewrite annotations Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241128094312.235637588@infradead.org \
    --to=peterz@infradead.org \
    --cc=chenhuacai@kernel.org \
    --cc=jpoimboe@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox