mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@kernel.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Miroslav Benes <mbenes@suse.cz>
Subject: [PATCH v2 4/9] objtool: Add symbol iteration helpers
Date: Wed, 12 Apr 2023 12:03:19 -0700	[thread overview]
Message-ID: <59023e5886ab125aa30702e633be7732b1acaa7e.1681325924.git.jpoimboe@kernel.org> (raw)
In-Reply-To: <cover.1681325924.git.jpoimboe@kernel.org>

Add [sec_]for_each_sym() and use them.

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 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 */
-- 
2.39.2


  parent reply	other threads:[~2023-04-12 19:04 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-12 19:03 [PATCH v2 0/9] objtool: warning improvements Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 1/9] scripts/objdump-func: Support multiple functions Josh Poimboeuf
2023-04-14 14:47   ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 2/9] objtool: Add WARN_INSN() Josh Poimboeuf
2023-04-14 14:47   ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 3/9] objtool: Limit unreachable warnings to once per function Josh Poimboeuf
2023-04-13  8:01   ` Peter Zijlstra
2023-04-13 15:03     ` Josh Poimboeuf
2023-04-12 19:03 ` Josh Poimboeuf [this message]
2023-04-14 14:47   ` [tip: objtool/core] objtool: Add symbol iteration helpers tip-bot2 for Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 5/9] objtool: Add verbose option for disassembling affected functions Josh Poimboeuf
2023-04-13  8:05   ` Peter Zijlstra
2023-04-13 15:05     ` Josh Poimboeuf
2023-04-13  8:08   ` Peter Zijlstra
2023-04-13 14:03     ` Miroslav Benes
2023-04-13 15:09       ` Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 6/9] objtool: Include backtrace in verbose mode Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 7/9] objtool: Remove superfluous dead_end_function() check Josh Poimboeuf
2023-04-14 14:47   ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 8/9] objtool: Detect missing __noreturn annotations Josh Poimboeuf
2023-04-13  8:48   ` Peter Zijlstra
2023-04-13 15:19     ` Josh Poimboeuf
2023-04-13 19:17       ` Peter Zijlstra
2023-04-13 14:19   ` Miroslav Benes
2023-04-13 15:32     ` Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 9/9] objtool: Ignore exc_double_fault() __noreturn warnings Josh Poimboeuf
2023-04-13  9:24   ` Peter Zijlstra
2023-04-14 21:16     ` Nick Desaulniers

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=59023e5886ab125aa30702e633be7732b1acaa7e.1681325924.git.jpoimboe@kernel.org \
    --to=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=peterz@infradead.org \
    --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

all inboxes | Powered by JetHome®