Commit 9290e772 authored by Josh Poimboeuf's avatar Josh Poimboeuf Committed by Peter Zijlstra

objtool: Add symbol iteration helpers

Add [sec_]for_each_sym() and use them.
Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/59023e5886ab125aa30702e633be7732b1acaa7e.1681325924.git.jpoimboe@kernel.org
parent 246b2c85
...@@ -470,7 +470,7 @@ static int decode_instructions(struct objtool_file *file) ...@@ -470,7 +470,7 @@ static int decode_instructions(struct objtool_file *file)
// printf("%s: last chunk used: %d\n", sec->name, (int)idx); // 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) if (func->type != STT_NOTYPE && func->type != STT_FUNC)
continue; continue;
...@@ -924,7 +924,7 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file) ...@@ -924,7 +924,7 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file)
static int create_cfi_sections(struct objtool_file *file) static int create_cfi_sections(struct objtool_file *file)
{ {
struct section *sec, *s; struct section *sec;
struct symbol *sym; struct symbol *sym;
unsigned int *loc; unsigned int *loc;
int idx; int idx;
...@@ -937,19 +937,14 @@ static int create_cfi_sections(struct objtool_file *file) ...@@ -937,19 +937,14 @@ static int create_cfi_sections(struct objtool_file *file)
} }
idx = 0; idx = 0;
for_each_sec(file, s) { for_each_sym(file, sym) {
if (!s->text) if (sym->type != STT_FUNC)
continue; continue;
list_for_each_entry(sym, &s->symbol_list, list) { if (strncmp(sym->name, "__cfi_", 6))
if (sym->type != STT_FUNC) continue;
continue;
if (strncmp(sym->name, "__cfi_", 6))
continue;
idx++; idx++;
}
} }
sec = elf_create_section(file->elf, ".cfi_sites", 0, sizeof(unsigned int), 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) ...@@ -957,28 +952,23 @@ static int create_cfi_sections(struct objtool_file *file)
return -1; return -1;
idx = 0; idx = 0;
for_each_sec(file, s) { for_each_sym(file, sym) {
if (!s->text) if (sym->type != STT_FUNC)
continue; continue;
list_for_each_entry(sym, &s->symbol_list, list) { if (strncmp(sym->name, "__cfi_", 6))
if (sym->type != STT_FUNC) continue;
continue;
if (strncmp(sym->name, "__cfi_", 6))
continue;
loc = (unsigned int *)sec->data->d_buf + idx; loc = (unsigned int *)sec->data->d_buf + idx;
memset(loc, 0, sizeof(unsigned int)); memset(loc, 0, sizeof(unsigned int));
if (elf_add_reloc_to_insn(file->elf, sec, if (elf_add_reloc_to_insn(file->elf, sec,
idx * sizeof(unsigned int), idx * sizeof(unsigned int),
R_X86_64_PC32, R_X86_64_PC32,
s, sym->offset)) sym->sec, sym->offset))
return -1; return -1;
idx++; idx++;
}
} }
return 0; return 0;
...@@ -2207,23 +2197,20 @@ static int add_func_jump_tables(struct objtool_file *file, ...@@ -2207,23 +2197,20 @@ static int add_func_jump_tables(struct objtool_file *file,
*/ */
static int add_jump_table_alts(struct objtool_file *file) static int add_jump_table_alts(struct objtool_file *file)
{ {
struct section *sec;
struct symbol *func; struct symbol *func;
int ret; int ret;
if (!file->rodata) if (!file->rodata)
return 0; return 0;
for_each_sec(file, sec) { for_each_sym(file, func) {
list_for_each_entry(func, &sec->symbol_list, list) { if (func->type != STT_FUNC)
if (func->type != STT_FUNC) continue;
continue;
mark_func_jump_tables(file, func); mark_func_jump_tables(file, func);
ret = add_func_jump_tables(file, func); ret = add_func_jump_tables(file, func);
if (ret) if (ret)
return ret; return ret;
}
} }
return 0; return 0;
...@@ -2535,30 +2522,27 @@ static bool is_profiling_func(const char *name) ...@@ -2535,30 +2522,27 @@ static bool is_profiling_func(const char *name)
static int classify_symbols(struct objtool_file *file) static int classify_symbols(struct objtool_file *file)
{ {
struct section *sec;
struct symbol *func; struct symbol *func;
for_each_sec(file, sec) { for_each_sym(file, func) {
list_for_each_entry(func, &sec->symbol_list, list) { if (func->bind != STB_GLOBAL)
if (func->bind != STB_GLOBAL) continue;
continue;
if (!strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR, if (!strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR,
strlen(STATIC_CALL_TRAMP_PREFIX_STR))) strlen(STATIC_CALL_TRAMP_PREFIX_STR)))
func->static_call_tramp = true; func->static_call_tramp = true;
if (arch_is_retpoline(func)) if (arch_is_retpoline(func))
func->retpoline_thunk = true; func->retpoline_thunk = true;
if (arch_is_rethunk(func)) if (arch_is_rethunk(func))
func->return_thunk = true; func->return_thunk = true;
if (arch_ftrace_match(func->name)) if (arch_ftrace_match(func->name))
func->fentry = true; func->fentry = true;
if (is_profiling_func(func->name)) if (is_profiling_func(func->name))
func->profiling_func = true; func->profiling_func = true;
}
} }
return 0; return 0;
...@@ -4213,7 +4197,7 @@ static int validate_section(struct objtool_file *file, struct section *sec) ...@@ -4213,7 +4197,7 @@ static int validate_section(struct objtool_file *file, struct section *sec)
struct symbol *func; struct symbol *func;
int warnings = 0; int warnings = 0;
list_for_each_entry(func, &sec->symbol_list, list) { sec_for_each_sym(sec, func) {
if (func->type != STT_FUNC) if (func->type != STT_FUNC)
continue; continue;
......
...@@ -474,7 +474,7 @@ static int read_symbols(struct elf *elf) ...@@ -474,7 +474,7 @@ static int read_symbols(struct elf *elf)
/* Create parent/child links for any cold subfunctions */ /* Create parent/child links for any cold subfunctions */
list_for_each_entry(sec, &elf->sections, list) { 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]; char pname[MAX_NAME_LEN + 1];
size_t pnamelen; size_t pnamelen;
if (sym->type != STT_FUNC) if (sym->type != STT_FUNC)
......
...@@ -188,4 +188,13 @@ struct symbol *find_func_containing(struct section *sec, unsigned long offset); ...@@ -188,4 +188,13 @@ struct symbol *find_func_containing(struct section *sec, unsigned long offset);
#define for_each_sec(file, sec) \ #define for_each_sec(file, sec) \
list_for_each_entry(sec, &file->elf->sections, list) 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 */ #endif /* _OBJTOOL_ELF_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment