mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhen Lei <thunder.leizhen@huawei.com>
To: Josh Poimboeuf <jpoimboe@kernel.org>,
	Jiri Kosina <jikos@kernel.org>, Miroslav Benes <mbenes@suse.cz>,
	Petr Mladek <pmladek@suse.com>,
	Joe Lawrence <joe.lawrence@redhat.com>,
	<live-patching@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Luis Chamberlain" <mcgrof@kernel.org>,
	<linux-modules@vger.kernel.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Subject: [PATCH v6 06/11] kallsyms: Add helper kallsyms_lookup_clang_name()
Date: Sat, 24 Sep 2022 20:20:46 +0800	[thread overview]
Message-ID: <20220924122051.362-7-thunder.leizhen@huawei.com> (raw)
In-Reply-To: <20220924122051.362-1-thunder.leizhen@huawei.com>

Literally, there is no sense that cleanup_symbol_name() is associated
with CLANG. So add helper kallsyms_lookup_clang_name() can enhance the
readability of the code. More importantly, if CONFIG_LTO_CLANG=n, there
is no need to execute that loop at all.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 kernel/kallsyms.c | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 22281dc9a49e35d..7366995f40395ec 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -266,6 +266,28 @@ static bool cleanup_symbol_name(char *s)
 	return false;
 }
 
+static int kallsyms_lookup_clang_name(unsigned char *namebuf, int len,
+				      const char *name,
+				      unsigned long *addr)
+{
+	unsigned long i;
+	unsigned int off;
+
+	if (!IS_ENABLED(CONFIG_LTO_CLANG))
+		return -ENOENT;
+
+	for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
+		off = kallsyms_expand_symbol(off, namebuf, len);
+
+		if (cleanup_symbol_name(namebuf) && strcmp(namebuf, name) == 0) {
+			*addr = kallsyms_sym_address(i);
+			return 0;
+		}
+	}
+
+	return -ENOENT;
+}
+
 static int kallsyms_lookup_compressed_name(unsigned char *namebuf, int len,
 					   unsigned long *addr)
 {
@@ -302,8 +324,7 @@ static int kallsyms_lookup_compressed_name(unsigned char *namebuf, int len,
 unsigned long kallsyms_lookup_name(const char *name)
 {
 	char namebuf[KSYM_NAME_LEN];
-	unsigned long i, addr;
-	unsigned int off;
+	unsigned long addr;
 	int ret, len;
 
 	/* Skip the search for empty string. */
@@ -315,12 +336,9 @@ unsigned long kallsyms_lookup_name(const char *name)
 	if (!ret)
 		return addr;
 
-	for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
-		off = kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));
-
-		if (cleanup_symbol_name(namebuf) && strcmp(namebuf, name) == 0)
-			return kallsyms_sym_address(i);
-	}
+	ret = kallsyms_lookup_clang_name(namebuf, len, name, &addr);
+	if (!ret)
+		return addr;
 
 	return module_kallsyms_lookup_name(name);
 }
-- 
2.25.1


  parent reply	other threads:[~2022-09-24 12:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-24 12:20 [PATCH v6 00/11] kallsyms: Optimizes the performance of lookup symbols Zhen Lei
2022-09-24 12:20 ` [PATCH v6 01/11] scripts/kallsyms: rename build_initial_tok_table() Zhen Lei
2022-09-24 12:20 ` [PATCH v6 02/11] scripts/kallsyms: don't compress symbol types Zhen Lei
2022-09-24 12:20 ` [PATCH v6 03/11] scripts/kallsyms: remove helper sym_name() and cleanup Zhen Lei
2022-09-24 12:20 ` [PATCH v6 04/11] scripts/kallsyms: generate kallsyms_best_token_table[] Zhen Lei
2022-09-24 12:20 ` [PATCH v6 05/11] kallsyms: Improve the performance of kallsyms_lookup_name() Zhen Lei
2022-09-24 12:20 ` Zhen Lei [this message]
2022-09-24 12:20 ` [PATCH v6 07/11] kallsyms: Add helper kallsyms_on_each_match_symbol() Zhen Lei
2022-09-24 12:20 ` [PATCH v6 08/11] livepatch: Use kallsyms_on_each_match_symbol() to improve performance Zhen Lei
2022-09-24 12:20 ` [PATCH v6 09/11] livepatch: Improve the search performance of module_kallsyms_on_each_symbol() Zhen Lei
2022-09-24 12:20 ` [PATCH v6 10/11] kallsyms: Delete an unused parameter related to kallsyms_on_each_symbol() Zhen Lei
2022-09-24 12:20 ` [PATCH v6 11/11] kallsyms: Add self-test facility Zhen Lei
2022-10-06  0:24   ` kernel test robot
2022-10-08  7:09     ` Leizhen (ThunderTown)

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=20220924122051.362-7-thunder.leizhen@huawei.com \
    --to=thunder.leizhen@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=ast@kernel.org \
    --cc=jikos@kernel.org \
    --cc=joe.lawrence@redhat.com \
    --cc=jolsa@kernel.org \
    --cc=jpoimboe@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mcgrof@kernel.org \
    --cc=mingo@redhat.com \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.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

all inboxes | Powered by JetHome®