All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: x86@kernel.org, jpoimboe@redhat.com, andrew.cooper3@citrix.com
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
	alexei.starovoitov@gmail.com, ndesaulniers@google.com,
	bpf@vger.kernel.org
Subject: [PATCH v3 01/16] objtool: Classify symbols
Date: Tue, 26 Oct 2021 14:01:33 +0200	[thread overview]
Message-ID: <20211026120309.658539311@infradead.org> (raw)
In-Reply-To: 20211026120132.613201817@infradead.org

In order to avoid calling str*cmp() on symbol names, over and over, do
them all once upfront and store the result.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 tools/objtool/check.c               |   34 ++++++++++++++++++++++------------
 tools/objtool/include/objtool/elf.h |    5 ++++-
 2 files changed, 26 insertions(+), 13 deletions(-)

--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1012,8 +1012,7 @@ static void add_call_dest(struct objtool
 	 * so they need a little help, NOP out any KCOV calls from noinstr
 	 * text.
 	 */
-	if (insn->sec->noinstr &&
-	    !strncmp(insn->call_dest->name, "__sanitizer_cov_", 16)) {
+	if (insn->sec->noinstr && insn->call_dest->kcov) {
 		if (reloc) {
 			reloc->type = R_NONE;
 			elf_write_reloc(file->elf, reloc);
@@ -1027,7 +1026,7 @@ static void add_call_dest(struct objtool
 		insn->type = sibling ? INSN_RETURN : INSN_NOP;
 	}
 
-	if (mcount && !strcmp(insn->call_dest->name, "__fentry__")) {
+	if (mcount && insn->call_dest->fentry) {
 		if (sibling)
 			WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset);
 
@@ -1077,7 +1076,7 @@ static int add_jump_destinations(struct
 		} else if (reloc->sym->type == STT_SECTION) {
 			dest_sec = reloc->sym->sec;
 			dest_off = arch_dest_reloc_offset(reloc->addend);
-		} else if (arch_is_retpoline(reloc->sym)) {
+		} else if (reloc->sym->retpoline_thunk) {
 			/*
 			 * Retpoline jumps are really dynamic jumps in
 			 * disguise, so convert them accordingly.
@@ -1218,7 +1217,7 @@ static int add_call_destinations(struct
 
 			add_call_dest(file, insn, dest, false);
 
-		} else if (arch_is_retpoline(reloc->sym)) {
+		} else if (reloc->sym->retpoline_thunk) {
 			/*
 			 * Retpoline calls are really dynamic calls in
 			 * disguise, so convert them accordingly.
@@ -1919,17 +1918,28 @@ static int read_intra_function_calls(str
 	return 0;
 }
 
-static int read_static_call_tramps(struct objtool_file *file)
+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 &&
-			    !strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR,
+			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 (arch_is_retpoline(func))
+				func->retpoline_thunk = true;
+
+			if (!strcmp(func->name, "__fentry__"))
+				func->fentry = true;
+
+			if (!strncmp(func->name, "__sanitizer_cov_", 16))
+				func->kcov = true;
 		}
 	}
 
@@ -1995,7 +2005,7 @@ static int decode_sections(struct objtoo
 	/*
 	 * Must be before add_{jump_call}_destination.
 	 */
-	ret = read_static_call_tramps(file);
+	ret = classify_symbols(file);
 	if (ret)
 		return ret;
 
@@ -2053,9 +2063,9 @@ static int decode_sections(struct objtoo
 
 static bool is_fentry_call(struct instruction *insn)
 {
-	if (insn->type == INSN_CALL && insn->call_dest &&
-	    insn->call_dest->type == STT_NOTYPE &&
-	    !strcmp(insn->call_dest->name, "__fentry__"))
+	if (insn->type == INSN_CALL &&
+	    insn->call_dest &&
+	    insn->call_dest->fentry)
 		return true;
 
 	return false;
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -55,7 +55,10 @@ struct symbol {
 	unsigned int len;
 	struct symbol *pfunc, *cfunc, *alias;
 	bool uaccess_safe;
-	bool static_call_tramp;
+	u8 static_call_tramp : 1;
+	u8 retpoline_thunk   : 1;
+	u8 fentry            : 1;
+	u8 kcov              : 1;
 	struct list_head pv_target;
 };
 



  reply	other threads:[~2021-10-26 12:08 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-26 12:01 [PATCH v3 00/16] x86: Rewrite the retpoline rewrite logic Peter Zijlstra
2021-10-26 12:01 ` Peter Zijlstra [this message]
2021-10-28  3:58   ` [PATCH v3 01/16] objtool: Classify symbols Josh Poimboeuf
2021-10-29  8:03   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 02/16] objtool: Explicitly avoid self modifying code in .altinstr_replacement Peter Zijlstra
2021-10-28  4:01   ` Josh Poimboeuf
2021-10-29  8:03   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 03/16] objtool: Shrink struct instruction Peter Zijlstra
2021-10-29  8:03   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 04/16] objtool,x86: Replace alternatives with .retpoline_sites Peter Zijlstra
2021-10-29  8:03   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 05/16] x86/retpoline: Remove unused replacement symbols Peter Zijlstra
2021-10-29  8:03   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 06/16] x86/asm: Fix register order Peter Zijlstra
2021-10-29  8:03   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 07/16] x86/asm: Fixup odd GEN-for-each-reg.h usage Peter Zijlstra
2021-10-29  8:03   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 08/16] x86/retpoline: Move the retpoline thunk declarations to nospec-branch.h Peter Zijlstra
2021-10-29  8:03   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 09/16] x86/retpoline: Create a retpoline thunk array Peter Zijlstra
2021-10-29  8:03   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 10/16] x86/alternative: Implement .retpoline_sites support Peter Zijlstra
2021-10-27 17:38   ` Borislav Petkov
2021-10-27 19:10     ` Peter Zijlstra
2021-10-29  8:02   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 11/16] x86/alternative: Handle Jcc __x86_indirect_thunk_\reg Peter Zijlstra
2021-10-28  9:29   ` Borislav Petkov
2021-10-29  8:02   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 12/16] x86/alternative: Try inline spectre_v2=retpoline,amd Peter Zijlstra
2021-10-29  8:02   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 13/16] x86/alternative: Add debug prints to apply_retpolines() Peter Zijlstra
2021-10-29  8:02   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 14/16] x86,bugs: Unconditionally allow spectre_v2=retpoline,amd Peter Zijlstra
2021-10-29  8:02   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 15/16] bpf, x86: Simplify computing label offsets Peter Zijlstra
2021-10-29  8:02   ` [tip: objtool/core] bpf,x86: " tip-bot2 for Peter Zijlstra
2021-10-26 12:01 ` [PATCH v3 16/16] bpf,x86: Respect X86_FEATURE_RETPOLINE* Peter Zijlstra
2021-10-29  8:02   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-10-26 18:26 ` [PATCH v3 00/16] x86: Rewrite the retpoline rewrite logic Alexei Starovoitov
2021-10-26 18:45   ` Peter Zijlstra
2021-10-26 20:00     ` Alexei Starovoitov
2021-10-26 21:05       ` Peter Zijlstra
2021-10-26 21:05         ` Alexei Starovoitov
2021-10-27  9:00           ` Peter Zijlstra
2021-10-27 17:32             ` Alexei Starovoitov
2021-10-28  5:17 ` Josh Poimboeuf
2021-10-28 17:43 ` Borislav Petkov
2021-10-29 12:43 ` Miroslav Benes

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=20211026120309.658539311@infradead.org \
    --to=peterz@infradead.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=bpf@vger.kernel.org \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ndesaulniers@google.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.